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: Thu, 09 May 2024 19:29:15 +0300 Organization: LINKOV.NET Message-ID: <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="28146"; 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 Thu May 09 18:36:57 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 1s56lN-00075a-By for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 May 2024 18:36:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s56l3-000834-Po; Thu, 09 May 2024 12:36:37 -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 1s56l2-00082u-BQ for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 12:36:36 -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 1s56l2-00046c-4f for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 12:36:36 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s56lR-00083J-UH for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 12:37:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 09 May 2024 16:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 70846 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.171527261330938 (code B ref -1); Thu, 09 May 2024 16:37:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 May 2024 16:36:53 +0000 Original-Received: from localhost ([127.0.0.1]:56201 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s56lI-00082w-NH for submit@debbugs.gnu.org; Thu, 09 May 2024 12:36:53 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:33968) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s56lC-00082q-Lp for submit@debbugs.gnu.org; Thu, 09 May 2024 12:36:51 -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 1s56kh-0007zy-1K for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 12:36:15 -0400 Original-Received: from relay1-d.mail.gandi.net ([2001:4b98:dc4:8::221]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s56ke-00040h-RV for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 12:36:14 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 6FFB4240004 for ; Thu, 9 May 2024 16:36:05 +0000 (UTC) X-GND-Sasl: juri@linkov.net Received-SPF: pass client-ip=2001:4b98:dc4:8::221; envelope-from=juri@linkov.net; helo=relay1-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:284764 Archived-At: --=-=-= Content-Type: text/plain 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': --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=imenu-flatten.patch 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)) --=-=-=--