From 4d4d9dc7d44038c32255197ceddc534f95275918 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sun, 3 Jun 2018 16:44:10 +1200 Subject: Add mail ftdetect rules --- vim/ftdetect/mail.vim | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 vim/ftdetect/mail.vim diff --git a/vim/ftdetect/mail.vim b/vim/ftdetect/mail.vim new file mode 100644 index 00000000..62113230 --- /dev/null +++ b/vim/ftdetect/mail.vim @@ -0,0 +1,4 @@ +" Mail messages +autocmd BufNewFile,BufRead + \ *.msg,mutt-*-*-* + \ setfiletype mail -- cgit v1.2.3 From 8e6412db2013b11cece845d4e6cbe541a1875bdb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 16:55:41 +1200 Subject: 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. --- Makefile | 10 ++++++ vim/after/ftplugin/markdown/autoformat.vim | 33 ++++++++++++++++++ vim/after/ftplugin/markdown/suspend_autoformat.vim | 34 ------------------- vim/autoload/ftplugin/markdown/autoformat.vim | 39 ++++++++++++++++++++++ 4 files changed, 82 insertions(+), 34 deletions(-) create mode 100644 vim/after/ftplugin/markdown/autoformat.vim delete mode 100644 vim/after/ftplugin/markdown/suspend_autoformat.vim create mode 100644 vim/autoload/ftplugin/markdown/autoformat.vim diff --git a/Makefile b/Makefile index fd08950d..345952cd 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ install-vim-after-indent \ install-vim-after-plugin \ install-vim-after-syntax \ + install-vim-autoload \ install-vim-bundle \ install-vim-compiler \ install-vim-config \ @@ -491,6 +492,7 @@ VIMDIR = $(HOME)/.vim VIMRC = $(HOME)/.vimrc install-vim: install-vim-after \ + install-vim-autoload \ install-vim-bundle \ install-vim-compiler \ install-vim-config \ @@ -522,6 +524,14 @@ install-vim-after-syntax: mkdir -p $(VIMDIR)/after/syntax cp -p -- vim/after/syntax/*.vim $(VIMDIR)/after/syntax +install-vim-autoload: + find vim/autoload \ + -type d -exec sh -c \ + 'mkdir -- $(VIMDIR)/"$${1#vim/}"' _ {} \; \ + -o \ + -type f -exec sh -c \ + 'cp -p -- "$$1" $(VIMDIR)/"$${1#vim/}"' _ {} \; + install-vim-bundle: install-vim-config find vim/bundle/*/* \ -type d -exec sh -c \ 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 + \ + \ call ftplugin#markdown#autoformat#Line() + +" Suspend auto-format when pasting anything with a linebreak +nnoremap + \ p + \ :call ftplugin#markdown#autoformat#PutBelow() +nnoremap + \ P + \ :call ftplugin#markdown#autoformat#PutAbove() + +" Undo all the above +if exists('b:undo_ftplugin') + let b:undo_ftplugin = b:undo_ftplugin + \ . '|setlocal formatoptions<' +endif diff --git a/vim/after/ftplugin/markdown/suspend_autoformat.vim b/vim/after/ftplugin/markdown/suspend_autoformat.vim deleted file mode 100644 index b2de7828..00000000 --- a/vim/after/ftplugin/markdown/suspend_autoformat.vim +++ /dev/null @@ -1,34 +0,0 @@ -" 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_suspend_autoformat') || &compatible - finish -endif -if !has('autocmd') || v:version < 700 - finish -endif -let b:did_ftplugin_markdown_suspend_autoformat = 1 -if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|unlet b:did_ftplugin_markdown_suspend_autoformat' -endif - -" When editing a code block, quietly remove auto 'a' from 'formatoptions' if -" present, flagging that we've done so; restore it once we move away. -autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter - \ - \ if getline('.') =~# '\m^ ' - \ | if &formatoptions =~# '\ma' - \ | setlocal formatoptions-=a - \ | let b:markdown_suspend_autoformat_suspended = 1 - \ | endif - \ | elseif exists('b:markdown_suspend_autoformat_suspended') - \ | setlocal formatoptions+=a - \ | unlet b:markdown_suspend_autoformat_suspended - \ | endif - -" Undo all the above -if exists('b:undo_ftplugin') - let b:undo_ftplugin = b:undo_ftplugin - \ . '|setlocal formatoptions<' -endif 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 -- cgit v1.2.3 From d4d2e8822108943f1aadd876053c6d9e65ab1659 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 18:07:32 +1200 Subject: Use heuristics on Markdown to guess autoformat --- vim/after/ftplugin/markdown/autoformat.vim | 4 ++++ vim/autoload/ftplugin/markdown/autoformat.vim | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim index 9a963fbb..8e476158 100644 --- a/vim/after/ftplugin/markdown/autoformat.vim +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -13,6 +13,10 @@ if exists('b:undo_ftplugin') \ . '|unlet b:did_ftplugin_markdown_autoformat' endif +" Turn on autoformatting if the buffer has no code-block lines with spaces +" that is longer than 'textwidth' +call ftplugin#markdown#autoformat#Load() + " Suspend auto-formatting when in a code block (four-space indent) autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter \ diff --git a/vim/autoload/ftplugin/markdown/autoformat.vim b/vim/autoload/ftplugin/markdown/autoformat.vim index 1d01c58e..f416da77 100644 --- a/vim/autoload/ftplugin/markdown/autoformat.vim +++ b/vim/autoload/ftplugin/markdown/autoformat.vim @@ -13,6 +13,30 @@ function! ftplugin#markdown#autoformat#Line() abort endif endfunction +" 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) +function! ftplugin#markdown#autoformat#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 = l:count + 1 + endif + endfor + if l:count * 100 / l:total < 5 + setlocal formatoptions+=a + else + setlocal formatoptions-=a + endif +endfunction + " Suspend auto-formatting when in a code block (four-space indent) function! ftplugin#markdown#autoformat#Put(above) abort let l:suspended = 0 -- cgit v1.2.3 From d0fbc06579efafd175fce6a6a7b5460d55311d11 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 18:09:36 +1200 Subject: Set and clear Markdown autocmd in group --- vim/after/ftplugin/markdown/autoformat.vim | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim index 8e476158..2bb4f87c 100644 --- a/vim/after/ftplugin/markdown/autoformat.vim +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -17,10 +17,16 @@ endif " that is longer than 'textwidth' call ftplugin#markdown#autoformat#Load() -" Suspend auto-formatting when in a code block (four-space indent) -autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter - \ - \ call ftplugin#markdown#autoformat#Line() +" Group autocommands +augroup ftplugin_markdown_autoformat + autocmd! + + " Suspend auto-formatting when in a code block (four-space indent) + autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter + \ + \ call ftplugin#markdown#autoformat#Line() + +augroup END " Suspend auto-format when pasting anything with a linebreak nnoremap @@ -34,4 +40,7 @@ nnoremap if exists('b:undo_ftplugin') let b:undo_ftplugin = b:undo_ftplugin \ . '|setlocal formatoptions<' + \ . '|augroup ftplugin_markdown_autoformat' + \ . '|autocmd!' + \ . '|augroup END' endif -- cgit v1.2.3 From 85d5c47d747b05668df688bc44ac827864740db3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 18:17:32 +1200 Subject: Don't load my HTML ftplugins for Markdown types The stock markdown.vim file loads in all the html.vim ftplugins too. This is probably a good idea for the stock files, but none of my HTML extension plugins are appropriate for Markdown, so exclude them. --- vim/after/ftplugin/html/lint.vim | 6 +++++- vim/after/ftplugin/html/tidy.vim | 6 +++++- vim/after/ftplugin/html/url_link.vim | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/vim/after/ftplugin/html/lint.vim b/vim/after/ftplugin/html/lint.vim index c0fdc44f..21f2a72c 100644 --- a/vim/after/ftplugin/html/lint.vim +++ b/vim/after/ftplugin/html/lint.vim @@ -1,8 +1,12 @@ " Only do this when not done yet for this buffer -" Also do nothing if 'compatible' enabled +" Also do nothing if 'compatible' enabled, or if the current filetype is +" actually markdown if exists('b:did_ftplugin_html_lint') || &compatible finish endif +if &filetype == 'markdown' + finish +endif let b:did_ftplugin_html_lint = 1 " Initialise undo variable if not already done diff --git a/vim/after/ftplugin/html/tidy.vim b/vim/after/ftplugin/html/tidy.vim index 519a7cd6..270e54e2 100644 --- a/vim/after/ftplugin/html/tidy.vim +++ b/vim/after/ftplugin/html/tidy.vim @@ -1,8 +1,12 @@ " Only do this when not done yet for this buffer -" Also do nothing if 'compatible' enabled +" Also do nothing if 'compatible' enabled, or if the current filetype is +" actually markdown if exists('b:did_ftplugin_html_tidy') || &compatible finish endif +if &filetype == 'markdown' + finish +endif let b:did_ftplugin_html_tidy = 1 if exists('b:undo_ftplugin') let b:undo_ftplugin = b:undo_ftplugin diff --git a/vim/after/ftplugin/html/url_link.vim b/vim/after/ftplugin/html/url_link.vim index 85e9d719..4102e768 100644 --- a/vim/after/ftplugin/html/url_link.vim +++ b/vim/after/ftplugin/html/url_link.vim @@ -1,8 +1,12 @@ " Only do this when not done yet for this buffer -" Also do nothing if 'compatible' enabled +" Also do nothing if 'compatible' enabled, or if the current filetype is +" actually markdown if exists('b:did_ftplugin_html_url_link') || &compatible finish endif +if &filetype == 'markdown' + finish +endif let b:did_ftplugin_html_url_link = 1 if exists('b:undo_ftplugin') let b:undo_ftplugin = b:undo_ftplugin -- cgit v1.2.3 From 3c7a5d27d22461144547fee3fb0d5ae02af5e8e9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 19:11:45 +1200 Subject: Move markdown_autoformat.vim funcs back to local No advantage to making them autoload --- Makefile | 10 ---- vim/after/ftplugin/markdown/autoformat.vim | 68 +++++++++++++++++++++++++-- vim/autoload/ftplugin/markdown/autoformat.vim | 63 ------------------------- 3 files changed, 64 insertions(+), 77 deletions(-) delete mode 100644 vim/autoload/ftplugin/markdown/autoformat.vim diff --git a/Makefile b/Makefile index 345952cd..fd08950d 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,6 @@ install-vim-after-indent \ install-vim-after-plugin \ install-vim-after-syntax \ - install-vim-autoload \ install-vim-bundle \ install-vim-compiler \ install-vim-config \ @@ -492,7 +491,6 @@ VIMDIR = $(HOME)/.vim VIMRC = $(HOME)/.vimrc install-vim: install-vim-after \ - install-vim-autoload \ install-vim-bundle \ install-vim-compiler \ install-vim-config \ @@ -524,14 +522,6 @@ install-vim-after-syntax: mkdir -p $(VIMDIR)/after/syntax cp -p -- vim/after/syntax/*.vim $(VIMDIR)/after/syntax -install-vim-autoload: - find vim/autoload \ - -type d -exec sh -c \ - 'mkdir -- $(VIMDIR)/"$${1#vim/}"' _ {} \; \ - -o \ - -type f -exec sh -c \ - 'cp -p -- "$$1" $(VIMDIR)/"$${1#vim/}"' _ {} \; - install-vim-bundle: install-vim-config find vim/bundle/*/* \ -type d -exec sh -c \ diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim index 2bb4f87c..7edcfbf6 100644 --- a/vim/after/ftplugin/markdown/autoformat.vim +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -13,9 +13,69 @@ if exists('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 !has('*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 = l:count + 1 + endif + endfor + if l:count * 100 / l:total < 5 + setlocal formatoptions+=a + else + setlocal formatoptions-=a + endif + endfunction +endif + +" Suspend auto-format when pasting anything with a linebreak +if !has('*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 + +" Suspend auto-formatting when in a code block (four-space indent) +if !has('*s:Put') + function! s: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 +endif + " Turn on autoformatting if the buffer has no code-block lines with spaces " that is longer than 'textwidth' -call ftplugin#markdown#autoformat#Load() +call s:Load() " Group autocommands augroup ftplugin_markdown_autoformat @@ -24,17 +84,17 @@ augroup ftplugin_markdown_autoformat " Suspend auto-formatting when in a code block (four-space indent) autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter \ - \ call ftplugin#markdown#autoformat#Line() + \ call s:Line() augroup END " Suspend auto-format when pasting anything with a linebreak nnoremap \ p - \ :call ftplugin#markdown#autoformat#PutBelow() + \ :call Put(0) nnoremap \ P - \ :call ftplugin#markdown#autoformat#PutAbove() + \ :call Put(1) " Undo all the above if exists('b:undo_ftplugin') diff --git a/vim/autoload/ftplugin/markdown/autoformat.vim b/vim/autoload/ftplugin/markdown/autoformat.vim deleted file mode 100644 index f416da77..00000000 --- a/vim/autoload/ftplugin/markdown/autoformat.vim +++ /dev/null @@ -1,63 +0,0 @@ -" 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 - -" 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) -function! ftplugin#markdown#autoformat#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 = l:count + 1 - endif - endfor - if l:count * 100 / l:total < 5 - setlocal formatoptions+=a - else - setlocal formatoptions-=a - 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 -- cgit v1.2.3 From ccad9e90002edc9ddfbc761b7130cbe265568fb8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 19:12:05 +1200 Subject: Clear markdown_autoformat.vim autocmds correctly --- vim/after/ftplugin/markdown/autoformat.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim index 7edcfbf6..b2152336 100644 --- a/vim/after/ftplugin/markdown/autoformat.vim +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -101,6 +101,6 @@ if exists('b:undo_ftplugin') let b:undo_ftplugin = b:undo_ftplugin \ . '|setlocal formatoptions<' \ . '|augroup ftplugin_markdown_autoformat' - \ . '|autocmd!' + \ . '|autocmd! * ' \ . '|augroup END' endif -- cgit v1.2.3 From c51af5740bca34da385ef807580f820313b6c358 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 19:14:38 +1200 Subject: Use case-insensitive Vim ==# --- vim/after/ftplugin/html/lint.vim | 2 +- vim/after/ftplugin/html/tidy.vim | 2 +- vim/after/ftplugin/html/url_link.vim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/after/ftplugin/html/lint.vim b/vim/after/ftplugin/html/lint.vim index 21f2a72c..b24b18c9 100644 --- a/vim/after/ftplugin/html/lint.vim +++ b/vim/after/ftplugin/html/lint.vim @@ -4,7 +4,7 @@ if exists('b:did_ftplugin_html_lint') || &compatible finish endif -if &filetype == 'markdown' +if &filetype ==# 'markdown' finish endif let b:did_ftplugin_html_lint = 1 diff --git a/vim/after/ftplugin/html/tidy.vim b/vim/after/ftplugin/html/tidy.vim index 270e54e2..6e612feb 100644 --- a/vim/after/ftplugin/html/tidy.vim +++ b/vim/after/ftplugin/html/tidy.vim @@ -4,7 +4,7 @@ if exists('b:did_ftplugin_html_tidy') || &compatible finish endif -if &filetype == 'markdown' +if &filetype ==# 'markdown' finish endif let b:did_ftplugin_html_tidy = 1 diff --git a/vim/after/ftplugin/html/url_link.vim b/vim/after/ftplugin/html/url_link.vim index 4102e768..2e600b5e 100644 --- a/vim/after/ftplugin/html/url_link.vim +++ b/vim/after/ftplugin/html/url_link.vim @@ -4,7 +4,7 @@ if exists('b:did_ftplugin_html_url_link') || &compatible finish endif -if &filetype == 'markdown' +if &filetype ==# 'markdown' finish endif let b:did_ftplugin_html_url_link = 1 -- cgit v1.2.3 From 9c539c41dcfdf68e5573fc7c9d64e5d2d1db5e5a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 19:38:52 +1200 Subject: Rearrange/correct markdown_autoformat.vim --- vim/after/ftplugin/markdown/autoformat.vim | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim index b2152336..78a2c23a 100644 --- a/vim/after/ftplugin/markdown/autoformat.vim +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -38,8 +38,9 @@ if !has('*s:Load') endif endfunction endif +call s:Load() -" Suspend auto-format when pasting anything with a linebreak +" Suspend auto-formatting when in a code block (four-space indent) if !has('*s:Line') function! s:Line() abort if getline('.') =~# '\m^ ' @@ -53,8 +54,14 @@ if !has('*s:Line') endif endfunction endif +augroup ftplugin_markdown_autoformat + autocmd! + autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter + \ + \ call s:Line() +augroup END -" Suspend auto-formatting when in a code block (four-space indent) +" Suspend auto-format when pasting anything with a linebreak if !has('*s:Put') function! s:Put(above) abort let l:suspended = 0 @@ -72,23 +79,6 @@ if !has('*s:Put') endif endfunction endif - -" Turn on autoformatting if the buffer has no code-block lines with spaces -" that is longer than 'textwidth' -call s:Load() - -" Group autocommands -augroup ftplugin_markdown_autoformat - autocmd! - - " Suspend auto-formatting when in a code block (four-space indent) - autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter - \ - \ call s:Line() - -augroup END - -" Suspend auto-format when pasting anything with a linebreak nnoremap \ p \ :call Put(0) -- cgit v1.2.3 From 99fe9596b3b8b4fcd653888132f757a9fb6a5e02 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 21:48:59 +1200 Subject: Support counts and registers in paste wrapping --- vim/after/ftplugin/markdown/autoformat.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim index 78a2c23a..3f620691 100644 --- a/vim/after/ftplugin/markdown/autoformat.vim +++ b/vim/after/ftplugin/markdown/autoformat.vim @@ -65,14 +65,14 @@ augroup END if !has('*s:Put') function! s:Put(above) abort let l:suspended = 0 - if &formatoptions =~# '\ma' && @" =~# '\m\n' + if &formatoptions =~# '\ma' && getreg() =~# '\m\n' setlocal formatoptions-=a let l:suspended = 1 endif if a:above - normal! P + execute 'normal! "'.v:register.v:count1.'P' else - normal! p + execute 'normal! "'.v:register.v:count1.'p' endif if l:suspended setlocal formatoptions+=a -- cgit v1.2.3 From dc5202d1f080d50657cc0a8ffb38c3f0a7f4e7e5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 4 Jun 2018 22:07:15 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index ac11890d..abe82ea1 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v0.44.0 -Sun Jun 3 04:28:13 UTC 2018 +tejr dotfiles v0.45.0 +Mon Jun 4 10:06:44 UTC 2018 -- cgit v1.2.3