unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#37611: [PATCH] Default FILE to the current buffer for list-tags
@ 2019-10-04  2:05 Hong Xu
  2019-10-04  7:59 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Hong Xu @ 2019-10-04  2:05 UTC (permalink / raw)
  To: 37611

* lisp/progmodes/etags.el (list-tags)
(tags--get-current-buffer-name-in-tags-file): Default FILE to the
current buffer for list-tags.
---
  lisp/progmodes/etags.el | 18 +++++++++++++++---
  1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index a03516100087..23acffcac299 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -1852,15 +1852,27 @@ tags-complete-tags-table-file
  	(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)))))
+    (when (string-prefix-p tag-dir (buffer-file-name))
+      (substring (buffer-file-name) (length tag-dir) nil))))
+
  ;;;###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)))
+  (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))
-- 
2.18.1






^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#37611: [PATCH] Default FILE to the current buffer for list-tags
  2019-10-04  2:05 bug#37611: [PATCH] Default FILE to the current buffer for list-tags Hong Xu
@ 2019-10-04  7:59 ` Eli Zaretskii
  2019-10-04 19:20   ` Hong Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2019-10-04  7:59 UTC (permalink / raw)
  To: Hong Xu; +Cc: 37611

> From: Hong Xu <hong@topbug.net>
> Date: Thu, 3 Oct 2019 19:05:08 -0700
> 
> * lisp/progmodes/etags.el (list-tags)
> (tags--get-current-buffer-name-in-tags-file): Default FILE to the
> current buffer for list-tags.
> ---
>   lisp/progmodes/etags.el | 18 +++++++++++++++---
>   1 file changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
> index a03516100087..23acffcac299 100644
> --- a/lisp/progmodes/etags.el
> +++ b/lisp/progmodes/etags.el
> @@ -1852,15 +1852,27 @@ tags-complete-tags-table-file
>   	(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."

Thanks.  The doc string of list-tags needs an update as result of
this, and also its documentation in the user manual.

Did you try this in the Emacs source tree?  We use the TAGS 'include'
facility to include various TAGS files in a single master file.  This
seems to get in the way when you invoke this command from a Lisp file,
because list-tags only recognizes one of the C source files as
completion candidates.  What does this do with your changes?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#37611: [PATCH] Default FILE to the current buffer for list-tags
  2019-10-04  7:59 ` Eli Zaretskii
@ 2019-10-04 19:20   ` Hong Xu
  2019-10-04 19:41     ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Hong Xu @ 2019-10-04 19:20 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 37611

On 10/4/19 12:59 AM, Eli Zaretskii wrote:
> Thanks.  The doc string of list-tags needs an update as result of
> this, and also its documentation in the user manual.

I will update the doc.

> 
> Did you try this in the Emacs source tree?  We use the TAGS 'include'
> facility to include various TAGS files in a single master file.  This
> seems to get in the way when you invoke this command from a Lisp file,
> because list-tags only recognizes one of the C source files as
> completion candidates.  What does this do with your changes?
> 

I tried in the Emacs source tree without problem (I ran universal ctags, "ctags -R -e ." from root of the source tree). How do you generate the TAGS file? Is there any instruction? I can take a look at it.






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#37611: [PATCH] Default FILE to the current buffer for list-tags
  2019-10-04 19:20   ` Hong Xu
@ 2019-10-04 19:41     ` Eli Zaretskii
  2019-10-05  0:38       ` Hong Xu
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2019-10-04 19:41 UTC (permalink / raw)
  To: Hong Xu; +Cc: 37611

> Cc: 37611@debbugs.gnu.org
> From: Hong Xu <hong@topbug.net>
> Date: Fri, 4 Oct 2019 12:20:46 -0700
> 
> > Did you try this in the Emacs source tree?  We use the TAGS 'include'
> > facility to include various TAGS files in a single master file.  This
> > seems to get in the way when you invoke this command from a Lisp file,
> > because list-tags only recognizes one of the C source files as
> > completion candidates.  What does this do with your changes?
> > 
> 
> I tried in the Emacs source tree without problem (I ran universal ctags, "ctags -R -e ." from root of the source tree). How do you generate the TAGS file? Is there any instruction? I can take a look at it.

I use "make TAGS", of course.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#37611: [PATCH] Default FILE to the current buffer for list-tags
  2019-10-04 19:41     ` Eli Zaretskii
@ 2019-10-05  0:38       ` Hong Xu
  2019-10-07  4:03         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 6+ messages in thread
From: Hong Xu @ 2019-10-05  0:38 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 37611

[-- Attachment #1: Type: text/plain, Size: 920 bytes --]

On 10/4/19 12:41 PM, Eli Zaretskii wrote:
>> Cc: 37611@debbugs.gnu.org
>> From: Hong Xu <hong@topbug.net>
>> Date: Fri, 4 Oct 2019 12:20:46 -0700
>>
>>> Did you try this in the Emacs source tree?  We use the TAGS 'include'
>>> facility to include various TAGS files in a single master file.  This
>>> seems to get in the way when you invoke this command from a Lisp file,
>>> because list-tags only recognizes one of the C source files as
>>> completion candidates.  What does this do with your changes?
>>>
>>
>> I tried in the Emacs source tree without problem (I ran universal ctags, "ctags -R -e ." from root of the source tree). How do you generate the TAGS file? Is there any instruction? I can take a look at it.
> 
> I use "make TAGS", of course.
> 


I updated the patch (as attached) so that it now works with the TAGS generated using `make TAGS` and also includes missing updates to docstring and info nodes.

[-- Attachment #2: 0001-Default-FILE-to-the-current-buffer-for-list-tags.patch --]
[-- Type: text/x-patch, Size: 3115 bytes --]

From a806553186635aeb0e7763490e41b0ac68e602c4 Mon Sep 17 00:00:00 2001
From: Hong Xu <hong@topbug.net>
Date: Thu, 3 Oct 2019 16:36:54 -0700
Subject: [PATCH] Default FILE to the current buffer for list-tags

* 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 (List Identifiers): Update `list-tags' doc.
---
 doc/emacs/maintaining.texi |  4 +++-
 lisp/progmodes/etags.el    | 25 +++++++++++++++++++------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
index 9a9957069fd6..519667dfbe92 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -2124,7 +2124,9 @@ List Identifiers
 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
diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index a03516100087..5edced5080e2 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -1852,15 +1852,28 @@ tags-complete-tags-table-file
 	(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))
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#37611: [PATCH] Default FILE to the current buffer for list-tags
  2019-10-05  0:38       ` Hong Xu
@ 2019-10-07  4:03         ` Lars Ingebrigtsen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-07  4:03 UTC (permalink / raw)
  To: Hong Xu; +Cc: 37611

Hong Xu <hong@topbug.net> writes:

> I updated the patch (as attached) so that it now works with the TAGS
> generated using `make TAGS` and also includes missing updates to
> docstring and info nodes.

Looks good to me, so I've now applied it to Emacs 27.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-10-07  4:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04  2:05 bug#37611: [PATCH] Default FILE to the current buffer for list-tags Hong Xu
2019-10-04  7:59 ` Eli Zaretskii
2019-10-04 19:20   ` Hong Xu
2019-10-04 19:41     ` Eli Zaretskii
2019-10-05  0:38       ` Hong Xu
2019-10-07  4:03         ` Lars Ingebrigtsen

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).