cohama / lexima.vim

Auto close parentheses and repeat by dot dot dot...
995 stars 46 forks source link

Add rule key 'input_after_with' supporting backreferences #120

Closed notuxic closed 2 years ago

notuxic commented 2 years ago

This PR adds an additional rule key "input_after_with" which can use backreferences to capture groups in the key "at".

This allows creation of rules where the closing string requires a substring of the opening string, such as in HTML tags or LaTeX environments.

Example usage for LaTeX:

"" add endwise rule for LaTeX environments
call lexima#add_rule({
\ 'filetype': 'tex',
\ 'char': '<CR>',
\ 'input': '<CR>',
\ 'input_after_with': '<CR>\\end{\1}',
\ 'at': '^.*\\begin{\([^}]*\)}\(\[.*\]\)*\%#$'
\ })
cohama commented 2 years ago

I can not merge this pr for now because of breaking dot-repetability.

notuxic commented 2 years ago

I'll look into it. But I don't have a lot of free time on my hands right now, so it may take a while until I get to it.

cohama commented 2 years ago

I finally merge it (rebase and resolve conflicts). See 7cc8f7390a1239e684af72b12ce2ce22fab3a3dd Thank you for your contribution.

I have changed the key and feature, use "with_submatch" instead of "input_after_with" so that both "input" and "input_after" can be used as replace pattern.

cohama commented 2 years ago

For now, you can use

"" add endwise rule for LaTeX environments
call lexima#add_rule({
\ 'filetype': 'tex',
\ 'char': '<CR>',
\ 'input': '<CR>',
\ 'input_after': '<CR>\\end{\1}',
\ 'at': '^.*\\begin{\([^}]*\)}\(\[.*\]\)*\%#$',
\ 'with_submatch': 1,
\ })