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

Highlight function names the same way as vs code? #59

Open
rbjorklin opened this issue Sep 14, 2020 · 2 comments
Open

Highlight function names the same way as vs code? #59

rbjorklin opened this issue Sep 14, 2020 · 2 comments
Assignees

Comments

@rbjorklin
Copy link

I quite like how vs-code highlights the function name in a color different from its arguments. Would that be possible in vim as well?

VS Code
vs-code-highlight

Vim
vim-highlight

@rbjorklin rbjorklin changed the title Highlight function names the same way as vc code? Highlight function names the same way as vs code? Sep 14, 2020
@mmottl
Copy link
Collaborator

mmottl commented Sep 28, 2020

I guess that would be possible, though you'd have to be careful with tuple bindings like let f1, f2 = ... or other irrefutable matches. I assume you'd be fine with coloring ordinary bindings like let x = 3, too. I'm not sure how much it would add to readability, but feel free to try implementing this if you like it. Just be warned: Vim highlighting rules are notoriously brittle and finicky so test well.

@Maelan
Copy link
Contributor

Maelan commented Oct 27, 2021

I did that at home! This is how course hacky and fairly limited, hence I did not propose it for merging. Put this for example in your ~/.vim/after/syntax/ocaml.vim:

" Highlight let‐binders, ie. identifiers which are given an immediate value.
" Limitations:
"   — does not recognize let-patterns like “let (a,b) = …” or “let (C x) = …”
" [ — does not recognize “let[@inline] f = …” nor “let (*lol*) f = …” ]
"   — does not support object values and methods
" Highlighting other binders (function arguments, “fun”, “function”, “try with”,
" match with”…) is much more difficult and would require writing a more accurate
" parser.
"syn match ocamlLetBinder /\(\<\(let\(\_s\+rec\)\?\|and\|for\)\>\_s\+\)\@<=\<\(\l\|_\)\(\w\|'\)*\>/
" This is a coarse approximation that recognize simple PPX annotations, as in
" “let[@inline] f = ...”.
syn match ocamlLetBinder /\(\<\(let\(\_s\+rec\)\?\|and\|for\)\>\_s*\(\[@\(@\|\w\|\.\|\_s\)*\]\_s*\)*\)\@<=\<\(\l\|_\)\(\w\|'\)*\>/

hi link ocamlLetBinder Identifier

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

3 participants