-
Notifications
You must be signed in to change notification settings - Fork 628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C/C++ Sort definitions before prototypes #4015
Comments
Well understandable. But Soriting is not the job of ctags. Hereafter, I will write about general sorting, not only definition v.s. prototype. citre (https://github.com/universal-ctags/citre), an extension for Emacs editor, does this. citre uses readtags command internally. With readtags, you can specify the order of listing with sort expressions. See https://docs.ctags.io/en/latest/man/readtags.1.html#sorting . If the readtags command doesn't fit your purpose, you can write your tool or library with libreadtags (https://github.com/universal-ctags/libreadtags) or https://github.com/universal-ctags/python-ctags3. |
This works for a client like gVim, where I could do this in less then 20 lines of Vim script in the latest version (which I plan to, some day...) But how about Wikipedia lists 25 clients using ctags, I am sure there are more. Are you sure |
Yes. Currently, I think ctags should not do too much in the area.
The client tools may be able to use the post-processed tags file. Embedding readtags into ctags is a way to implement the idea you proposed. |
Hello
If I enable prototypes, I can get many tags generated for the same function, but only one of them (mostly) will be a definition.
For multiple tags of the same name (like declarations of the same function), can ctags please sort them so the definition always shows up before the prototypes and other references ?
To be clear,
ctags
currently outputs definition tags (withroles:def
) for prototypes, which is not actually correct. At least in C and C++, but also other languages. So let me say implementing #1796 (introduce prototype role) would be great.But prototypes are not exactly references either, not in the proper sense. The function declared in a prototype does not have to exist, and the program is still correct, as long as the function remains unused (never called; the function type can still be used, for example in a sizeof() expression or with decltype()). So there is nothing to be referenced.
However when no definition is available or desired (for external libraries for example), then the prototype from the library header is the next best thing.
So what I really need as an user is to get the function definition first, if there one, or the prototype otherwise.
Can ctags add sort order for tags of the same name, and sort them with the definition first, and the prototypes after ? Because most code editors would show the first tag first ...
The text was updated successfully, but these errors were encountered: