diff options
-rw-r--r-- | VERSION | 4 | ||||
-rw-r--r-- | vim/after/ftplugin/mail.vim | 13 | ||||
-rw-r--r-- | vim/after/ftplugin/perl.vim | 64 | ||||
-rw-r--r-- | vim/vimrc | 6 |
4 files changed, 82 insertions, 5 deletions
@@ -1,2 +1,2 @@ -tejr dotfiles v1.42.0 -Thu Aug 2 21:23:24 UTC 2018 +tejr dotfiles v1.43.0 +Sat Aug 4 01:13:45 UTC 2018 diff --git a/vim/after/ftplugin/mail.vim b/vim/after/ftplugin/mail.vim index 74261d8c..34c524e1 100644 --- a/vim/after/ftplugin/mail.vim +++ b/vim/after/ftplugin/mail.vim @@ -33,3 +33,16 @@ let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>q' \ . '|nunmap <buffer> <LocalLeader>Q' \ . '|nunmap <buffer> <LocalLeader>QQ' \ . '|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> +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>l' diff --git a/vim/after/ftplugin/perl.vim b/vim/after/ftplugin/perl.vim index 2a350805..777c3ad4 100644 --- a/vim/after/ftplugin/perl.vim +++ b/vim/after/ftplugin/perl.vim @@ -13,11 +13,75 @@ let b:undo_ftplugin .= '|unlet b:current_compiler' setlocal matchpairs+=<:> let b:undo_ftplugin .= '|setlocal matchpairs<' +" Function to add boilerplate intelligently +function! s:Boilerplate() abort + + " Flag whether the buffer started blank + let l:blank = line2byte(line('$') + 1) <= 2 + + " This is a .pm file, guess its package name from path + if expand('%:e') ==# 'pm' + + let l:match = matchlist(expand('%:p'), '.*/lib/\(.\+\).pm$') + if len(l:match) + let l:package = substitute(l:match[1], '/', '::', 'g') + else + let l:package = expand('%:t:r') + endif + + " Otherwise, just use 'main' + else + let l:package = 'main' + endif + + " Lines always to add + let l:lines = [ + \ 'package '.l:package.';', + \ '', + \ 'use strict;', + \ 'use warnings;', + \ 'use utf8;', + \ '', + \ 'use 5.006;', + \ '', + \ 'our $VERSION = ''0.01'';', + \ '' + \ ] + + " Conditional lines depending on package + if l:package ==# 'main' + let l:lines = ['#!perl'] + l:lines + else + let l:lines = l:lines + ['', '1;'] + endif + + " Add all the lines in the array + for l:line in l:lines + call append(line('.') - 1, l:line) + endfor + + " If we started in a completely empty buffer, delete the current blank line + if l:blank + delete + endif + + " If we added a trailing '1' for a package, move the cursor up two lines + if l:package !=# 'main' + -2 + endif + +endfunction + " Stop here if the user doesn't want ftplugin mappings if exists('g:no_plugin_maps') || exists('g:no_perl_maps') finish endif +" Add boilerplate intelligently +nnoremap <buffer> <silent> <LocalLeader>b + \ :<C-U>call <SID>Boilerplate()<CR> +let b:undo_ftplugin .= '|nunmap <buffer> <LocalLeader>b' + " Mappings to choose compiler nnoremap <buffer> <LocalLeader>c \ :<C-U>compiler perl<CR> @@ -266,7 +266,7 @@ nnoremap <Bslash>n :<C-U>setlocal number! number?<CR> nnoremap <Bslash>N :<C-U>set ruler! ruler?<CR> " \o opens a line below in paste mode nmap <Bslash>o <Plug>(PasteOpenBelow) -" \o opens a line above in paste mode +" \O opens a line above in paste mode nmap <Bslash>O <Plug>(PasteOpenAbove) " \p toggles paste mode nnoremap <Bslash>p :<C-U>set paste! paste?<CR> @@ -307,8 +307,8 @@ nnoremap <Bslash>+ :<C-U>call vimrc#Anchor('1GgqG')<CR> " \. runs the configured make program into the location list nnoremap <Bslash>. :<C-U>lmake!<CR> -" \< and \> adjusts indent of last edit; good for pasting -nnoremap <Bslash>< :<C-U>'[,']<<CR> +" \< and \> adjust indent of last edit; good for pasting +nnoremap <Bslash><lt> :<C-U>'[,']<lt><CR> nnoremap <Bslash>> :<C-U>'[,']><CR> " \/ types :vimgrep for me ready to enter a search pattern |