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