aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/NEWS9
-rw-r--r--lisp/imenu.el41
2 files changed, 41 insertions, 9 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 0653ce74287..35ba75b9feb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1665,6 +1665,15 @@ the 'grep' results editable. The edits will be reflected in the buffer
1665visiting the originating file. Typing 'C-c C-c' will leave the Grep 1665visiting the originating file. Typing 'C-c C-c' will leave the Grep
1666Edit mode. 1666Edit mode.
1667 1667
1668** Imenu
1669
1670---
1671*** New user option 'imenu-allow-duplicate-menu-items'.
1672This specifies whether Imenu can include duplicate menu items.
1673Duplicate items are now allowed by default (option value 't'), which
1674restores the behavior before Emacs 29. Customize this to nil to get the
1675behavior of Emacs 29 and Emacs 30.
1676
1668** Time Stamp 1677** Time Stamp
1669 1678
1670--- 1679---
diff --git a/lisp/imenu.el b/lisp/imenu.el
index 0cf18447f62..41c4b5cee91 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -193,6 +193,18 @@ uses `imenu--generic-function')."
193 :type 'number 193 :type 'number
194 :version "28.1") 194 :version "28.1")
195 195
196(defcustom imenu-allow-duplicate-menu-items t
197 "Non-nil means that Imenu can include duplicate menu items.
198For example, if the buffer contains multiple definitions of function
199`foo' then a menu item is included for each of them.
200Otherwise, only the first such definition is accessible from the menu.
201
202This option applies only to an Imenu menu, not also to the use of
203command `imenu', which uses `completing-read' to read a menu item.
204The use of that command doesn't allow duplicate items."
205 :type 'boolean
206 :version "31.1")
207
196;;;###autoload 208;;;###autoload
197(defvar-local imenu-generic-expression nil 209(defvar-local imenu-generic-expression nil
198 "List of definition matchers for creating an Imenu index. 210 "List of definition matchers for creating an Imenu index.
@@ -505,15 +517,26 @@ Non-nil arguments are in recursive calls."
505(defun imenu--create-keymap (title alist &optional cmd) 517(defun imenu--create-keymap (title alist &optional cmd)
506 `(keymap ,title 518 `(keymap ,title
507 ,@(mapcar 519 ,@(mapcar
508 (lambda (item) 520 (if imenu-allow-duplicate-menu-items
509 `(,(intern (car item)) ,(car item) 521 (lambda (item)
510 ,@(cond 522 `(,(car item)
511 ((imenu--subalist-p item) 523 ,(car item)
512 (imenu--create-keymap (car item) (cdr item) cmd)) 524 ,@(cond
513 (t 525 ((imenu--subalist-p item)
514 (lambda () (interactive) 526 (imenu--create-keymap (car item) (cdr item) cmd))
515 (if cmd (funcall cmd item) item)))))) 527 (t
516 (seq-filter #'identity alist)))) 528 (lambda () (interactive)
529 (if cmd (funcall cmd item) item))))))
530 (lambda (item)
531 `(,(intern (car item))
532 ,(car item)
533 ,@(cond
534 ((imenu--subalist-p item)
535 (imenu--create-keymap (car item) (cdr item) cmd))
536 (t
537 (lambda () (interactive)
538 (if cmd (funcall cmd item) item)))))))
539 (remq nil alist))))
517 540
518(defun imenu--in-alist (str alist) 541(defun imenu--in-alist (str alist)
519 "Check whether the string STR is contained in multi-level ALIST." 542 "Check whether the string STR is contained in multi-level ALIST."