Skip to content

Commit

Permalink
use ivy for imenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen Bin committed Dec 17, 2015
1 parent a1b3dff commit f8a9895
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lisp/init-evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
"lq" 'highlight-symbol-query-replace
"ln" 'highlight-symbol-nav-mode ; use M-n/M-p to navigation between symbols
"bm" 'pomodoro-start ;; beat myself
"im" 'helm-imenu
"im" 'ivy-imenu
"ii" 'ido-imenu
"ij" 'rimenu-jump
"." 'evil-ex
Expand Down
20 changes: 19 additions & 1 deletion lisp/init-misc.el
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,25 @@ buffer is not visiting a file."

;; {{ imenu
(setq imenu-max-item-length 128)
(setq imenu-max-item-length 64)

(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 ()
(interactive)
(let ((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)))))
;; }}

;; {{ recentf-mode
Expand Down

0 comments on commit f8a9895

Please sign in to comment.