Incorrect highlighting of commented out function definitions
Closed this issue · 3 comments
dkearns commented
Hi,
The following is currently highlighted as a function definition rather than a comment.
#foo() {}
Thanks,
Doug
chrisbra commented
Hm, this comes from the fact that #
is part of syn iskeyword
setting. I don't know what pattern \k
matches, so not sure how to remove #
from the \k
.
This patch fixes it and should work, but not sure whether this breaks anything else (and I do not use zsh syntax scripts that much to notice myself):
diff --git a/syntax/zsh.vim b/syntax/zsh.vim
index ddb19b5..7efacbd 100644
--- a/syntax/zsh.vim
+++ b/syntax/zsh.vim
@@ -78,7 +78,7 @@ syn keyword zshException always
syn keyword zshKeyword function nextgroup=zshKSHFunction skipwhite
syn match zshKSHFunction contained '\w\S\+'
-syn match zshFunction '^\s*\k\+\ze\s*()'
+syn match zshFunction '^\s*[^#]\+\k\+\ze\s*()'
syn match zshOperator '||\|&&\|;\|&!\='
Hopefully this does not break anything.
danielshahaf commented
This patch fixes it and should work, but not sure whether this breaks anything else (and I do not use zsh syntax scripts that much to notice myself):
```patch
diff --git a/syntax/zsh.vim b/syntax/zsh.vim
index ddb19b5..7efacbd 100644
--- a/syntax/zsh.vim
+++ b/syntax/zsh.vim
@@ -78,7 +78,7 @@ syn keyword zshException always
syn keyword zshKeyword function nextgroup=zshKSHFunction skipwhite
syn match zshKSHFunction contained '\w\S\+'
-syn match zshFunction '^\s*\k\+\ze\s*()'
+syn match zshFunction '^\s*[^#]\+\k\+\ze\s*()'
syn match zshOperator '||\|&&\|;\|&!\='
```
Hopefully this does not break anything.
It'll break single-letter function names, such as «f() {}». Also, the character class might match non-keyword characters, which could probably break something or other. I'm not sure what to suggest: perhaps a zero-width negative lookahead, to ensure the first character matched by \k isn't a comment marker?
As an aside, the pattern would also match «if ()», which isn't a function definition — it's the reserved word «if» followed by an (incomplete) anonymous function (likewise for «while», etc.) — but that's not a problem in practice: «if ()» doesn't highlight "if" as zshFunction but as zshConditional.