GTags in Emacs


I usually code in Python and When I have a lot of functions in different files in a project then it is desirable to jump to the function definition from its identifier at point. In Emacs, Elpy attached a function to Meta-. called (elpy-goto-definition) that works sometimes and doesn't most of the time on remote files. There are some other good options to tackle this problem like elpy-rgrep-symbol, rgrep but they are not efficient for me. I also tried LSP mode (mspyls) which works good in local but always complains about server time elapsed over tramp. I was really in desperate need of this feature that works over tramp because most of my editings are based on the servers. I saw about GNU-GLOBAL on some online platform which is widely used by C-programmers for use-cases as of mine. I looked in to it and found that they work too for python with extra plugins. The idea is simple that they create TAG files of your source codes before hand and Emacs can use those TAG files to navigate around the project. For this I followed gtags-spacemacs which works for my vanilla-Emacs too. To make it work over tramp I had to install gnu-global on server for which I am writing this article for my future reference.

Install gnu-global on server

If you have the admin rights on the server then you can follow the same instruction as of gtags-spacemacs and everything works fine otherwise you need to install gnu-global by downloading the source and installing on the preferred location. Before installing gnu-global, first I had to install all the dependencies. The steps are as followed.

  1. ctags:
  2. gperf:
  3. libtool:
  4. texinfo:

Finally add the path-to-install/bin folder to the bashrc export PATH="/projappl/project_2001838/bin:$PATH" to access them from terminal directly.

Now we can install the gnu-global with following three commands.

  • ./configure –with-exuberant-ctags=/path/to/install/bin/ctags –prefix=/path/to/install/
  • make
  • make install

Creating TAGs and accessing from Emacs

  • Once gnu-global is installed, I can go to any project directory and type gtags --gtagslabel=pygments to create gtags. In order to access them from Emacs, I installed helm-gtags.
  • Before using helm-gtags over tramp, I need to tell the tramp the path of gnu-global in the server. So I added (add-to-list 'tramp-remote-path "/path/to/install/bin") line to my init.el. Now you are ready to go. The screenshot shows it in action. We can go to any fucntion identifier and then it can take us to function definition even defined in another file.


Author: Soumya Tripathy

Created: 2020-10-26 Mon 15:29