unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 32024@debbugs.gnu.org
Subject: bug#32024: 27.0; [PATCH] `imenu--generic-function'
Date: Sat, 30 Jun 2018 15:53:22 -0700 (PDT)	[thread overview]
Message-ID: <e96656c3-9a71-4da1-9f7d-7e551026874b@default> (raw)

[-- 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)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;

             reply	other threads:[~2018-06-30 22:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-30 22:53 Drew Adams [this message]
2018-07-07  9:18 ` bug#32024: 27.0; [PATCH] `imenu--generic-function' 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e96656c3-9a71-4da1-9f7d-7e551026874b@default \
    --to=drew.adams@oracle.com \
    --cc=32024@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).