StanAngeloff / php.vim

An up-to-date Vim syntax for PHP (7.x supported)
477 stars 69 forks source link

Is there a way to not use @Spell for strings, keep it for comments only #94

Closed mudrd8mz closed 4 years ago

mudrd8mz commented 5 years ago

I'd like to have spell check enabled when editing the PHP files, but I would like to have it enabled for PHP comments only. I can see that the syntax/php.vim adds @Spell cluster to all phpStringDouble, phpBacktick, phpStringSingle, phpHereDoc etc regions. I would need to selectively enable it for phpComment and phpCommentTitle only.

I was trying to find a way to somehow override it with @NoSpell in my .vimrc but I failed.

Can you suggest a good way to have the spell check enabled for comments only and not all strings? The only way that works for me now is modifying the upstream and removing the @Spell from the upstream php.vim file (which I'd prefer to avoid).

Thank you in advance for suggestions.

mudrd8mz commented 4 years ago

For the record, this is what seems to work for me. Is there a way to have this behaviour configurable?

diff --git a/syntax/php.vim b/syntax/php.vim
index f5d6826272..3823f3004e 100644
--- a/syntax/php.vim
+++ b/syntax/php.vim
@@ -658,13 +658,13 @@ endif

 " String
 if (exists("php_parent_error_open") && php_parent_error_open)
-  syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+  contains=@Spell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained keepend
-  syn region phpBacktick matchgroup=phpStringDelimiter start=+`+ skip=+\\\\\|\\"+ end=+`+  contains=@Spell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained keepend
-  syn region phpStringSingle matchgroup=phpStringDelimiter start=+'+ skip=+\\\\\|\\'+ end=+'+  contains=@Spell,@phpAddStrings,phpStrEsc contained keepend
+  syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+  contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained keepend
+  syn region phpBacktick matchgroup=phpStringDelimiter start=+`+ skip=+\\\\\|\\"+ end=+`+  contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained keepend
+  syn region phpStringSingle matchgroup=phpStringDelimiter start=+'+ skip=+\\\\\|\\'+ end=+'+  contains=@NoSpell,@phpAddStrings,phpStrEsc contained keepend
 else
-  syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+  contains=@Spell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained extend keepend
-  syn region phpBacktick matchgroup=phpStringDelimiter start=+`+ skip=+\\\\\|\\"+ end=+`+  contains=@Spell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained extend keepend
-  syn region phpStringSingle matchgroup=phpStringDelimiter start=+'+ skip=+\\\\\|\\'+ end=+'+  contains=@Spell,@phpAddStrings,phpStrEsc contained keepend extend
+  syn region phpStringDouble matchgroup=phpStringDelimiter start=+"+ skip=+\\\\\|\\"+ end=+"+  contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained extend keepend
+  syn region phpBacktick matchgroup=phpStringDelimiter start=+`+ skip=+\\\\\|\\"+ end=+`+  contains=@NoSpell,@phpAddStrings,phpIdentifier,phpSpecialChar,phpIdentifierSimply,phpIdentifierComplex,phpStrEsc contained extend keepend
+  syn region phpStringSingle matchgroup=phpStringDelimiter start=+'+ skip=+\\\\\|\\'+ end=+'+  contains=@NoSpell,@phpAddStrings,phpStrEsc contained keepend extend
 endif

 syn case match
mudrd8mz commented 4 years ago

Is there a way to have this behaviour configurable?

Right, so finally this is probably what I was looking for:

autocmd BufEnter *.php syntax cluster phpAddStrings add=@NoSpell

but there might be a cleaner way to achieve it.

StanAngeloff commented 4 years ago

This is actually a pretty good way to deal with it. The commit which introduced spelling in strings can be found here.

mudrd8mz commented 4 years ago

Great, many thanks for the reply and for the useful plugin.