2

I'm trying to port my tagging workflow from Vim & ctags to Emacs & etags. I currently use git hooks to write a tags file to .git/tags in ctags format whenever I commit/merge/etc. This keeps each project indexed with an up-to-date tags file.

fugitive.vim makes sure Vim will look for tags in the .git directory associated with the current buffer. For a Ruby project that uses gems, bundler.vim ensures Vim will look for tags in each included gem's directory.

This lets me navigate freely throughout various projects without having to tell Vim where to find tags. I've added a git hook to write tags to .git/etags in the etags format, but I'm not sure how to get Emacs to find tags files automatically. I'd like to avoid hard-coding the value of tags-table-list if possible.

Before I reinvent the wheel and translate the logic of fugitive.vim and bundler.vim into elisp, is there an existing solution for this kind of thing?

4

I use etags-table, available as a package from Marmalade. Install the package and put

(setq etags-table-search-up-depth 99)

in your init file. Then, then you do a tag lookup, Emacs will look for a TAGS file in the directory containing the current file and in the parent directories recursively up to 99 levels. More generally, Emacs remembers the associated tag table file for every buffer. You can set the variable etags-table-alist to match file name patterns to tag file names if your tag file are not called TAGS or not stored at the root of each project.

  • etags-table is no longer in ELPA or MELPA. I'm using Emacs 25. Is there some equivalent functionality that's compatible? – Dan Halbert Oct 10 '18 at 16:05
  • 1
    @DanHalbert I think I made a mistake: it seems to only ever have been in Marmalade. It doesn't seem to have been modified in a while, but Emacs has good backward compatibility, so there's no reason why it wouldn't work in recent versions of Emacs. – Gilles Oct 10 '18 at 21:11
  • marmalade-repo.org/packages/etags-table-1.1.el still works, with emacs 25. But marmalade-repo.org is reported to be defunct, has certificate problems and is probably in danger of disappearing completely. The identical file is discussed and available via emacswiki.org/emacs/EtagsTable – Dan Halbert Oct 11 '18 at 12:41
2

You can write a hook for loading visit-tags-table:

(add-hook 'c++-mode-hook (lambda ()
  (locate-dominating-file (file-name-directory (buffer-file-name)) ".git/etags"))

Although, from what I'm reading at the docs, the tags-table-list is the way to go.

EDIT: Shortened code per @phils

  • 2
    C-h f locate-dominating-file – phils Dec 26 '16 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.