unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Hong Xu <hong@topbug.net>
To: 37518@debbugs.gnu.org
Subject: bug#37518: [PATCH] Search upward from current dir for the default TAGS file
Date: Thu, 26 Sep 2019 02:52:30 -0700	[thread overview]
Message-ID: <b1a3bfe6-d7be-28cc-da10-118da65e79fd@topbug.net> (raw)

* lisp/progmodes/etags.el (tags--find-default-tags-dir)
(tags--find-default-tags-dir-impl, visit-tags-table): Search
upward from current dir for the default TAGS file
---
  lisp/progmodes/etags.el | 38 ++++++++++++++++++++++++++++++++------
  1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index a03516100087..81f0f135c577 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -274,6 +274,29 @@ tags-table-mode
    (setq buffer-undo-list t)
    (initialize-new-tags-table))
  
+(defun tags--find-default-tags-dir-impl (current-dir)
+  "Implements finding the directory that hosts the default TAGS file.
+It finds the first directory that contains a file named TAGS encountered
+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-impl parent-dir))))))
+
+(defun tags--find-default-tags-dir ()
+  "Find the directory that hosts the default TAGS file.
+It is the first directory that contains a file named TAGS encountered
+searching upward from `default-directory'."
+  (let ((default-tag-dir
+          (tags--find-default-tags-dir-impl default-directory)))
+    (if default-tag-dir
+        default-tag-dir
+      default-directory)))
+
  ;;;###autoload
  (defun visit-tags-table (file &optional local)
    "Tell tags commands to use tags table file FILE.
@@ -286,12 +309,15 @@ visit-tags-table
  When you find a tag with \\[find-tag], the buffer it finds the tag
  in is given a local value of this variable which is the name of the tags
  file the tag was in."
-  (interactive (list (read-file-name "Visit tags table (default TAGS): "
-				     default-directory
-				     (expand-file-name "TAGS"
-						       default-directory)
-				     t)
-		     current-prefix-arg))
+  (interactive
+   (let ((default-tag-dir (tags--find-default-tags-dir)))
+     (list (read-file-name
+            "Visit tags table (default TAGS): "
+            ;; default to TAGS from default-directory up to root.
+            default-tag-dir
+            (expand-file-name "TAGS" default-tag-dir)
+            t)))
+           current-prefix-arg)
    (or (stringp file) (signal 'wrong-type-argument (list 'stringp file)))
    ;; Bind tags-file-name so we can control below whether the local or
    ;; global value gets set.
-- 
2.20.1







             reply	other threads:[~2019-09-26  9:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26  9:52 Hong Xu [this message]
2019-10-07  4:19 ` bug#37518: [PATCH] Search upward from current dir for the default TAGS file Lars Ingebrigtsen
2019-10-07  4:48   ` Hong Xu
2019-10-07 16:24     ` Eli Zaretskii
2019-10-07 17:36       ` Hong Xu
2019-10-07 18:43         ` Eli Zaretskii
2019-10-07 18:52           ` Hong Xu
2019-10-08 16:45         ` Lars Ingebrigtsen
2019-10-08 19:46           ` Phil Sainty
2019-10-09  0:38             ` Hong Xu
2019-10-09  5:01             ` Hong Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b1a3bfe6-d7be-28cc-da10-118da65e79fd@topbug.net \
    --to=hong@topbug.net \
    --cc=37518@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).