leoliu / ggtags

Emacs frontend to GNU Global source code tagging system.
http://elpa.gnu.org
577 stars 56 forks source link

Support for universal-ctags #132

Closed CSRaghunandan closed 7 years ago

CSRaghunandan commented 8 years ago

Hello,

I'm running on Mac, emacs 25.1-1. I install global and installed universal-ctags using brew. But, when I try to generate tags, gtags exits with an error (because I do not have ctags installed) and emacs is executing gtags command with ctags label.

after browsing a bit, I found out that to use gtags with universal tags, we need to specify gtagslabel as new-ctags and as expected, if run gtags --gtagslabel=new-ctags in shell, the tags are generated. I get an error if i try to use gtags with ctags as label.

Even after I added export GTAGSLABEL=new-ctags in my bash_profile, emacs still tries to run gtags with ctags label instead of new-ctags label and I get this error :-

gtags: execvp failed.
gtags: unexpected EOF.

How can I fix this problem? Is there a way to instruct ggtags-mode to always use universal-ctags ?

leoliu commented 8 years ago

If I remember correctly, GTAGSLABEL is only used to choose the target in gtags.conf, which has something like these lines:

default:\
        :tc=native:tc=pygments:
native:\
        :tc=gtags:tc=htags:
user:\
        :tc=user-custom:tc=htags:
ctags:\
        :tc=exuberant-ctags:tc=htags:
pygments:\
        :tc=pygments-parser:tc=htags:
.......

If I am not mistaken the ctags executable is specified at compile time, so no amount of setting GTAGSLABEL will help.

You might want to raise this issue on global's mailing list so that it can work better with universal-ctags.

CSRaghunandan commented 8 years ago

I was going through this reddit thread and people have mentioned they got it to work with universal-ctags. I was thinking, I did something wrong with my setup that messed things up. I followed the exact steps mentioned in that thread, but to no avail :(

leoliu commented 8 years ago

I guess you need to compile global and point to the universal-ctags executable something like this:

./configure --prefix=${global_install_dir} --with-exuberant-ctags=${my_ctags_bin_location}
CSRaghunandan commented 8 years ago

I compiled global like so :- ./configure --with-exuberant-ctags=/usr/local/bin/ctags /usr/local/bin/ctags points to the universal-ctags executable. It did not work.

Do I have to remove and compile it again like you mentioned above ? Would it make any difference?

leoliu commented 8 years ago

Looks like you compiled it correctly. Try this to see if it global works without using the ggtags frontend.

  1. copy $HOME/.globalrc to your project as file gtags.conf
  2. change gtags.conf
default:\
        :tc=native:

to

default:\
        :tc=ctags:
  1. In shell/terminal, cd your project root and run gtags

Does it work i.e. complete without errors?

CSRaghunandan commented 8 years ago

Hmm setting default to :tc=ctags: doesn't seem to work for universal-ctags. Instead I changed default to :tc-new-ctags: and it seems to work.

BUT, there is one big problem. Even if i make a slight modification for the files and save it, the tags stop working. I see no definitions in it. I've to delete the tags and regenerate them again. This is not how it's supposed to work I guess? Whats going on?

CSRaghunandan commented 8 years ago

EDIT: Tag files work fine for python-mode. I was testing with rust-mode and the problem i mentioned above is in rust-mode. I'll try for some other modes and report back.

EDIT 2: in js2-mode it works fine the first time i create it. But after I save it, ggtags-mode tries to use ctags backend and it blows up with an error again. Only python-mode works. somehow, i've no idea how. On the bright side, I finally got global to work with universal-ctags. But, it looks like it has no support in ggtags-mode :(

leoliu commented 8 years ago

That's indeed odd. I suggest report to gnu global mailing list where people would have better idea.

Schievel1 commented 4 months ago

If someone stumbles upon this problem: GNU Global needs to be compiled with ./configure --with-universal-ctags=/usr/local/bin/ctags or whereever your universal-ctags binary is. For example, the universal-ctags binary for Gentoo is /usr/bin/exuberant-ctags [sic] from the package dev-util/ctags (which gets it's source from https://github.com/universal-ctags/ctags, yes it is really confusing). ggtags is using the gtagslabel ctags. You can simulate it's behavior with the command gtags --gtagslabel=ctags You can use the environment variable GTAGSLABEL to change this and get this environment variable in emacs somehow. (Some emacsen create their own environment once and then load in from a file. So check if it's really set with M-x getenv.) There is this in /etc/gtags.conf

new-ctags:\
    :tc=universal-ctags:tc=htags:

and running gtags --gtagslabel=new-ctags works indeed. So setting GTAGSLABEL=new-ctags should work.

Or, to make it use universal-ctags permanently, you can change the lines in /etc/gtags.conf from

ctags:\
    :tc=exuberant-ctags:tc=htags:

to

ctags:\
    :tc=universal-ctags:tc=htags: