Solved How to use ctags provided in base system ?

D

Deleted member 57104

Guest
Hello.
I can't figure out how to use default ctags with vi. Whenever I run find . -type f -name '*.[ch]' | xargs ctags -a it generates tags file but I can't use it with vi. Am I doing something wrong ?
 
Could be the file is to large for vi or too many lines, vim should open the file without a glitch if you have access to it.
You could split the file and later put it back together....
 
... but I can't use it with vi.
What do you mean by that? Is there no file (yes, you said there is)? Do you not know the file name? Can vi not open it? If yes, what error message do you get? Can you read the content of the file with more? If you can open the file, is the problem that you can't see the correct content? Or do you not know what content to expect? Or is the output so complex that it is correct and complete, but it is impractical to work with?

If you expect help, you need to give us way more detail than "can't use it".
 
I believe, the OP means the usability of the resulting tags file. I always had problems with it too, I dropped using the stock ctags in favor of devel/ctags. I find the latter a lot easier to use (at least for C projects): exctags -R generates a comprehensive list of tags.
 
What do you mean by that?
As aragats pointed out, I mean the usability of the resulting tags file. vi and vim can't find tags using it. the error message is
Code:
main: tag not found
I am looking for the way of using the stock ctags instead of exctags.
 
I guess this is what you look for right?, opened with vi btw..
Code:
ABDATE  /usr/ports/astro/luna/files/patch-pyramid.h     /^ typedef long ABDATE;$/
ABORT   /usr/local/lib/perl5/5.28/mach/CORE/unixish.h   /^#define ABORT() kill(PerlProc_getpid(),SIGABRT);$/
ABS     /usr/local/include/glib-2.0/glib/gmacros.h      /^#define ABS(a)           (((a) < 0) ? -(a) : (a))$/
ABSPATH /usr/local/include/bash/general.h       /^#  define ABSPATH(x)  ((x)[0] == '\/')$/
ABS_SET /usr/include/sys/linker_set.h   /^#define ABS_SET(set, sym)     __MAKE_SET(set, sym)$/
ACC     /usr/include/sys/kbio.h /^#define ACC(x)                ((x)+F_ACC)$/
ACCEPT_LOCK     /usr/include/sys/socketvar.h    /^#define       ACCEPT_LOCK()                   mtx_lock(&accept_mtx)$/
ACCEPT_LOCK_ASSERT      /usr/include/sys/socketvar.h    /^#define       ACCEPT_LOCK_ASSERT()            mtx_assert(&accept_m/
ACCEPT_UNLOCK   /usr/include/sys/socketvar.h    /^#define       ACCEPT_UNLOCK()                 mtx_unlock(&accept_mtx)$/
ACCEPT_UNLOCK_ASSERT    /usr/include/sys/socketvar.h    /^#define       ACCEPT_UNLOCK_ASSERT()          mtx_assert(&accept/
 
Well maybe have a look at your own find rule, it points to you dotcurrent dir.
Don't know if that was intended, but I used
Code:
find / -type f -name '*.[ch]' | xargs ctags -a
and had no trouble opening the file with vi;)
 
that's what I used too but it doesn't work for me for some reason :(
 
and had no trouble opening the file with vi
I think you didn't get the point. It's not about opening the tags file.
With vi/vim you open e.g. a C file, and try to find a tag definition by pressing Ctrl-] on a function/variable/macro.
You get "tag not found" message. However, using tags file created by exctags -R always works.
 
But the problem is that I need to know how to utilize the stock ctags, not exctags.
 
Sorry I misunderstood I thought it was about that find command..
I understand now, quote from the man :oops: oops
^] Searches for the word which is after the cursor as a tag. Equivalent to typing :ta, this word, and
then a CR. Mnemonically, this command is “ right to” (7.3).
 
According to some web pages, the stock ctags doesn't play nice with vi and or vim on FreeBSD. Since I don't use vi myself (and simply read the resulting ctags file by hand, I don't use it in emacs directly), I had never noticed that fact. The stock ctags seems to work fine for me, and returns a complete-looking and sensible list for my source code. According to the WikiPedia page for ctags, there is a difference in the output format of exctags and ctags.

You may just have to switch to using exctags. Why do you say that you can't use exctags? Another question: Are you using the stock vi or vim? It could be that vim is "too advanced" to work with the old ctags format, and perhaps the stock vi might work.
 
I am using stock vi and I can use exctags, however i want to find a way to use stock ctags.
 
By looking at the outputs of ctags(1) and exctags(1), it seems, that it might be possible to do a final format conversion using sed(1). Since exctags includes #defines by default, you want to run ctags from base with the -d option. Once the tags file has been created execute the following command:
Code:
sed -e '/#define.*$/s|.|&;" d       file:|;' -e '/#define.*$/\!s|.|&;" f|;' -i ".base" tags

This would convert the tags file to the supposed ex-tags format and move the original tags file to tags.base.

PS: Why does the forums editor spoil the sed command when placed as a command line? Is this a kind of an idiotic smily conversion?
sed -e '/#define.[I]$/s|.[/I]|&;" d file:|;' -e '/#define.[I]$/\!s|.[/I]|&;" f|;' -i ".base" tags
 
According to the [ANCHOR=[URL]https://en.wikipedia.org/wiki/Ctags]Wikipedia[/URL] page[/ANCHOR] the ctags output format is a subset of the exctags output format. If true, there is no way to convert ctags -> exctags, since there isn't enough information in all cases.

But then, the same web page says that vi should work with ctags, which doesn't seem to be true. Honestly, I don't know how to resolve this conflict.
 
ralphbsz, ctags just doesn't support multiple files per tag, which I think should be fine if you have multiple tags.
 
Back
Top