Open civing opened 9 years ago
Now records in quotes are found – please let me know if it works as you expected.
Hi!
Special records are now added to the tags file. Thats perfect! However, vim can't seem to correctly follow the special records listed in the tags file.
Example:
test.erl: -module(test). -record(test, {none}). record('Bla-bla', {none}).
test() ->
Test = #'Bla-bla',
Test2 = #test.
tags:
#test ./test.erl /^-\s*record\s*(\s*test>/;" r file:
#test@ ./test.erl /^-\s*record\s*(\s*'test@'/;" r file:
Bla-bla ./test.erl /^-\s*record\s*(\s*'Bla-bla'/;" r file:
test ./test.erl /^-\s*record\s*(\s*test>/;" r file:
test ./test.erl /^test>/;" f file:
test ./test.erl 1;" M
test.erl ./test.erl 1;" F
test:test ./test.erl /^test>/;" f
test@ ./test.erl /^-\s*record\s*(\s*'test@'/;" r file:
Pressing <C-]> yields for different scenarios:
Placing the cursor over the "B" in #'Bla-bla' will render E426: tag not found: Bla
Placing the cursor over the "-" in #'Bla-bla' will render E426: tag not found: -
Placing the cursor over the "b" in #'Bla-bla' will render E426: tag not found: bla
Is this something that can be fixed in the overriden VimErlangTagsSelect() function?
Many thanks! Per
Is this something that can be fixed in the overriden VimErlangTagsSelect() function?
Indeed. Instead of doing "_vawo
here, we should do one of two things (I prefer the second one):
"_vi'o
to select the Bla-bla
string. This would not however eliminate the problem of not being able to distinguish between macros and records with the same name that we have now with quoted record names (the ticket was about plain record names)."_va'o
to select the 'Bla-bla'
string (which becomes #'Bla-bla'
after the next few lines, thus eliminating the macro vs record problem). For this to work though, we also need to change the tags generator to contain #'Bla-bla'
instead of #Bla-bla
. Which is fine, and in retrospect actually more logical than the current #Bla-bla
.The other tricky part is deciding whether we are in a record name with a plain atom syntax or one with a quoted atom syntax. Assuming that you use the vim-erlang syntax file (which is also the one shipped with Vim 7.4), then synIDattr(synID(line('.'), col('.'), 1), 'name') ==# 'erlangQuotedAtom'
should do that trick.
Another though I had is that maybe we should also generate #'Bla-bla'
-like tags for all records. Even if someone defines a record as record(myrecord
, other files might refer to it as #'myrecord'
. On the other hand, this would make the tags file even larger (now we have every record twice, this way we would have most of them 3 times).
If you feel like contributing, this is a great opportunity ;) Otherwise (no worries in that case) before I implement the above, you can manually do a vi'
before pressing C-]
, and that should take you to the record definition.
I will give it a shot! Bare in mind that I'm new to both Erlang and vim scripting though. :)
I did a simple hack for this particular 'Bla-bla' atom. Its a delicate problem since any character is valid in a quoted atom:
An atom is a literal, a constant with name. An atom should be enclosed in single quotes (') if it does not begin with a lower-case letter or if it contains other characters than alphanumeric characters, underscore (_), or @.
I guess one of your solution above is better. In the meantime, maybe my hack will do. Pull request coming up..
Its a delicate problem
Indeed :) Making the space character work within record names is especially difficult, because a tag in a tag file cannot contain whitespace. So even my proposal doesn't fix the particular case of the space character.
In the meantime, maybe my hack will do. Pull request coming up..
Unfortunately this PR would break cases where there is no space around a -
(or ->
or --
) token. Consider what happens if we try to follow lists:min
in the following function: Vim would actually try to follow -lists:min
.
min_max_diff(L) ->
lists:max(L)-lists:min(A).
You are absolutely correct Csaba, sorry for not considering that..
When record name is enclosed with quotes it's not added to the list of tags.
example: test.erl: -module(test). -record(test, {none}). -record('test@', {none}).
tags: !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted/
test ./test.erl /^-\srecord\s(\s*test>/;" r file: