From: Juri Linkov <juri@linkov.net>
To: 70846@debbugs.gnu.org
Subject: bug#70846: Imenu flatten
Date: Thu, 09 May 2024 19:29:15 +0300 [thread overview]
Message-ID: <861q6b7xus.fsf@mail.linkov.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 328 bytes --]
This patch revives the feature existed in the initial version of imenu.el,
but that was unfortunately removed later.
When comparing it with the version in breadcrumb-jump that was discussed in
https://lists.gnu.org/archive/html/emacs-devel/2023-12/msg00278.html
the advantage of this version is that it doesn't use 'cl-loop':
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: imenu-flatten.patch --]
[-- Type: text/x-diff, Size: 2365 bytes --]
diff --git a/lisp/imenu.el b/lisp/imenu.el
index f628936cedc..ccc73fe42d2 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -66,6 +66,13 @@ imenu
:group 'convenience
:link '(custom-manual "(elisp)Imenu"))
+(defcustom imenu-flatten nil
+ "If non-nil, popup the completion buffer with a flattened menu.
+The string from `imenu-level-separator' is used to separate names of
+nested levels while flattening nested indexes with name concatenation."
+ :type 'boolean
+ :version "30.1")
+
(defcustom imenu-use-markers t
"Non-nil means use markers instead of integers for Imenu buffer positions.
@@ -142,8 +149,7 @@ imenu-space-replacement
(defcustom imenu-level-separator ":"
"The separator between index names of different levels.
-Used for making mouse-menu titles and for flattening nested indexes
-with name concatenation."
+Used for flattening nested indexes with name concatenation."
:type 'string)
(defcustom imenu-generic-skip-comments-and-strings t
@@ -763,6 +770,26 @@ imenu--mouse-menu
menu)))))
(popup-menu map event)))
+(defun imenu--flatten-index-alist (index-alist &optional concat-names prefix)
+ ;; Takes a nested INDEX-ALIST and returns a flat index alist.
+ ;; If optional CONCAT-NAMES is non-nil, then a nested index has its
+ ;; name and a space concatenated to the names of the children.
+ ;; Third argument PREFIX is for internal use only.
+ (mapcan
+ (lambda (item)
+ (let* ((name (car item))
+ (pos (cdr item))
+ (new-prefix (and concat-names
+ (if prefix
+ (concat prefix imenu-level-separator name)
+ name))))
+ (cond
+ ((or (markerp pos) (numberp pos))
+ (list (cons new-prefix pos)))
+ (t
+ (imenu--flatten-index-alist pos concat-names new-prefix)))))
+ index-alist))
+
(defun imenu-choose-buffer-index (&optional prompt alist)
"Let the user select from a buffer index and return the chosen index.
@@ -792,6 +819,8 @@ imenu-choose-buffer-index
;; Create a list for this buffer only when needed.
(while (eq result t)
(setq index-alist (if alist alist (imenu--make-index-alist)))
+ (when imenu-flatten
+ (setq index-alist (imenu--flatten-index-alist index-alist t)))
(setq result
(if (and imenu-use-popup-menu
(or (eq imenu-use-popup-menu t) mouse-triggered))
next reply other threads:[~2024-05-09 16:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-09 16:29 Juri Linkov [this message]
2024-05-09 16:45 ` bug#70846: Imenu flatten Eli Zaretskii
2024-05-10 6:52 ` Juri Linkov
2024-05-10 7:29 ` Eli Zaretskii
2024-05-10 16:45 ` Juri Linkov
2024-05-11 10:33 ` Eli Zaretskii
2024-05-12 6:55 ` Juri Linkov
2024-05-12 7:10 ` Eli Zaretskii
2024-05-12 16:37 ` Juri Linkov
2024-05-12 17:17 ` Eli Zaretskii
2024-05-13 6:57 ` Juri Linkov
2024-05-13 7:46 ` Eli Zaretskii
2024-05-14 6:05 ` Juri Linkov
2024-05-14 6:34 ` Eli Zaretskii
2024-05-10 17:06 ` Juri Linkov
2024-05-28 17:53 ` Juri Linkov
2024-05-29 18:05 ` Juri Linkov
2024-06-06 5:35 ` Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=861q6b7xus.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=70846@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.