GNU bug report logs - #27772
25.2; Choosing tags files

Previous Next

Package: emacs;

Reported by: Daniel Lopez <daniel.lopez999 <at> gmail.com>

Date: Thu, 20 Jul 2017 13:51:02 UTC

Severity: minor

Tags: fixed, patch

Found in version 25.2

Fixed in version 26.1

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 27772 in the body.
You can then email your comments to 27772 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#27772; Package emacs. (Thu, 20 Jul 2017 13:51:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Lopez <daniel.lopez999 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 20 Jul 2017 13:51:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.2; Choosing tags files
Date: Thu, 20 Jul 2017 14:49:10 +0100
Having problems while trying to choose multiple tags tables, via 
tags-table-list, to apply to a specific buffer only by setting that 
variable in a buffer-local way:

Test case:

Prepare a couple of directories each with with a TAGS file:

### Bash code start ###

mkdir /tmp/emacs_tags_test
cd /tmp/emacs_tags_test

mkdir foo_files
cd foo_files
echo "const int foo_const = 1;" > foo.h
ctags -e foo.h
cd ..

mkdir bar_files
cd bar_files
echo "const int bar_const = 1;" > bar.h
ctags -e bar.h
cd ..

### Bash code end ###

Start emacs -Q and run the following to open a new file and set 
tags-table-list buffer-locally to reference both TAGS files:

### Elisp start ###

(progn
  (find-file "/tmp/emacs_tags_test/main.cpp")  ;;(this is a new file)

  (setq-local tags-table-list
      '("/tmp/emacs_tags_test/foo_files/TAGS"
        "/tmp/emacs_tags_test/bar_files/TAGS"))
)

### Elisp end ###

Do M-x xref-find-definitions. I get the prompt "Find definitions of:". I 
hit TAB hoping to get a list giving the choices of "foo_const" and 
"bar_const", but instead am prompted:

Visit tags table (default TAGS): /tmp/emacs_tags_test/bar_files/

I press Enter reluctantly to accept the default. I'm returned to the
"Find definitions of:" prompt, and "bar_const" is the sole completion
(no "foo_const" which I also wanted).

An aside: The global value of tags-file-name has now been set to
 "/tmp/emacs_tags_test/bar_files/TAGS"
and the global value of tags-table-list has now been set to
 ("/tmp/emacs_tags_test/bar_files/TAGS")
while the local value of tags-table-list is unchanged from what I set it to:
 ("/tmp/emacs_tags_test/foo_files/TAGS" 
"/tmp/emacs_tags_test/bar_files/TAGS")

If I do another M-x xref-find-definitions now, I still get "bar_const"
as the sole completion (instead of the choice of two I wanted).

(End test case)


I made some incomplete investigations into visit-tags-table-buffer
where this seems to be implemented - I saw that at one point it seems to 
explicitly look up the local value of tags-file name:

  ;; First, try a local variable.
  (cdr (assq 'tags-file-name (buffer-local-variables)))

Inspired by that I tried changing the part below where it seems to get 
the value of tags-table-list:

  ;; Fifth, use the user variable giving the table list.
  ;; Find the first element of the list that actually exists.
  (let ((list tags-table-list)

to go explicitly via the (buffer-local-variables) alist as well:

  (let ((list (or (cdr (assq 'tags-table-list 
(buffer-local-variables))) tags-table-list))

but it didn't seem to change the outcome of the above test case at all. 
The rest of that function seems a bit too complicated for me to delve 
into right now (and I admit I've worked around this for myself, for now, 
by setting before-advice on visit-tags-table-buffer to set the global 
value of tags-table-list to what I want every time).

Daniel

---



In GNU Emacs 25.2.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.22.10)
 of 2017-04-22 built on juergen
Windowing system distributor 'The X.Org Foundation', version 11.0.11903000
Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-modules
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe
 -fstack-protector-strong' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 MODULES

Important settings:
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: C++/l

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t


electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t

Recent messages:
("/tmp/emacs_tags_test/foo_files/TAGS" 
"/tmp/emacs_tags_test/bar_files/TAGS")
Making tags completion table for /tmp/emacs_tags_test/bar_files/TAGS...
Starting a new list of tags tables
Making tags completion table for /tmp/emacs_tags_test/bar_files/TAGS...done
Quit
Type C-x 1 to delete the help window.
Making completion list...

Quit
completing-read-default: Command attempted to use minibuffer while in 
minibuffer

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message dired format-spec rfc822 mml
mml-sec password-cache epg epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils pp help-fns
thingatpt etags xref cl-seq project ring eieio byte-opt bytecomp
byte-compile cconv eieio-core cl-macs gv cl-extra help-mode cc-mode
cc-fonts easymenu cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs cl-loaddefs pcase cl-lib time-date mule-util tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
dbusbind inotify dynamic-setting system-font-setting font-render-setting
move-toolbar gtk x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 116530 3695)
 (symbols 48 23070 0)
 (miscs 40 53 111)
 (strings 32 23520 5093)
 (string-bytes 1 794931)
 (vectors 16 16526)
 (vector-slots 8 487720 4910)
 (floats 8 230 253)
 (intervals 56 297 7)
 (buffers 976 23))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27772; Package emacs. (Mon, 07 Aug 2017 01:45:01 GMT) Full text and rfc822 format available.

Message #8 received at 27772 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Daniel Lopez <daniel.lopez999 <at> gmail.com>
Cc: 27772 <at> debbugs.gnu.org
Subject: Re: bug#27772: 25.2; Choosing tags files
Date: Sun, 06 Aug 2017 21:45:56 -0400
[Message part 1 (text/plain, inline)]
tags 27772 + patch
severity 27772 minor
quit

Daniel Lopez <daniel.lopez999 <at> gmail.com> writes:

> mkdir foo_files
> cd foo_files
> echo "const int foo_const = 1;" > foo.h
> ctags -e foo.h

Hmm...

    $ ctags -e foo.h 
    ctags: invalid option -- 'e'
        Try 'ctags --help' for a complete list of options.
    $ ctags --version
    ctags (GNU Emacs 25.2.50)
    Copyright (C) 2017 Free Software Foundation, Inc.
    This program is distributed under the terms in ETAGS.README

Using 'etags foo.h' I can reproduce your results.

> I made some incomplete investigations into visit-tags-table-buffer
> where this seems to be implemented - I saw that at one point it seems
> to explicitly look up the local value of tags-file name:
>
>   ;; First, try a local variable.
>   (cdr (assq 'tags-file-name (buffer-local-variables)))
>
> Inspired by that I tried changing the part below where it seems to get
> the value of tags-table-list:
>
>   ;; Fifth, use the user variable giving the table list.
>   ;; Find the first element of the list that actually exists.
>   (let ((list tags-table-list)
>
> to go explicitly via the (buffer-local-variables) alist as well:
>
>   (let ((list (or (cdr (assq 'tags-table-list
> (buffer-local-variables))) tags-table-list))
>
> but it didn't seem to change the outcome of the above test case at
> all.

The problem is that the buffer gets changed by the time we reach there.
The following patch seems to fix it (no need to explicitly use
`buffer-local-variables' since normal variable access will check the
buffer-local value first.  I think the use of `buffer-local-variables'
above is meant to ignore the global value of `tags-file-name').

[v1-0001-Respect-buffer-local-value-of-tags-table-list-Bug.patch (text/x-diff, inline)]
From 884e23043dc263126341f297953d89ce28d7dd9a Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sun, 6 Aug 2017 21:35:04 -0400
Subject: [PATCH v1] Respect buffer-local value of tags-table-list (Bug#27772)

* lisp/progmodes/etags.el (visit-tags-table-buffer): Save the current
around the `tags-table-including' calls so as to get buffer local
variables from the right buffer later.
---
 lisp/progmodes/etags.el | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index 8d635cb6d4..222dea1a2a 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -599,12 +599,13 @@ (defun visit-tags-table-buffer (&optional cont cbuf)
 		;; 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
-- 
2.11.1


Added tag(s) patch. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Mon, 07 Aug 2017 01:45:02 GMT) Full text and rfc822 format available.

Severity set to 'minor' from 'normal' Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Mon, 07 Aug 2017 01:45:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27772; Package emacs. (Mon, 07 Aug 2017 16:11:02 GMT) Full text and rfc822 format available.

Message #15 received at 27772 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: npostavs <at> users.sourceforge.net
Cc: 27772 <at> debbugs.gnu.org, daniel.lopez999 <at> gmail.com
Subject: Re: bug#27772: 25.2; Choosing tags files
Date: Mon, 07 Aug 2017 19:10:38 +0300
> From: npostavs <at> users.sourceforge.net
> Date: Sun, 06 Aug 2017 21:45:56 -0400
> Cc: 27772 <at> debbugs.gnu.org
> 
> The problem is that the buffer gets changed by the time we reach there.
> The following patch seems to fix it (no need to explicitly use
> `buffer-local-variables' since normal variable access will check the
> buffer-local value first.

Seems reasonable, thanks.

> * lisp/progmodes/etags.el (visit-tags-table-buffer): Save the current
                                                                ^^^^^^^
You meant "current buffer", I presume.

Do etags-tests.el still pass after this change?  If so, would it be
possible to add a test for this bug?

Other than that, LGTM.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27772; Package emacs. (Tue, 08 Aug 2017 02:55:02 GMT) Full text and rfc822 format available.

Message #18 received at 27772 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: daniel.lopez999 <at> gmail.com, 27772 <at> debbugs.gnu.org
Subject: Re: bug#27772: 25.2; Choosing tags files
Date: Mon, 07 Aug 2017 22:55:57 -0400
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

>> * lisp/progmodes/etags.el (visit-tags-table-buffer): Save the current
>                                                                 ^^^^^^^
> You meant "current buffer", I presume.

Whoops, yes.

> Do etags-tests.el still pass after this change?

Yep, all 2 of them.

> If so, would it be possible to add a test for this bug?

Okay, the following basically works.  Although without the patch, the
test doesn't fail cleanly, it rather gets stuck waiting for input (the
TAGS table filename).

[v2-0001-Respect-buffer-local-value-of-tags-table-list-Bug.patch (text/x-diff, inline)]
From e3d3edfedf81543612367aee9a5aa53600d3c5c8 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sun, 6 Aug 2017 21:35:04 -0400
Subject: [PATCH v2] 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.
---
 lisp/progmodes/etags.el            | 13 +++++++------
 test/lisp/progmodes/etags-tests.el | 27 +++++++++++++++++++++------
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index 8d635cb6d4..222dea1a2a 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -599,12 +599,13 @@ visit-tags-table-buffer
 		;; 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
diff --git a/test/lisp/progmodes/etags-tests.el b/test/lisp/progmodes/etags-tests.el
index eec8a02f1b..950c853c09 100644
--- a/test/lisp/progmodes/etags-tests.el
+++ b/test/lisp/progmodes/etags-tests.el
@@ -26,6 +26,11 @@
 
 (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 +43,7 @@ y-or-n-p
     (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 +59,7 @@ y-or-n-p
     (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 +87,20 @@ y-or-n-p
   (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)))
+    (let ((tag-tables tags-table-list)
+          (tags-file-name nil))
+      (should (visit-tags-table-buffer))
+      (should (equal tags-file-name (car tag-tables))))))
-- 
2.11.1


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27772; Package emacs. (Tue, 08 Aug 2017 14:22:01 GMT) Full text and rfc822 format available.

Message #21 received at 27772 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: npostavs <at> users.sourceforge.net
Cc: daniel.lopez999 <at> gmail.com, 27772 <at> debbugs.gnu.org
Subject: Re: bug#27772: 25.2; Choosing tags files
Date: Tue, 08 Aug 2017 17:21:19 +0300
> From: npostavs <at> users.sourceforge.net
> Cc: 27772 <at> debbugs.gnu.org,  daniel.lopez999 <at> gmail.com
> Date: Mon, 07 Aug 2017 22:55:57 -0400
> 
> > If so, would it be possible to add a test for this bug?
> 
> Okay, the following basically works.  Although without the patch, the
> test doesn't fail cleanly, it rather gets stuck waiting for input (the
> TAGS table filename).

Would it be possible to work around that by replacing some function
(like we already do in this test)?  If not, please push, and thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27772; Package emacs. (Wed, 09 Aug 2017 00:01:02 GMT) Full text and rfc822 format available.

Message #24 received at 27772 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: daniel.lopez999 <at> gmail.com, 27772 <at> debbugs.gnu.org
Subject: Re: bug#27772: 25.2; Choosing tags files
Date: Tue, 08 Aug 2017 20:02:10 -0400
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: npostavs <at> users.sourceforge.net
>> Cc: 27772 <at> debbugs.gnu.org,  daniel.lopez999 <at> gmail.com
>> Date: Mon, 07 Aug 2017 22:55:57 -0400
>> 
>> > If so, would it be possible to add a test for this bug?
>> 
>> Okay, the following basically works.  Although without the patch, the
>> test doesn't fail cleanly, it rather gets stuck waiting for input (the
>> TAGS table filename).
>
> Would it be possible to work around that by replacing some function
> (like we already do in this test)?  If not, please push, and thanks.

Oh yeah, that's easy (why didn't I do that right away?  Must have been
tired or something.)

[v3-0001-Respect-buffer-local-value-of-tags-table-list-Bug.patch (text/x-diff, inline)]
From 6df75e619d2438483e917b4c3a4c8a50f10db93c Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sun, 6 Aug 2017 21:35:04 -0400
Subject: [PATCH v3] 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.
---
 lisp/progmodes/etags.el            | 13 +++++++------
 test/lisp/progmodes/etags-tests.el | 31 +++++++++++++++++++++++++------
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index 8d635cb6d4..222dea1a2a 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -599,12 +599,13 @@ visit-tags-table-buffer
 		;; 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
diff --git a/test/lisp/progmodes/etags-tests.el b/test/lisp/progmodes/etags-tests.el
index eec8a02f1b..0153f327ba 100644
--- a/test/lisp/progmodes/etags-tests.el
+++ b/test/lisp/progmodes/etags-tests.el
@@ -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 @@ y-or-n-p
     (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 @@ y-or-n-p
     (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 @@ y-or-n-p
   (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))))))
-- 
2.11.1


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27772; Package emacs. (Fri, 11 Aug 2017 01:45:02 GMT) Full text and rfc822 format available.

Message #27 received at 27772 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: daniel.lopez999 <at> gmail.com, 27772 <at> debbugs.gnu.org
Subject: Re: bug#27772: 25.2; Choosing tags files
Date: Thu, 10 Aug 2017 21:46:16 -0400
tags 27772 fixed
close 27772 26.1
quit

npostavs <at> users.sourceforge.net writes:

>>> Okay, the following basically works.  Although without the patch, the
>>> test doesn't fail cleanly, it rather gets stuck waiting for input (the
>>> TAGS table filename).
>>
>> Would it be possible to work around that by replacing some function
>> (like we already do in this test)?  If not, please push, and thanks.
>
> Oh yeah, that's easy (why didn't I do that right away?  Must have been
> tired or something.)

Pushed to master.

[1: 179499cde9]: 2017-08-10 21:30:37 -0400
  Respect buffer-local value of tags-table-list (Bug#27772)
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=179499cde921a28c82400b1674520da245b93bb9




Added tag(s) fixed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Fri, 11 Aug 2017 01:45:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 26.1, send any further explanations to 27772 <at> debbugs.gnu.org and Daniel Lopez <daniel.lopez999 <at> gmail.com> Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Fri, 11 Aug 2017 01:45:04 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27772; Package emacs. (Fri, 11 Aug 2017 03:50:02 GMT) Full text and rfc822 format available.

Message #34 received at 27772 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
To: 27772 <at> debbugs.gnu.org
Subject: Re: bug#27772 acknowledged by developer (Re: bug#27772: 25.2;
 Choosing tags files)
Date: Fri, 11 Aug 2017 04:46:54 +0100
On 11/08/17 02:45, GNU bug Tracking System wrote:
> This is an automatic notification regarding your bug report
> #27772: 25.2; Choosing tags files,
> which was filed against the emacs package.
> 
> Thank you for your report, which has now been closed.
> You can view the full report at
> http://debbugs.gnu.org/cgi/bugreport.cgi?bug=27772
> 
> If you require further information, please followup to 27772 <at> debbugs.gnu.org.
> 
> debbugs.gnu.org maintainers
> (administrator, GNU bugs database)
> 
> 

Thanks for seeing to this, guys - I had a quick try with the modified 
visit-tags-table-buffer in my running Emacs, and it seems to fix my 
original problem.

Daniel




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 08 Sep 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 204 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.