To: vim-dev@vim.org Subject: patch 5.5.032 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.5.032 (depends on patch 5.5.025) Problem: Patch 5.5.025 wasn't right. And C highlighting was still not working correctly for a #define. Solution: Added "excludenl" argument to ":syntax", to be able not to extend a containing item when there is a match with the end-of-line. Files: src/syntax.c, runtime/doc/syntax.txt, runtime/syntax/c.vim *** ../vim-5.5.31/src/syntax.c Sun Oct 17 15:45:09 1999 --- src/syntax.c Tue Oct 19 10:42:33 1999 *************** *** 162,167 **** --- 162,168 ---- #define HL_SKIPWHITE 0x100 /* nextgroup can skip white space */ #define HL_SKIPEMPTY 0x200 /* nextgroup can skip empty lines */ #define HL_KEEPEND 0x400 /* end match always kept */ + #define HL_EXCLUDENL 0x800 /* exclude NL from match */ #define SYN_ITEMS(buf) ((struct syn_pattern *)((buf)->b_syn_patterns.ga_data)) *************** *** 1701,1714 **** * Only for a region the search for the end continues after * the end of the contained item. If the contained match * included the end-of-line, break here, the region continues. ! * Don't do this when "keepend" is used. */ if (SYN_ITEMS(syn_buf)[cur_si->si_idx].sp_type == SPTYPE_START ! && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND)) ! && keepend_level < 0) { update_si_end(cur_si, line, (int)current_col); ! if (current_next_flags & HL_HAS_EOL) break; } } --- 1702,1719 ---- * Only for a region the search for the end continues after * the end of the contained item. If the contained match * included the end-of-line, break here, the region continues. ! * Don't do this when: ! * - "keepend" is used for the contained item ! * - not at the end of the line (could be end="x$"me=e-1). ! * - "excludenl" is used (HL_HAS_EOL won't be set) */ if (SYN_ITEMS(syn_buf)[cur_si->si_idx].sp_type == SPTYPE_START ! && !(cur_si->si_flags & (HL_MATCH | HL_KEEPEND))) { update_si_end(cur_si, line, (int)current_col); ! if ((current_next_flags & HL_HAS_EOL) ! && keepend_level < 0 ! && line[current_col] == NUL) break; } } *************** *** 2639,2644 **** --- 2644,2654 ---- msg_puts_attr((char_u *)"keepend", attr); msg_putchar(' '); } + if (spp->sp_flags & HL_EXCLUDENL) + { + msg_puts_attr((char_u *)"excludenl", attr); + msg_putchar(' '); + } if (spp->sp_flags & HL_TRANSP) { msg_puts_attr((char_u *)"transparent", attr); *************** *** 3084,3089 **** --- 3094,3100 ---- } flagtab[] = { {"contained", 9, HL_CONTAINED}, {"oneline", 7, HL_ONELINE}, {"keepend", 7, HL_KEEPEND}, + {"excludenl", 9, HL_EXCLUDENL}, {"transparent", 11, HL_TRANSP}, {"skipnl", 6, HL_SKIPNL}, {"skipwhite", 9, HL_SKIPWHITE}, *************** *** 3385,3391 **** init_syn_patterns(); vim_memset(&item, 0, sizeof(item)); rest = get_syn_pattern(rest, &item); ! if (vim_regcomp_had_eol()) flags |= HL_HAS_EOL; /* Get options after the pattern */ --- 3396,3402 ---- init_syn_patterns(); vim_memset(&item, 0, sizeof(item)); rest = get_syn_pattern(rest, &item); ! if (vim_regcomp_had_eol() && !(flags & HL_EXCLUDENL)) flags |= HL_HAS_EOL; /* Get options after the pattern */ *************** *** 3586,3592 **** * Get the syntax pattern and the following offset(s). */ rest = get_syn_pattern(rest, ppp->pp_synp); ! if (item == ITEM_END && vim_regcomp_had_eol()) ppp->pp_synp->sp_flags |= HL_HAS_EOL; ppp->pp_matchgroup_id = matchgroup_id; ++pat_count; --- 3597,3604 ---- * Get the syntax pattern and the following offset(s). */ rest = get_syn_pattern(rest, ppp->pp_synp); ! if (item == ITEM_END && vim_regcomp_had_eol() ! && !(flags & HL_EXCLUDENL)) ppp->pp_synp->sp_flags |= HL_HAS_EOL; ppp->pp_matchgroup_id = matchgroup_id; ++pat_count; *** ../vim-5.5.31/runtime/doc/syntax.txt Wed Sep 22 10:06:42 1999 --- runtime/doc/syntax.txt Wed Oct 20 10:10:32 1999 *************** *** 1,4 **** ! *syntax.txt* For Vim version 5.5. Last change: 1999 Sep 19 VIM REFERENCE MANUAL by Bram Moolenaar --- 1,4 ---- ! *syntax.txt* For Vim version 5.5. Last change: 1999 Oct 20 VIM REFERENCE MANUAL by Bram Moolenaar *************** *** 1046,1051 **** --- 1046,1055 ---- variations at once: > :syntax keyword VimCommand ab[breviate] n[ext] + Don't forget that a keyword can only be recognized if all the + characters are included in the 'iskeyword' option. If one character + isn't, the keyword will never be recognized. + A keyword always has higher priority than a match or region, the keyword is used if more than one item matches. Keywords do not nest and a keyword can't contain anything else. *************** *** 1069,1080 **** DEFINING MATCHES *:syn-match* ! :sy[ntax] match {group-name} [{options}] {pattern} [{options}] This defines one match. {group-name} A syntax group name such as "Comment". [{options}] See |:syn-arguments| below. {pattern} The search pattern that defines the match. See |:syn-pattern| below. --- 1073,1087 ---- DEFINING MATCHES *:syn-match* ! :sy[ntax] match {group-name} [{options}] [excludenl] {pattern} [{options}] This defines one match. {group-name} A syntax group name such as "Comment". [{options}] See |:syn-arguments| below. + [excludenl] Don't make a pattern with the end-of-line "$" + extend a containing match or region. Must be + given before the pattern. |:syn-excludenl| {pattern} The search pattern that defines the match. See |:syn-pattern| below. *************** *** 1087,1092 **** --- 1094,1100 ---- :sy[ntax] region {group-name} [{options}] [matchgroup={group_name}] [keepend] + [excludenl] start={start_pattern} .. [skip={skip_pattern}] end={end_pattern} .. *************** *** 1105,1110 **** --- 1113,1122 ---- keepend Don't allow contained matches to go past a match with the end pattern. See |:syn-keepend|. + excludenl Don't make a pattern with the end-of-line "$" + extend a containing match or item. Only + useful for end patterns. Must be given before + the patterns it applies to. |:syn-excludenl| start={start_pattern} The search pattern that defines the start of the region. See |:syn-pattern| below. skip={skip_pattern} The search pattern that defines text inside *************** *** 1125,1131 **** When more than one start pattern is given, a match with one of these is sufficient. This means there is an OR relation between the start ! patterns. The first one that matches is used. The same is true for the end patterns. The search for the end pattern starts at the start of the region. --- 1137,1143 ---- When more than one start pattern is given, a match with one of these is sufficient. This means there is an OR relation between the start ! patterns. The last one that matches is used. The same is true for the end patterns. The search for the end pattern starts at the start of the region. *************** *** 1163,1168 **** --- 1175,1195 ---- after each contained match. When "keepend" is included, the first encountered match with an end pattern is used, truncating any contained matches. + + *:syn-excludenl* + When a pattern for a match or end pattern of a region includes a '$' + to match the end-of-line, it will make an item that it is contained in + continue on the next line. For example, a match with "\\$" (backslash + at the end of the line) can make a match continue that would normally + stop at the end of the line. This is the default behaviour. If this + is not wanted, there are two ways to avoid it: + 1. Use "keepend" for the the containing item. This will keep all + contained matches from extending the match or region. It can be + used when all contained items must not extend the containing item. + 2. Use "excludenl" in the contained item. This will keep that match + from extending the containing match or region. It can be used if + only some contained items must not extend the containing item. + "excludenl" must be given before the pattern it applies to. *:syn-matchgroup* "matchgroup" can be used to highlight the start and/or end pattern *** ../vim-5.5.31/runtime/syntax/c.vim Wed Sep 22 10:06:30 1999 --- runtime/syntax/c.vim Tue Oct 19 10:49:47 1999 *************** *** 1,7 **** " Vim syntax file " Language: C " Maintainer: Bram Moolenaar ! " Last change: 1999 Sep 18 " Remove any old syntax stuff hanging around syn clear --- 1,7 ---- " Vim syntax file " Language: C " Maintainer: Bram Moolenaar ! " Last change: 1999 Oct 19 " Remove any old syntax stuff hanging around syn clear *************** *** 25,36 **** --- 25,42 ---- endif if exists("c_no_cformat") syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial + " cCppString: same as cString, but ends at end of line + syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial else syn match cFormat "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([diuoxXfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained syn match cFormat "%%" contained syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat + " cCppString: same as cString, but ends at end of line + syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat hi link cFormat cSpecial endif + hi link cCppString cString + syn match cCharacter "L\='[^\\]'" syn match cCharacter "L'[^']*'" contains=cSpecial syn match cSpecialError "L\='\\[^'\"?\\abfnrtv]'" *************** *** 42,48 **** "when wanted, highlight trailing white space if exists("c_space_errors") if !exists("c_no_trail_space_error") ! syn match cSpaceError "\s\+$" endif if !exists("c_no_tab_space_error") syn match cSpaceError " \+\t"me=e-1 --- 48,54 ---- "when wanted, highlight trailing white space if exists("c_space_errors") if !exists("c_no_trail_space_error") ! syn match cSpaceError excludenl "\s\+$" endif if !exists("c_no_tab_space_error") syn match cSpaceError " \+\t"me=e-1 *************** *** 50,65 **** endif "catch errors caused by wrong parenthesis and brackets ! syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,@cCommentGroup,cUserCont,cUserLabel,cBitField,cCommentSkip,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom if exists("c_no_bracket_error") ! syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup syn match cParenError ")" syn match cErrInParen contained "[{}]" else ! syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cErrInBracket syn match cParenError "[\])]" syn match cErrInParen contained "[\]{}]" ! syn region cBracket transparent start='\[' end=']' contains=ALLBUT,@cParenGroup,cErrInParen syn match cErrInBracket contained "[);{}]" endif --- 56,77 ---- endif "catch errors caused by wrong parenthesis and brackets ! syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cUserCont,cUserLabel,cBitField,cCommentSkip,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom if exists("c_no_bracket_error") ! syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString ! " cCppParen: same as cParen but ends at end-of-line; used in cDefine ! syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString syn match cParenError ")" syn match cErrInParen contained "[{}]" else ! syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString ! " cCppParen: same as cParen but ends at end-of-line; used in cDefine ! syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString syn match cParenError "[\])]" syn match cErrInParen contained "[\]{}]" ! syn region cBracket transparent start='\[' end=']' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString ! " cCppBracket: same as cParen but ends at end-of-line; used in cDefine ! syn region cCppBracket transparent start='\[' skip='\\$' excludenl end=']' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString syn match cErrInBracket contained "[);{}]" endif *************** *** 145,151 **** syn keyword cConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX endif ! syn region cPreCondit start="^\s*#\s*\(if\|ifdef\|ifndef\|elif\|else\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cString,cCharacter,cNumbers,cCommentError,cSpaceError syn match cPreCondit "^\s*#\s*\(else\|endif\)\>" if !exists("c_no_if0") syn region cCppOut start="^\s*#\s*if\s\+0\>" end=".\|$" contains=cCppOut2 --- 157,163 ---- syn keyword cConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX endif ! syn region cPreCondit start="^\s*#\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1 contains=cComment,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError syn match cPreCondit "^\s*#\s*\(else\|endif\)\>" if !exists("c_no_if0") syn region cCppOut start="^\s*#\s*if\s\+0\>" end=".\|$" contains=cCppOut2 *************** *** 156,167 **** syn match cIncluded contained "<[^>]*>" syn match cInclude "^\s*#\s*include\>\s*["<]" contains=cIncluded "syn match cLineSkip "\\$" ! syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom syn region cDefine start="^\s*#\s*\(define\|undef\)\>" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup ! syn region cPreProc start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup " Highlight User Labels ! syn cluster cMultiGroup contains=cIncluded,cSpecial,@cCommentGroup,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom syn region cMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup " Avoid matching foo::bar() in C++ by requiring that the next char is not ':' syn cluster cLabelGroup contains=cUserLabel --- 168,179 ---- syn match cIncluded contained "<[^>]*>" syn match cInclude "^\s*#\s*include\>\s*["<]" contains=cIncluded "syn match cLineSkip "\\$" ! syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cParen,cBracket syn region cDefine start="^\s*#\s*\(define\|undef\)\>" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup ! syn region cPreProc start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup " Highlight User Labels ! syn cluster cMultiGroup contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOut,cCppOut2,cCppSkip,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString syn region cMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup " Avoid matching foo::bar() in C++ by requiring that the next char is not ':' syn cluster cLabelGroup contains=cUserLabel *** ../vim-5.5.31/src/version.c Sun Oct 24 19:27:14 1999 --- src/version.c Sun Oct 24 19:28:17 1999 *************** *** 420,420 **** --- 420,421 ---- { /* Add new patch number below this line */ + 32, -- OLD WOMAN: King of the WHO? ARTHUR: The Britons. OLD WOMAN: Who are the Britons? "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\-- \ \ www.vim.org/iccf www.moolenaar.net www.vim.org / /