Emacs 30: etags-regen-mode

It's been close to one year that I exclusively use Emacs for anything I do on a computer, be coding activities, be reading emails or man pages, be writing music sheets with GNU lilypond. I decommissioned all the specific tools (like vim, mutt) which all require a mental effort to remember the shortcuts of. Using Emacs is a guarantee to have a unified set of tools at hand.

Last week, after the announcement of version 30, I compiled Emacs mainly because wanted the new `use-package` ability to install package directly from a version control repository which is convenient when you maintain a fork of a package. For instance, now without adding any package to bring the feature to `use-package`, I have the following in my configuration:

(use-package chruby
  :vc (:url "https://github.com/stac47/chruby.el.git" :branch "main"))

I also discovered the etags-regen-mode which gives the possibility to automate the project tags generation.

Before this, I used to run etags manually from times to times mainly when a symbol was no more findable or when I was no more directed to the right place in a source file.

find . -name '*.rb' -print | etags -

And I created an interactive command to automatically search in visit the TAGS file in a project.

(use-package project
  :init
  (defun stac/project-tags ()
    "When in a project, visit the tags file at the root of the project."
    (interactive)
    (if (project-current)
        (let* ((proj-root (expand-file-name (project-root (project-current))))
               (old-tags-file tags-file-name)
               (new-tags-file (concat proj-root "TAGS")))
          (if (equal old-tags-file new-tags-file)
              (message "Tags file not changed: %s" old-tags-file)
            (visit-tags-table new-tags-file)
            (message "Tags file changed: %s -> %s" old-tags-file new-tags-file)))
      (message "No current project")))
  :bind
  (:map project-prefix-map
        ("t" . stac/project-tags)
        ("m" . magit-project-status)))

Now with the etags-regen-mode minor mode, I can automate all this. I just created a .dir-locals.el file at the root of the project I want the tags to be generated from with something like:

((nil . ((etags-regen-program-options . ("--language=ruby"))
         (mode . etags-regen))))

When the TAGS file does not exist, it will be generated the first time a file is saved on the project. Depending upon your project size, it may be a bit long and Emacs freezes. Hence, I feared some lag each time I saved a file, but it is not the case: only the modified file is passed to etags program to update the current TAGS file.

Adopted. Thanks all the Emacs developers for this jewel given to humanity.

Emacs 30.1 (Org mode 9.7.11)

Validate