unofficial mirror of bug-gnu-emacs@gnu.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

* bug#15560: 24.3.50; [patch] * imenu.el (imenu--generic-function): Don't generate index for comments area.
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2013-10-08 21:58 UTC (permalink / raw)
  To: William Xu, 15560

> It is annoying when imenu generates index also for functions found
> in comments area.

Yes!  And no.  It depends what you want at the particular time.
Sometimes you have multiple versions of a definition, with all
but one commented out, and you *want* Imenu to present you with
all of them, for easy navigation among them. 

> imenu will generate two filesys_init, which makes imenu useless.

No, not useless - see above.  Sometimes annoying, sometimes useful.

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

It's not great to impose this behavior on users: they lose a feature
that way.  Better to let users choose, and let them toggle the behavior.

(I do that in Imenu+, for instance: the Imenu menu always contains
these additional menu items, which affect Imenu behavior: Toggle
Case-Sensitive Name-Sort, Toggle Ignoring Commented Defs, Toggle
Sorting.)





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

* bug#15560: 24.3.50; [patch] * imenu.el (imenu--generic-function): Don't generate index for comments area.
  2013-10-08 21:58 ` Drew Adams
@ 2013-10-09  9:21   ` William Xu
  2013-10-09 12:23     ` Stefan Monnier
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: William Xu @ 2013-10-09  9:21 UTC (permalink / raw)
  To: Drew Adams; +Cc: 15560

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

2013/10/9 Drew Adams <drew.adams@oracle.com>

    > It is annoying when imenu generates index also for functions found
    > in comments area.

    Yes!  And no.  It depends what you want at the particular time.
    Sometimes you have multiple versions of a definition, with all
    but one commented out, and you *want* Imenu to present you with
    all of them, for easy navigation among them.

In the source codes i'm working with, there are very long change history at
the
beginning of file.  So for me, imenu becomes almost useless.  I'm using
imenu as
a function indexer, like those in modern IDEs, where they usually ignore
commentted defs.


-William

[-- Attachment #2: Type: text/html, Size: 828 bytes --]

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

* bug#15560: 24.3.50; [patch] * imenu.el (imenu--generic-function): Don't generate index for comments area.
  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
  2 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2013-10-09 12:23 UTC (permalink / raw)
  To: William Xu; +Cc: 15560

> a function indexer, like those in modern IDEs, where they usually ignore
> commentted defs.

While it may be occasionally handy to include code that's in comment,
the default should indeed be to skip comments.


        Stefan





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

* bug#15560: 24.3.50; [patch] * imenu.el (imenu--generic-function): Don't generate index for comments area.
  2013-10-09  9:21   ` William Xu
  2013-10-09 12:23     ` Stefan Monnier
@ 2013-10-09 14:31     ` Drew Adams
  2013-11-24 21:28     ` Dmitry Gutov
  2 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2013-10-09 14:31 UTC (permalink / raw)
  To: William Xu; +Cc: 15560

>     > It is annoying when imenu generates index also for functions found
>     > in comments area.
> 
>   Yes!  And no.  It depends what you want at the particular time.
>   ^^^^
>   Sometimes you have multiple versions of a definition, with all
>   but one commented out, and you *want* Imenu to present you with
>   all of them, for easy navigation among them.
> 
> In the source codes i'm working with, there are very long change history at the
> beginning of file.  So for me, imenu becomes almost useless.  I'm using imenu as
> a function indexer, like those in modern IDEs, where they usually ignore
> commentted defs.-William

Did you see my emphatic "Yes!"?

I agree that this is usually the behavior one wants, which is why I
implemented it (years ago), and why I chose ignoring commented definitions
as the default behavior.

My point is that sometimes it can be useful to not ignore commented
definitions, and that users should be the ones to choose the behavior that
is most useful to them.  That's all.





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

* bug#15560: 24.3.50; [patch] * imenu.el (imenu--generic-function): Don't generate index for comments area.
  2013-10-09 12:23     ` Stefan Monnier
@ 2013-10-09 14:31       ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2013-10-09 14:31 UTC (permalink / raw)
  To: Stefan Monnier, William Xu; +Cc: 15560

> > a function indexer, like those in modern IDEs, where they usually ignore
> > commentted defs.
> 
> While it may be occasionally handy to include code that's in comment,
> the default should indeed be to skip comments.

Of course.  The point is that it should be a user choice, and one that is
easy to make and unmake.





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

* bug#15560: 24.3.50; [patch] * imenu.el (imenu--generic-function): Don't generate index for comments area.
  2013-10-09  9:21   ` William Xu
  2013-10-09 12:23     ` Stefan Monnier
  2013-10-09 14:31     ` Drew Adams
@ 2013-11-24 21:28     ` Dmitry Gutov
  2 siblings, 0 replies; 7+ messages in thread
From: Dmitry Gutov @ 2013-11-24 21:28 UTC (permalink / raw)
  To: William Xu; +Cc: 15560-done

Version: 24.4

William Xu <william.xwl@gmail.com> writes:

> 2013/10/9 Drew Adams <drew.adams@oracle.com>
>
>> It is annoying when imenu generates index also for functions found
>> in comments area.
>
> Yes! And no. It depends what you want at the particular time.

See new user option `imenu-generic-skip-comments-and-strings', added in
115213.





^ permalink raw reply	[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 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).