emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I use tags to go to begv_byte instead of BEGV_BYTE?


From: Wojciech Meyer
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
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Stefan Monnier <address@hidden> 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

=== 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)))
 
+
+(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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]