aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHong Xu2019-10-08 18:43:47 +0200
committerLars Ingebrigtsen2019-10-08 18:43:56 +0200
commitba57f1a4273cabb53cbae86ad34b0a4bf01e1513 (patch)
tree902d530795e2ecc156390e61663b83301ab17c6d
parent1793d4979b3a38fd9ece1412cbc9ff2d2ed3ab3f (diff)
downloademacs-ba57f1a4273cabb53cbae86ad34b0a4bf01e1513.tar.gz
emacs-ba57f1a4273cabb53cbae86ad34b0a4bf01e1513.zip
Search upward from current dir for the default TAGS file
* doc/emacs/maintaining.texi (Select Tags Table): Update the doc of `visit-tags-table' (bug#37518). * lisp/progmodes/etags.el (tags--find-default-tags-dir-recursively) (visit-tags-table): Search upward from current dir for the default TAGS file.
-rw-r--r--doc/emacs/maintaining.texi11
-rw-r--r--lisp/progmodes/etags.el31
2 files changed, 31 insertions, 11 deletions
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index 519667dfbe9..ef448dd595b 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -2666,11 +2666,12 @@ etags --language=none \
2666@subsection Selecting a Tags Table 2666@subsection Selecting a Tags Table
2667 2667
2668@findex visit-tags-table 2668@findex visit-tags-table
2669 Emacs has at any time at most one @dfn{selected} tags table. All the 2669 Emacs has at any time at most one @dfn{selected} tags table. All
2670commands for working with tags tables use the selected one. To select 2670the commands for working with tags tables use the selected one. To
2671a tags table, type @kbd{M-x visit-tags-table}, which reads the tags 2671select a tags table, type @kbd{M-x visit-tags-table}, which reads the
2672table file name as an argument, with @file{TAGS} in the default 2672tags table file name as an argument, with @file{TAGS} defaulting to
2673directory as the default. 2673the first directory that contains a file named @file{TAGS} encountered
2674when recursively searching upward from the default directory.
2674 2675
2675@vindex tags-file-name 2676@vindex tags-file-name
2676 Emacs does not actually read in the tags table contents until you 2677 Emacs does not actually read in the tags table contents until you
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index c40422dbc5c..906ab37c6b9 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -274,6 +274,19 @@ buffer-local and set them to nil."
274 (setq buffer-undo-list t) 274 (setq buffer-undo-list t)
275 (initialize-new-tags-table)) 275 (initialize-new-tags-table))
276 276
277(defun tags--find-default-tags-dir-recursively (current-dir)
278 "Find the directory in which the default TAGS file lives.
279It is the first directory that contains a file named TAGS
280encountered when recursively searching upward from CURRENT-DIR."
281 (let ((tag-filename (expand-file-name "TAGS" current-dir)))
282 (if (file-exists-p tag-filename)
283 current-dir
284 (let ((parent-dir
285 (file-name-directory (directory-file-name current-dir))))
286 (if (string= parent-dir current-dir) ;; root dir is reached
287 nil
288 (tags--find-default-tags-dir-recursively parent-dir))))))
289
277;;;###autoload 290;;;###autoload
278(defun visit-tags-table (file &optional local) 291(defun visit-tags-table (file &optional local)
279 "Tell tags commands to use tags table file FILE. 292 "Tell tags commands to use tags table file FILE.
@@ -286,12 +299,18 @@ from Lisp, if the optional arg LOCAL is non-nil, set the local value.
286When you find a tag with \\[find-tag], the buffer it finds the tag 299When you find a tag with \\[find-tag], the buffer it finds the tag
287in is given a local value of this variable which is the name of the tags 300in is given a local value of this variable which is the name of the tags
288file the tag was in." 301file the tag was in."
289 (interactive (list (read-file-name "Visit tags table (default TAGS): " 302 (interactive
290 default-directory 303 (let ((default-tag-dir
291 (expand-file-name "TAGS" 304 (or (tags--find-default-tags-dir-recursively default-directory)
292 default-directory) 305 default-directory)))
293 t) 306 (list (read-file-name
294 current-prefix-arg)) 307 "Visit tags table (default TAGS): "
308 ;; default to TAGS from default-directory up to root.
309 default-tag-dir
310 (expand-file-name "TAGS" default-tag-dir)
311 t)
312 current-prefix-arg)))
313
295 (or (stringp file) (signal 'wrong-type-argument (list 'stringp file))) 314 (or (stringp file) (signal 'wrong-type-argument (list 'stringp file)))
296 ;; Bind tags-file-name so we can control below whether the local or 315 ;; Bind tags-file-name so we can control below whether the local or
297 ;; global value gets set. 316 ;; global value gets set.