Update Emacs/VIM tags with inotify

When you use the tags interface for Emacs or with VIM you have to generate your tag file everytime you have a new class or things get changed.  Would not be cool to have inotify monitoring your project directory and run the etags command to generate it.

With incron you have cron that can watch some portion of the filesystem and generate an action if certain event appears.  So after installed (aptitude/urpmi) it I have configured this incrontab entry :

/home/chmouel/git/myproject IN_CLOSE_WRITE /home/chmouel/update-ctags.sh py $@ $@/$#

The script update-ctags.sh takes 3 argument one is the type of file to update when it’s changed it accept multipe of them if you delimit with a pipe ie: py|inc|php|c and the two others are identifier from incron to give the base directory and the full path which is something you should not have to change.

The update-ctags is simple as follow which could be hacked for your convenience :


ACCEPTED_EXTENSION="$(echo $1|sed 's/|/ /g')"

[[ -z ${FILE_EXT} ]] && exit

for extension in $ACCEPTED_EXTENSION;do
    [[ $extension == $FILE_EXT ]] && processing=true

find ${BASE_DIR} ! -wholename './.git/*'  -a ! -wholename './.svn/*' -a ! -name '*.pyc' -a ! -name '*~' -a ! -name '*#' -print0| xargs -0 etags -o ${BASE_DIR}/TAGS 2>/dev/null >/dev/null
/home/chmouel/git/swift-container IN_CLOSE_WRITE /home/chmouel/updatectags.sh py $@ $@/$#

4 thoughts on “Update Emacs/VIM tags with inotify”

  1. I use OMake for this ( http://omake.metaprl.org/ ), if you run it with omake -P it monitors the filesystem for changes and rebuild the tag file as soon as you modify any files.

    Works well and was easy to install via apt-get as far as I can remember.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.