aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-08-14 19:40:11 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-08-14 19:40:11 +1200
commitfc083db2efae845a4f6eff2eac977f164debcb9e (patch)
tree84d99c057c59d5074088d57004e8a9dc90d9f65e
parente9d2bc6b4e0a912fa1256f38137233dd2056fada (diff)
downloaddotfiles-fc083db2efae845a4f6eff2eac977f164debcb9e.tar.gz
Move Vim mail functions to autoload
-rw-r--r--vim/after/ftplugin/mail.vim71
-rw-r--r--vim/autoload/mail.vim58
2 files changed, 65 insertions, 64 deletions
diff --git a/vim/after/ftplugin/mail.vim b/vim/after/ftplugin/mail.vim
index 612dc523..0b762e61 100644
--- a/vim/after/ftplugin/mail.vim
+++ b/vim/after/ftplugin/mail.vim
@@ -50,81 +50,24 @@ let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>q'
\ . '|xunmap <buffer> <LocalLeader>Q'
" Flag a message as unimportant
-function! s:FlagUnimportant()
- call cursor(1, 1)
- call search('^$')
- -
- call append(line('.'), 'X-Priority: 5')
- call append(line('.'), 'Importance: Low')
-endfunction
nnoremap <buffer>
\ <LocalLeader>l
- \ <C-U>:call <SID>FlagUnimportant()<CR>
+ \ <C-U>:call mail#FlagUnimportant()<CR>
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>l'
-" Move through quoted paragraphs like normal-mode `{` and `}`
-function! s:NewBlank(count, up, visual) abort
-
- " Reselect visual selection
- if a:visual
- normal! gv
- endif
-
- " Flag for whether we've started a block
- let l:block = 0
-
- " Flag for the number of blocks passed
- let l:blocks = 0
-
- " Iterate through buffer lines
- let l:num = line('.')
- while a:up ? l:num > 1 : l:num < line('$')
-
- " If the line is blank
- if getline(l:num) =~# '^[ >]*$'
-
- " If we'd moved through a non-blank block already, reset that flag and
- " bump up the block count
- if l:block
- let l:block = 0
- let l:blocks += 1
- endif
-
- " If we've hit the number of blocks, end the loop
- if l:blocks == a:count
- break
- endif
-
- " If the line is not blank, flag that we're going through a block
- else
- let l:block = 1
- endif
-
- " Move the line number or up or down depending on direction
- let l:num += a:up ? -1 : 1
-
- endwhile
-
- " Move to line if nonzero and not equal to the current line
- if l:num != line('.')
- execute 'normal '.l:num.'G'
- endif
-
-endfunction
-
" Maps using NewBlank() function above for quoted paragraph movement
nnoremap <buffer> <silent> <LocalLeader>[
- \ :<C-U>call <SID>NewBlank(v:count1, 1, 0)<CR>
+ \ :<C-U>call mail#NewBlank(v:count1, 1, 0)<CR>
nnoremap <buffer> <silent> <LocalLeader>]
- \ :<C-U>call <SID>NewBlank(v:count1, 0, 0)<CR>
+ \ :<C-U>call mail#NewBlank(v:count1, 0, 0)<CR>
onoremap <buffer> <silent> <LocalLeader>[
- \ :<C-U>call <SID>NewBlank(v:count1, 1, 0)<CR>
+ \ :<C-U>call mail#NewBlank(v:count1, 1, 0)<CR>
onoremap <buffer> <silent> <LocalLeader>]
- \ :<C-U>call <SID>NewBlank(v:count1, 0, 0)<CR>
+ \ :<C-U>call mail#NewBlank(v:count1, 0, 0)<CR>
xnoremap <buffer> <silent> <LocalLeader>[
- \ :<C-U>call <SID>NewBlank(v:count1, 1, 1)<CR>
+ \ :<C-U>call mail#NewBlank(v:count1, 1, 1)<CR>
xnoremap <buffer> <silent> <LocalLeader>]
- \ :<C-U>call <SID>NewBlank(v:count1, 0, 1)<CR>
+ \ :<C-U>call mail#NewBlank(v:count1, 0, 1)<CR>
let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>['
\ . '|nunmap <buffer> <LocalLeader>]'
\ . '|ounmap <buffer> <LocalLeader>['
diff --git a/vim/autoload/mail.vim b/vim/autoload/mail.vim
new file mode 100644
index 00000000..4e8232c8
--- /dev/null
+++ b/vim/autoload/mail.vim
@@ -0,0 +1,58 @@
+" Flag a message as unimportant
+function! mail#FlagUnimportant()
+ call cursor(1, 1)
+ call search('^$')
+ -
+ call append(line('.'), 'X-Priority: 5')
+ call append(line('.'), 'Importance: Low')
+endfunction
+
+" Move through quoted paragraphs like normal-mode `{` and `}`
+function! mail#NewBlank(count, up, visual) abort
+
+ " Reselect visual selection
+ if a:visual
+ normal! gv
+ endif
+
+ " Flag for whether we've started a block
+ let l:block = 0
+
+ " Flag for the number of blocks passed
+ let l:blocks = 0
+
+ " Iterate through buffer lines
+ let l:num = line('.')
+ while a:up ? l:num > 1 : l:num < line('$')
+
+ " If the line is blank
+ if getline(l:num) =~# '^[ >]*$'
+
+ " If we'd moved through a non-blank block already, reset that flag and
+ " bump up the block count
+ if l:block
+ let l:block = 0
+ let l:blocks += 1
+ endif
+
+ " If we've hit the number of blocks, end the loop
+ if l:blocks == a:count
+ break
+ endif
+
+ " If the line is not blank, flag that we're going through a block
+ else
+ let l:block = 1
+ endif
+
+ " Move the line number or up or down depending on direction
+ let l:num += a:up ? -1 : 1
+
+ endwhile
+
+ " Move to line if nonzero and not equal to the current line
+ if l:num != line('.')
+ execute 'normal '.l:num.'G'
+ endif
+
+endfunction