From ee4f026188438f2531364fb042af91b427c0b944 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 24 Nov 2013 23:23:47 +0200 Subject: [PATCH] * lisp/imenu.el (imenu-generic-skip-comments-and-strings): New option. (imenu--generic-function): Use it. Fixes: debbugs:15560 --- etc/NEWS | 4 ++++ lisp/ChangeLog | 6 ++++++ lisp/imenu.el | 11 ++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index dcb2e614d4..6cff14d274 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -639,6 +639,10 @@ whether it is safe to use Bash's --noediting option. These days +++ ** There is a new macro `skip-unless' for skipping ERT tests. See the manual. +** Imenu + +*** New option `imenu-generic-skip-comments-and-strings'. + * New Modes and Packages in Emacs 24.4 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 286a32cbf7..36c4c6ae4e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-11-24 Dmitry Gutov + + * imenu.el (imenu-generic-skip-comments-and-strings): + New option (Bug#15560). + (imenu--generic-function): Use it. + 2013-11-24 Jorgen Schaefer * minibuffer.el (completion--in-region-1): Scroll the correct diff --git a/lisp/imenu.el b/lisp/imenu.el index d79b0abeeb..f41fcda271 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -185,6 +185,13 @@ with name concatenation." :type 'string :group 'imenu) +(defcustom imenu-generic-skip-comments-and-strings t + "When non-nil, ignore text inside comments and strings. +Only affects `imenu--generic-function'." + :type 'boolean + :group 'imenu + :version "24.4") + ;;;###autoload (defvar imenu-generic-expression nil "List of definition matchers for creating an Imenu index. @@ -796,7 +803,9 @@ depending on PATTERNS." ;; 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)) + (unless (or (member item (cdr menu)) + (and imenu-generic-skip-comments-and-strings + (nth 8 (syntax-ppss)))) (setcdr menu (cons item (cdr menu))))) ;; Go to the start of the match, to make sure we -- 2.20.1