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

Vim syntax match for variable definitions #1426

Merged
merged 6 commits into from
Sep 8, 2017
Merged

Vim syntax match for variable definitions #1426

merged 6 commits into from
Sep 8, 2017

Conversation

tdewolff
Copy link
Contributor

@tdewolff tdewolff commented Sep 5, 2017

This adds a match for variable definitions so that they can be highlighted using a color scheme. Variable definitions are the foo and bar in:

foo := ...
foo, bar := ...

This adds a match for variable definitions, such as:

    foo := ...
    foo, bar := ...
Match for variable definition highlighting
@arp242
Copy link
Contributor

arp242 commented Sep 5, 2017

Two comments:

  1. It only seems to work for the last variable? Using this:

    :syn match goVarDefs /\w\+\(,\s*\w+\)*\s*\ze:=/
    :hi def link goVarDefs Statement
    

    Gives me (the brownish colour being Statement):

    2017-09-05-220910_254x127_scrot

    Is this intentional? It seems strange to me (I would expect both a and err to be highlighted).

  2. The syntax groups isn't highlighted by default, but will still be applied, which will be a performance hit. You should probably put this behind a variable (like the existing g:go_highlight_* ones).

@tdewolff
Copy link
Contributor Author

tdewolff commented Sep 5, 2017

Hmm that is strange, it works for multiple variable for me (that's the (,\s* ... ) part). I'll do some testing

EDIT: hm, I've double checked and tested, but it works fine for both a and err for me, can you confirm that you copied the goVarDefs correctly?

@arp242
Copy link
Contributor

arp242 commented Sep 6, 2017

Just tested again; it really doesn't work for me in Vim 8.0.987 with the current vim-go master, even in my "minimal" setup without vimrc and just the vim-go plugin.

It looks like the problem is you forgot to add a \ to the + inside the capture group; if I add that it works:

syn match goVarDefs /\w\+\(,\s*\w\+\)*\s*\ze:=/

I don't know why it works for you...

Also, to avoid highlighting spaces between the last variable and := (only shows if you set the highlight to something with a different background colour):

syn match goVarDefs /\w\+\(,\s*\w\+\)*\ze\(\s*:=\)/

And with \v added to cure the Leaning Toothpick Syndrome and make it a wee bit more readable:

syn match goVarDefs /\v\w+(,\s*\w+)*\ze(\s*:\=)/

@tdewolff
Copy link
Contributor Author

tdewolff commented Sep 6, 2017

Ah I see you are well versed in Vim regexes. I've changed it.

@fatih
Copy link
Owner

fatih commented Sep 6, 2017

@Carpetsmoker I've added you to the repo. From now on please feel free to merge & review syntax based PR's as I think you're the best fit. Just don't forgot to update the Changelog.

@arp242
Copy link
Contributor

arp242 commented Sep 6, 2017

Thanks @fatih 👍

- Highlight `goVarDefs` so that enabling `g:go_highlight_variable_declarations`
  actually does something out of the box.
- Add documentation for the new `g:go_highlight_variable_declarations` setting.
@arp242 arp242 merged commit 0be825d into fatih:master Sep 8, 2017
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 this pull request may close these issues.

3 participants