emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master adfad96 007/272: support imenu


From: Oleh Krehel
Subject: [elpa] master adfad96 007/272: support imenu
Date: Mon, 25 Apr 2016 10:13:13 +0000

branch: master
commit adfad9605ade2f8faabf09cec16408b26e32d422
Author: Chen Bin <address@hidden>
Commit: Chen Bin <address@hidden>

    support imenu
---
 counsel.el |   26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/counsel.el b/counsel.el
index 9c86ec0..44fac93 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1296,6 +1296,32 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
     (insert (substring-no-properties s))
     (setq counsel-completion-end (point))))
 
+(defun counsel-imenu-get-candidates-from (alist  &optional prefix)
+  "Create a list of (key . value) from ALIST.
+PREFIX is used to create the key."
+  (cl-loop for elm in alist
+           nconc (if (imenu--subalist-p elm)
+                       (counsel-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))))))))
+
+;;;###autoload
+(defun counsel-imenu ()
+  "Jump to a buffer position indexed by imenu."
+  (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:"
+              (counsel-imenu-get-candidates-from (delete (assoc "*Rescan*" 
items) items))
+              :action (lambda (pos) (goto-char pos)))))
+
 (provide 'counsel)
 
 ;;; counsel.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]