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: Tue, 28 May 2024 20:53:18 +0300 Organization: LINKOV.NET Message-ID: <86mso9akmp.fsf@mail.linkov.net> References: <861q6b7xus.fsf@mail.linkov.net> <86frupmwao.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="7484"; 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 Tue May 28 20:00:20 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 1sC17T-0001iz-Il for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 28 May 2024 20:00:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sC175-00063D-C8; Tue, 28 May 2024 13:59:55 -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 1sC173-00062e-Jd for bug-gnu-emacs@gnu.org; Tue, 28 May 2024 13:59:53 -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 1sC173-0007SG-BT for bug-gnu-emacs@gnu.org; Tue, 28 May 2024 13:59:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sC17C-0006R9-Ms for bug-gnu-emacs@gnu.org; Tue, 28 May 2024 14:00: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: Tue, 28 May 2024 18:00: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.171691917424644 (code B ref 70846); Tue, 28 May 2024 18:00:02 +0000 Original-Received: (at 70846) by debbugs.gnu.org; 28 May 2024 17:59:34 +0000 Original-Received: from localhost ([127.0.0.1]:49778 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sC16j-0006PQ-No for submit@debbugs.gnu.org; Tue, 28 May 2024 13:59:34 -0400 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:49871) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sC16i-0006P6-C0 for 70846@debbugs.gnu.org; Tue, 28 May 2024 13:59:33 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 55D8C1BF204 for <70846@debbugs.gnu.org>; Tue, 28 May 2024 17:58:55 +0000 (UTC) In-Reply-To: <86frupmwao.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 10 May 2024 20:06:07 +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:286106 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: Here is the final patch that adds an option to group Imenu completions. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=imenu-flatten-group.patch diff --git a/lisp/imenu.el b/lisp/imenu.el index 93d84106ec1..3aec32fa708 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -151,15 +151,18 @@ imenu-level-separator (defcustom imenu-flatten nil "Whether to flatten the list of sections in an imenu or show it nested. If nil, use nested indexes. -If t, pop up the completion buffer with a flattened menu. +If `prefix', pop up the completion buffer with a flattened menu +where section names are used as a prefix. If `annotation', use completion annotation as a suffix to append section names after the index names. +If `group', split completions into groups. The string from `imenu-level-separator' is used to separate names of nested levels while flattening nested indexes with name concatenation." :type '(choice (const :tag "Nested" nil) - (const :tag "By prefix" t) - (const :tag "By suffix" annotation)) + (const :tag "By prefix" prefix) + (const :tag "By annotation" annotation) + (const :tag "By group" group)) :version "30.1") (defcustom imenu-generic-skip-comments-and-strings t @@ -758,7 +761,13 @@ imenu--completion-buffer ,@(when (eq imenu-flatten 'annotation) `(:annotation-function ,(lambda (s) (get-text-property - 0 'imenu-section s)))))) + 0 'imenu-section s)))) + ,@(when (eq imenu-flatten 'group) + `(:group-function + ,(lambda (s transform) + (if transform s + (get-text-property + 0 'imenu-section s))))))) (unless imenu-eager-completion-buffer (minibuffer-completion-help))) (setq name (completing-read prompt @@ -801,15 +810,20 @@ imenu--flatten-index-alist (new-prefix (and concat-names (if prefix (concat prefix imenu-level-separator name) - (if (eq imenu-flatten 'annotation) - (propertize name 'imenu-choice item) - name))))) + name)))) (cond ((not (imenu--subalist-p item)) - (list (cons (if (and (eq imenu-flatten 'annotation) prefix) - (propertize name 'imenu-section - (format " (%s)" prefix)) - new-prefix) + (list (cons (pcase imenu-flatten + ('annotation + (if prefix + (propertize name + 'imenu-section (format " (%s)" prefix) + 'imenu-choice item) + (propertize new-prefix 'imenu-choice item))) + ('group (propertize name + 'imenu-section (or prefix "*") + 'imenu-choice item)) + (_ new-prefix)) pos))) (t (imenu--flatten-index-alist pos concat-names new-prefix))))) --=-=-=--