aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDrew Adams2018-07-07 19:20:45 +0300
committerEli Zaretskii2018-07-07 19:20:45 +0300
commit77166e0da2d58f2f6436989b7059d913be5b3439 (patch)
treeaf6c1569af4eb4b07039bb7922af07a675b12e17
parentea2f96837d00f5475cd48fc7bf62c19d1045c055 (diff)
downloademacs-77166e0da2d58f2f6436989b7059d913be5b3439.tar.gz
emacs-77166e0da2d58f2f6436989b7059d913be5b3439.zip
Fix 2 minor bugs in 'imenu--generic-function'
* lisp/imenu.el (imenu--generic-function): Move point to START before checking whether the current item is inside a comment or a string. Remove any empty menus that could have been added before returning. (Bug#32024)
-rw-r--r--lisp/imenu.el12
1 files changed, 10 insertions, 2 deletions
diff --git a/lisp/imenu.el b/lisp/imenu.el
index 94ee6bc83a7..7d4363993de 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -60,6 +60,7 @@
60;;; Code: 60;;; Code:
61 61
62(eval-when-compile (require 'cl-lib)) 62(eval-when-compile (require 'cl-lib))
63(require 'cl-seq)
63 64
64;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 65;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
65;;; 66;;;
@@ -819,7 +820,8 @@ depending on PATTERNS."
819 ;; Insert the item unless it is already present. 820 ;; Insert the item unless it is already present.
820 (unless (or (member item (cdr menu)) 821 (unless (or (member item (cdr menu))
821 (and imenu-generic-skip-comments-and-strings 822 (and imenu-generic-skip-comments-and-strings
822 (nth 8 (syntax-ppss)))) 823 (save-excursion
824 (goto-char start) (nth 8 (syntax-ppss)))))
823 (setcdr menu 825 (setcdr menu
824 (cons item (cdr menu))))) 826 (cons item (cdr menu)))))
825 ;; Go to the start of the match, to make sure we 827 ;; Go to the start of the match, to make sure we
@@ -833,7 +835,13 @@ depending on PATTERNS."
833 (setcdr item (sort (cdr item) 'imenu--sort-by-position)))) 835 (setcdr item (sort (cdr item) 'imenu--sort-by-position))))
834 (let ((main-element (assq nil index-alist))) 836 (let ((main-element (assq nil index-alist)))
835 (nconc (delq main-element (delq 'dummy index-alist)) 837 (nconc (delq main-element (delq 'dummy index-alist))
836 (cdr main-element))))) 838 (cdr main-element)))
839 ;; Remove any empty menus. That can happen because of skipping
840 ;; things inside comments or strings.
841 (when (consp (car index-alist))
842 (setq index-alist (cl-delete-if-not
843 (lambda (it) (cdr it))
844 index-alist)))))
837 845
838;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 846;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
839;;; 847;;;