Subject: bug#27772: 25.2; Choosing tags files

From: [email-masked]
Date: Sun, 06 Aug 2017 21:45:56 -0400

tags 27772 + patch
severity 27772 minor
quit

Daniel Lopez <[email-masked]> 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').

>From 884e23043dc263126341f297953d89ce28d7dd9a Mon Sep 17 00:00:00 2001
From: Noam Postavsky <[email-masked]>
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