diff options
author | Alan Pearce | 2015-12-22 16:45:20 +0100 |
---|---|---|
committer | Alan Pearce | 2015-12-22 16:45:20 +0100 |
commit | d26b9612b863553148562ea72398a472fe04adf9 (patch) | |
tree | 7028a9a859ac215e6f52dc494959e2f2c305dd26 | |
parent | 72303ddc158dc7aa26fe041e9be646bca857babd (diff) | |
download | dotfiles-d26b9612b863553148562ea72398a472fe04adf9.tar.lz dotfiles-d26b9612b863553148562ea72398a472fe04adf9.tar.zst dotfiles-d26b9612b863553148562ea72398a472fe04adf9.zip |
Override imenu with nested version
-rw-r--r-- | tag-emacs/emacs.d/init.org | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tag-emacs/emacs.d/init.org b/tag-emacs/emacs.d/init.org index a25c615..6c3b9a3 100644 --- a/tag-emacs/emacs.d/init.org +++ b/tag-emacs/emacs.d/init.org @@ -1165,12 +1165,34 @@ replace helm and ido. :bind (("C-s" . swiper) ("C-r" . swiper) ("C-c C-r" . ivy-resume) - ("C-x i" . imenu) + ("C-x i" . ivy-imenu-goto) ("C-=" . swiper)) :config (progn (setq ivy-use-virtual-buffers t ivy-re-builders-alist '((internal-complete-buffer . ivy--regex-fuzzy) (t . ivy--regex-plus))) + (defun ivy-imenu-get-candidates-from (alist &optional prefix) + (cl-loop for elm in alist + nconc (if (imenu--subalist-p elm) + (ivy-imenu-get-candidates-from + (cl-loop for (e . v) in (cdr elm) collect + (cons e (if (integerp v) (copy-marker v) v))) + (concat prefix (if prefix ".") (car elm))) + (and (cdr elm) ; bug in imenu, should not be needed. + (setcdr elm (copy-marker (cdr elm))) ; Same as [1]. + (list (cons (concat prefix (if prefix ".") (car elm)) + (copy-marker (cdr elm)))))))) + + (defun ivy-imenu-goto () + "Go to buffer position" + (interactive) + (let ((imenu-auto-rescan t) items) + (unless (featurep 'imenu) + (require 'imenu nil t)) + (setq items (imenu--make-index-alist t)) + (ivy-read "imenu items:" + (ivy-imenu-get-candidates-from (delete (assoc "*Rescan*" items) items)) + :action (lambda (k) (goto-char k))))) (ivy-set-actions 'ivy-switch-buffer '(("k" (lambda (x) (kill-buffer x) (ivy--reset-state ivy-last)) |