emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 77166e0: Fix 2 minor bugs in 'imenu--generic-functi


From: Eli Zaretskii
Subject: [Emacs-diffs] master 77166e0: Fix 2 minor bugs in 'imenu--generic-function'
Date: Sat, 7 Jul 2018 12:21:38 -0400 (EDT)

branch: master
commit 77166e0da2d58f2f6436989b7059d913be5b3439
Author: Drew Adams <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    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)
---
 lisp/imenu.el | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lisp/imenu.el b/lisp/imenu.el
index 94ee6bc..7d43639 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -60,6 +60,7 @@
 ;;; Code:
 
 (eval-when-compile (require 'cl-lib))
+(require 'cl-seq)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;
@@ -819,7 +820,8 @@ depending on PATTERNS."
                  ;; Insert the item unless it is already present.
                  (unless (or (member item (cdr menu))
                               (and imenu-generic-skip-comments-and-strings
-                                   (nth 8 (syntax-ppss))))
+                                   (save-excursion
+                                     (goto-char start) (nth 8 (syntax-ppss)))))
                    (setcdr menu
                            (cons item (cdr menu)))))
                ;; Go to the start of the match, to make sure we
@@ -833,7 +835,13 @@ depending on PATTERNS."
        (setcdr item (sort (cdr item) 'imenu--sort-by-position))))
     (let ((main-element (assq nil index-alist)))
       (nconc (delq main-element (delq 'dummy index-alist))
-            (cdr main-element)))))
+             (cdr main-element)))
+    ;; Remove any empty menus.  That can happen because of skipping
+    ;; things inside comments or strings.
+    (when (consp (car index-alist))
+      (setq index-alist  (cl-delete-if-not
+                          (lambda (it) (cdr it))
+                          index-alist)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]