Get markers from entries when flattening imenu

This commit is contained in:
Ivan Malison 2016-08-17 17:55:24 -07:00
parent 4ed90ddf30
commit 001af75c85
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8

View File

@ -505,17 +505,15 @@ to get this behavior out of functions that provide a nested imenu
index.
#+BEGIN_SRC emacs-lisp
(defvar imalison:imenu-separator ".")
(defvar imalison:imenu-get-markers-from-entry-strings t)
(cl-defun imalison:flatten-index-entry (index-entry &optional (prefix ""))
(cl-destructuring-bind (entry-name . rest) index-entry
(message "%s" rest)
(let ((new-entry-name (concat prefix entry-name))
(original-properties (text-properties-at 0 entry-name)))
;; Inherit any text-properties that were attached to the
;; original entry.
(set-text-properties 0 (length new-entry-name)
original-properties
new-entry-name)
(entry-marker
(when imalison:imenu-get-markers-from-entry-strings
(imalison:get-marker-from-string entry-name))))
(if (listp rest)
;; Internal Node
(let* ((new-prefix (concat new-entry-name imalison:imenu-separator))
@ -523,14 +521,17 @@ index.
(cl-mapcan (lambda (entry)
(imalison:flatten-index-entry entry new-prefix))
rest)))
(if original-properties
(if entry-marker
;; When the entry had properties, we may want to keep
;; it around, because it might have a marker attached.
(cons (list new-entry-name) flattened-subentries)
(cons (cons new-entry-name entry-marker) flattened-subentries)
flattened-subentries))
;; Leaf Node
(list (cons new-entry-name rest))))))
(defun imalison:get-marker-from-string (string)
(--first (markerp it) (text-properties-at 0 string)))
(defun imalison:flatten-imenu-index (index)
(cl-mapcan 'imalison:flatten-index-entry index))