]> git.wincent.com - pinnacle.git/commitdiff
Fix regex capture groups
authorGreg Hurrell <greg@hurrell.net>
Wed, 7 Jun 2017 21:26:52 +0000 (14:26 -0700)
committerGreg Hurrell <greg@hurrell.net>
Wed, 7 Jun 2017 21:33:28 +0000 (14:33 -0700)
This is hard to read, but given something like:

  (a)*(b)(c)*

And input like:

  aaaaaabccccc

Vim is going to capture only the last "a" matched by "(a)*".

To make it capture the whole thing we need to turn:

  (a)*

into:

  (%(a)*)

ie. make the inner "(a)" non-capturing.

With Vim's unfortunate escaping, these examples get a bit uglier:

   \(\%(a\)*\)

instead of:

  (%(a)*)

and so on...

This fixes the issue we had where a group like `Underlined`:

  term=underline cterm=underline ctermfg=1 gui=underline guifg=#cc6666

was being emboldened incorrectly as:

  cterm=bold ctermfg=1 gui=bold,underline guifg=#cc6666

Because the following sequence would occur:

1. Search for "gui=...", identifying "ctermfg=..." as the prefix and
   "guifg=..." as the suffix.
2. Throw away "cterm=bold" while reconstructing the new highlight,
   because it was not correctly captured.
3. etc... all bets are off here because we've already thrown away data.

autoload/pinnacle.vim

index 5931e84751cab349f42862791789faab6d09fbcb..1e4d40337c058c2554a62fedae0505df9e8677d5 100644 (file)
@@ -234,9 +234,9 @@ function! pinnacle#decorate(style, group) abort
     " Check for existing setting.
     let l:matches = matchlist(
       \   l:original,
-      \   '^\([^ ]\+ \)*' .
+      \   '^\(\%([^ ]\+ \)*\)' .
       \   '\(' . l:lhs . '=[^ ]\+\)' .
-      \   '\( .\+\)*$'
+      \   '\(\%( [^ ]\+\)*\)$'
       \ )
     if l:matches == []
       " No setting, add one with just a:style in it