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/after/ftplugin/markdown/autoformat.vim | |
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/after/ftplugin/markdown/autoformat.vim')
-rw-r--r-- | vim/after/ftplugin/markdown/autoformat.vim | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim new file mode 100644 index 00000000..9a963fbb --- /dev/null +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -0,0 +1,33 @@ +" Only do this when not done yet for this buffer +" Also do nothing if 'compatible' enabled, or if no autocmd feature, or if Vim +" is too old to support the needed autocmd events +if exists('b:did_ftplugin_markdown_autoformat') || &compatible + finish +endif +if !has('autocmd') || v:version < 700 + finish +endif +let b:did_ftplugin_markdown_autoformat = 1 +if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|unlet b:did_ftplugin_markdown_autoformat' +endif + +" Suspend auto-formatting when in a code block (four-space indent) +autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter + \ <buffer> + \ call ftplugin#markdown#autoformat#Line() + +" Suspend auto-format when pasting anything with a linebreak +nnoremap <buffer> <silent> + \ p + \ :<C-u>call ftplugin#markdown#autoformat#PutBelow()<CR> +nnoremap <buffer> <silent> + \ P + \ :<C-u>call ftplugin#markdown#autoformat#PutAbove()<CR> + +" Undo all the above +if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal formatoptions<' +endif |