unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Globally apply xref-etags-mode
@ 2023-11-11 11:23 Matt
  2023-11-11 13:58 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Matt @ 2023-11-11 11:23 UTC (permalink / raw)
  To: emacs-devel

I'm working from a local copy of a specific org-mode checkout and want xref to navigate within the checkout directory, not within the currently loaded Org mode (which is not /tmp/org-mode).

It seems like xref-etags-mode is what I need.  However, it only appears to apply locally.  I cannot get it to function globally; I must call it on every buffer.

For example, I've built and visited TAGS for /tmp/org-mode.  

cd /tmp
git clone https://git.savannah.gnu.org/git/emacs/org-mode.git
cd org-mode
git -c advice.detachedHead=false checkout 9183e3c723b812360d1042196416d521db590e9f
ctags -eR .

(find-file "/tmp/org-mode/lisp/ob-shell.el")
(visit-tags-table "/tmp/org-mode/TAGS")

I call M-x xref-etags-mode in the buffer visiting ob-shell.el.  I search for "babel-eval" and call xref-find-definitions.  This takes me to /tmp/org-mode/lisp/ob-eval.el as expected.  However, if I check C-h v xref-etags-mode, I see that it's nil in the ob-eval.el buffer.  Calling xref-find-definitions on "org-assert-version", it fails to take me anywhere.  (When I run it with my full init, it takes me to the Emacs system directory lisp/org/org-macs.el.gz.)  Calling M-x xref-etags-mode within the buffer visiting ob-eval.el allows me to call xref-find-definitions and takes me to the expected file, /tmp/org-mode/lisp/org-macs.el.

I can set a hook that calls xref-etags-mode after every jump:

   (add-hook 'xref-after-jump-hook (lambda () (xref-etags-mode 1)))

However, I find all this behavior unexpected.  I would expect xref-etags-mode to apply globally.  It's not clear to me why it's only buffer local.  If there's some reason I'm missing, then I would expect to see a global-xref-etags-mode function.  This don't seem to exist.

Is this expected behavior?  If not, should I put in a PR that adds :global t to the define-minor-mode xref-etags-mode?




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

* Re: Globally apply xref-etags-mode
  2023-11-11 11:23 Globally apply xref-etags-mode Matt
@ 2023-11-11 13:58 ` Eli Zaretskii
  2023-11-11 14:15   ` Matt
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2023-11-11 13:58 UTC (permalink / raw)
  To: Matt; +Cc: emacs-devel

> Date: Sat, 11 Nov 2023 12:23:21 +0100
> From: Matt <matt@excalamus.com>
> 
> It seems like xref-etags-mode is what I need.  However, it only appears to apply locally.  I cannot get it to function globally; I must call it on every buffer.

The usual way of solving this is with a hooks, like some mode hook or
maybe find-file-hook.



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

* Re: Globally apply xref-etags-mode
  2023-11-11 13:58 ` Eli Zaretskii
@ 2023-11-11 14:15   ` Matt
  2023-11-12  1:35     ` Dmitry Gutov
  0 siblings, 1 reply; 6+ messages in thread
From: Matt @ 2023-11-11 14:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


 ---- On Sat, 11 Nov 2023 14:58:54 +0100  Eli Zaretskii  wrote --- 

 > The usual way of solving this is with a hooks, like some mode hook or
 > maybe find-file-hook.

Thank you.

It appears like the benefit of using hooks for this is fine grained control.

To help future readers with a similar question, I was able to achieve the behavior I want with the following:

;; we want xref to navigate within the checkout directory, not within
;; the currently loaded Org mode (which is not the checkout).

;; generate TAGS file
(call-interactively
 #'(lambda ()
     "Basically calls 'ctags -eR [DIR]' on the given directory."
     (interactive)
     (xc/build-tags "/tmp/org-mode/" nil nil t)))

;; enable `xref-etags-mode' for buffers visiting files in the Org mode
;; clone directory
(add-hook 'xref-after-jump-hook
          (lambda ()
            (if (string= "tmp" (cadr (file-name-split (file-name-directory (buffer-file-name)))))
                (xref-etags-mode 1))))

;; open the file of interest
(find-file-other-window "/tmp/org-mode/lisp/ob-shell.el")

;;  Bootstrap the TAGS referencing
(with-current-buffer "ob-shell.el"
  (xref-etags-mode))




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

* Re: Globally apply xref-etags-mode
  2023-11-11 14:15   ` Matt
@ 2023-11-12  1:35     ` Dmitry Gutov
  2023-11-12  6:22       ` Eli Zaretskii
  2023-11-12  9:47       ` Matt
  0 siblings, 2 replies; 6+ messages in thread
From: Dmitry Gutov @ 2023-11-12  1:35 UTC (permalink / raw)
  To: Matt, Eli Zaretskii; +Cc: emacs-devel

On 11/11/2023 16:15, Matt wrote:
>              (if (string= "tmp" (cadr (file-name-split (file-name-directory (buffer-file-name)))))

This should be shorter:

   (if (string-match-p "^/tmp/" (buffer-file-name))

> ;;  Bootstrap the TAGS referencing
> (with-current-buffer "ob-shell.el"
>    (xref-etags-mode))

Or just 'M-x xref-etags-mode'?

If there is a significant demand for it, we could add 
global-xref-etags-mode (with 'define-globalized-minor-mode'), which 
would affect all buffers. But so far questions like this one seem rare 
enough.

And for some reason or other, you also decided to only turn this minor 
mode on in certain files.



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

* Re: Globally apply xref-etags-mode
  2023-11-12  1:35     ` Dmitry Gutov
@ 2023-11-12  6:22       ` Eli Zaretskii
  2023-11-12  9:47       ` Matt
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2023-11-12  6:22 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: matt, emacs-devel

> Date: Sun, 12 Nov 2023 03:35:28 +0200
> Cc: emacs-devel <emacs-devel@gnu.org>
> From: Dmitry Gutov <dmitry@gutov.dev>
> 
> If there is a significant demand for it, we could add 
> global-xref-etags-mode (with 'define-globalized-minor-mode'), which 
> would affect all buffers. But so far questions like this one seem rare 
> enough.

It makes no sense to me to have a this as a global mode, since it
couldn't be TRT for all the major modes.



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

* Re: Globally apply xref-etags-mode
  2023-11-12  1:35     ` Dmitry Gutov
  2023-11-12  6:22       ` Eli Zaretskii
@ 2023-11-12  9:47       ` Matt
  1 sibling, 0 replies; 6+ messages in thread
From: Matt @ 2023-11-12  9:47 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Eli Zaretskii, emacs-devel


 ---- On Sun, 12 Nov 2023 02:35:28 +0100  Dmitry Gutov  wrote --- 

Thank you for the code improvements.
 
 > And for some reason or other, you also decided to only turn this minor 
 > mode on in certain files.

This is a logic error.  Ideally, I'd like to lookup Org functions using the clone in /tmp and everything else using the normal mechanism.  I'm not sure how to do that.  Turning on xref-etags-mode was a poorly thought out attempt to limit where TAGS was used for lookup.

Turning on xref-etags-mode through hooks (for all files) is a good-enough solution for what I need.  Although non-org symbols aren't found, I can still navigate to them through Emacs help (C-h f, C-h v, etc.)



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

end of thread, other threads:[~2023-11-12  9:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-11 11:23 Globally apply xref-etags-mode Matt
2023-11-11 13:58 ` Eli Zaretskii
2023-11-11 14:15   ` Matt
2023-11-12  1:35     ` Dmitry Gutov
2023-11-12  6:22       ` Eli Zaretskii
2023-11-12  9:47       ` Matt

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