aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-04 22:09:48 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-04 22:09:48 +1200
commit8a42dd3142fcbea5c022ff7b027a276b3caacd4c (patch)
tree33babf2620a44a10e801a1bff49ae110ae5af899
parentMerge branch 'release/v0.44.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-8a42dd3142fcbea5c022ff7b027a276b3caacd4c.tar.gz
dotfiles-8a42dd3142fcbea5c022ff7b027a276b3caacd4c.zip
Merge branch 'release/v0.45.0'v0.45.0
* release/v0.45.0: Bump VERSION Support counts and registers in paste wrapping Rearrange/correct markdown_autoformat.vim Use case-insensitive Vim ==# Clear markdown_autoformat.vim autocmds correctly Move markdown_autoformat.vim funcs back to local Don't load my HTML ftplugins for Markdown types Set and clear Markdown autocmd in group Use heuristics on Markdown to guess autoformat Refactor suspend_autoformat.vim, add autoload Add mail ftdetect rules
-rw-r--r--VERSION4
-rw-r--r--vim/after/ftplugin/html/lint.vim6
-rw-r--r--vim/after/ftplugin/html/tidy.vim6
-rw-r--r--vim/after/ftplugin/html/url_link.vim6
-rw-r--r--vim/after/ftplugin/markdown/autoformat.vim96
-rw-r--r--vim/after/ftplugin/markdown/suspend_autoformat.vim34
-rw-r--r--vim/ftdetect/mail.vim4
7 files changed, 117 insertions, 39 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
diff --git a/vim/after/ftplugin/html/lint.vim b/vim/after/ftplugin/html/lint.vim
index c0fdc44f..b24b18c9 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..6e612feb 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..2e600b5e 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
diff --git a/vim/after/ftplugin/markdown/autoformat.vim b/vim/after/ftplugin/markdown/autoformat.vim
new file mode 100644
index 00000000..3f620691
--- /dev/null
+++ b/vim/after/ftplugin/markdown/autoformat.vim
@@ -0,0 +1,96 @@
+" 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
+
+" 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
+call s:Load()
+
+" Suspend auto-formatting when in a code block (four-space indent)
+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
+augroup ftplugin_markdown_autoformat
+ autocmd!
+ autocmd BufWinEnter,CursorMoved,CursorMovedI,WinEnter
+ \ <buffer>
+ \ call s:Line()
+augroup END
+
+" Suspend auto-format when pasting anything with a linebreak
+if !has('*s:Put')
+ function! s:Put(above) 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
+ if l:suspended
+ setlocal formatoptions+=a
+ endif
+ endfunction
+endif
+nnoremap <buffer> <silent>
+ \ p
+ \ :<C-u>call <SID>Put(0)<CR>
+nnoremap <buffer> <silent>
+ \ P
+ \ :<C-u>call <SID>Put(1)<CR>
+
+" Undo all the above
+if exists('b:undo_ftplugin')
+ let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|setlocal formatoptions<'
+ \ . '|augroup ftplugin_markdown_autoformat'
+ \ . '|autocmd! * <buffer>'
+ \ . '|augroup END'
+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
- \ <buffer>
- \ 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/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