Subject: [PATCH] Simplify the search of the default tags file in, `visit-tags-table'
From: Hong Xu <[email-masked]>
To: bug-gnu-emacs <[email-masked]>
Cc: Phil Sainty <[email-masked]>, Lars Ingebrigtsen <[email-masked]>, Eli Zaretskii <[email-masked]>
Date: Tue, 8 Oct 2019 21:59:40 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

* lisp/progmodes/etags.el (visit-tags-table): Reimplement
`tags--find-default-tags-dir-recursively' using the much simpler
`locate-dominating-file'. Following up bug#37518.
---
  lisp/progmodes/etags.el | 15 +--------------
  1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index 906ab37c6b9f..6784894ba87e 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -274,19 +274,6 @@ tags-table-mode
    (setq buffer-undo-list t)
    (initialize-new-tags-table))

-(defun tags--find-default-tags-dir-recursively (current-dir)
-  "Find the directory in which the default TAGS file lives.
-It is the first directory that contains a file named TAGS
-encountered when recursively searching upward from CURRENT-DIR."
-  (let ((tag-filename (expand-file-name "TAGS" current-dir)))
-    (if (file-exists-p tag-filename)
-        current-dir
-      (let ((parent-dir
-             (file-name-directory (directory-file-name current-dir))))
-        (if (string= parent-dir current-dir)  ;; root dir is reached
-            nil
-          (tags--find-default-tags-dir-recursively parent-dir))))))
-
  ;;;###autoload
  (defun visit-tags-table (file &optional local)
    "Tell tags commands to use tags table file FILE.
@@ -301,7 +288,7 @@ visit-tags-table
  file the tag was in."
    (interactive
     (let ((default-tag-dir
-           (or (tags--find-default-tags-dir-recursively default-directory)
+           (or (locate-dominating-file default-directory "TAGS")
                 default-directory)))
       (list (read-file-name
              "Visit tags table (default TAGS): "
--
2.20.1