From c31c7ed2df3d3cea91d981e8bde922f0836710ef Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 Jun 2018 11:31:04 +1200 Subject: Pass in mapped key directly, not a flag This seems obvious now. --- vim/ftplugin/markdown/autoformat.vim | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/vim/ftplugin/markdown/autoformat.vim b/vim/ftplugin/markdown/autoformat.vim index 80bd034c..a76735d9 100644 --- a/vim/ftplugin/markdown/autoformat.vim +++ b/vim/ftplugin/markdown/autoformat.vim @@ -63,17 +63,13 @@ augroup END " Suspend auto-format when pasting anything with a linebreak if !exists('*s:Put') - function! s:Put(above) abort + function! s:Put(key) abort let l:suspended = 0 if &formatoptions =~# '\ma' && getreg() =~# '\m\n' setlocal formatoptions-=a let l:suspended = 1 endif - if a:above - execute 'normal! "'.v:register.v:count1.'P' - else - execute 'normal! "'.v:register.v:count1.'p' - endif + execute 'normal! "'.v:register.v:count1.a:key if l:suspended setlocal formatoptions+=a endif @@ -81,10 +77,10 @@ if !exists('*s:Put') endif nnoremap \ p - \ :call Put(0) + \ :call Put('p') nnoremap \ P - \ :call Put(1) + \ :call Put('P') " Undo all the above if exists('b:undo_ftplugin') -- cgit v1.2.3 From ba773f84978a3658edc4253b3382819cf1de9a36 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 Jun 2018 11:41:25 +1200 Subject: Use += shorthand in Vim ftplugin We're already very dependent on Vim >=7 for this ftplugin, so we may as well use all its syntactic sugar. --- vim/ftplugin/markdown/autoformat.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/ftplugin/markdown/autoformat.vim b/vim/ftplugin/markdown/autoformat.vim index a76735d9..f714dad4 100644 --- a/vim/ftplugin/markdown/autoformat.vim +++ b/vim/ftplugin/markdown/autoformat.vim @@ -28,7 +28,7 @@ if !exists('*s:Load') if strlen(l:line) > l:width \ && stridx(l:line, ' ') > -1 \ && l:line !~# '\m^ ' - let l:count = l:count + 1 + let l:count += 1 endif endfor if l:count * 100 / l:total < 5 -- cgit v1.2.3 From 19b81a4278166f79fc1093702fe7d254981f8dfd Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 Jun 2018 12:34:51 +1200 Subject: Add global options for markdown_autoformat.vim --- vim/ftplugin/markdown/autoformat.vim | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/vim/ftplugin/markdown/autoformat.vim b/vim/ftplugin/markdown/autoformat.vim index f714dad4..4b7e2f77 100644 --- a/vim/ftplugin/markdown/autoformat.vim +++ b/vim/ftplugin/markdown/autoformat.vim @@ -38,7 +38,9 @@ if !exists('*s:Load') endif endfunction endif -call s:Load() +if !exists('g:markdown_autoformat_load') || g:markdown_autoformat_load + call s:Load() +endif " Suspend auto-formatting when in a code block (four-space indent) if !exists('*s:Line') @@ -54,12 +56,14 @@ if !exists('*s:Line') endif endfunction endif -augroup ftplugin_markdown_autoformat - autocmd! - autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter - \ - \ call s:Line() -augroup END +if !exists('g:markdown_autoformat_line') || g:markdown_autoformat_line + augroup ftplugin_markdown_autoformat + autocmd! + autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter + \ + \ call s:Line() + augroup END +endif " Suspend auto-format when pasting anything with a linebreak if !exists('*s:Put') @@ -75,12 +79,14 @@ if !exists('*s:Put') endif endfunction endif -nnoremap - \ p - \ :call Put('p') -nnoremap - \ P - \ :call Put('P') +if !exists('g:markdown_autoformat_put') || g:markdown_autoformat_put + nnoremap + \ p + \ :call Put('p') + nnoremap + \ P + \ :call Put('P') +endif " Undo all the above if exists('b:undo_ftplugin') -- cgit v1.2.3 From 96804727405411def5638697ae0bbdf063b86855 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 Jun 2018 12:42:21 +1200 Subject: Add ftplugin infrastructure and comments Preparing for spinoff release --- vim/ftplugin/markdown/autoformat.vim | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/vim/ftplugin/markdown/autoformat.vim b/vim/ftplugin/markdown/autoformat.vim index 4b7e2f77..aa805267 100644 --- a/vim/ftplugin/markdown/autoformat.vim +++ b/vim/ftplugin/markdown/autoformat.vim @@ -1,6 +1,14 @@ -" 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 +" +" markdown/autoformat.vim: Refine control over the 'formatoptions' flag 'a' +" for automatic formatting when editing Markdown documents: +" +" - Turn it on automatically on load if the buffer looks wrapped +" - Suspend it if editing a line in a code block (indented by four spaces) +" - Suspend it if pasting something with a linebreak +" +" Author: Tom Ryder +" License: Same as Vim itself +" if exists('b:did_ftplugin_markdown_autoformat') || &compatible finish endif @@ -15,9 +23,11 @@ endif " Turn on autoformatting if less than 5% of the buffer's lines meet all three " of these conditions: -" * Longer than 'textwidth' -" * Contains at least one space (not an unsplittable line) -" * Not a code block (indented with at least four spaces) +" +" - Longer than 'textwidth' +" - Contains at least one space (not an unsplittable line) +" - Not a code block (indented with at least four spaces) +" if !exists('*s:Load') function! s:Load() abort let l:width = &textwidth ? &textwidth : 79 -- cgit v1.2.3 From aa288d9289bc57e44cbb1f50a74c38de63d639ad Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 Jun 2018 13:09:23 +1200 Subject: Restore ftplugin extras to vim/after dir This reverts commit a14bc50. Changed my mind; decided it's tidier this way. --- Makefile | 9 +-- vim/after/ftplugin/markdown/autoformat.vim | 108 +++++++++++++++++++++++++++++ vim/after/ftplugin/markdown/spell.vim | 21 ++++++ vim/after/ftplugin/php/check.vim | 57 +++++++++++++++ vim/ftplugin/markdown/autoformat.vim | 108 ----------------------------- vim/ftplugin/markdown/spell.vim | 21 ------ vim/ftplugin/php/check.vim | 57 --------------- 7 files changed, 188 insertions(+), 193 deletions(-) create mode 100644 vim/after/ftplugin/markdown/autoformat.vim create mode 100644 vim/after/ftplugin/markdown/spell.vim create mode 100644 vim/after/ftplugin/php/check.vim delete mode 100644 vim/ftplugin/markdown/autoformat.vim delete mode 100644 vim/ftplugin/markdown/spell.vim delete mode 100644 vim/ftplugin/php/check.vim diff --git a/Makefile b/Makefile index 134935ae..7cc4ad1d 100644 --- a/Makefile +++ b/Makefile @@ -546,13 +546,8 @@ install-vim-ftdetect: cp -p -- vim/ftdetect/*.vim $(VIMDIR)/ftdetect install-vim-ftplugin: - mkdir -p $(VIMDIR)/ftplugin - find vim/ftplugin \ - -type d -exec sh -c \ - 'mkdir -p -- $(VIMDIR)/"$${1#vim/}"' _ {} \; \ - -o \ - -type f -exec sh -c \ - 'cp -p -- "$$1" $(VIMDIR)/"$${1#vim/}"' _ {} \; + mkdir -p -- $(VIMDIR)/indent + cp -p -- vim/indent/*.vim $(VIMDIR)/indent install-vim-indent: mkdir -p -- $(VIMDIR)/indent diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim new file mode 100644 index 00000000..aa805267 --- /dev/null +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -0,0 +1,108 @@ +" +" markdown/autoformat.vim: Refine control over the 'formatoptions' flag 'a' +" for automatic formatting when editing Markdown documents: +" +" - Turn it on automatically on load if the buffer looks wrapped +" - Suspend it if editing a line in a code block (indented by four spaces) +" - Suspend it if pasting something with a linebreak +" +" Author: Tom Ryder +" License: Same as Vim itself +" +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 + +" Turn on autoformatting if less than 5% of the buffer's lines meet all three +" of these conditions: +" +" - Longer than 'textwidth' +" - Contains at least one space (not an unsplittable line) +" - Not a code block (indented with at least four spaces) +" +if !exists('*s:Load') + function! s:Load() abort + let l:width = &textwidth ? &textwidth : 79 + let l:count = 0 + let l:total = line('$') + for l:li in range(1, l:total) + let l:line = getline(l:li) + if strlen(l:line) > l:width + \ && stridx(l:line, ' ') > -1 + \ && l:line !~# '\m^ ' + let l:count += 1 + endif + endfor + if l:count * 100 / l:total < 5 + setlocal formatoptions+=a + else + setlocal formatoptions-=a + endif + endfunction +endif +if !exists('g:markdown_autoformat_load') || g:markdown_autoformat_load + call s:Load() +endif + +" Suspend auto-formatting when in a code block (four-space indent) +if !exists('*s:Line') + function! s: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 +endif +if !exists('g:markdown_autoformat_line') || g:markdown_autoformat_line + augroup ftplugin_markdown_autoformat + autocmd! + autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter + \ + \ call s:Line() + augroup END +endif + +" Suspend auto-format when pasting anything with a linebreak +if !exists('*s:Put') + function! s:Put(key) abort + let l:suspended = 0 + if &formatoptions =~# '\ma' && getreg() =~# '\m\n' + setlocal formatoptions-=a + let l:suspended = 1 + endif + execute 'normal! "'.v:register.v:count1.a:key + if l:suspended + setlocal formatoptions+=a + endif + endfunction +endif +if !exists('g:markdown_autoformat_put') || g:markdown_autoformat_put + nnoremap + \ p + \ :call Put('p') + nnoremap + \ P + \ :call Put('P') +endif + +" Undo all the above +if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal formatoptions<' + \ . '|augroup ftplugin_markdown_autoformat' + \ . '|autocmd! * ' + \ . '|augroup END' +endif diff --git a/vim/after/ftplugin/markdown/spell.vim b/vim/after/ftplugin/markdown/spell.vim new file mode 100644 index 00000000..05fc7c00 --- /dev/null +++ b/vim/after/ftplugin/markdown/spell.vim @@ -0,0 +1,21 @@ +" Only do this when not done yet for this buffer +" Also do nothing if 'compatible' enabled, or if the 'spell' feature isn't +" available +if exists('b:did_ftplugin_markdown_spell') || &compatible + finish +endif +if !has('spell') + finish +endif +let b:did_ftplugin_markdown_spell = 1 +if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|unlet b:did_ftplugin_markdown_spell' +endif + +" Spellcheck documents by default +setlocal spell +if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal spell<' +endif diff --git a/vim/after/ftplugin/php/check.vim b/vim/after/ftplugin/php/check.vim new file mode 100644 index 00000000..33077a72 --- /dev/null +++ b/vim/after/ftplugin/php/check.vim @@ -0,0 +1,57 @@ +" Only do this when not done yet for this buffer +" Also do nothing if 'compatible' enabled +if exists('b:did_ftplugin_php_check') || &compatible + finish +endif +let b:did_ftplugin_php_check = 1 +if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|unlet b:did_ftplugin_php_check' +endif + +" Build function for checker +if !exists('*s:PhpCheck') + function s:PhpCheck() + let l:save_makeprg = &l:makeprg + let l:save_errorformat = &l:errorformat + unlet! g:current_compiler + compiler php + + " 7.4.191 is the earliest version with the :S file name modifier, which we + " really should use if we can + if v:version >= 704 || v:version == 704 && has('patch191') + make! %:S + else + make! % + endif + + let &l:makeprg = l:save_makeprg + let &l:errorformat = l:save_errorformat + cwindow + endfunction +endif + +" Set up a mapping for the checker, if we're allowed +if !exists('g:no_plugin_maps') && !exists('g:no_php_maps') + + " Define a mapping target + nnoremap + \ PhpCheck + \ :call PhpCheck() + if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|nunmap PhpCheck' + endif + + " If there isn't a key mapping already, use a default one + if !hasmapto('PhpCheck') + nmap + \ c + \ PhpCheck + if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|nunmap c' + endif + endif + +endif diff --git a/vim/ftplugin/markdown/autoformat.vim b/vim/ftplugin/markdown/autoformat.vim deleted file mode 100644 index aa805267..00000000 --- a/vim/ftplugin/markdown/autoformat.vim +++ /dev/null @@ -1,108 +0,0 @@ -" -" markdown/autoformat.vim: Refine control over the 'formatoptions' flag 'a' -" for automatic formatting when editing Markdown documents: -" -" - Turn it on automatically on load if the buffer looks wrapped -" - Suspend it if editing a line in a code block (indented by four spaces) -" - Suspend it if pasting something with a linebreak -" -" Author: Tom Ryder -" License: Same as Vim itself -" -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 - -" Turn on autoformatting if less than 5% of the buffer's lines meet all three -" of these conditions: -" -" - Longer than 'textwidth' -" - Contains at least one space (not an unsplittable line) -" - Not a code block (indented with at least four spaces) -" -if !exists('*s:Load') - function! s:Load() abort - let l:width = &textwidth ? &textwidth : 79 - let l:count = 0 - let l:total = line('$') - for l:li in range(1, l:total) - let l:line = getline(l:li) - if strlen(l:line) > l:width - \ && stridx(l:line, ' ') > -1 - \ && l:line !~# '\m^ ' - let l:count += 1 - endif - endfor - if l:count * 100 / l:total < 5 - setlocal formatoptions+=a - else - setlocal formatoptions-=a - endif - endfunction -endif -if !exists('g:markdown_autoformat_load') || g:markdown_autoformat_load - call s:Load() -endif - -" Suspend auto-formatting when in a code block (four-space indent) -if !exists('*s:Line') - function! s: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 -endif -if !exists('g:markdown_autoformat_line') || g:markdown_autoformat_line - augroup ftplugin_markdown_autoformat - autocmd! - autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter - \ - \ call s:Line() - augroup END -endif - -" Suspend auto-format when pasting anything with a linebreak -if !exists('*s:Put') - function! s:Put(key) abort - let l:suspended = 0 - if &formatoptions =~# '\ma' && getreg() =~# '\m\n' - setlocal formatoptions-=a - let l:suspended = 1 - endif - execute 'normal! "'.v:register.v:count1.a:key - if l:suspended - setlocal formatoptions+=a - endif - endfunction -endif -if !exists('g:markdown_autoformat_put') || g:markdown_autoformat_put - nnoremap - \ p - \ :call Put('p') - nnoremap - \ P - \ :call Put('P') -endif - -" Undo all the above -if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal formatoptions<' - \ . '|augroup ftplugin_markdown_autoformat' - \ . '|autocmd! * ' - \ . '|augroup END' -endif diff --git a/vim/ftplugin/markdown/spell.vim b/vim/ftplugin/markdown/spell.vim deleted file mode 100644 index 05fc7c00..00000000 --- a/vim/ftplugin/markdown/spell.vim +++ /dev/null @@ -1,21 +0,0 @@ -" Only do this when not done yet for this buffer -" Also do nothing if 'compatible' enabled, or if the 'spell' feature isn't -" available -if exists('b:did_ftplugin_markdown_spell') || &compatible - finish -endif -if !has('spell') - finish -endif -let b:did_ftplugin_markdown_spell = 1 -if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|unlet b:did_ftplugin_markdown_spell' -endif - -" Spellcheck documents by default -setlocal spell -if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal spell<' -endif diff --git a/vim/ftplugin/php/check.vim b/vim/ftplugin/php/check.vim deleted file mode 100644 index 33077a72..00000000 --- a/vim/ftplugin/php/check.vim +++ /dev/null @@ -1,57 +0,0 @@ -" Only do this when not done yet for this buffer -" Also do nothing if 'compatible' enabled -if exists('b:did_ftplugin_php_check') || &compatible - finish -endif -let b:did_ftplugin_php_check = 1 -if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|unlet b:did_ftplugin_php_check' -endif - -" Build function for checker -if !exists('*s:PhpCheck') - function s:PhpCheck() - let l:save_makeprg = &l:makeprg - let l:save_errorformat = &l:errorformat - unlet! g:current_compiler - compiler php - - " 7.4.191 is the earliest version with the :S file name modifier, which we - " really should use if we can - if v:version >= 704 || v:version == 704 && has('patch191') - make! %:S - else - make! % - endif - - let &l:makeprg = l:save_makeprg - let &l:errorformat = l:save_errorformat - cwindow - endfunction -endif - -" Set up a mapping for the checker, if we're allowed -if !exists('g:no_plugin_maps') && !exists('g:no_php_maps') - - " Define a mapping target - nnoremap - \ PhpCheck - \ :call PhpCheck() - if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|nunmap PhpCheck' - endif - - " If there isn't a key mapping already, use a default one - if !hasmapto('PhpCheck') - nmap - \ c - \ PhpCheck - if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|nunmap c' - endif - endif - -endif -- cgit v1.2.3 From 39627969dac81be22aef4c0a50548f9e31ed19f9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 Jun 2018 13:11:57 +1200 Subject: Merge bundle install into one command --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7cc4ad1d..93d12a0b 100644 --- a/Makefile +++ b/Makefile @@ -525,8 +525,8 @@ install-vim-after-syntax: install-vim-bundle: install-vim-config find vim/bundle/*/* \ -type d -exec sh -c \ - 'mkdir -p -- $(VIMDIR)/"$${1#vim/bundle/*/}"' _ {} \; - find vim/bundle/*/*/* \ + 'mkdir -p -- $(VIMDIR)/"$${1#vim/bundle/*/}"' _ {} \; \ + -o \ -type f -exec sh -c \ 'cp -p -- "$$1" $(VIMDIR)/"$${1#vim/bundle/*/}"' _ {} \; vim -eT dumb -c 'helptags $(VIMDIR)/doc' -c quit -- cgit v1.2.3 From 73fb9e19126049dca8fd4c3755b3e45098616a84 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 Jun 2018 13:16:47 +1200 Subject: Spin off markdown_autoformat as its own distro --- .gitmodules | 3 + vim/after/ftplugin/markdown/autoformat.vim | 108 ----------------------------- vim/bundle/markdown_autoformat | 1 + 3 files changed, 4 insertions(+), 108 deletions(-) delete mode 100644 vim/after/ftplugin/markdown/autoformat.vim create mode 160000 vim/bundle/markdown_autoformat diff --git a/.gitmodules b/.gitmodules index 9bda87e8..212a4e52 100644 --- a/.gitmodules +++ b/.gitmodules @@ -17,6 +17,9 @@ [submodule "vim/bundle/mail_mutt"] path = vim/bundle/mail_mutt url = https://sanctum.geek.nz/code/vim-mail-mutt.git +[submodule "vim/bundle/markdown_autoformat"] + path = vim/bundle/markdown_autoformat + url = https://sanctum.geek.nz/code/vim-markdown-autoformat.git [submodule "vim/bundle/put_blank_lines"] path = vim/bundle/put_blank_lines url = https://sanctum.geek.nz/code/vim-put-blank-lines.git diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim deleted file mode 100644 index aa805267..00000000 --- a/vim/after/ftplugin/markdown/autoformat.vim +++ /dev/null @@ -1,108 +0,0 @@ -" -" markdown/autoformat.vim: Refine control over the 'formatoptions' flag 'a' -" for automatic formatting when editing Markdown documents: -" -" - Turn it on automatically on load if the buffer looks wrapped -" - Suspend it if editing a line in a code block (indented by four spaces) -" - Suspend it if pasting something with a linebreak -" -" Author: Tom Ryder -" License: Same as Vim itself -" -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 - -" Turn on autoformatting if less than 5% of the buffer's lines meet all three -" of these conditions: -" -" - Longer than 'textwidth' -" - Contains at least one space (not an unsplittable line) -" - Not a code block (indented with at least four spaces) -" -if !exists('*s:Load') - function! s:Load() abort - let l:width = &textwidth ? &textwidth : 79 - let l:count = 0 - let l:total = line('$') - for l:li in range(1, l:total) - let l:line = getline(l:li) - if strlen(l:line) > l:width - \ && stridx(l:line, ' ') > -1 - \ && l:line !~# '\m^ ' - let l:count += 1 - endif - endfor - if l:count * 100 / l:total < 5 - setlocal formatoptions+=a - else - setlocal formatoptions-=a - endif - endfunction -endif -if !exists('g:markdown_autoformat_load') || g:markdown_autoformat_load - call s:Load() -endif - -" Suspend auto-formatting when in a code block (four-space indent) -if !exists('*s:Line') - function! s: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 -endif -if !exists('g:markdown_autoformat_line') || g:markdown_autoformat_line - augroup ftplugin_markdown_autoformat - autocmd! - autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter - \ - \ call s:Line() - augroup END -endif - -" Suspend auto-format when pasting anything with a linebreak -if !exists('*s:Put') - function! s:Put(key) abort - let l:suspended = 0 - if &formatoptions =~# '\ma' && getreg() =~# '\m\n' - setlocal formatoptions-=a - let l:suspended = 1 - endif - execute 'normal! "'.v:register.v:count1.a:key - if l:suspended - setlocal formatoptions+=a - endif - endfunction -endif -if !exists('g:markdown_autoformat_put') || g:markdown_autoformat_put - nnoremap - \ p - \ :call Put('p') - nnoremap - \ P - \ :call Put('P') -endif - -" Undo all the above -if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal formatoptions<' - \ . '|augroup ftplugin_markdown_autoformat' - \ . '|autocmd! * ' - \ . '|augroup END' -endif diff --git a/vim/bundle/markdown_autoformat b/vim/bundle/markdown_autoformat new file mode 160000 index 00000000..0b403358 --- /dev/null +++ b/vim/bundle/markdown_autoformat @@ -0,0 +1 @@ +Subproject commit 0b403358bc35c4a1303b2a4e7ca8c536b13222fa -- cgit v1.2.3 From 2431983ed433719e2746753e5c80472ea2aa90f2 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 5 Jun 2018 13:19:56 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 15dfadf5..74f9bf2e 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v0.46.0 -Mon Jun 4 10:44:39 UTC 2018 +tejr dotfiles v0.47.0 +Tue Jun 5 01:19:50 UTC 2018 -- cgit v1.2.3