mirror of
https://codeberg.org/scip/dot-emacs.git
synced 2025-12-16 20:10:58 +01:00
63 lines
2.4 KiB
EmacsLisp
63 lines
2.4 KiB
EmacsLisp
;;; ** load imenu
|
|
(require 'imenu)
|
|
(define-key global-map [C-down-mouse-2] 'imenu)
|
|
|
|
;; via https://superuser.com/questions/601982/how-to-quickly-navigate-jump-between-functions-on-emacs
|
|
(defun ido-imenu ()
|
|
"Update the imenu index and then use ido to select a symbol to navigate to.
|
|
Symbols matching the text at point are put first in the completion list."
|
|
(interactive)
|
|
(imenu--make-index-alist)
|
|
(let ((name-and-pos '())
|
|
(symbol-names '()))
|
|
(flet ((addsymbols
|
|
(symbol-list)
|
|
(when (listp symbol-list)
|
|
(dolist (symbol symbol-list)
|
|
(let ((name nil) (position nil))
|
|
(cond
|
|
((and (listp symbol) (imenu--subalist-p symbol))
|
|
(addsymbols symbol))
|
|
|
|
((listp symbol)
|
|
(setq name (car symbol))
|
|
(setq position (cdr symbol)))
|
|
|
|
((stringp symbol)
|
|
(setq name symbol)
|
|
(setq position
|
|
(get-text-property 1 'org-imenu-marker symbol))))
|
|
|
|
(unless (or (null position) (null name))
|
|
(add-to-list 'symbol-names name)
|
|
(add-to-list 'name-and-pos (cons name position))))))))
|
|
(addsymbols imenu--index-alist))
|
|
;; If there are matching symbols at point, put them at the beginning
|
|
;; of `symbol-names'.
|
|
(let ((symbol-at-point (thing-at-point 'symbol)))
|
|
(when symbol-at-point
|
|
(let* ((regexp (concat (regexp-quote symbol-at-point) "$"))
|
|
(matching-symbols
|
|
(delq nil (mapcar
|
|
(lambda (symbol)
|
|
(if (string-match regexp symbol) symbol))
|
|
symbol-names))))
|
|
(when matching-symbols
|
|
(sort matching-symbols (lambda (a b) (> (length a) (length b))))
|
|
(mapc
|
|
(lambda (symbol)
|
|
(setq symbol-names (cons symbol (delete symbol symbol-names))))
|
|
matching-symbols)))))
|
|
(let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
|
|
(position (cdr (assoc selected-symbol name-and-pos))))
|
|
(push-mark)
|
|
(if (overlayp position)
|
|
(goto-char (overlay-start position))
|
|
(goto-char position)))))
|
|
|
|
;; (global-set-key (kbd "C-c C-j") 'ido-imenu)
|
|
|
|
|
|
(provide 'init-imenu)
|
|
;;; init-imenu.el ends here
|