Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically create/update a TAGS file with emacs?

Tags:

emacs

ctags

Is there any plugin for emacs to automatically update the TAGS file in my C project (for example on buffer save or access) or create a new one if there is no TAGS file present?

I am running on Windows (without Cygwin), so all the fancy shell scripting does not help. I was hoping for a native emacs solution not using any external scripting.

I already tried build-tags.el and etags-table.el but none of these really worked (the way I wanted).

Any other ideas?

like image 952
cschol Avatar asked Feb 14 '09 03:02

cschol


2 Answers

etags-update may help in your case. I didn't test it, but according to the readme:

etags-update.el is a Emacs global minor mode that updates your TAGS when saving a file.

I found it on the Emacswiki page for building TAGS files

like image 78
Valentin Jacquemin Avatar answered Nov 06 '22 05:11

Valentin Jacquemin


Here is how I generate a TAGS file for a C project:

  1. M-x cd YOUR_DIRECTORY
  2. M-x compile
  3. find . -name "*.[chCH]" -print | etags -

That will create a TAGS file in the current directory for all sub directories and files.

Here is a emacs function that does the exact same thing:

(defun compile-tags ()
  "compile etags for the current project"
  (interactive)
  (cd "YOUR_DIRECTORY")
  (compile "find . -name \"*.[chCH]\" -print | etags -"))

NOTE: if you are on windows you'll need to install cygwin and make sure c:\cygwin\bin is in your path so that you get find in your path. Also make sure the emacs bin directory is in your path so that you can get etags as well.

like image 10
Justin Tanner Avatar answered Nov 06 '22 05:11

Justin Tanner