* etags - Word separators with xref-find-definitions
@ 2021-07-25 8:56 Christian Barthel
2021-07-25 14:02 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Christian Barthel @ 2021-07-25 8:56 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I am using a TAGS file with a custom regex for SQL function, view
and table definitions. At the moment, I am using this:
--8<---------------cut here---------------start------------->8---
etags --language=none \
--regex='/[ \t]*create\( or replace\)*[ \t][ \t]*\(function\|view\|table\)[ \t]*\([^ (]*\)/\3/i'
*.sql
--8<---------------cut here---------------end--------------->8---
The TAGS file contains identifiers like ‘schema.objectname’.
However, when I am trying to use M-. (xref-find-definitions), it
either searches for ‘schema’ or ‘objectname’ (depending on the
location of the point).
Is it possible to customize the xref function such that it
recognize ‘schema.objectname’? Are there any variables to
control the behavior of M-. ?
(Something similar happens for LaTeX references: I am using
\label{chapter:foobar}, but the : is lost and I can’t easily jump
to the reference)
My current workaround is to use C-u M-. and enter the name
manually but it would be nicer to directly jump to the definition.
Thanks!
--
Christian Barthel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: etags - Word separators with xref-find-definitions
2021-07-25 8:56 etags - Word separators with xref-find-definitions Christian Barthel
@ 2021-07-25 14:02 ` Eli Zaretskii
2021-07-25 17:52 ` Christian Barthel
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2021-07-25 14:02 UTC (permalink / raw)
To: help-gnu-emacs
> From: Christian Barthel <bch@online.de>
> Date: Sun, 25 Jul 2021 10:56:01 +0200
>
> I am using a TAGS file with a custom regex for SQL function, view
> and table definitions. At the moment, I am using this:
>
> --8<---------------cut here---------------start------------->8---
> etags --language=none \
> --regex='/[ \t]*create\( or replace\)*[ \t][ \t]*\(function\|view\|table\)[ \t]*\([^ (]*\)/\3/i'
> *.sql
> --8<---------------cut here---------------end--------------->8---
>
> The TAGS file contains identifiers like ‘schema.objectname’.
> However, when I am trying to use M-. (xref-find-definitions), it
> either searches for ‘schema’ or ‘objectname’ (depending on the
> location of the point).
>
> Is it possible to customize the xref function such that it
> recognize ‘schema.objectname’? Are there any variables to
> control the behavior of M-. ?
You need to customize the etags.el function that is used to guess the
symbol at point. The function is this:
(defun find-tag--default ()
(funcall (or find-tag-default-function
(get major-mode 'find-tag-default-function)
#'find-tag-default)))
So either customizing find-tag-default-function to point to a function
of your choice, or making such a function local to the SQL major mode
by putting the property on the major-mode's symbol, should do the
job. You will probably need to write the function itself, though.
> (Something similar happens for LaTeX references: I am using
> \label{chapter:foobar}, but the : is lost and I can’t easily jump
> to the reference)
You could do the same there, just with a slightly different function.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: etags - Word separators with xref-find-definitions
2021-07-25 14:02 ` Eli Zaretskii
@ 2021-07-25 17:52 ` Christian Barthel
2021-07-25 19:04 ` Eli Zaretskii
2021-07-26 14:45 ` Leo Butler
0 siblings, 2 replies; 5+ messages in thread
From: Christian Barthel @ 2021-07-25 17:52 UTC (permalink / raw)
To: help-gnu-emacs
On Sun, Jul 25 2021, Eli Zaretskii wrote:
>> Is it possible to customize the xref function such that it
>> recognize ‘schema.objectname’? Are there any variables to
>> control the behavior of M-. ?
>
> You need to customize the etags.el function that is used to guess the
> symbol at point. The function is this:
>
> (defun find-tag--default ()
> (funcall (or find-tag-default-function
> (get major-mode 'find-tag-default-function)
> #'find-tag-default)))
>
> So either customizing find-tag-default-function to point to a function
> of your choice, or making such a function local to the SQL major mode
> by putting the property on the major-mode's symbol, should do the
> job. You will probably need to write the function itself, though.
OK, thanks so far. My first draft for this looks something like
this:
--8<---------------cut here---------------start------------->8---
(defun find-sql-identifier ()
(when (thing-at-point-looking-at
"\\([.a-zA-Z0-9]*\\)" 50)
(if (match-beginning 1)
(buffer-substring (match-beginning 1) (match-end 1))
"")))
(put major-mode 'find-tag-default-function 'find-sql-identifier)
--8<---------------cut here---------------end--------------->8---
This works for my contrived SQL file as expected, but I guess
that I need some further improvements when using this on a larger
sql code repository .
I think that I will execute the put function (setting
find-tag-default-function) in the sql-mode-hook or is there a
better place to do this?
--
Christian Barthel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: etags - Word separators with xref-find-definitions
2021-07-25 17:52 ` Christian Barthel
@ 2021-07-25 19:04 ` Eli Zaretskii
2021-07-26 14:45 ` Leo Butler
1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2021-07-25 19:04 UTC (permalink / raw)
To: help-gnu-emacs
> From: Christian Barthel <bch@online.de>
> Date: Sun, 25 Jul 2021 19:52:58 +0200
>
> I think that I will execute the put function (setting
> find-tag-default-function) in the sql-mode-hook or is there a
> better place to do this?
It's possible. An alternative is to do that up front in your init
file, and then you can do that just once.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: etags - Word separators with xref-find-definitions
2021-07-25 17:52 ` Christian Barthel
2021-07-25 19:04 ` Eli Zaretskii
@ 2021-07-26 14:45 ` Leo Butler
1 sibling, 0 replies; 5+ messages in thread
From: Leo Butler @ 2021-07-26 14:45 UTC (permalink / raw)
To: Christian Barthel; +Cc: help-gnu-emacs
Christian Barthel <bch@online.de> writes:
> On Sun, Jul 25 2021, Eli Zaretskii wrote:
>
>>> Is it possible to customize the xref function such that it
>>> recognize ‘schema.objectname’? Are there any variables to
>>> control the behavior of M-. ?
>>
>> You need to customize the etags.el function that is used to guess the
>> symbol at point. The function is this:
>>
>> (defun find-tag--default ()
>> (funcall (or find-tag-default-function
>> (get major-mode 'find-tag-default-function)
>> #'find-tag-default)))
>>
>> So either customizing find-tag-default-function to point to a function
>> of your choice, or making such a function local to the SQL major mode
>> by putting the property on the major-mode's symbol, should do the
>> job. You will probably need to write the function itself, though.
>
> OK, thanks so far. My first draft for this looks something like
> this:
>
> (defun find-sql-identifier ()
> (when (thing-at-point-looking-at
> "\\([.a-zA-Z0-9]*\\)" 50)
> (if (match-beginning 1)
> (buffer-substring (match-beginning 1) (match-end 1))
> "")))
> (put major-mode 'find-tag-default-function 'find-sql-identifier)
Thanks for these pointers, Eli and Christian. I was able to fix a
similar problem I had with `xref-find-definitions' when trying to use it
with latex-mode to look up bibtex citations.
Leo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-07-26 14:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-25 8:56 etags - Word separators with xref-find-definitions Christian Barthel
2021-07-25 14:02 ` Eli Zaretskii
2021-07-25 17:52 ` Christian Barthel
2021-07-25 19:04 ` Eli Zaretskii
2021-07-26 14:45 ` Leo Butler
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).