all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#32024: 27.0; [PATCH] `imenu--generic-function'
@ 2018-06-30 22:53 Drew Adams
  2018-07-07  9:18 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Adams @ 2018-06-30 22:53 UTC (permalink / raw
  To: 32024

[-- Attachment #1: Type: text/plain, Size: 1064 bytes --]

Attached is a patch for two bugs in `imenu--generic-function'.  I ran
into them when using a function value for argument REGEXP, though
neither has to do particularly with that use case.  Instead, they both
have to do with the case where items are within comments or strings,
which might be skipped.

1. When checking whether the current item is inside a comment or string,
   it's necessary to first move point to position START.  Otherwise, the
   test is made at bol (which might not be within a comment or string,
   even though the START position is).

2. At the end, it's necessary to remove any empty menus that could have
   been added.  That can happen because of skipping things inside
   comments or strings.

In GNU Emacs 27.0.50 (build 3, x86_64-w64-mingw32)
 of 2018-03-21
Repository revision: e70d0c9e66d7a8609450b2889869d16aeb0363b5
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --without-dbus --host=x86_64-w64-mingw32
 --without-compress-install -C 'CFLAGS=-O2 -static -g3''

[-- Attachment #2: imenu-2018-06-30.patch --]
[-- Type: application/octet-stream, Size: 1174 bytes --]

diff -u imenu.el imenu-2018-06-30-patched.el
--- imenu.el	2018-06-30 15:34:46.614653600 -0700
+++ imenu-2018-06-30-patched.el	2018-06-30 15:44:17.946791000 -0700
@@ -817,7 +817,7 @@
 		  ;; 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
@@ -831,7 +831,10 @@
 	(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  (imenup-delete-if-not (lambda (it) (cdr it)) index-alist)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;

^ permalink raw reply	[flat|nested] 4+ messages in thread
[parent not found: <<e96656c3-9a71-4da1-9f7d-7e551026874b@default>]

end of thread, other threads:[~2018-07-07 16:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-30 22:53 bug#32024: 27.0; [PATCH] `imenu--generic-function' Drew Adams
2018-07-07  9:18 ` Eli Zaretskii
     [not found] <<e96656c3-9a71-4da1-9f7d-7e551026874b@default>
     [not found] ` <<83efgfjtei.fsf@gnu.org>
2018-07-07 14:27   ` Drew Adams
2018-07-07 16:22     ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.