unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Wojciech Meyer <wojciech.meyer@googlemail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Andreas Schwab <schwab@linux-m68k.org>,
	Lennart Borgman <lennart.borgman@gmail.com>,
	Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: How do I use tags to go to begv_byte instead of BEGV_BYTE?
Date: Sun, 29 Aug 2010 02:04:59 +0100	[thread overview]
Message-ID: <8762yup6tg.fsf@gmail.com> (raw)
In-Reply-To: <jwvtypxcins.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 24 May 2010 13:31:40 -0400")

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

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Nowadays, I think etags.el would deserve to be improved so as to taken
> the major mode into account, and also so as to give precedence to
> case-exact matches, and also to automatically try the second-choice if
> the first makes you jump to where you started.
>
> IOW patches welcome,

Here is another one.

`tags-major-mode-sensitive' customisation allows to specify if `etags'
package should be sensitive on a major mode. If so, it looks only for
files with the names matching entries of `auto-mode-alist' of the major mode.
It does not hit performance that much, if it is a problem, making a
simple assumption about last search would be sufficient (however I've
checked it on the Emacs code base, and seems to run OK).

BTW: Integrating etags with ede projects might be a good idea.

Cheers;
Wojciech


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: etags-major-mode-sensitive.patch --]
[-- Type: text/x-diff, Size: 3211 bytes --]

=== modified file 'lisp/progmodes/etags.el'
--- lisp/progmodes/etags.el	2010-08-14 23:01:42 +0000
+++ lisp/progmodes/etags.el	2010-08-29 00:46:18 +0000
@@ -103,6 +103,15 @@
   :group 'etags
   :type 'boolean)
 
+(defcustom tags-major-mode-sensitive 'default
+  "*Control whether major mode determines allowed file extensions during 
+tags search."
+  :group 'etags
+  :type '(choice (const :tag "Major mode file types only" t)
+		 (const :tag "All files " nil)
+		 (other :tag "Use default" default))
+  :version "21.1")
+
 (defvar tags-table-computed-list nil
   "List of tags tables to search, computed from `tags-table-list'.
 This includes tables implicitly included by other tables.  The list is not
@@ -879,7 +888,8 @@
   ;; Save the current buffer's value of `find-tag-hook' before
   ;; selecting the tags table buffer.  For the same reason, save value
   ;; of `tags-file-name' in case it has a buffer-local value.
-  (let ((local-find-tag-hook find-tag-hook))
+  (let ((local-find-tag-hook find-tag-hook)
+	(current-major-mode major-mode))
     (if (eq '- next-p)
 	;; Pop back to a previous location.
 	(if (ring-empty-p tags-location-ring)
@@ -919,7 +929,7 @@
                  find-tag-regexp-next-line-after-failure-p
                find-tag-next-line-after-failure-p)
              (if regexp-p "matching" "containing")
-             (or (not next-p) (not last-tag)))
+             (or (not next-p) (not last-tag)) current-major-mode)
 	  (set-marker marker (point))
 	  (run-hooks 'local-find-tag-hook)
 	  (ring-insert tags-location-ring marker)
@@ -1061,6 +1071,26 @@
     (goto-char (marker-position marker))
     (set-marker marker nil nil)))
 \f
+
+(defun tags-file-name-qualified-p (file-name current-major-mode)
+  "Is file name qualified? Return always t if `tags-major-mode-sensitive' 
+is nil. Otherwise return if the file matches major-mode file name regexp."
+  (if (or 
+       (null tags-major-mode-sensitive) 
+       (eq tags-major-mode-sensitive 'default))
+      t
+    (let ((al auto-mode-alist)
+	  (found nil))
+      (while (and (not found) al)
+	(let* ((x (car al))
+	       (file-name-regex (car x))
+	       (major-mode-sym (cdr x)))
+	(setq al (cdr al))
+	(setq found (and
+		     (eq current-major-mode major-mode-sym)
+		     (string-match file-name-regex file-name)))))
+      found)))
+
 (defvar tag-lines-already-matched nil
   "Matches remembered between calls.") ; Doc string: calls to what?
 
@@ -1069,7 +1099,8 @@
 			  order
 			  next-line-after-failure-p
 			  matching
-			  first-search)
+			  first-search
+			  current-major-mode)
   "Internal tag-finding function.
 PATTERN is a string to pass to arg SEARCH-FORWARD-FUNC, and to any
 member of the function list ORDER.  If ORDER is nil, use saved state
@@ -1129,7 +1160,8 @@
 	  (while order
 	    (while (funcall search-forward-func pattern nil t)
 	      ;; Naive match found.  Qualify the match.
-	      (and (funcall (car order) pattern)
+	      (and (tags-file-name-qualified-p (file-of-tag) current-major-mode)
+		   (funcall (car order) pattern)
 		   ;; Make sure it is not a previous qualified match.
 		   (not (member (set-marker match-marker (save-excursion
 							   (beginning-of-line)


  parent reply	other threads:[~2010-08-29  1:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-24 13:24 How do I use tags to go to begv_byte instead of BEGV_BYTE? Lennart Borgman
2010-05-24 15:22 ` Andreas Schwab
2010-05-24 15:37   ` Lennart Borgman
2010-05-24 15:52     ` Andreas Schwab
2010-05-24 16:06       ` Lennart Borgman
2010-05-24 17:31         ` Stefan Monnier
2010-05-24 18:29           ` Lennart Borgman
2010-08-29  1:04           ` Wojciech Meyer [this message]
2010-08-30 21:39             ` Wojciech Meyer
2010-09-01 12:38               ` Francesco Potortì
2010-09-01 20:00                 ` Wojciech Meyer
2010-09-01 20:39                   ` Wojciech Meyer
2010-09-01 20:59                     ` Francesco Potortì
2010-09-01 20:57                   ` Francesco Potortì
2010-09-01 21:36                     ` Wojciech Meyer

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=8762yup6tg.fsf@gmail.com \
    --to=wojciech.meyer@googlemail.com \
    --cc=emacs-devel@gnu.org \
    --cc=lennart.borgman@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    --cc=schwab@linux-m68k.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).