From 4880c4b1e12a9ad3eb0a0ce8d7317c876d70f87f Mon Sep 17 00:00:00 2001 From: Reed Esau Date: Wed, 27 Aug 2014 21:32:29 -0600 Subject: [PATCH] Scan for syntax stack for autoformat A fix for #11 where there wasn't any syntax stack at the end of a line containing text where we don't want to initiate autoformat. --- autoload/pencil.vim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/autoload/pencil.vim b/autoload/pencil.vim index 42e982e..bc26616 100644 --- a/autoload/pencil.vim +++ b/autoload/pencil.vim @@ -56,7 +56,16 @@ endf fun! s:enable_autoformat() " don't enable autoformat if in a code block or table let l:okay_to_enable = 1 - for l:sid in synstack(line('.'), col('.')) + let l:col = col('.') + " at end of line there may be no synstack, so scan back + while l:col > 0 + let l:stack = synstack(line('.'), l:col) + if l:stack != [] + break + en + let l:col -= 1 + endw + for l:sid in l:stack if match(synIDattr(l:sid, 'name'), \ g:pencil#autoformat_blacklist_re) >= 0 let l:okay_to_enable = 0