diff options
| author | Eli Zaretskii | 2024-10-04 14:39:50 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2024-10-04 14:39:50 +0300 |
| commit | e9dcf0c57ddea6a3ac3136e82cdb740326e735d4 (patch) | |
| tree | dc5b8fc51b8278a90e355e9c6393abd2202398cb | |
| parent | 51ef05f684c779b492965571cf9a169b93e86aa0 (diff) | |
| download | emacs-e9dcf0c57ddea6a3ac3136e82cdb740326e735d4.tar.gz emacs-e9dcf0c57ddea6a3ac3136e82cdb740326e735d4.zip | |
Fix 'list-tags' when invoked from a non-file buffer
This use case was broken by the improvement that attempts to
offer the current buffer's file name as the default file whose
tags to list.
* lisp/progmodes/etags.el
(tags--get-current-buffer-name-in-tags-file): Doc fix. Return nil
if no file is associated with the current buffer, and avoid
signaling an error if 'buffer-file-name' returns nil. (Bug#37611)
(list-tags): Doc fix. Signal an error if the user specifies no
file name at the prompt.
* doc/emacs/maintaining.texi (List Identifiers): Fix wording of
the documentation of 'list-tags'.
| -rw-r--r-- | doc/emacs/maintaining.texi | 15 | ||||
| -rw-r--r-- | lisp/progmodes/etags.el | 37 |
2 files changed, 32 insertions, 20 deletions
diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index 3c34afbaa20..a632ffda4ab 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi | |||
| @@ -2664,14 +2664,13 @@ loaded, this command can use it to generate completion candidates. | |||
| 2664 | @xref{Symbol Completion}. | 2664 | @xref{Symbol Completion}. |
| 2665 | 2665 | ||
| 2666 | @findex list-tags | 2666 | @findex list-tags |
| 2667 | @kbd{M-x list-tags} reads the name of one of the files covered by | 2667 | @kbd{M-x list-tags} reads the name of one of the files covered by the |
| 2668 | the selected tags table, and displays a list of tags defined in that | 2668 | selected tags table, with completion, and displays the list of tags |
| 2669 | file. Do not include a directory as part of the file name unless the | 2669 | defined in that file; it offers the current buffer's file name as the |
| 2670 | file name recorded in the tags table includes a directory. This | 2670 | default file whose tags to list. Do not include a directory as part of |
| 2671 | command works only with the etags backend, and requires a tags table | 2671 | the file name unless the file name recorded in the tags table includes a |
| 2672 | for the project to be available. @xref{Tags Tables}. If used | 2672 | directory. This command works only with the etags backend, and requires |
| 2673 | interactively, the default tag is file name of the current buffer if | 2673 | a tags table for the project to be available. @xref{Tags Tables}. |
| 2674 | used interactively. | ||
| 2675 | 2674 | ||
| 2676 | @findex tags-next-file | 2675 | @findex tags-next-file |
| 2677 | @kbd{M-x tags-next-file} visits files covered by the selected tags table. | 2676 | @kbd{M-x tags-next-file} visits files covered by the selected tags table. |
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index d3eb0d46e9b..35dc0215046 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el | |||
| @@ -1894,27 +1894,40 @@ description of the arguments." | |||
| 1894 | (try-completion string (tags-table-files) predicate)))) | 1894 | (try-completion string (tags-table-files) predicate)))) |
| 1895 | 1895 | ||
| 1896 | (defun tags--get-current-buffer-name-in-tags-file () | 1896 | (defun tags--get-current-buffer-name-in-tags-file () |
| 1897 | "Get the file name that the current buffer corresponds in the tags file." | 1897 | "Return file name that corresponds to the current buffer in the tags table. |
| 1898 | (let ((tag-dir | 1898 | This returns the file name which corresponds to the current buffer relative |
| 1899 | (save-excursion | 1899 | to the directory of the current tags table (see `visit-tags-table-buffer'). |
| 1900 | (visit-tags-table-buffer) | 1900 | If no file is associated with the current buffer, this function returns nil." |
| 1901 | (file-name-directory (buffer-file-name))))) | 1901 | (let ((buf-fname (buffer-file-name))) |
| 1902 | (file-relative-name (buffer-file-name) tag-dir))) | 1902 | ;; FIXME: Are there interesting cases where 'buffer-file-name' |
| 1903 | ;; returns nil, but there's some file we expect to find in TAGS that | ||
| 1904 | ;; is associated with the buffer? The obvious cases of Dired and | ||
| 1905 | ;; Info buffers are not interesting for TAGS, but are there any | ||
| 1906 | ;; others? | ||
| 1907 | (if buf-fname | ||
| 1908 | (let ((tag-dir | ||
| 1909 | (save-excursion | ||
| 1910 | (visit-tags-table-buffer) | ||
| 1911 | (file-name-directory buf-fname)))) | ||
| 1912 | (file-relative-name buf-fname tag-dir))))) | ||
| 1903 | 1913 | ||
| 1904 | ;;;###autoload | 1914 | ;;;###autoload |
| 1905 | (defun list-tags (file &optional _next-match) | 1915 | (defun list-tags (file &optional _next-match) |
| 1906 | "Display list of tags in file FILE. | 1916 | "Display list of tags in file FILE. |
| 1907 | This searches only the first table in the list, and no included | 1917 | Interactively, prompt for FILE, with completion, offering the current |
| 1908 | tables. FILE should be as it appeared in the `etags' command, | 1918 | buffer's file name as the defaul. |
| 1909 | usually without a directory specification. If called | 1919 | This command searches only the first table in the list of tags tables, |
| 1910 | interactively, FILE defaults to the file name of the current | 1920 | and does not search included tables. |
| 1911 | buffer." | 1921 | FILE should be as it was submitted to the `etags' command, which usually |
| 1922 | means relative to the directory of the tags table file." | ||
| 1912 | (interactive (list (completing-read | 1923 | (interactive (list (completing-read |
| 1913 | "List tags in file: " | 1924 | "List tags in file: " |
| 1914 | 'tags-complete-tags-table-file | 1925 | 'tags-complete-tags-table-file |
| 1915 | nil t | 1926 | nil t |
| 1916 | ;; Default FILE to the current buffer. | 1927 | ;; Default FILE to the current buffer's file. |
| 1917 | (tags--get-current-buffer-name-in-tags-file)))) | 1928 | (tags--get-current-buffer-name-in-tags-file)))) |
| 1929 | (if (string-empty-p file) | ||
| 1930 | (user-error "You must specify a file name")) | ||
| 1918 | (with-output-to-temp-buffer "*Tags List*" | 1931 | (with-output-to-temp-buffer "*Tags List*" |
| 1919 | (princ (substitute-command-keys "Tags in file `")) | 1932 | (princ (substitute-command-keys "Tags in file `")) |
| 1920 | (tags-with-face 'highlight (princ file)) | 1933 | (tags-with-face 'highlight (princ file)) |