some vim syntax fixes for multi-lined commands

99 views
Skip to first unread message

Alexey Radkov

unread,
Nov 11, 2012, 11:43:25 AM11/11/12
to vim...@vim.org
Hi.

Here are some fixes for errors in vim syntax highlight for multi-lined commands found when looking through my .vimrc and other vim sources. I used to keep lines in sources short (78 columns for vim) so i often used line breaks.

The patch against current hg version (also attached):


--- runtime/syntax/vim.vim    2012-11-11 15:56:35.733116733 +0400
+++ runtime/syntax/vim.vim.new    2012-11-11 19:35:46.579257610 +0400
@@ -152,8 +152,8 @@
 syn cluster    vimOperGroup    contains=vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimRegister,vimContinue
 syn match    vimOper    "\(==\|!=\|>=\|<=\|=\~\|!\~\|>\|<\|=\)[?#]\{0,2}"    skipwhite nextgroup=vimString,vimSpecFile
 syn match    vimOper    "||\|&&\|[-+.]"    skipwhite nextgroup=vimString,vimSpecFile
-syn region    vimOperParen     oneline matchgroup=vimParenSep    start="(" end=")" contains=@vimOperGroup
-syn region    vimOperParen    oneline matchgroup=vimSep    start="{" end="}" contains=@vimOperGroup nextgroup=vimVar,vimFuncVar
+syn region    vimOperParen     matchgroup=vimParenSep    start="(" end=")" contains=@vimOperGroup
+syn region    vimOperParen    matchgroup=vimSep    start="{" end="}" contains=@vimOperGroup nextgroup=vimVar,vimFuncVar
 if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_noopererror")
  syn match    vimOperError    ")"
 endif
@@ -328,7 +328,7 @@
 syn match    vimMapBang    contained    "!"            skipwhite nextgroup=vimMapMod,vimMapLhs
 syn match    vimMapMod    contained    "\c<\(buffer\|expr\|\(local\)\=leader\|plug\|script\|sid\|unique\|silent\)\+>" contains=vimMapModKey,vimMapModErr skipwhite nextgroup=vimMapMod,vimMapLhs
 syn match    vimMapRhs    contained    ".*" contains=vimNotation,vimCtrlChar    skipnl nextgroup=vimMapRhsExtend
-syn match    vimMapRhsExtend    contained    "^\s*\\.*$"            contains=vimContinue
+syn match    vimMapRhsExtend    contained    "^\s*\\.*$"            contains=vimNotation,vimCtrlChar,vimContinue    skipnl nextgroup=vimMapRhsExtend
 syn case ignore
 syn keyword    vimMapModKey    contained    buffer    expr    leader    localleader    plug    script    sid    silent    unique
 syn case match


The error cases and explanations:


1. Source:

nmap <silent> ,h :if !exists("w:m1") <Bar><Bar>  w:m1 == 0 <Bar>
            \ ShowFormatHints <Bar> echo "Show format hints" <Bar> else <Bar>
            \ HideFormatHints <Bar> echo "Hide format hints" <Bar> endif<CR>



What's wrong in highlights:
a. <Bar>'s in second line are not highlighted
b. 3rd line is highlighted differently than vimMapRhs

What's wrong in syntax/vim.vim
a. vimMapRhsExtend must contain same groups as vimRhs, i.e. vimNotation,vimCtrlChar
b. vimRhsExtend could span more than 1 line, i.e. it should contain 'skipnl nextgroup=vimMapRhsExtend'


2. Source:

let g:WikiGlobal.nested_syntaxes = {'c': 'c', 'c++': 'cpp', 'perl': 'perl',
            \ 'python': 'python', 'sh': 'sh'}


What's wrong in highlights:
area 'c++': 'cpp' wrongly highlighted ( ++ as operator and following it ': ' as string)

What's wrong in syntax/vim.vim:
vimOperParen for "{}" is 'oneline' by some reason, why? This makes no syntax group for symbols '{' and '}'. Removing 'oneline' makes them correctly of 'vimSep' group.


3. Source

call add(g:TagMgrTags, map(map(map(split(s:line, '\s*::\s*'),
            \ 'substitute(v:val, "^!$", "", "")'),
            \ 'substitute(v:val, "\\([*?]\\)", "\\\\\\1", "g")'),
            \ 'expand(v:val)'))


What's wrong in highlights:
closing parens ')', ')' and '))' in 2nd, 3rd and 4th lines respectively are highlighted with red (vimOperError)

What's wrong in syntax/vim.vim:
same as in the case 2., only for "()" parens. Why they should be 'oneline'?


Cheers, Alexey.



vim_syntax-20121111.patch

Alexey Radkov

unread,
Nov 12, 2012, 1:50:17 AM11/12/12
to vim_dev


---------- Forwarded message ----------
From: Alexey Radkov <alexey...@gmail.com>
Date: 2012/11/11
Subject: some vim syntax fixes for multi-lined commands
To: vim...@vim.org


(missed vim_dev@googlegroups recipient)
vim_syntax-20121111.patch

Alexey Radkov

unread,
Nov 13, 2012, 4:37:45 AM11/13/12
to vim_dev
Hi.

I found another issue with vim sources syntax highlights.

In the following code:

fun! VimwikiLinkHandler(link)
  let link = a:link
  if link =~ "vlocal:" || link =~ "vfile:"
    let link = link[1:]
  else
    return 0
  endif
  " blah-blah
endif


line 'if link =~ "vlocal:" || link =~ "vfile:"' will be highlighted incorrectly because link is mistakenly regarded as part of region vimHiLink and highlighted as vimCommand (and the trail of the line is also spoiled). 'link[1:]' is also mistakenly regarded as part of region vimHiLink. The problem is in definition of vimHiLink: it should check if '\(def\%[ault]\s\+\)\=link\>\|\<def\>' is prceded by '\(\<hi\%[ghlight]\s\+\)'. So the new patch (including previous changes) is:

--- runtime/syntax/vim.vim    2012-11-13 11:47:49.841267569 +0400
+++ runtime/syntax/vim.vim.new    2012-11-13 13:22:36.769912872 +0400

@@ -152,8 +152,8 @@
 syn cluster    vimOperGroup    contains=vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimRegister,vimContinue
 syn match    vimOper    "\(==\|!=\|>=\|<=\|=\~\|!\~\|>\|<\|=\)[?#]\{0,2}"    skipwhite nextgroup=vimString,vimSpecFile
 syn match    vimOper    "||\|&&\|[-+.]"    skipwhite nextgroup=vimString,vimSpecFile
-syn region    vimOperParen     oneline matchgroup=vimParenSep    start="(" end=")" contains=@vimOperGroup
-syn region    vimOperParen    oneline matchgroup=vimSep    start="{" end="}" contains=@vimOperGroup nextgroup=vimVar,vimFuncVar
+syn region    vimOperParen     matchgroup=vimParenSep    start="(" end=")" contains=@vimOperGroup
+syn region    vimOperParen    matchgroup=vimSep    start="{" end="}" contains=@vimOperGroup nextgroup=vimVar,vimFuncVar
 if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_noopererror")
  syn match    vimOperError    ")"
 endif
@@ -328,7 +328,7 @@
 syn match    vimMapBang    contained    "!"            skipwhite nextgroup=vimMapMod,vimMapLhs
 syn match    vimMapMod    contained    "\c<\(buffer\|expr\|\(local\)\=leader\|plug\|script\|sid\|unique\|silent\)\+>" contains=vimMapModKey,vimMapModErr skipwhite nextgroup=vimMapMod,vimMapLhs
 syn match    vimMapRhs    contained    ".*" contains=vimNotation,vimCtrlChar    skipnl nextgroup=vimMapRhsExtend
-syn match    vimMapRhsExtend    contained    "^\s*\\.*$"            contains=vimContinue
+syn match    vimMapRhsExtend    contained    "^\s*\\.*$"            contains=vimNotation,vimCtrlChar,vimContinue    skipnl nextgroup=vimMapRhsExtend
 syn case ignore
 syn keyword    vimMapModKey    contained    buffer    expr    leader    localleader    plug    script    sid    silent    unique
 syn case match
@@ -520,7 +520,7 @@
 syn keyword    vimHiClear    contained    clear    nextgroup=vimHiGroup
 
 " Highlight: link {{{2
-syn region    vimHiLink    contained oneline matchgroup=vimCommand start="\<\(def\%[ault]\s\+\)\=link\>\|\<def\>" end="$"    contains=vimHiGroup,vimGroup,vimHLGroup,vimNotation
+syn region    vimHiLink    contained oneline matchgroup=vimCommand start="\(\<hi\%[ghlight]\s\+\)\@<=\(\(def\%[ault]\s\+\)\=link\>\|\<def\>\)" end="$"    contains=vimHiGroup,vimGroup,vimHLGroup,vimNotation
 syn cluster vimFuncBodyList add=vimHiLink
 
 " Control Characters {{{2



The patch is also included.

Cheers, Alexey.


2012/11/12 Alexey Radkov <alexey...@gmail.com>
vim_syntax-20121113.patch

Charles Campbell

unread,
Nov 13, 2012, 4:03:23 PM11/13/12
to vim...@googlegroups.com
Alexey Radkov wrote:
> Hi.
>
> I found another issue with vim sources syntax highlights.
>
> In the following code:
>
> fun! VimwikiLinkHandler(link)
> let link = a:link
> if link =~ "vlocal:" || link =~ "vfile:"
> let link = link[1:]
> else
> return 0
> endif
> " blah-blah
> endif
Hello!

I will accept the patches (except for the duplicate patching in the last
one, which was rejected).

Please try the version in
http://www.drchip.org/astronaut/vim/index.html#SYNTAX_VIM

(I don't remember why the onelines were there, I'm afraid)

BTW, I prefer direct email contact for patches rather than via the
mailing list.

Thank you for your contributions,
C Campbell

Alexey Radkov

unread,
Nov 14, 2012, 2:16:06 AM11/14/12
to vim_dev
Hi Charles.

Thank you!


2012/11/14 Charles Campbell <Charles.E...@nasa.gov>

Alexey Radkov wrote:
Hi.

I found another issue with vim sources syntax highlights.

In the following code:

fun! VimwikiLinkHandler(link)
  let link = a:link
  if link =~ "vlocal:" || link =~ "vfile:"
    let link = link[1:]
  else
    return 0
  endif
  " blah-blah
endif
Hello!

I will accept the patches (except for the duplicate patching in the last one, which was rejected).

Yes, the 2nd patch included the first, therefore same part in 2nd patch was rejected.


I tried. It works fine!
 

(I don't remember why the onelines were there, I'm afraid)

BTW, I prefer direct email contact for patches rather than via the mailing list.

Ok, sure. But i did not know whom i should address with that.
 

Thank you for your contributions,
C Campbell


--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Cheers, Alexey.

Charles E Campbell Jr

unread,
Nov 14, 2012, 2:55:55 PM11/14/12
to vim...@googlegroups.com
Alexey Radkov wrote:
> Hi Charles.
>
> Thank you!

You're welcome!
>
>
> 2012/11/14 Charles Campbell <Charles.E...@nasa.gov
> <mailto:Charles.E...@nasa.gov>>
(snipped)
>
> BTW, I prefer direct email contact for patches rather than via the
> mailing list.
>
>
> Ok, sure. But i did not know whom i should address with that.
At the top of the syntax files the Maintainers (usually) include their
email address. Mine is there, although one has to manually remove the
NOSPAM embedded therein.

Regards,
Charles Campbell

Reply all
Reply to author
Forward
0 new messages