Skip to content

when a record and a module have the same name. #14

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

Closed
youthy opened this issue Jul 18, 2014 · 3 comments
Closed

when a record and a module have the same name. #14

youthy opened this issue Jul 18, 2014 · 3 comments

Comments

@youthy
Copy link

youthy commented Jul 18, 2014

hello,
I think ErlangTags is very nice,but I have a little bit problem is that when a record name is the same as any module,the ctrl + ] always jump to the module,not the record.
I hope this can be solved.
thks.

hcs42 added a commit that referenced this issue Jul 19, 2014
vim-erlang-tags.erl generates extra tags (#rec for records), and when C-] is
hit on a record, the # is counted as part of the name, so only records tags
will be considered. If there are several records with the same name, it is
still not guaranteed that C-] will jump to the correct one.

Same was implemented for macros and '?'.
@hcs42
Copy link
Member

hcs42 commented Jul 19, 2014

Hi,

There is bad news and good news.

The bad news

The bad news is that vim-erlang-tags cannot always jump to the correct location because of Vim's limitations in handling tags. vim-erlang-tags uses only one trick (adding ":" to the list of keyword characters temporarily), and then uses Vim's mechanisms for deciding which tag to jump to. This mechanism is not very smart. In this Stack Overflow post, @weisslj tried to write a more intelligent function that decides where to jump when the user presses C-], instead of letting Vim itself make the decision; but he still couldn't solve the problem that local tags from the first one will be prioritized over the local tags of the second one. For example if we have these files:

% x.erl

f() ->
    g().

g() ->
    ok.

% y.erl

f() ->
    g().

g() ->
    ok.

and generate separate tags files for them:

$ vim-erlang-tags.erl x.erl -o x.tags
$ vim-erlang-tags.erl y.erl -o y.tags

and add them to Vim:

set tags=x.tags,y.tags

then hitting C-] on "g" in the body of "y:f" will erroneously jump to the definition of "x:g", because when it found the "best" match in the first tags file ("x.tags"), it didn't even look at the second tags file.

The problem with writing a smart function that makes the decision instead of Vim is (as @weisslj explained) that "while taglist() and :tselect return the order independent of the file order in 'tags', but dependant on the current file, :tag uses the order in 'tags'. The best solution would be a new tagselect() function that can navigate exactly to an item in the list returned by taglist(). It was suggested on the mailing list in 2005 and received positive replies, but was not implemented since then."

The good news 1

There is a simple workaround. When Vim jumps to a tag, it actually remembers all possible locations. So if you have both a module and a record named x, and press C-] while standing on x, Vim will jump to either the module or the record, but it will remember the other hit too. You just need to type :tn to jump to the next hit.

The good news 2

In this particular case, I implemented a fix in my "records" branch. Please try it and report back if it works.

If you are standing on a record whose name is preceded with a # character, C-] will jump to the record. So e.g. if you have #x in the code, and the cursor is on x, and hit C-], we will jump to an x record. Note that if x is defined in a header file, and another x record is defined in another header file, it is still not guaranteed that we jump to the correct x. (This is beyond the capabilities of Vim and vim-erlang-tags, even if the tagselect() proposal above is implemented. But that's fine, that's why we have :tn.)

@youthy
Copy link
Author

youthy commented Jul 22, 2014

Hi, it's reaaaaaally coooool!
both good news1 and 2 can solve my problem.
It works very well.
thks again, I really appreciate your help~ ;-)

hcs42 added a commit that referenced this issue Jul 25, 2014
(#14) Jump to record/marco after '#' or '?'
@hcs42
Copy link
Member

hcs42 commented Jul 25, 2014

Thanks for the feedback, I merged the patch in #15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants