From 07098738f311b3fbb9cd8d60fbafb5dcf47a5beb Mon Sep 17 00:00:00 2001 From: ghetto Date: Sun, 9 Feb 2020 09:12:34 +0100 Subject: [PATCH 1/2] Option g:minisnip_backreffirst --- autoload/minisnip.vim | 4 +++- doc/minisnip.txt | 12 ++++++++++-- plugin/minisnip.vim | 1 + syntax/minisnip.vim | 2 ++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/autoload/minisnip.vim b/autoload/minisnip.vim index 36dae0d..c4bc2fe 100644 --- a/autoload/minisnip.vim +++ b/autoload/minisnip.vim @@ -151,7 +151,9 @@ function! s:SelectPlaceholder() abort let @s=substitute(@s, '\V' . g:minisnip_backrefmarker . '\(\d\)', \"\\=\"'\" . substitute(get( \ s:placeholder_texts, - \ len(s:placeholder_texts) - str2nr(submatch(1)), '' + \ g:minisnip_backreffirst ? + \ str2nr(submatch(1)) : + \ len(s:placeholder_texts) - str2nr(submatch(1)), '' \), \"'\", \"''\", 'g') . \"'\"", 'g') " evaluate what's left let @s=eval(@s) diff --git a/doc/minisnip.txt b/doc/minisnip.txt index 2694de1..fa24797 100644 --- a/doc/minisnip.txt +++ b/doc/minisnip.txt @@ -123,8 +123,8 @@ Default: '\\~' When this is present, followed by a single digit `n`, in a placeholder that also starts with |'g:minisnip_evalmarker'|, it will be replaced with the `n`th -to last previous placeholder value, surrounded by quotes. Here is an example -of how it can be used: > +placeholder value, according to |'g:minisnip_backreffirst'|, surrounded by +quotes. Here is an example of how it can be used: > #ifndef {{+INCLUDE_GUARD+}} #define {{+~\~1+}} @@ -135,6 +135,14 @@ of how it can be used: > This will automatically fill the `#define` line with the value entered on the `#ifndef` line upon jumping to it. +------------------------------------------------------------------------------- + *'g:minisnip_backreffirst'* +Default: 0 + +If set to 0, backreferences will be replaced with the `n`th to last +placeholder value. If set to a non 0 value, the `n`th from first placeholder +will be used instead. + ------------------------------------------------------------------------------- *'g:minisnip_finalstartdelim'* *'g:minisnip_finalenddelim'* diff --git a/plugin/minisnip.vim b/plugin/minisnip.vim index c88a6a0..9b7186e 100644 --- a/plugin/minisnip.vim +++ b/plugin/minisnip.vim @@ -14,6 +14,7 @@ let g:minisnip_finalenddelim = get(g:, 'minisnip_finalenddelim', '-}}') let g:minisnip_evalmarker = get(g:, 'minisnip_evalmarker', '~') let g:minisnip_donotskipmarker = get(g:, 'minisnip_donotskipmarker', '`') let g:minisnip_backrefmarker = get(g:, 'minisnip_backrefmarker', '\\~') +let g:minisnip_backreffirst = get(g:, 'minisnip_backreffirst', 0) " this is the pattern used to find placeholders let g:minisnip_delimpat = '\V' . g:minisnip_startdelim . '\.\{-}' . g:minisnip_enddelim diff --git a/syntax/minisnip.vim b/syntax/minisnip.vim index cf872b7..b84eff3 100644 --- a/syntax/minisnip.vim +++ b/syntax/minisnip.vim @@ -26,6 +26,8 @@ endif " Get the minisnip defined delimiters exe "syntax match minisnipKeyword /" . g:minisnip_startdelim . "/" exe "syntax match minisnipKeyword /" . g:minisnip_enddelim . "/" +exe "syntax match minisnipKeyword /" . g:minisnip_finalstartdelim . "/" +exe "syntax match minisnipKeyword /" . g:minisnip_finalenddelim . "/" highlight default link minisnipKeyword Keyword From 4ede4cb20d002639fcbbca4cfc69f753dbedc1ae Mon Sep 17 00:00:00 2001 From: ghetto Date: Sun, 9 Feb 2020 10:23:45 +0100 Subject: [PATCH 2/2] fixed indentaion --- autoload/minisnip.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/minisnip.vim b/autoload/minisnip.vim index c4bc2fe..769fe9e 100644 --- a/autoload/minisnip.vim +++ b/autoload/minisnip.vim @@ -152,8 +152,8 @@ function! s:SelectPlaceholder() abort \"\\=\"'\" . substitute(get( \ s:placeholder_texts, \ g:minisnip_backreffirst ? - \ str2nr(submatch(1)) : - \ len(s:placeholder_texts) - str2nr(submatch(1)), '' + \ str2nr(submatch(1)) : + \ len(s:placeholder_texts) - str2nr(submatch(1)), '' \), \"'\", \"''\", 'g') . \"'\"", 'g') " evaluate what's left let @s=eval(@s)