Fixes to syntax/sh.vim: escaped quotes, case statements
(resending with correct cc: address information) Hi, I've noted a number of issues with the bourne shell syntax highlighting, and have finally got around to coding a patch to fix them. 1. "while" highlighting broken after function definitions: > foo() { }; while true; do :; done 2. "while" highlighting whole predicate unnecessarily: > while pgrep vim; do :; done 3. Marking escaped quotes as errors after parameter dereference operators: > echo ${foo+\"yes\"} > echo ${foo+\'yes\'} 4. Escaping close parens broken in case matches: > case x in \));; esac 5. Escaping quotes broken in lots of places: echo \"hello\" echo \'hello\' echo \`hello\` My motivation - and primary testcase - has been GNU Libtool (/usr/bin/libtool), which has over 7500 lines of fairly complex sh constructs. With the attached patch it seems to get highlighted quite well. Ed Catmur --~--~-~--~~~---~--~~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~--~~~~--~~--~--~--- --- vim71/runtime/syntax/sh.vim 2007/10/20 19:35:31 1.1 +++ vim71/runtime/syntax/sh.vim 2007/10/20 21:46:17 @@ -71,7 +71,7 @@ syn case match " Clusters: [EMAIL PROTECTED] clusters {{{1 "== syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq -syn cluster shCaseList [EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq +syn cluster shCaseList [EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shRepeat,shSetList,shSource,shStatement,shVariable,shCtrlSeq syn cluster shColonList [EMAIL PROTECTED] syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shNumber,shOperator,shPosnParm,shExSingleQuote,shSingleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest,shCtrlSeq syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial @@ -81,7 +81,7 @@ syn cluster shDerefVarList contains=shDe syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq syn cluster shExprList2 [EMAIL PROTECTED],@shCaseList,shTest -syn cluster shFunctionList [EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shFunctionStart,shCtrlSeq +syn cluster shFunctionList [EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shRepeat,shSetList,shSource,shStatement,shVariable,shOperator,shFunctionStart,shCtrlSeq if exists("b:is_kornshell") || exists("b:is_bash") syn cluster shFunctionList add=shDblBrace,shDblParen endif @@ -182,7 +182,6 @@ else syn region shFor matchgroup=shLoop start="\" end="\" end="\"me=e-2 [EMAIL PROTECTED],shDblParen skipwhite nextgroup=shCurlyIn endif if exists("b:is_kornshell") || exists("b:is_bash") - syn cluster shCaseList add=shRepeat syn region shRepeat matchgroup=shLoop start="\" end="\" end="\"me=e-2 [EMAIL PROTECTED],shDblParen,shDblBrace syn region shRepeat matchgroup=shLoop start="\" end="\" end="\"me=e-2 [EMAIL PROTECTED],shDblParen,shDblBrace syn region shCaseEsac matchgroup=shConditional start="\" matchgroup=shConditional end="\" end="\" [EMAIL PROTECTED] @@ -195,9 +194,9 @@ syn match shComma contained "," " Case: case...esac {{{1 " -syn match shCaseBar contained skipwhite "[^|"`'()]\{-}|"hs=e nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote +syn match shCaseBar contained skipwhite "\([^|"`'()\\]\|\\.\)\{-}|"hs=e nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar -syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\([^#$()'" \t]\|\\.\)\{-})"ms=s,hs=e end=";;" end="esac"me=s-1 [EMAIL PROTECTED] nextgroup=shCaseStart,shCase,shComment +syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\([^#$()'" \t\\]\|\\.\)\{-})"ms=s,hs=e end=";;" end="esac"me=s-1 [EMAIL PROTECTED] nextgroup=shCaseStart,shCase,shComment if g:sh_fold_enabled syn region shCaseEsac fold matchgroup=shConditional start="\" end="\" [EMAIL PROTECTED] else @@ -209,14 +208,14 @@ if exists("b:is_bash") else syn region shCaseExSingleQuote matchgroup=Error start
Fixes to syntax/sh.vim: escaped quotes, case statements
Hi, I've noted a number of issues with the bourne shell syntax highlighting, and have finally got around to coding a patch to fix them. 1. "while" highlighting broken after function definitions: > foo() { }; while true; do :; done 2. "while" highlighting whole predicate unnecessarily: > while pgrep vim; do :; done 3. Marking escaped quotes as errors after parameter dereference operators: > echo ${foo+\"yes\"} > echo ${foo+\'yes\'} 4. Escaping close parens broken in case matches: > case x in \));; esac 5. Escaping quotes broken in lots of places: echo \"hello\" echo \'hello\' echo \`hello\` My motivation - and primary testcase - has been GNU Libtool (/usr/bin/libtool), which has over 7500 lines of fairly complex sh constructs. With the attached patch it seems to get highlighted quite well. Ed Catmur --~--~-~--~~~---~--~~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~--~~~~--~~--~--~--- --- vim71/runtime/syntax/sh.vim 2007/10/20 19:35:31 1.1 +++ vim71/runtime/syntax/sh.vim 2007/10/20 21:46:17 @@ -71,7 +71,7 @@ syn case match " Clusters: [EMAIL PROTECTED] clusters {{{1 "== syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq -syn cluster shCaseList [EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq +syn cluster shCaseList [EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shRepeat,shSetList,shSource,shStatement,shVariable,shCtrlSeq syn cluster shColonList [EMAIL PROTECTED] syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shNumber,shOperator,shPosnParm,shExSingleQuote,shSingleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest,shCtrlSeq syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial @@ -81,7 +81,7 @@ syn cluster shDerefVarList contains=shDe syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq syn cluster shExprList2 [EMAIL PROTECTED],@shCaseList,shTest -syn cluster shFunctionList [EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shFunctionStart,shCtrlSeq +syn cluster shFunctionList [EMAIL PROTECTED],shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shRepeat,shSetList,shSource,shStatement,shVariable,shOperator,shFunctionStart,shCtrlSeq if exists("b:is_kornshell") || exists("b:is_bash") syn cluster shFunctionList add=shDblBrace,shDblParen endif @@ -182,7 +182,6 @@ else syn region shFor matchgroup=shLoop start="\" end="\" end="\"me=e-2 [EMAIL PROTECTED],shDblParen skipwhite nextgroup=shCurlyIn endif if exists("b:is_kornshell") || exists("b:is_bash") - syn cluster shCaseList add=shRepeat syn region shRepeat matchgroup=shLoop start="\" end="\" end="\"me=e-2 [EMAIL PROTECTED],shDblParen,shDblBrace syn region shRepeat matchgroup=shLoop start="\" end="\" end="\"me=e-2 [EMAIL PROTECTED],shDblParen,shDblBrace syn region shCaseEsac matchgroup=shConditional start="\" matchgroup=shConditional end="\" end="\" [EMAIL PROTECTED] @@ -195,9 +194,9 @@ syn match shComma contained "," " Case: case...esac {{{1 " -syn match shCaseBar contained skipwhite "[^|"`'()]\{-}|"hs=e nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote +syn match shCaseBar contained skipwhite "\([^|"`'()\\]\|\\.\)\{-}|"hs=e nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar -syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\([^#$()'" \t]\|\\.\)\{-})"ms=s,hs=e end=";;" end="esac"me=s-1 [EMAIL PROTECTED] nextgroup=shCaseStart,shCase,shComment +syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\([^#$()'" \t\\]\|\\.\)\{-})"ms=s,hs=e end=";;" end="esac"me=s-1 [EMAIL PROTECTED] nextgroup=shCaseStart,shCase,shComment if g:sh_fold_enabled syn region shCaseEsac fold matchgroup=shConditional start="\" end="\" [EMAIL PROTECTED] else @@ -209,14 +208,14 @@ if exists("b:is_bash") else syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\|\\.+ end=+'+ contains=shStringS
Re: Wish: opposite to split() ...
Ben Schmidt schrieb: > Andy Wokula wrote: >> ... and I don't mean join(). >> >> I'd like to have a function like split(), except for it should collect all >> the _matches_ in a list. "matchlist()" would be a good name for it, >> unfortunately it's already taken. >> >> How would I do it now? > > A naive and inefficient but simple implementation: > > function ListOfMatches(subject,pattern) > let l:matches = [] > let l:matchnum = 1 > let l:curmatch = matchstr(a:subject, a:pattern, 0, l:matchnum) > while l:curmatch != "" > let l:matches = add(l:matches, l:curmatch) > let l:matchnum = l:matchnum + 1 > let l:curmatch = matchstr(a:subject, a:pattern, 0, l:matchnum) > endwhile > return l:matches > endfunction > > E.g. > > :echo ListOfMatches("abracadabra","a.") > > ['ab', 'ac', 'ad', 'ab'] > > Enjoy! > > Ben. Thx for your solution. It has a small drawback though: :echo ListOfMatches("abc", 'ab\|bc') ['ab', 'bc'] -- Andy I already sent this message two days ago ... it got lost? --~--~-~--~~~---~--~~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~--~~~~--~~--~--~---
Re: is this a bug or a feature??
denis wrote: > > > On Oct 13, 4:41 am, Ilya Sher <[EMAIL PROTECTED]> wrote: >> denis wrote: > [snip] >>> eh? is this a bug or a feature? >> It's a feature. >> The point is that terminal might be resized when running >> the external command so VIM will try to re-detect it >> after executing any external command. >> >> Detection of the terminal size is described in >> :he window-size > > Thanks. so, this somewhat makes sense. However, I am starting a vim - > g, > which is not running in the terminal. It sounds like in my case > expected behavior should be different? I'm sorry but I don't know about that. > > -d > > > > -- Beating the averages: http://www.paulgraham.com/avg.html Python paradox: http://www.paulgraham.com/pypar.html Bad Vista:http://badvista.org/ XML sucks:http://c2.com/cgi/wiki?XmlSucks For robots (please don't mail me there): [EMAIL PROTECTED] --~--~-~--~~~---~--~~ You received this message from the "vim_dev" maillist. For more information, visit http://www.vim.org/maillist.php -~--~~~~--~~--~--~---