all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#70846: Imenu flatten
@ 2024-05-09 16:29 Juri Linkov
  2024-05-09 16:45 ` Eli Zaretskii
  2024-05-10 17:06 ` Juri Linkov
  0 siblings, 2 replies; 18+ messages in thread
From: Juri Linkov @ 2024-05-09 16:29 UTC (permalink / raw)
  To: 70846

[-- 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))

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-06-06  5:35 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-09 16:29 bug#70846: Imenu flatten Juri Linkov
2024-05-09 16:45 ` 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

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.