bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27772: 25.2; Choosing tags files


From: npostavs
Subject: bug#27772: 25.2; Choosing tags files
Date: Tue, 08 Aug 2017 20:02:10 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

>> From: npostavs@users.sourceforge.net
>> Cc: 27772@debbugs.gnu.org,  daniel.lopez999@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.)

>From 6df75e619d2438483e917b4c3a4c8a50f10db93c Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]