Skip to content
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

Records with name enclosed with quotes #19

Open
civing opened this issue Jan 23, 2015 · 7 comments
Open

Records with name enclosed with quotes #19

civing opened this issue Jan 23, 2015 · 7 comments

Comments

@civing
Copy link

civing commented Jan 23, 2015

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(\stest>/;" r file:
test ./test.erl /^-\s
record\s*(\s*test>/;" r file:
test ./test.erl 1;" M
test.erl ./test.erl 1;" F

@civing civing changed the title Records with sname enclosed with quotes Records with name enclosed with quotes Jan 23, 2015
@hcs42 hcs42 closed this as completed in 3efa61f Jan 24, 2015
@hcs42
Copy link
Member

hcs42 commented Jan 24, 2015

Now records in quotes are found – please let me know if it works as you expected.

@civing
Copy link
Author

civing commented Jan 26, 2015

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:
#Bla-bla ./test.erl /^-\srecord\s(\s*'Bla-bla'/;" r file:
#test ./test.erl /^-\srecord\s(\stest>/;" r file:
#test@ ./test.erl /^-\s
record\s*(\s*'test@'/;" r file:
Bla-bla ./test.erl /^-\srecord\s(\s*'Bla-bla'/;" r file:
test ./test.erl /^-\srecord\s(\stest>/;" 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

@hcs42
Copy link
Member

hcs42 commented Jan 26, 2015

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):

  • Do a "_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).
  • Do a "_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.

@hcs42 hcs42 reopened this Jan 26, 2015
@civing
Copy link
Author

civing commented Jan 26, 2015

I will give it a shot!
Bare in mind that I'm new to both Erlang and vim scripting though. :)

@civing
Copy link
Author

civing commented Jan 31, 2015

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..

civing added a commit to civing/vim-erlang-tags that referenced this issue Jan 31, 2015
@hcs42
Copy link
Member

hcs42 commented Feb 1, 2015

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).

@civing
Copy link
Author

civing commented Feb 14, 2015

You are absolutely correct Csaba, sorry for not considering that..

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

Successfully merging a pull request may close this issue.

2 participants