all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#15560: 24.3.50; [patch] * imenu.el (imenu--generic-function): Don't generate index for comments area.
@ 2013-10-08  8:17 William Xu
  2013-10-08 21:58 ` Drew Adams
  0 siblings, 1 reply; 7+ messages in thread
From: William Xu @ 2013-10-08  8:17 UTC (permalink / raw)
  To: 15560


[-- Attachment #1.1: Type: text/plain, Size: 363 bytes --]

It is annoying when imenu generates index also for functions found in
comments area.  e.g., in c-mode:

/*
a : Modified filesys_init()
  : hello
*/

uint8 filesys_init( void )
    {
    }

imenu will generate two filesys_init, which makes imenu useless.

This patch skips comment area completely.  In this case, it will
generate only one filesys_init.


-William

[-- Attachment #1.2: Type: text/html, Size: 467 bytes --]

[-- Attachment #2: 0001-imenu.el-imenu-generic-function-Don-t-generate-index.patch --]
[-- Type: application/octet-stream, Size: 3396 bytes --]

From ed923157d43273a6d21498b64a0ca2869838651b Mon Sep 17 00:00:00 2001
From: William Xu <william.xwl@gmail.com>
Date: Tue, 8 Oct 2013 16:15:47 +0800
Subject: [PATCH] * imenu.el (imenu--generic-function): Don't generate index
 for comments area.

---
 lisp/imenu.el | 52 ++++++++++++++++++++++++++--------------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/lisp/imenu.el b/lisp/imenu.el
index d79b0ab..9f95ff0 100644
--- a/lisp/imenu.el
+++ b/lisp/imenu.el
@@ -745,7 +745,6 @@ depending on PATTERNS."
     (unwind-protect			; For syntax table.
 	(save-match-data
 	  (set-syntax-table table)
-
 	  ;; Map over the elements of imenu-generic-expression
 	  ;; (typically functions, variables ...).
 	  (dolist (pat patterns)
@@ -774,31 +773,32 @@ depending on PATTERNS."
 			  ;; because it means a bad regexp was specified.
 			  (not (= (match-beginning 0) (match-end 0))))
 		(setq start (point))
-		;; Record the start of the line in which the match starts.
-		;; That's the official position of this definition.
-		(goto-char (match-beginning index))
-		(beginning-of-line)
-		(setq beg (point))
-		;; Add this sort of submenu only when we've found an
-		;; item for it, avoiding empty, duff menus.
-		(unless (assoc menu-title index-alist)
-		  (push (list menu-title) index-alist))
-		(if imenu-use-markers
-		    (setq beg (copy-marker beg)))
-		(let ((item
-		       (if function
-			   (nconc (list (match-string-no-properties index)
-					beg function)
-				  rest)
-			 (cons (match-string-no-properties index)
-			       beg)))
-		      ;; This is the desired submenu,
-		      ;; starting with its title (or nil).
-		      (menu (assoc menu-title index-alist)))
-		  ;; Insert the item unless it is already present.
-		  (unless (member item (cdr menu))
-		    (setcdr menu
-			    (cons item (cdr menu)))))
+                ;; Record the start of the line in which the match starts.
+                ;; That's the official position of this definition.
+                (goto-char (match-beginning index))
+                (beginning-of-line)
+                (setq beg (point))
+                ;; Add this sort of submenu only when we've found an
+                ;; item for it, avoiding empty, duff menus.
+                (unless (assoc menu-title index-alist)
+                  (push (list menu-title) index-alist))
+                (if imenu-use-markers
+                    (setq beg (copy-marker beg)))
+                (let ((item
+                       (if function
+                           (nconc (list (match-string-no-properties index)
+                                        beg function)
+                                  rest)
+                         (cons (match-string-no-properties index)
+                               beg)))
+                      ;; This is the desired submenu,
+                      ;; starting with its title (or nil).
+                      (menu (assoc menu-title index-alist)))
+                  (unless (nth 8 (syntax-ppss)) ; inside comment block? 
+                    ;; Insert the item unless it is already present.
+                    (unless (member item (cdr menu))
+                      (setcdr menu
+                              (cons item (cdr menu))))))
 		;; Go to the start of the match, to make sure we
 		;; keep making progress backwards.
 		(goto-char start))))
-- 
1.8.1.2


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-11-24 21:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-08  8:17 bug#15560: 24.3.50; [patch] * imenu.el (imenu--generic-function): Don't generate index for comments area William Xu
2013-10-08 21:58 ` Drew Adams
2013-10-09  9:21   ` William Xu
2013-10-09 12:23     ` Stefan Monnier
2013-10-09 14:31       ` Drew Adams
2013-10-09 14:31     ` Drew Adams
2013-11-24 21:28     ` Dmitry Gutov

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.