EtagsTable

This extension sets the tags table(s) based on the current file (inspired by XEmacs’ etags handling). ‘etags-table-alist’ is a list of lists, where the car of each sublist is compared to the current filename. If it matches, all the rest of the list elements are put on ‘tags-table-list’. If ‘etags-table-search-up-depth’ is an integer, the file path will be searched upwards for a tags file. If one is found, it will be added to the tags table list; this is actually done first so the local TAGS file is at the head of the list.

When you switch files and do something tag-related, the tags table list is automatically recomputed.

Installing with XEmacs compatibility

In XEmacs the ‘etags-table-alist’ is actually called ‘tag-table-alist’ and XEmacs will search up directories to find the TAGS file, so to ensure compatible emulation of XEmacs functionality you’d have to do the following:

(require 'etags-table)
(setq tag-table-alist 
      '(("~/.emacs.d/" . "~/.emacs.d/TAGS")
        ("~/projects/source/" . "~/.TAGS/projects.tags")))
(setq etags-table-alist tag-table-alist)
(setq etags-table-search-up-depth 10)

Search in standard headers with etags-table.el

Setting

(require 'etags-table)
(setq etags-table-search-up-depth 10)

allow you build TAGS file on root of project and move accross definition in project. But if you need jump in different project or in standard headers, just add:

(setq etags-table-alist
      (list
       ;; For jumping to standard headers:
       '(".*\\.\\([ch]\\|cpp\\)" "c:/Program Files/Microsoft SDKs/Windows/v6.1/Include/TAGS")
       ;; For jumping across project:
       '("/home/devel/proj1/" "/home/devel/proj2/TAGS" "/home/devel/proj3/TAGS")
       '("/home/devel/proj2/" "/home/devel/proj1/TAGS" "/home/devel/proj3/TAGS")
       '("/home/devel/proj3/" "/home/devel/proj1/TAGS" "/home/devel/proj2/TAGS")
       ))

Or may be you need (add-to-list 'etags-table-alist ...).

Also note that instead of updating ‘etags-table-alist’ you can include all tag-symblols in single project TAGS file (NOTE: we use additional options for standard headers as function prototypes does not included in TAGS file by default):

  $ cd $proj
  $ { \
      ls lib/xulrunner-sdk/include/plugin/np*.h; \
      ls lib/xulrunner-sdk/include/xpcom/*.h; \
      ls /usr/include/win32/win*.h; \
    } | etags --declarations -
  $ find . '(' -type d -name .svn -o -name dist -o -name lib ')' -prune -o -type f \
      '(' -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.rc' ')' -print; \
      | etags -a -

Or same with ctags:

  $ cd $proj
  $ { \
      ls lib/xulrunner-sdk/include/plugin/np*.h; \
      ls lib/xulrunner-sdk/include/xpcom/*.h; \
      ls /usr/include/win32/win*.h; \
    } | ctags --c-kinds=+p+x --c++-kinds=+p+x --tag-relative=yes -e -L -
  $ find . '(' -type d -name .svn -o -name dist -o -name lib ')' -prune -o -type f \
      '(' -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.rc' ')' -print; \
      | ctags --tag-relative=yes -e --append -L -

--gavenkoa


It was not clear how to use this - after some digging I found out that the best way is to use this together with etags-select.el (from EtagsSelect) with the key bindings that redefine, for example, M-. to run etags-select-find-tag. So to make it work, download etags-select.el and etags-table.el into your emacs extensions directory (the one that is searched by ‘require’) and add into .emacs:

(require 'etags-select)
(require 'etags-table)
(global-set-key "\M-." 'etags-select-find-tag)

- AlexBolgarov


CategoryProgrammerUtils CategoryNavigation