diff options
| -rw-r--r-- | doc/emacs/maintaining.texi | 11 | ||||
| -rw-r--r-- | lisp/progmodes/etags.el | 31 |
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 |
| 2670 | commands for working with tags tables use the selected one. To select | 2670 | the commands for working with tags tables use the selected one. To |
| 2671 | a tags table, type @kbd{M-x visit-tags-table}, which reads the tags | 2671 | select a tags table, type @kbd{M-x visit-tags-table}, which reads the |
| 2672 | table file name as an argument, with @file{TAGS} in the default | 2672 | tags table file name as an argument, with @file{TAGS} defaulting to |
| 2673 | directory as the default. | 2673 | the first directory that contains a file named @file{TAGS} encountered |
| 2674 | when 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. | ||
| 279 | It is the first directory that contains a file named TAGS | ||
| 280 | encountered 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. | |||
| 286 | When you find a tag with \\[find-tag], the buffer it finds the tag | 299 | When you find a tag with \\[find-tag], the buffer it finds the tag |
| 287 | in is given a local value of this variable which is the name of the tags | 300 | in is given a local value of this variable which is the name of the tags |
| 288 | file the tag was in." | 301 | file 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. |