From 0c20e4136a298a73e21047d12cc5049595fb8445 Mon Sep 17 00:00:00 2001 From: Adnan Zafar Date: Wed, 8 Jun 2016 12:25:17 -0400 Subject: [PATCH] Fix visual placeholder in legacy parser The fix for #177 only handled the case where a visual placeholder was on a line with an indent. With this commit, all cases should be handled. Hopefully. See #233 --- autoload/snipmate/legacy.vim | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/autoload/snipmate/legacy.vim b/autoload/snipmate/legacy.vim index 035c5eec..7ff39cbe 100644 --- a/autoload/snipmate/legacy.vim +++ b/autoload/snipmate/legacy.vim @@ -12,8 +12,7 @@ function! snipmate#legacy#process_snippet(snip) abort else let visual = '' endif - let snippet = substitute(snippet, '\n\(\t\+\).\{-\}\zs{VISUAL}', - \ substitute(escape(visual, '%\'), "\n", "\n\\\\1", 'g'), 'g') + let snippet = s:substitute_visual(snippet, visual) " Evaluate eval (`...`) expressions. " Backquotes prefixed with a backslash "\" are ignored. @@ -118,6 +117,16 @@ function! snipmate#legacy#build_stops(snip, lnum, col, indent) abort return [stops, i + 1] endfunction +function! s:substitute_visual(snippet, visual) abort + let lines = [] + for line in split(a:snippet, "\n") + let indent = matchstr(line, '^\t\+') + call add(lines, substitute(line, '{VISUAL}', + \ substitute(escape(a:visual, '%\'), "\n", "\n" . indent, 'g'), 'g')) + endfor + return join(lines, "\n") +endfunction + " Counts occurences of haystack in needle function! s:count(haystack, needle) abort let counter = 0