all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
@ 2019-09-26  9:52 Hong Xu
  2019-10-07  4:19 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 11+ messages in thread
From: Hong Xu @ 2019-09-26  9:52 UTC (permalink / raw)
  To: 37518

* lisp/progmodes/etags.el (tags--find-default-tags-dir)
(tags--find-default-tags-dir-impl, visit-tags-table): Search
upward from current dir for the default TAGS file
---
  lisp/progmodes/etags.el | 38 ++++++++++++++++++++++++++++++++------
  1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index a03516100087..81f0f135c577 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -274,6 +274,29 @@ tags-table-mode
    (setq buffer-undo-list t)
    (initialize-new-tags-table))
  
+(defun tags--find-default-tags-dir-impl (current-dir)
+  "Implements finding the directory that hosts the default TAGS file.
+It finds the first directory that contains a file named TAGS encountered
+searching upward from CURRENT-DIR."
+  (let ((tag-filename (expand-file-name "TAGS" current-dir)))
+    (if (file-exists-p tag-filename)
+        current-dir
+      (let ((parent-dir
+             (file-name-directory (directory-file-name current-dir))))
+        (if (string= parent-dir current-dir)  ;; root dir is reached
+            nil
+          (tags--find-default-tags-dir-impl parent-dir))))))
+
+(defun tags--find-default-tags-dir ()
+  "Find the directory that hosts the default TAGS file.
+It is the first directory that contains a file named TAGS encountered
+searching upward from `default-directory'."
+  (let ((default-tag-dir
+          (tags--find-default-tags-dir-impl default-directory)))
+    (if default-tag-dir
+        default-tag-dir
+      default-directory)))
+
  ;;;###autoload
  (defun visit-tags-table (file &optional local)
    "Tell tags commands to use tags table file FILE.
@@ -286,12 +309,15 @@ visit-tags-table
  When you find a tag with \\[find-tag], the buffer it finds the tag
  in is given a local value of this variable which is the name of the tags
  file the tag was in."
-  (interactive (list (read-file-name "Visit tags table (default TAGS): "
-				     default-directory
-				     (expand-file-name "TAGS"
-						       default-directory)
-				     t)
-		     current-prefix-arg))
+  (interactive
+   (let ((default-tag-dir (tags--find-default-tags-dir)))
+     (list (read-file-name
+            "Visit tags table (default TAGS): "
+            ;; default to TAGS from default-directory up to root.
+            default-tag-dir
+            (expand-file-name "TAGS" default-tag-dir)
+            t)))
+           current-prefix-arg)
    (or (stringp file) (signal 'wrong-type-argument (list 'stringp file)))
    ;; Bind tags-file-name so we can control below whether the local or
    ;; global value gets set.
-- 
2.20.1







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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-09-26  9:52 bug#37518: [PATCH] Search upward from current dir for the default TAGS file Hong Xu
@ 2019-10-07  4:19 ` Lars Ingebrigtsen
  2019-10-07  4:48   ` Hong Xu
  0 siblings, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-07  4:19 UTC (permalink / raw)
  To: Hong Xu; +Cc: 37518

Hong Xu <hong@topbug.net> writes:

> * lisp/progmodes/etags.el (tags--find-default-tags-dir)
> (tags--find-default-tags-dir-impl, visit-tags-table): Search
> upward from current dir for the default TAGS file

Sounds good.  Some minor comments:

[...]

>  +(defun tags--find-default-tags-dir-impl (current-dir)

We don't really call functions for "-impl" or the like -- as this
recurses upwards, what about calling it something more descriptive like
`tags--find-default-tags-dir-recursively'?

[...]

> +(defun tags--find-default-tags-dir ()
> +  "Find the directory that hosts the default TAGS file.
> +It is the first directory that contains a file named TAGS encountered
> +searching upward from `default-directory'."
> +  (let ((default-tag-dir
> +          (tags--find-default-tags-dir-impl default-directory)))
> +    (if default-tag-dir
> +        default-tag-dir
> +      default-directory)))

This is basically

(or (tags--find-default-tags-dir-impl default-directory)
    default-directory)

so I don't think this intermediary function is needed.

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





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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-07  4:19 ` Lars Ingebrigtsen
@ 2019-10-07  4:48   ` Hong Xu
  2019-10-07 16:24     ` Eli Zaretskii
  0 siblings, 1 reply; 11+ messages in thread
From: Hong Xu @ 2019-10-07  4:48 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 37518

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

Thanks. I've attached an updated patch below.

On 10/6/19 9:19 PM, Lars Ingebrigtsen wrote:
> 
>>   +(defun tags--find-default-tags-dir-impl (current-dir)
> 
> We don't really call functions for "-impl" or the like -- as this
> recurses upwards, what about calling it something more descriptive like
> `tags--find-default-tags-dir-recursively'?

Makes sense.


> 
> This is basically
> 
> (or (tags--find-default-tags-dir-impl default-directory)
>      default-directory)
> 
> so I don't think this intermediary function is needed.

How could I forget the magical "or" :)

[-- Attachment #2: 0001-Search-upward-from-current-dir-for-the-default-TAGS-.patch --]
[-- Type: text/x-patch, Size: 3734 bytes --]

From db1a9407f427c9d08957b9552560ff9dbb753c48 Mon Sep 17 00:00:00 2001
From: Hong Xu <hong@topbug.net>
Date: Sun, 6 Oct 2019 21:42:57 -0700
Subject: [PATCH] Search upward from current dir for the default TAGS file

* lisp/progmodes/etags.el (tags--find-default-tags-dir-recursively)
(visit-tags-table): Search upward from current dir for the default
TAGS file

* doc/emacs/maintaining.texi (Select Tags Table): Update the doc
of `visit-tags-table'.
---
 doc/emacs/maintaining.texi | 11 ++++++-----
 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 519667dfbe92..9d1da2ee497a 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -2666,11 +2666,12 @@ Select Tags Table
 @subsection Selecting a Tags Table
 
 @findex visit-tags-table
-  Emacs has at any time at most one @dfn{selected} tags table.  All the
-commands for working with tags tables use the selected one.  To select
-a tags table, type @kbd{M-x visit-tags-table}, which reads the tags
-table file name as an argument, with @file{TAGS} in the default
-directory as the default.
+  Emacs has at any time at most one @dfn{selected} tags table.  All
+the commands for working with tags tables use the selected one.  To
+select a tags table, type @kbd{M-x visit-tags-table}, which reads the
+tags table file name as an argument, with @file{TAGS} defaulting to
+the first directory that contains a file named TAGS encountered when
+recursively searching upward from the default directory.
 
 @vindex tags-file-name
   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 c40422dbc5c3..5cc62543415f 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -274,6 +274,19 @@ tags-table-mode
   (setq buffer-undo-list t)
   (initialize-new-tags-table))
 
+(defun tags--find-default-tags-dir-recursively (current-dir)
+  "Find the directory that hosts the default TAGS file.
+It is the first directory that contains a file named TAGS
+encountered when recursively searching upward from CURRENT-DIR."
+  (let ((tag-filename (expand-file-name "TAGS" current-dir)))
+    (if (file-exists-p tag-filename)
+        current-dir
+      (let ((parent-dir
+             (file-name-directory (directory-file-name current-dir))))
+        (if (string= parent-dir current-dir)  ;; root dir is reached
+            nil
+          (tags--find-default-tags-dir-recursively parent-dir))))))
+
 ;;;###autoload
 (defun visit-tags-table (file &optional local)
   "Tell tags commands to use tags table file FILE.
@@ -286,12 +299,18 @@ visit-tags-table
 When you find a tag with \\[find-tag], the buffer it finds the tag
 in is given a local value of this variable which is the name of the tags
 file the tag was in."
-  (interactive (list (read-file-name "Visit tags table (default TAGS): "
-				     default-directory
-				     (expand-file-name "TAGS"
-						       default-directory)
-				     t)
-		     current-prefix-arg))
+  (interactive
+   (let ((default-tag-dir
+           (or (tags--find-default-tags-dir-recursively default-directory)
+               default-directory)))
+     (list (read-file-name
+            "Visit tags table (default TAGS): "
+            ;; default to TAGS from default-directory up to root.
+            default-tag-dir
+            (expand-file-name "TAGS" default-tag-dir)
+            t)))
+   current-prefix-arg)
+
   (or (stringp file) (signal 'wrong-type-argument (list 'stringp file)))
   ;; Bind tags-file-name so we can control below whether the local or
   ;; global value gets set.
-- 
2.20.1


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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-07  4:48   ` Hong Xu
@ 2019-10-07 16:24     ` Eli Zaretskii
  2019-10-07 17:36       ` Hong Xu
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2019-10-07 16:24 UTC (permalink / raw)
  To: Hong Xu; +Cc: larsi, 37518

> From: Hong Xu <hong@topbug.net>
> Date: Sun, 6 Oct 2019 21:48:52 -0700
> Cc: 37518@debbugs.gnu.org
> 
> +tags table file name as an argument, with @file{TAGS} defaulting to
> +the first directory that contains a file named TAGS encountered when
> +recursively searching upward from the default directory.

The second instance of "TAGS" should also have the @file markup.

> +(defun tags--find-default-tags-dir-recursively (current-dir)
> +  "Find the directory that hosts the default TAGS file.

"hosts" might be somewhat confusing.  How about

  Find the directory with the default TAGS file.

?





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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-07 16:24     ` Eli Zaretskii
@ 2019-10-07 17:36       ` Hong Xu
  2019-10-07 18:43         ` Eli Zaretskii
  2019-10-08 16:45         ` Lars Ingebrigtsen
  0 siblings, 2 replies; 11+ messages in thread
From: Hong Xu @ 2019-10-07 17:36 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, 37518

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

See the attached update.

On 10/7/19 9:24 AM, Eli Zaretskii wrote:
>> From: Hong Xu <hong@topbug.net>
>> Date: Sun, 6 Oct 2019 21:48:52 -0700
>> Cc: 37518@debbugs.gnu.org
> 
> The second instance of "TAGS" should also have the @file markup.

Yes.

> 
>> +(defun tags--find-default-tags-dir-recursively (current-dir)
>> +  "Find the directory that hosts the default TAGS file.
> 
> "hosts" might be somewhat confusing.  How about
> 
>    Find the directory with the default TAGS file.
> 

I changed it to

      Find the directory in which the default TAGS file sits.

Hopefully this is more articulate than "with".

[-- Attachment #2: 0001-Search-upward-from-current-dir-for-the-default-TAGS-.patch --]
[-- Type: text/x-patch, Size: 3744 bytes --]

From c970ae7913bdf4803be07d6fcf895359825747bc Mon Sep 17 00:00:00 2001
From: Hong Xu <hong@topbug.net>
Date: Sun, 6 Oct 2019 21:42:57 -0700
Subject: [PATCH] Search upward from current dir for the default TAGS file

* lisp/progmodes/etags.el (tags--find-default-tags-dir-recursively)
(visit-tags-table): Search upward from current dir for the default
TAGS file

* doc/emacs/maintaining.texi (Select Tags Table): Update the doc
of `visit-tags-table'.
---
 doc/emacs/maintaining.texi | 11 ++++++-----
 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 519667dfbe92..ef448dd595be 100644
--- a/doc/emacs/maintaining.texi
+++ b/doc/emacs/maintaining.texi
@@ -2666,11 +2666,12 @@ Select Tags Table
 @subsection Selecting a Tags Table
 
 @findex visit-tags-table
-  Emacs has at any time at most one @dfn{selected} tags table.  All the
-commands for working with tags tables use the selected one.  To select
-a tags table, type @kbd{M-x visit-tags-table}, which reads the tags
-table file name as an argument, with @file{TAGS} in the default
-directory as the default.
+  Emacs has at any time at most one @dfn{selected} tags table.  All
+the commands for working with tags tables use the selected one.  To
+select a tags table, type @kbd{M-x visit-tags-table}, which reads the
+tags table file name as an argument, with @file{TAGS} defaulting to
+the first directory that contains a file named @file{TAGS} encountered
+when recursively searching upward from the default directory.
 
 @vindex tags-file-name
   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 c40422dbc5c3..e5cf5f156559 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -274,6 +274,19 @@ tags-table-mode
   (setq buffer-undo-list t)
   (initialize-new-tags-table))
 
+(defun tags--find-default-tags-dir-recursively (current-dir)
+  "Find the directory in which the default TAGS file sits.
+It is the first directory that contains a file named TAGS
+encountered when recursively searching upward from CURRENT-DIR."
+  (let ((tag-filename (expand-file-name "TAGS" current-dir)))
+    (if (file-exists-p tag-filename)
+        current-dir
+      (let ((parent-dir
+             (file-name-directory (directory-file-name current-dir))))
+        (if (string= parent-dir current-dir)  ;; root dir is reached
+            nil
+          (tags--find-default-tags-dir-recursively parent-dir))))))
+
 ;;;###autoload
 (defun visit-tags-table (file &optional local)
   "Tell tags commands to use tags table file FILE.
@@ -286,12 +299,18 @@ visit-tags-table
 When you find a tag with \\[find-tag], the buffer it finds the tag
 in is given a local value of this variable which is the name of the tags
 file the tag was in."
-  (interactive (list (read-file-name "Visit tags table (default TAGS): "
-				     default-directory
-				     (expand-file-name "TAGS"
-						       default-directory)
-				     t)
-		     current-prefix-arg))
+  (interactive
+   (let ((default-tag-dir
+           (or (tags--find-default-tags-dir-recursively default-directory)
+               default-directory)))
+     (list (read-file-name
+            "Visit tags table (default TAGS): "
+            ;; default to TAGS from default-directory up to root.
+            default-tag-dir
+            (expand-file-name "TAGS" default-tag-dir)
+            t)))
+   current-prefix-arg)
+
   (or (stringp file) (signal 'wrong-type-argument (list 'stringp file)))
   ;; Bind tags-file-name so we can control below whether the local or
   ;; global value gets set.
-- 
2.20.1


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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-07 17:36       ` Hong Xu
@ 2019-10-07 18:43         ` Eli Zaretskii
  2019-10-07 18:52           ` Hong Xu
  2019-10-08 16:45         ` Lars Ingebrigtsen
  1 sibling, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2019-10-07 18:43 UTC (permalink / raw)
  To: Hong Xu; +Cc: larsi, 37518

> Cc: larsi@gnus.org, 37518@debbugs.gnu.org
> From: Hong Xu <hong@topbug.net>
> Date: Mon, 7 Oct 2019 10:36:36 -0700
> 
> > "hosts" might be somewhat confusing.  How about
> > 
> >    Find the directory with the default TAGS file.
> > 
> 
> I changed it to
> 
>       Find the directory in which the default TAGS file sits.

We are splitting hair, but I'd like to use "lives" instead of "sits".





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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-07 18:43         ` Eli Zaretskii
@ 2019-10-07 18:52           ` Hong Xu
  0 siblings, 0 replies; 11+ messages in thread
From: Hong Xu @ 2019-10-07 18:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: larsi, 37518

On 10/7/19 11:43 AM, Eli Zaretskii wrote:
>> Cc: larsi@gnus.org, 37518@debbugs.gnu.org
>> From: Hong Xu <hong@topbug.net>
>> Date: Mon, 7 Oct 2019 10:36:36 -0700
>>
>>> "hosts" might be somewhat confusing.  How about
>>>
>>>     Find the directory with the default TAGS file.
>>>
>>
>> I changed it to
>>
>>        Find the directory in which the default TAGS file sits.
> 
> We are splitting hair, but I'd like to use "lives" instead of "sits".
> 

Sounds good to me.






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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-07 17:36       ` Hong Xu
  2019-10-07 18:43         ` Eli Zaretskii
@ 2019-10-08 16:45         ` Lars Ingebrigtsen
  2019-10-08 19:46           ` Phil Sainty
  1 sibling, 1 reply; 11+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-08 16:45 UTC (permalink / raw)
  To: Hong Xu; +Cc: 37518

Hong Xu <hong@topbug.net> writes:

> See the attached update.

Thanks; I've now applied it (along with the "lives" change from Eli; I
also fixed an apparently wrongly placed parenthesis in the interactive
spec).

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





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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-08 16:45         ` Lars Ingebrigtsen
@ 2019-10-08 19:46           ` Phil Sainty
  2019-10-09  0:38             ` Hong Xu
  2019-10-09  5:01             ` Hong Xu
  0 siblings, 2 replies; 11+ messages in thread
From: Phil Sainty @ 2019-10-08 19:46 UTC (permalink / raw)
  To: Hong Xu; +Cc: Lars Ingebrigtsen, 37518

I might be missing something here, but this sounds like it reimplements
`locate-dominating-file'?  Could the patch be rewritten to use that?

-Phil






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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-08 19:46           ` Phil Sainty
@ 2019-10-09  0:38             ` Hong Xu
  2019-10-09  5:01             ` Hong Xu
  1 sibling, 0 replies; 11+ messages in thread
From: Hong Xu @ 2019-10-09  0:38 UTC (permalink / raw)
  To: Phil Sainty; +Cc: Lars Ingebrigtsen, 37518



On October 8, 2019 12:46:50 PM PDT, Phil Sainty <psainty@orcon.net.nz> wrote:
>I might be missing something here, but this sounds like it reimplements
>`locate-dominating-file'?  Could the patch be rewritten to use that?
>

I think you are right about it. Will send a patch.






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

* bug#37518: [PATCH] Search upward from current dir for the default TAGS file
  2019-10-08 19:46           ` Phil Sainty
  2019-10-09  0:38             ` Hong Xu
@ 2019-10-09  5:01             ` Hong Xu
  1 sibling, 0 replies; 11+ messages in thread
From: Hong Xu @ 2019-10-09  5:01 UTC (permalink / raw)
  To: Phil Sainty; +Cc: Lars Ingebrigtsen, 37518

On 10/8/19 12:46 PM, Phil Sainty wrote:
> I might be missing something here, but this sounds like it reimplements
> `locate-dominating-file'?  Could the patch be rewritten to use that?
> 
Thanks, a patch has been sent to bug#37673







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

end of thread, other threads:[~2019-10-09  5:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-26  9:52 bug#37518: [PATCH] Search upward from current dir for the default TAGS file Hong Xu
2019-10-07  4:19 ` Lars Ingebrigtsen
2019-10-07  4:48   ` Hong Xu
2019-10-07 16:24     ` Eli Zaretskii
2019-10-07 17:36       ` Hong Xu
2019-10-07 18:43         ` Eli Zaretskii
2019-10-07 18:52           ` Hong Xu
2019-10-08 16:45         ` Lars Ingebrigtsen
2019-10-08 19:46           ` Phil Sainty
2019-10-09  0:38             ` Hong Xu
2019-10-09  5:01             ` Hong Xu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.