diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-04 16:55:41 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-04 16:55:41 +1200 |
commit | 8e6412db2013b11cece845d4e6cbe541a1875bdb (patch) | |
tree | e92219358c9eb86166854bdca69365597d6a9c95 /vim/autoload | |
parent | Add mail ftdetect rules (diff) | |
download | dotfiles-8e6412db2013b11cece845d4e6cbe541a1875bdb.tar.gz dotfiles-8e6412db2013b11cece845d4e6cbe541a1875bdb.zip |
Refactor suspend_autoformat.vim, add autoload
* Add a function to suspend autoformatting for the duration of pasting
lines.
* Factor the ftplugin's functions out to be autoloaded; this requires
Vim >=7.0, but it already needed that.
* Add Makefile infrastructure for new autoload directories/files.
Diffstat (limited to 'vim/autoload')
-rw-r--r-- | vim/autoload/ftplugin/markdown/autoformat.vim | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vim/autoload/ftplugin/markdown/autoformat.vim b/vim/autoload/ftplugin/markdown/autoformat.vim new file mode 100644 index 00000000..1d01c58e --- /dev/null +++ b/vim/autoload/ftplugin/markdown/autoformat.vim @@ -0,0 +1,39 @@ +" Autoload functions for after/ftplugin/markdown/autoformat.vim + +" Suspend auto-format when pasting anything with a linebreak +function! ftplugin#markdown#autoformat#Line() abort + if getline('.') =~# '\m^ ' + if &formatoptions =~# '\ma' + setlocal formatoptions-=a + let b:markdown_autoformat_suspended = 1 + endif + elseif exists('b:markdown_autoformat_suspended') + setlocal formatoptions+=a + unlet b:markdown_autoformat_suspended + endif +endfunction + +" Suspend auto-formatting when in a code block (four-space indent) +function! ftplugin#markdown#autoformat#Put(above) abort + let l:suspended = 0 + if &formatoptions =~# '\ma' && @" =~# '\m\n' + setlocal formatoptions-=a + let l:suspended = 1 + endif + if a:above + normal! P + else + normal! p + endif + if l:suspended + setlocal formatoptions+=a + endif +endfunction + +" Wrapper functions for #Put() above/below +function! ftplugin#markdown#autoformat#PutAbove() abort + call ftplugin#markdown#autoformat#Put(1) +endfunction +function! ftplugin#markdown#autoformat#PutBelow() abort + call ftplugin#markdown#autoformat#Put(0) +endfunction |