]> git.eshelyaron.com Git - emacs.git/commitdiff
Default FILE to the current buffer for list-tags
authorHong Xu <hong@topbug.net>
Mon, 7 Oct 2019 04:03:21 +0000 (06:03 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 7 Oct 2019 04:03:21 +0000 (06:03 +0200)
* doc/emacs/maintaining.texi (List Identifiers): Update
`list-tags' doc (bug#37611).
* lisp/progmodes/etags.el (list-tags)
(tags--get-current-buffer-name-in-tags-file): Default FILE to the
current buffer for list-tags.

doc/emacs/maintaining.texi
lisp/progmodes/etags.el

index 9a9957069fd6a196353384c4f08bd3c49e7fc993..519667dfbe92d98bf5d26a3e3f4d6797fd9a8724 100644 (file)
@@ -2124,7 +2124,9 @@ the selected tags table, and displays a list of tags defined in that
 file.  Do not include a directory as part of the file name unless the
 file name recorded in the tags table includes a directory.  This
 command works only with the etags backend, and requires a tags table
-for the project to be available.  @xref{Tags Tables}.
+for the project to be available.  @xref{Tags Tables}.  If used
+interactively, the default tag is file name of the current buffer if
+used interactively.
 
 @c Sadly, the new-and-improved Xref feature doesn't provide anything
 @c close to the described below features of the now-obsoleted
index a03516100087c6c4f4d3b92c580e095a81eee6f8..5edced5080e26e7d78733694e58ec97dafb35a16 100644 (file)
@@ -1852,15 +1852,28 @@ For non-interactive use, superceded by `fileloop-initialize-replace'."
        (all-completions string (tags-table-files) predicate)
       (try-completion string (tags-table-files) predicate))))
 
+(defun tags--get-current-buffer-name-in-tags-file ()
+  "Get the file name that the current buffer corresponds in the tags file."
+  (let ((tag-dir
+         (save-excursion
+           (visit-tags-table-buffer)
+           (file-name-directory (buffer-file-name)))))
+    (file-relative-name (buffer-file-name) tag-dir)))
+
 ;;;###autoload
 (defun list-tags (file &optional _next-match)
   "Display list of tags in file FILE.
-This searches only the first table in the list, and no included tables.
-FILE should be as it appeared in the `etags' command, usually without a
-directory specification."
-  (interactive (list (completing-read "List tags in file: "
-                                     'tags-complete-tags-table-file
-                                     nil t nil)))
+This searches only the first table in the list, and no included
+tables.  FILE should be as it appeared in the `etags' command,
+usually without a directory specification.  If called
+interactively, FILE defaults to the file name of the current
+buffer."
+  (interactive (list (completing-read
+                      "List tags in file: "
+                      'tags-complete-tags-table-file
+                      nil t
+                      ;; Default FILE to the current buffer.
+                      (tags--get-current-buffer-name-in-tags-file))))
   (with-output-to-temp-buffer "*Tags List*"
     (princ (substitute-command-keys "Tags in file `"))
     (tags-with-face 'highlight (princ file))