dev.fron.io nixrc / 8f03357
emacs(webkit): bang tidy history presentation Tony Olagbaiye a month ago
2 changed file(s) with 108 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
44 demand = true;
55 after = [ "ivy" "counsel" ];
66 config = ''
7 (unless (fboundp 'ivy-rich-switch-buffer-transformer)
8 (defun ivy-rich-switch-buffer-transformer (arg)
9 arg))
10 (ivy-rich-mode 1)
7 (defvar ivy-mode nil)
8 (defvar counsel-mode nil)
9 (defvar counsel-projectile-mode nil)
10
11 (defun maybe-restart-counsel-projectile ()
12 (when counsel-projectile-mode
13 (counsel-projectile-mode nil))
14 (counsel-projectile-mode t))
15
16 (add-hook 'ivy-mode-hook 'ivy-rich-mode)
17 (add-hook 'ivy-rich-mode-hook 'maybe-restart-counsel-projectile)
18 (ivy-rich-mode ivy-mode)
19
20 (setq ivy-rich-project-root-cache-mode t)
21 (setq ivy-rich-path-style 'abbrev)
22 '';
23 };
24 emacs.loader.all-the-icons-ivy = {
25 demand = true;
26 after = [ "ivy" "all-the-icons" ];
27 };
28 emacs.loader.all-the-icons-ivy-rich = {
29 demand = true;
30 after = [ "ivy-rich" "all-the-icons" ];
31 config = ''
32 (add-hook 'ivy-mode-hook 'all-the-icons-ivy-rich-mode)
33 (add-hook 'all-the-icons-ivy-rich-mode-hook 'maybe-restart-counsel-projectile)
34 (all-the-icons-ivy-rich-mode ivy-mode)
1135 '';
1236 };
1337 }
9595 (setq webkit-dark-mode nil)
9696 '';
9797 };
98 emacs.loader.webkit-history = {
99 demand = true;
100 inherit (config.emacs.loader.webkit) package;
101 after = [ "webkit" ];
102 config = ''
103 (defun webkit-history-completion-text (item)
104 (let* ((title (webkit-history-item-title item))
105 (uri (webkit-history-item-uri item))
106 (visit-count (webkit-history-item-visit-count item))
107 (last-time (webkit-history-item-last-time item))
108 (text (concat title " (" uri ")")))
109 (put-text-property (+ 2 (length title)) (1- (length text)) 'face 'link text)
110 (propertize text
111 'webkit-title title
112 'webkit-uri uri
113 'webkit-visit-count visit-count
114 'webkit-last-time last-time)))
115
116 (defun webkit-history-completing-read (prompt)
117 "Prompt for a URI using COMPLETING-READ from webkit history."
118 (let ((completions ())
119 (key-to-count (lambda (k) (webkit-history-item-visit-count
120 (gethash (cdr k) webkit-history-table))))
121 (key-to-time (lambda (k) (webkit-history-item-last-time
122 (gethash (cdr k) webkit-history-table)))))
123 (maphash (lambda (k v)
124 (push (cons (webkit-history-completion-text v) k) completions))
125 webkit-history-table)
126 (setq completions (sort completions (lambda (k1 k2)
127 (let ((c1 (funcall key-to-count k1))
128 (c2 (funcall key-to-count k2))
129 (t1 (funcall key-to-time k1))
130 (t2 (funcall key-to-time k2)))
131 (if (= c1 c2)
132 (> t1 t2)
133 (> c1 c2))))))
134 (let* ((completion (ivy-read prompt completions
135 :caller 'webkit-history-completing-read))
136 (uri (cdr (assoc completion completions))))
137 (if uri uri completion))))
138
139 (defun ivy-rich-webkit-history-title (candidate)
140 (let* ((data (text-properties-at 0 candidate))
141 (value (plist-get data 'webkit-title)))
142 (if value value (ivy-rich-webkit-history-uri))))
143
144 (defun ivy-rich-webkit-history-uri (candidate)
145 (let* ((data (text-properties-at 0 candidate))
146 (value (plist-get data 'webkit-uri)))
147 (if value value "?:")))
148
149 (defun ivy-rich-webkit-history-visit-count (candidate)
150 (let* ((data (text-properties-at 0 candidate))
151 (value (plist-get data 'webkit-visit-count)))
152 (if value (format "% 5d times" value) " ? times")))
153
154 (defun ivy-rich-webkit-history-last-time (candidate)
155 (let* ((data (text-properties-at 0 candidate))
156 (value (plist-get data 'webkit-last-time)))
157 (if value (format-time-string "%Y-%m-%d %H:%M:%S" value) "?")))
158
159 (progn
160 (unless (memq 'webkit-history-completing-read
161 ivy-rich-display-transformers-list)
162 (add-to-list ivy-rich-display-transformers-list
163 'webkit-history-completing-read
164 t #'ignore)
165 (add-to-list ivy-rich-display-transformers-list nil t #'ignore))
166 (setcar (cdr (plist-get ivy-rich-display-transformers-list
167 'webkit-history-completing-read))
168 '((ivy-rich-webkit-history-title (:width 0.4))
169 (ivy-rich-webkit-history-uri (:width 0.4
170 :face font-lock-string-face))
171 (ivy-rich-webkit-history-last-time (:width 0.1
172 :face font-lock-comment-face))
173 (ivy-rich-webkit-history-visit-count (:align right
174 :face font-lock-constant-face))))
175 nil)
176 '';
177 };
98178 }