bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#53749: 29.0.50; [PATCH] Xref backend for TeX buffers


From: David Fussner
Subject: bug#53749: 29.0.50; [PATCH] Xref backend for TeX buffers
Date: Sun, 9 Jun 2024 19:42:29 +0100

Hi Stefan, 

Thanks very much for the review. I'll try to address most of it in a revised patch tomorrow, but I did want to explain now that the default implementation of xref-find-references in xref.el uses semantic symref functionality to search files. The TeX backend puts a wrapper around it, but doesn't, following Dmitry's advice, try to reinvent that wheel. As for where we set the filepattern variable, I don't mind, but AUCTeX is setting it internally for their modes, so it seemed OK in tex-mode, too.

More tomorrow, and thanks again. 

David. 

On Sun, 9 Jun 2024, 12:36 Stefan Kangas, <stefankangas@gmail.com> wrote:
David Fussner <dfussner@googlemail.com> writes:

> In case the changeset might prove acceptable for version 30, I attach
> the latest patch, which clears out the code I was using to simplify
> testing of the AUCTeX modes.

I have some comments and questions:

- Does this need a NEWS entry?

- I see the brief text you added to tex-mode.el explaining more about
  expl3, but perhaps there should be a clear explanation in the commit
  message too.

- [Optional: In most places you use spaces for indentation, but here and
  there, there is a single tab followed by one or more spaces.  Consider
  using only spaces.]

> From: David Fussner <dfussner@googlemail.com>
> Date: Wed, 5 Jun 2024 10:26:18 +0100
> Subject: [PATCH] Provide a modified xref backend for TeX buffers

[Don't forget to add the bug number to the ChangeLog.]

> diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi
> index 579098c81b1..a064103aa25 100644
> --- a/doc/emacs/maintaining.texi
> +++ b/doc/emacs/maintaining.texi
> @@ -2529,6 +2529,15 @@ Identifier Search
>  referenced.  The XREF mode commands are available in this buffer, see
>  @ref{Xref Commands}.
>
> +When invoked in a buffer whose major mode uses the @code{etags} backend,
> +@kbd{M-?} searches files and buffers whose major mode matches that of
> +the original buffer.  It guesses that mode from file extensions, so if
> +@kbd{M-?} seems to be skipping relevant buffers or files, try
> +customizing either the variable @code{semantic-symref-filepattern-alist}

Why does this speak of Semantic?  Does `xref-find-references` depend on
it somehow?

> diff --git a/lib-src/etags.c b/lib-src/etags.c
> index 03bc55de03d..6bc734e7df0 100644
> --- a/lib-src/etags.c
> +++ b/lib-src/etags.c
> @@ -5740,11 +5756,25 @@ Scheme_functions (FILE *inf)
>  static linebuffer *TEX_toktab = NULL; /* Table with tag tokens */
>
>  /* Default set of control sequences to put into TEX_toktab.
> -   The value of environment var TEXTAGS is prepended to this.  */
> +   The value of environment var TEXTAGS is prepended to this.
> +   (2024) Add variants of '\def', some additional LaTeX (and
> +   former xparse) commands, common variants from the
> +   'etoolbox' package, and the main expl3 commands. */

Do we really need this comment?  Isn't the git log enough?

> diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
> index 97c950267c6..fbf08840699 100644
> --- a/lisp/textmodes/tex-mode.el
> +++ b/lisp/textmodes/tex-mode.el
> @@ -636,6 +636,14 @@ tex-font-lock-keywords-2
>             3 '(tex-font-lock-append-prop 'bold) 'append)))))
>     "Gaudy expressions to highlight in TeX modes.")
>
> +(defvar-local tex-expl-region-list nil
> +  "List of region boundaries where expl3 syntax is active.
> +It will be nil in buffers where expl3 syntax is always active, e.g.,

Please prefer "for example" to "e.g.".

> +(defvar-local tex-expl-buffer-p nil
> +  "Non-nil in buffers where expl3 syntax is always active.")

What does "always active" mean as compared to just "active"?
Does this need to be elaborated?

> +;; Populate `semantic-symref-filepattern-alist' for the in-tree modes;
> +;; AUCTeX is doing the same for its modes.
> +(with-eval-after-load 'semantic/symref/grep
> +  (defvar semantic-symref-filepattern-alist)
> +  (push '(latex-mode "*.[tT]e[xX]" "*.ltx" "*.sty" "*.cl[so]"
> +                     "*.bbl" "*.drv" "*.hva")
> +        semantic-symref-filepattern-alist)
> +  (push '(plain-tex-mode "*.[tT]e[xX]" "*.ins")
> +        semantic-symref-filepattern-alist)
> +  (push '(doctex-mode "*.dtx") semantic-symref-filepattern-alist))

Doesn't this stuff rather belong in semantic itself?

> +(cl-defmethod xref-backend-references ((_backend (eql 'tex-etags)) identifier)
> +  "Find references of IDENTIFIER in TeX buffers and files."
> +  (require 'semantic/symref/grep)

Are we sure that we want to make this depend on semantic?

Is there any way around that?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]