Subject: bug#67687: Feature request: automatic tags management

From: Stefan Kangas <[email-masked]>
Date: Fri, 29 Dec 2023 14:29:43 -0800

Dmitry Gutov <[email-masked]> writes:

> Fixed a typo in dir-locals and implemented better support for
> etags-regen-ignores (though with one omission).
>
> To me it looks good to check in now.

Thanks for working on this long overdue feature.

Do we really need a minor mode for this, or should it just be a
defcustom in etags?  We have tons of minor modes for this or that
various minor feature, and the list in e.g. `C-h m' is really starting
to look really long, at least in my use.  I wonder whether that is
really justified.

> diff --git a/.dir-locals.el b/.dir-locals.el
> index e087aa89cd1..ce7febca851 100644
> --- a/.dir-locals.el
> +++ b/.dir-locals.el
> @@ -8,6 +8,12 @@
>           (vc-git-annotate-switches . "-w")
>           (bug-reference-url-format . "https://debbugs.gnu.org/%s")
>  	 (diff-add-log-use-relative-names . t)
> +         (etags-regen-regexp-alist
> +          .
> +          ((("c" "objc") .
> +            ("/[ \t]*DEFVAR_[A-Z_ \t(]+\"\\([^\"]+\\)\"/\\1/"
> +             "/[ \t]*DEFVAR_[A-Z_ \t(]+\"[^\"]+\",[ \t]\\([A-Za-z0-9_]+\\)/\\1/"))))
> +         (etags-regen-ignores . ("test/manual/etags/"))

I'm not terribly familiar with how etags is implemented, so please
forgive me if some of these questions are naive.

Is there any way around having to do so much manual setup to get this to
work?  The above regexp is rather complex.

And is the idea that users will customize this by themselves?  Is it
feasible to shift most of that work to major mode authors [perhaps only
partially]?

> diff --git a/lisp/progmodes/etags-regen.el b/lisp/progmodes/etags-regen.el
> new file mode 100644
> index 00000000000..88b730195c3
> --- /dev/null
> +++ b/lisp/progmodes/etags-regen.el
> @@ -0,0 +1,411 @@
> +;;; etags-regen.el --- Auto-(re)regenerating tags  -*- lexical-binding: t -*-
> +
> +;; Copyright (C) 2021, 2023 Free Software Foundation, Inc.

Using just 2021-2023 here is fine.

> +;;; Commentary:
> +
> +;; Simple automatic tags generation with updates on save.
> +;;
> +;; The goal of this mode is to provide a feature that should be
> +;; familiar to the users of certain lightweight programmer's editors,
> +;; such as Sublime Text.  Which is "go to definition" with automatic
> +;; indexing, added in ST3 (released in 2017).

This makes it sound like we're just copying others, when we could be
more confident.  Emacs has had the described feature since before 2017.
I propose dropping all references to Sublime Text and reducing the above
to simply saying:

    This library provides automatic indexing for Emacs "go to
    definition" feature, the `xref-go-forward' command (bound to `M-.'
    by default).

> +;; At the moment reindexing works off before/after-save-hook, but to
> +;; handle more complex changes (e.g. the user switching to another

(We usually prefer "for example" to "e.g.".)