From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#70846: Imenu flatten Date: Fri, 10 May 2024 20:06:07 +0300 Organization: LINKOV.NET Message-ID: <86frupmwao.fsf@mail.linkov.net> References: <861q6b7xus.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14004"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) To: 70846@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 10 19:08:36 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s5TjW-0003SS-Iq for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 10 May 2024 19:08:34 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5Tj3-0003PW-Dm; Fri, 10 May 2024 13:08:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s5Tj2-0003Ou-DQ for bug-gnu-emacs@gnu.org; Fri, 10 May 2024 13:08:04 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s5Tj1-0008MJ-W1 for bug-gnu-emacs@gnu.org; Fri, 10 May 2024 13:08:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s5Tj0-0004bn-IE for bug-gnu-emacs@gnu.org; Fri, 10 May 2024 13:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 10 May 2024 17:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70846 X-GNU-PR-Package: emacs Original-Received: via spool by 70846-submit@debbugs.gnu.org id=B70846.171536086817704 (code B ref 70846); Fri, 10 May 2024 17:08:02 +0000 Original-Received: (at 70846) by debbugs.gnu.org; 10 May 2024 17:07:48 +0000 Original-Received: from localhost ([127.0.0.1]:43096 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s5Til-0004bT-Hi for submit@debbugs.gnu.org; Fri, 10 May 2024 13:07:48 -0400 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:55625) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s5TiU-0004bA-EM for 70846@debbugs.gnu.org; Fri, 10 May 2024 13:07:45 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id B5E98E0006 for <70846@debbugs.gnu.org>; Fri, 10 May 2024 17:07:24 +0000 (UTC) In-Reply-To: <861q6b7xus.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 09 May 2024 19:29:15 +0300") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:284828 Archived-At: --=-=-= Content-Type: text/plain > +(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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=imenu-flatten-annotation.patch 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)) --=-=-=--