all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 70846@debbugs.gnu.org
Subject: bug#70846: Imenu flatten
Date: Fri, 10 May 2024 20:06:07 +0300	[thread overview]
Message-ID: <86frupmwao.fsf@mail.linkov.net> (raw)
In-Reply-To: <861q6b7xus.fsf@mail.linkov.net> (Juri Linkov's message of "Thu,  09 May 2024 19:29:15 +0300")

[-- Attachment #1: Type: text/plain, Size: 381 bytes --]

> +(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

Here is another useful value for `imenu-flatten' that
will show section names as a suffix instead of a prefix:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: imenu-flatten-annotation.patch --]
[-- Type: text/x-diff, Size: 1877 bytes --]

diff --git a/lisp/imenu.el b/lisp/imenu.el
index 9c0c1ae144e..ccf5a0dc576 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -147,10 +147,16 @@ imenu-level-separator
 
 (defcustom imenu-flatten nil
   "Whether to flatten the list of sections in an imenu or show it nested.
-If non-nil, popup the completion buffer with a flattened menu.
+If nil, use nested indexes.
+If t, popup the completion buffer with a flattened menu.
+If `annotation', use completion annotation as a suffix
+to append section names after the index names.
+
 The string from `imenu-level-separator' is used to separate names of
 nested levels while flattening nested indexes with name concatenation."
-  :type 'boolean
+  :type '(choice (const :tag "Nested" nil)
+                 (const :tag "By prefix" t)
+                 (const :tag "By suffix" annotation))
   :version "30.1")
 
 (defcustom imenu-generic-skip-comments-and-strings t
@@ -743,7 +749,10 @@ imenu--completion-buffer
     ;; Display the completion buffer.
     (minibuffer-with-setup-hook
         (lambda ()
-          (setq-local completion-extra-properties '(:category imenu))
+          (setq-local completion-extra-properties
+                      `( :category imenu
+                         :annotation-function
+                         ,(lambda (s) (get-text-property 0 'imenu-section s))))
           (unless imenu-eager-completion-buffer
             (minibuffer-completion-help)))
       (setq name (completing-read prompt
@@ -787,7 +796,11 @@ imenu--flatten-index-alist
 			       name))))
        (cond
 	((not (imenu--subalist-p item))
-	 (list (cons new-prefix pos)))
+	 (list (cons (if (and (eq imenu-flatten 'annotation) prefix)
+			 (propertize name 'imenu-section
+				     (format " (%s)" prefix))
+		       name)
+		     pos)))
 	(t
 	 (imenu--flatten-index-alist pos concat-names new-prefix)))))
    index-alist))

  parent reply	other threads:[~2024-05-10 17:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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=86frupmwao.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.