Respect buffer-local value of tags-table-list (Bug#27772)

* lisp/progmodes/etags.el (visit-tags-table-buffer): Save the current
buffer around the `tags-table-including' calls so as to get buffer
local variables from the right buffer later.
* test/lisp/progmodes/etags-tests.el (etags-visit-tags-table-buffer):
New test.
* test/lisp/progmodes/etags-tests.el (etags-tests--test-dir): New
constant.
(etags-bug-158, etags-bug-23164): Use it so that when running the test
interactively, setting EMACS_TEST_DIRECTORY is not needed.
This commit is contained in:
Noam Postavsky 2017-08-06 21:35:04 -04:00
parent 81656add81
commit 179499cde9
2 changed files with 32 additions and 12 deletions

View file

@ -599,12 +599,13 @@ Returns t if it visits a tags table, or nil if there are no more in the list."
;; be frobnicated, and CONT will be set non-nil so we don't
;; do it below.
(and buffer-file-name
(or
;; First check only tables already in buffers.
(tags-table-including buffer-file-name t)
;; Since that didn't find any, now do the
;; expensive version: reading new files.
(tags-table-including buffer-file-name nil)))
(save-current-buffer
(or
;; First check only tables already in buffers.
(tags-table-including buffer-file-name t)
;; Since that didn't find any, now do the
;; expensive version: reading new files.
(tags-table-including buffer-file-name nil))))
;; Fourth, use the user variable tags-file-name, if it is
;; not already in the current list.
(and tags-file-name

View file

@ -23,9 +23,15 @@
(require 'ert)
(require 'etags)
(eval-when-compile (require 'cl-lib))
(defvar his-masters-voice t)
(defconst etags-tests--test-dir
(or (getenv "EMACS_TEST_DIRECTORY")
(expand-file-name "../../.."
(or load-file-name buffer-file-name))))
(defun y-or-n-p (_prompt)
"Replacement for `y-or-n-p' that returns what we tell it to."
his-masters-voice)
@ -38,8 +44,7 @@
(set-buffer buf-with-global-tags)
(setq default-directory (expand-file-name "."))
(visit-tags-table
(expand-file-name "manual/etags/ETAGS.good_1"
(getenv "EMACS_TEST_DIRECTORY")))
(expand-file-name "manual/etags/ETAGS.good_1" etags-tests--test-dir))
;; Check that tags in ETAGS.good_1 are recognized.
(setq xref-buf (xref-find-definitions "LL_Task_Procedure_Access/t"))
(should (bufferp xref-buf))
@ -55,8 +60,7 @@
(setq default-directory (expand-file-name "."))
(let (his-masters-voice)
(visit-tags-table
(expand-file-name "manual/etags/ETAGS.good_3"
(getenv "EMACS_TEST_DIRECTORY"))
(expand-file-name "manual/etags/ETAGS.good_3" etags-tests--test-dir)
t))
;; Check that tags in ETAGS.good_1 are recognized.
(setq xref-buf (xref-find-definitions "LL_Task_Procedure_Access/t"))
@ -84,8 +88,23 @@
(set-buffer (get-buffer-create "*foobar*"))
(fundamental-mode)
(visit-tags-table
(expand-file-name "manual/etags/ETAGS.good_3"
(getenv "EMACS_TEST_DIRECTORY"))
(expand-file-name "manual/etags/ETAGS.good_3" etags-tests--test-dir)
t)
(should (equal (should-error (xref-find-definitions "foobar123"))
'(user-error "No definitions found for: foobar123"))))
(ert-deftest etags-buffer-local-tags-table-list ()
"Test that a buffer-local value of `tags-table-list' is used."
(let ((file (make-temp-file "etag-test-tmpfile")))
(set-buffer (find-file-noselect file))
(fundamental-mode)
(setq-local tags-table-list
(list (expand-file-name "manual/etags/ETAGS.good_3"
etags-tests--test-dir)))
(cl-letf ((tag-tables tags-table-list)
(tags-file-name nil)
((symbol-function 'read-file-name)
(lambda (&rest _)
(error "We should not prompt the user"))))
(should (visit-tags-table-buffer))
(should (equal tags-file-name (car tag-tables))))))