Subject: bug#27772: 25.2; Choosing tags files

From: Daniel Lopez <[email-masked]>
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))