Last active
September 27, 2020 09:22
-
-
Save todesking/8f32b7042439752dc9d6124c3bd68a38 to your computer and use it in GitHub Desktop.
syntax-region's odd behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax clear | |
syntax match expr_name /\K\k*/ nextgroup=B | |
syntax region outer | |
\ start=/(/ end=/)/ | |
\ contains=inner | |
syntax region inner | |
\ start=/(/ end=/)/ | |
\ contains=expr_name | |
\ contained | |
highlight outer guifg=#00ffff | |
highlight inner guifg=#ff0000 | |
highlight expr_name guifg=#ff00ff | |
" Expected: ((aaa)) | |
" ^ ^ outer | |
" ^ ^ inner | |
" ^^^ expr_name | |
" Actual: ((aaa)) | |
" ^^ ^ inner | |
" ^^^ expr_name | |
" ^ outer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Using matchgroup to avoid above behavior. | |
" :help :syn-contains says: | |
" > The contained groups will also match in the start and end patterns of a | |
" > region. If this is not wanted, the "matchgroup" argument can be used | |
" > |:syn-matchgroup|. | |
syntax clear | |
syntax match expr_name /\K\k*/ nextgroup=B | |
syntax region outer | |
\ matchgroup=outer_parenthesis | |
\ start=/(/ end=/)/ | |
\ contains=inner | |
syntax region inner | |
\ matchgroup=inner_parenthesis | |
\ start=/(/ end=/)/ | |
\ contains=expr_name | |
\ contained | |
highlight outer_parenthesis guifg=#00ffff | |
highlight inner_parenthesis guifg=#ff0000 | |
highlight expr_name guifg=#ff00ff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment