|
80 | 80 | (propertize (car entry) 'face 'default) |
81 | 81 | "\n")) |
82 | 82 | (len (length text))) |
83 | | - (add-text-properties 0 len `(index ,index) text) |
84 | | - (add-text-properties 0 len `(title ,title) text) |
85 | | - (add-text-properties 0 len `(marker ,(cdr entry)) text) |
86 | | - (add-text-properties 0 len `(padding ,padding) text) |
| 83 | + (add-text-properties 0 len `(index ,index title ,title marker ,(cdr entry) padding ,padding) text) |
87 | 84 | text)) |
88 | 85 |
|
89 | 86 | (defvar-local lsp-ui-imenu-ov nil) |
|
136 | 133 | (interactive) |
137 | 134 | (setq lsp-ui-imenu--origin (current-buffer)) |
138 | 135 | (imenu--make-index-alist) |
139 | | - (let ((list imenu--index-alist) |
140 | | - queue) |
| 136 | + (let ((list imenu--index-alist)) |
141 | 137 | (with-current-buffer (get-buffer-create "*lsp-ui-imenu*") |
142 | | - (setq buffer-read-only nil) |
143 | | - (remove-overlays) |
144 | | - (erase-buffer) |
145 | | - (let ((padding (or (and (eq lsp-ui-imenu-kind-position 'top) 1) |
146 | | - (--> (--filter (imenu--subalist-p it) list) |
147 | | - (--map (length (car it)) it) |
148 | | - (-max (or it '(1)))))) |
149 | | - (color-index 0)) |
150 | | - (--each-indexed list |
151 | | - (-let* (((title . entries) it)) |
152 | | - (if (not (imenu--subalist-p it)) |
153 | | - (push it queue) |
154 | | - (when queue |
155 | | - (--each queue |
156 | | - (insert (lsp-ui-imenu--make-line " " 0 padding it color-index))) |
157 | | - (lsp-ui-imenu--put-separator) |
158 | | - (setq color-index (1+ color-index)) |
159 | | - (setq queue nil)) |
160 | | - (lsp-ui-imenu--put-kind title padding color-index) |
161 | | - (--each-indexed entries |
162 | | - (insert (lsp-ui-imenu--make-line title it-index padding it color-index))) |
163 | | - (lsp-ui-imenu--put-separator) |
164 | | - (setq color-index (1+ color-index)) |
165 | | - ))) |
166 | | - (--each queue |
167 | | - (insert (lsp-ui-imenu--make-line " " 0 padding it color-index))) |
| 138 | + (let* ((padding (or (and (eq lsp-ui-imenu-kind-position 'top) 1) |
| 139 | + (--> (-filter 'imenu--subalist-p list) |
| 140 | + (--map (length (car it)) it) |
| 141 | + (-max (or it '(1)))))) |
| 142 | + (grouped-by-subs (-partition-by 'imenu--subalist-p list)) |
| 143 | + (color-index 0) |
| 144 | + buffer-read-only) |
| 145 | + (remove-overlays) |
| 146 | + (erase-buffer) |
| 147 | + (lsp-ui-imenu--put-separator) |
| 148 | + (dolist (group grouped-by-subs) |
| 149 | + (if (imenu--subalist-p (car group)) |
| 150 | + (dolist (kind group) |
| 151 | + (-let* (((title . entries) kind)) |
| 152 | + (lsp-ui-imenu--put-kind title padding color-index) |
| 153 | + (--each-indexed entries |
| 154 | + (insert (lsp-ui-imenu--make-line title it-index padding it color-index))) |
| 155 | + (lsp-ui-imenu--put-separator) |
| 156 | + (setq color-index (1+ color-index)))) |
| 157 | + (--each-indexed group |
| 158 | + (insert (lsp-ui-imenu--make-line " " it-index padding it color-index))) |
| 159 | + (lsp-ui-imenu--put-separator) |
| 160 | + (setq color-index (1+ color-index)))) |
168 | 161 | (lsp-ui-imenu-mode) |
169 | 162 | (setq header-line-format " ") |
170 | 163 | (setq mode-line-format '(:eval (lsp-ui-imenu--win-separator))) |
|
209 | 202 | (while (not (= (get-text-property (point) 'index) 0)) |
210 | 203 | (forward-line -1))) |
211 | 204 |
|
212 | | -(defun lsp-ui-imenu--go nil |
| 205 | +(defun lsp-ui-imenu--visit nil |
213 | 206 | (interactive) |
214 | 207 | (let ((marker (get-text-property (point) 'marker))) |
215 | 208 | (select-window (get-buffer-window lsp-ui-imenu--origin)) |
216 | 209 | (goto-char marker) |
217 | 210 | (pulse-momentary-highlight-one-line (point) 'next-error))) |
218 | 211 |
|
219 | | -(defun lsp-ui-imenu--look nil |
| 212 | +(defun lsp-ui-imenu--view nil |
220 | 213 | (interactive) |
221 | 214 | (let ((marker (get-text-property (point) 'marker))) |
222 | 215 | (with-selected-window (get-buffer-window lsp-ui-imenu--origin) |
|
231 | 224 | (define-key map (kbd "q") 'lsp-ui-imenu--kill) |
232 | 225 | (define-key map (kbd "<right>") 'lsp-ui-imenu--next-kind) |
233 | 226 | (define-key map (kbd "<left>") 'lsp-ui-imenu--prev-kind) |
234 | | - (define-key map (kbd "<return>") 'lsp-ui-imenu--look) |
235 | | - (define-key map (kbd "<M-return>") 'lsp-ui-imenu--go) |
| 227 | + (define-key map (kbd "<return>") 'lsp-ui-imenu--view) |
| 228 | + (define-key map (kbd "<M-return>") 'lsp-ui-imenu--visit) |
236 | 229 | (setq lsp-ui-imenu-mode-map map))) |
237 | 230 |
|
238 | 231 | (define-derived-mode lsp-ui-imenu-mode special-mode "lsp-ui-imenu" |
|
0 commit comments