From 91b0c2ed5b9d3066ce7df12ee5eff56a1cb8b2f3 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 5 Jul 2018 00:36:42 +1200 Subject: Correct 'softtabstop' test in indent/vim.vim --- vim/after/indent/vim.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/after/indent/vim.vim b/vim/after/indent/vim.vim index 4f2f42f8..dd5f4f32 100644 --- a/vim/after/indent/vim.vim +++ b/vim/after/indent/vim.vim @@ -5,7 +5,7 @@ if exists('b:undo_indent') endif " If we need to set 'softtabstop' too, do it -if &softtabstop == -1 +if &softtabstop != -1 setlocal softtabstop=2 if exists('b:undo_indent') let b:undo_indent = b:undo_indent . '|setlocal softtabstop<' -- cgit v1.2.3 From 8c593979abc6400b1b00ccf425c41483ac03c74a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 5 Jul 2018 11:00:18 +1200 Subject: Future-proof README.md discussion of Vim plugins --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9792a162..6c88ad44 100644 --- a/README.md +++ b/README.md @@ -357,12 +357,8 @@ structures like functions, I like to implement it as a plugin in `~/.vim/doc`. They eventually get either discarded or spun off into their own repositories, -added to this repository as submodules instead, and uploaded to -[vim.org](https://www.vim.org/account/profile.php?user_id=73687). - -In the current version, there are no local plugins; everything's got its own -repository. All plugins and colorschemes are available as submodules in -`~/.vim/bundle`. They are installed into `~/.vim`. +added to this repository as submodules under `vim/bundle` instead, and uploaded +to [vim.org](https://www.vim.org/account/profile.php?user_id=73687). I still use two third-party plugins: Tim Pope's [repeat.vim](https://www.vim.org/scripts/script.php?script_id=2136) and -- cgit v1.2.3 From 2ba8ba9d035f3071ae03b9929d2b6cfde4b0f6db Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 5 Jul 2018 11:01:30 +1200 Subject: Add shebang_update.vim plugin This plugin updates the filetype after every insert operation that changes the first line. No documentation yet. --- vim/autoload/shebang.vim | 7 +++++++ vim/plugin/shebang_update.vim | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 vim/autoload/shebang.vim create mode 100644 vim/plugin/shebang_update.vim diff --git a/vim/autoload/shebang.vim b/vim/autoload/shebang.vim new file mode 100644 index 00000000..f39fcf48 --- /dev/null +++ b/vim/autoload/shebang.vim @@ -0,0 +1,7 @@ +" If the first line was changed in the last insert operation, re-run script +" detection +function! shebang#Update() abort + if line("'[") == 1 + runtime scripts.vim + endif +endfunction diff --git a/vim/plugin/shebang_update.vim b/vim/plugin/shebang_update.vim new file mode 100644 index 00000000..1dbcaf67 --- /dev/null +++ b/vim/plugin/shebang_update.vim @@ -0,0 +1,20 @@ +" +" shabeng_update.vim: If the first line of a file was changed, re-run +" scripts.vim to do shebang detection to update the filetype. +" +" Author: Tom Ryder +" License: Same as Vim itself +" +if exists('g:loaded_shebang_update') || &compatible + finish +endif +if v:version < 700 + finish +endif +let g:loaded_shebang_update = 1 + +" Call the update function whenever leaving insert mode +augroup shebang_update + autocmd! + autocmd InsertLeave * call shebang#Update() +augroup END -- cgit v1.2.3 From 5052da3068b95aa03cb00db9905798db8e323e4f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 5 Jul 2018 22:43:28 +1200 Subject: Disable 'shiftround' in Vim for a while After experimenting, I suspect it's actually causing more grief than it saves. --- vim/vimrc | 1 - 1 file changed, 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 4b2803fe..361c049e 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -34,7 +34,6 @@ endif " The all-important default indent settings; filetypes to tweak set autoindent " Use indent of previous line on new lines set expandtab " Use spaces instead of tabs -set shiftround " Round indenting to multiples of 'shiftwidth' set shiftwidth=4 " Indent with four spaces " Spaces to insert on Tab key insert -- cgit v1.2.3 From 36f86684f4645c171e3d6fbf072aaafe11eaa6c1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 6 Jul 2018 00:49:16 +1200 Subject: Add \k, \q, and \y .vimrc mappings Using all of the lowercase alphabet now. --- vim/vimrc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vim/vimrc b/vim/vimrc index 361c049e..fe7e3a6c 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -238,6 +238,8 @@ nnoremap h :set hlsearch! hlsearch? nnoremap i :set incsearch! incsearch? " \j jumps to buffers (jetpack) nnoremap j :buffers:buffer +" \k shows my marks +nnoremap k :marks " \l toggles showing tab, end-of-line, and trailing whitespace nnoremap l :set list! list? " \m shows all maps @@ -252,6 +254,8 @@ nmap o PasteOpenBelow nmap O PasteOpenAbove " \p toggles paste mode nnoremap p :set paste! paste? +" \q formats the current paragraph +nnoremap q gqap " \r reloads .vimrc nnoremap r :source $MYVIMRC " \s toggles spell checking @@ -268,6 +272,8 @@ nnoremap V :let b: t: w: nnoremap w :set wrap! wrap? " \x strips trailing whitespace via a custom plugin nmap x StripTrailingWhitespace +" \y shows all registers +nnoremap y :registers " \z sets NZ English spelling (compare \u) nnoremap z :setlocal spelllang=en_nz -- cgit v1.2.3 From fb2b8f82bb3fc999191b0a225cccc2c15c8284ea Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 6 Jul 2018 09:22:52 +1200 Subject: Rearrange Vim's VimL indent file --- vim/after/indent/vim.vim | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/vim/after/indent/vim.vim b/vim/after/indent/vim.vim index dd5f4f32..73b4e430 100644 --- a/vim/after/indent/vim.vim +++ b/vim/after/indent/vim.vim @@ -1,13 +1,14 @@ " Observe VimL conventions for two-space indents setlocal shiftwidth=2 -if exists('b:undo_indent') - let b:undo_indent = b:undo_indent . '|setlocal shiftwidth<' +if v:version > 703 || v:version == 703 && has('patch693') + setlocal softtabstop=-1 +else + setlocal softtabstop=2 endif -" If we need to set 'softtabstop' too, do it -if &softtabstop != -1 - setlocal softtabstop=2 - if exists('b:undo_indent') - let b:undo_indent = b:undo_indent . '|setlocal softtabstop<' - endif +" Commands to undo the above +if exists('b:undo_indent') + let b:undo_indent = b:undo_indent + \ . '|setlocal shiftwidth<' + \ . '|setlocal softtabstop<' endif -- cgit v1.2.3 From 6013e361d0d826bd661abd62a22bec0a6286c613 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 6 Jul 2018 13:28:20 +1200 Subject: Remove .vimrc 'report' setting The default is fine. --- vim/vimrc | 3 --- 1 file changed, 3 deletions(-) diff --git a/vim/vimrc b/vim/vimrc index fe7e3a6c..63be1692 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -104,9 +104,6 @@ set nomodeline " Treat numbers with a leading zero as decimal, not octal set nrformats-=octal -" Always tell me the number of lines changed by a command -set report=0 - " Abbreviate some more regularly displayed messages set shortmess+=I " Don't show startup splash screen set shortmess+=m " [Modified] -> [+] -- cgit v1.2.3 From aa11fe749a37ceebb8eb25ba9ea1efe4d17d0e62 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 6 Jul 2018 13:40:59 +1200 Subject: Correct has() to exists() in .vimrc --- vim/vimrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/vimrc b/vim/vimrc index 63be1692..300fc3a5 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -14,7 +14,7 @@ if has('autocmd') endif " Options dependent on the syntax feature -if has('syntax') && !has('g:syntax_on') +if has('syntax') && !exists('g:syntax_on') " Use syntax highlighting syntax enable -- cgit v1.2.3 From e361a2824d4b6fad81f4ab538afec11f7c40ea0c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 6 Jul 2018 17:33:10 +1200 Subject: Add attempt at own Vim Perl indenting --- vim/indent/perl.vim | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 vim/indent/perl.vim diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim new file mode 100644 index 00000000..a3aea053 --- /dev/null +++ b/vim/indent/perl.vim @@ -0,0 +1,74 @@ +" Vim indent file for Perl5, because the stock one is way too complicated. I +" want something predictable rather than magical, and it's all going through +" perltidy(1) in the end anyway. + +" Only load this indent file when no other was loaded. +if exists('b:did_indent') || &compatible + finish +endif +let b:did_indent = 1 + +" Define indent function +function! GetPerlIndent() + + " Get properties of current line + let l:cn = v:lnum + let l:cl = getline(l:cn) + let l:ci = indent(l:cn) + + " Get properties of previous non-blank line + let l:pn = prevnonblank(v:lnum - 1) + if !l:pn + return 0 + endif + let l:pl = getline(l:pn) + let l:pi = indent(l:pn) + + " Get value of 'shiftwidth' + let l:sw = shiftwidth() + + " Don't touch comments + if l:pl =~# '^\s*#' + return l:pi + + " After opening brace + elseif l:pl =~# '[{([]\s*$' + + " Closing brace + if l:cl =~# '^\s*[])}]' + return l:pi + + " Block content + else + return l:pi + l:sw + endif + + " Closing brace + elseif l:cl =~# '^\s*[])}]' + + " Reduce indent if possible + if l:pi >= l:sw + return l:pi - l:sw + else + return 0 + endif + + " After a semicolon, comma, or closing brace + elseif l:pl =~# '[;,}]\s*$' + return l:pi - (l:pi % l:sw) + + " Continued line; add half shiftwidth + elseif l:sw >= 2 + return l:pi + l:sw / 2 + endif + +endfunction + +" Indent settings +setlocal indentexpr=GetPerlIndent() +setlocal indentkeys+=0},0),0] + +" Undo all of the above crap +let b:undo_indent = '|setlocal indentexpr<' + \ . '|setlocal indentkeys<' + \ . '|delfunction GetPerlIndent' -- cgit v1.2.3 From 498be6c6b55152fdc8fb1109525c3a7e40746ac4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 6 Jul 2018 18:23:34 +1200 Subject: Add a comment to Vim Perl indent rules --- vim/indent/perl.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index a3aea053..a3509dbf 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -1,6 +1,8 @@ " Vim indent file for Perl5, because the stock one is way too complicated. I " want something predictable rather than magical, and it's all going through " perltidy(1) in the end anyway. +" +" The biggest gap in this is getting heredocs wrong; use 'paste' for that. " Only load this indent file when no other was loaded. if exists('b:did_indent') || &compatible -- cgit v1.2.3 From c9da3d324cdaf57adb10a0d6ca29928145877c59 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 6 Jul 2018 18:24:04 +1200 Subject: Refactor opening of Vim Perl indent script --- vim/indent/perl.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index a3509dbf..890e2e3e 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -13,16 +13,15 @@ let b:did_indent = 1 " Define indent function function! GetPerlIndent() - " Get properties of current line - let l:cn = v:lnum - let l:cl = getline(l:cn) - let l:ci = indent(l:cn) - - " Get properties of previous non-blank line + " Just return 0 if we have no previous line to work from let l:pn = prevnonblank(v:lnum - 1) if !l:pn return 0 endif + + " Get line properties + let l:cl = getline(v:lnum) + let l:ci = indent(l:cn) let l:pl = getline(l:pn) let l:pi = indent(l:pn) -- cgit v1.2.3 From c30a12e7e866f5b51701ab637932103c43fa2f9a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 00:58:45 +1200 Subject: Adjust leading comment for Vim Perl indent --- vim/indent/perl.vim | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 890e2e3e..ee7028ec 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -1,8 +1,4 @@ -" Vim indent file for Perl5, because the stock one is way too complicated. I -" want something predictable rather than magical, and it's all going through -" perltidy(1) in the end anyway. -" -" The biggest gap in this is getting heredocs wrong; use 'paste' for that. +" Custom Vim indent file for Perl5; the stock one didn't suit me. " Only load this indent file when no other was loaded. if exists('b:did_indent') || &compatible -- cgit v1.2.3 From 14f4daaacca9e36a5281e54c105ca5d90fc70c87 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:00:43 +1200 Subject: Get 'shiftwidth' in Vim Perl indent portably From `:help shiftwidth()`: > Returns the effective value of 'shiftwidth'. This is the 'shiftwidth' > value unless it is zero, in which case it is the 'tabstop' value. This > function was introduced with patch 7.3.694 in 2012, everybody should > have it by now. I'd like my stuff to work on older versions, though, and it's not hard to make it work. --- vim/indent/perl.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index ee7028ec..edb91028 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -22,7 +22,9 @@ function! GetPerlIndent() let l:pi = indent(l:pn) " Get value of 'shiftwidth' - let l:sw = shiftwidth() + let l:sw = exists('*shiftwidth') + \ ? shiftwidth() + \ : &shiftwidth " Don't touch comments if l:pl =~# '^\s*#' -- cgit v1.2.3 From 2fc20ae4ed9fb78a79826a1fc2e983d84763b2b0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:06:23 +1200 Subject: Wrap comments with `gq` in Git commit messages I like quoting things in Git commit messages, as if they were mail messages. This was supposed to be fixed in commit a5b8367, but I didn't add all the necessary flags. --- vim/after/ftplugin/gitcommit.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/after/ftplugin/gitcommit.vim b/vim/after/ftplugin/gitcommit.vim index b7538c9c..d903e84e 100644 --- a/vim/after/ftplugin/gitcommit.vim +++ b/vim/after/ftplugin/gitcommit.vim @@ -14,6 +14,6 @@ let b:undo_ftplugin = b:undo_ftplugin " Make angle brackets behave like mail quotes setlocal comments+=n:> -setlocal formatoptions+=cor +setlocal formatoptions+=coqr let b:undo_ftplugin = b:undo_ftplugin \ . '|setlocal comments< formatoptions<' -- cgit v1.2.3 From 579cf9aba14bcf67b4237470104dafc64af9054a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:10:14 +1200 Subject: Adjust a few Vim Perl indent comments --- vim/indent/perl.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index edb91028..43137e9c 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -9,7 +9,7 @@ let b:did_indent = 1 " Define indent function function! GetPerlIndent() - " Just return 0 if we have no previous line to work from + " Get previous line, bail if none let l:pn = prevnonblank(v:lnum - 1) if !l:pn return 0 @@ -26,7 +26,7 @@ function! GetPerlIndent() \ ? shiftwidth() \ : &shiftwidth - " Don't touch comments + " Just follow comment indent if l:pl =~# '^\s*#' return l:pi @@ -42,7 +42,7 @@ function! GetPerlIndent() return l:pi + l:sw endif - " Closing brace + " Entering closing brace elseif l:cl =~# '^\s*[])}]' " Reduce indent if possible @@ -56,7 +56,7 @@ function! GetPerlIndent() elseif l:pl =~# '[;,}]\s*$' return l:pi - (l:pi % l:sw) - " Continued line; add half shiftwidth + " Continued line; add half 'shiftwidth' elseif l:sw >= 2 return l:pi + l:sw / 2 endif @@ -67,7 +67,7 @@ endfunction setlocal indentexpr=GetPerlIndent() setlocal indentkeys+=0},0),0] -" Undo all of the above crap +" How to undo all of that let b:undo_indent = '|setlocal indentexpr<' \ . '|setlocal indentkeys<' \ . '|delfunction GetPerlIndent' -- cgit v1.2.3 From 7edf55dfc061bddef3c8242531ed7f3dcbd91fb7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:12:09 +1200 Subject: Rearrange settings in Vim Perl indent script The version of this indent script bundled with Vim sets the 'indentexpr' and 'indentkeys' options before the GetPerlIndent() function; may as well follow that pattern. --- vim/indent/perl.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 43137e9c..35270e2c 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -6,6 +6,10 @@ if exists('b:did_indent') || &compatible endif let b:did_indent = 1 +" Indent settings +setlocal indentexpr=GetPerlIndent() +setlocal indentkeys=o,O,0},0),0] + " Define indent function function! GetPerlIndent() @@ -63,10 +67,6 @@ function! GetPerlIndent() endfunction -" Indent settings -setlocal indentexpr=GetPerlIndent() -setlocal indentkeys+=0},0),0] - " How to undo all of that let b:undo_indent = '|setlocal indentexpr<' \ . '|setlocal indentkeys<' -- cgit v1.2.3 From ed12cdd64e0c222f9f6d7ca204d651e82e7dec9f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:14:36 +1200 Subject: Remove unneeded parens in Vim Perl indent script The modulo operator has a higher precedence than the subtraction operator, so it doesn't need to be cuddled. --- vim/indent/perl.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 35270e2c..443dc565 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -58,7 +58,7 @@ function! GetPerlIndent() " After a semicolon, comma, or closing brace elseif l:pl =~# '[;,}]\s*$' - return l:pi - (l:pi % l:sw) + return l:pi - l:pi % l:sw " Continued line; add half 'shiftwidth' elseif l:sw >= 2 -- cgit v1.2.3 From 625a4dc4e8381b63134b1becce9172da22a363c5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:17:36 +1200 Subject: Refactor rules in Vim Perl indent script I think this is mixing two changes I made, which I neglected to commit separately. --- vim/indent/perl.vim | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 443dc565..51e8b26c 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -34,27 +34,15 @@ function! GetPerlIndent() if l:pl =~# '^\s*#' return l:pi - " After opening brace - elseif l:pl =~# '[{([]\s*$' - - " Closing brace - if l:cl =~# '^\s*[])}]' - return l:pi - - " Block content - else - return l:pi + l:sw - endif - " Entering closing brace elseif l:cl =~# '^\s*[])}]' + return l:pi >= l:sw + \ ? l:pi - l:sw - l:pi % l:sw + \ : 0 - " Reduce indent if possible - if l:pi >= l:sw - return l:pi - l:sw - else - return 0 - endif + " After opening brace + elseif l:pl =~# '[{([]\s*$' + return l:pi + l:sw " After a semicolon, comma, or closing brace elseif l:pl =~# '[;,}]\s*$' -- cgit v1.2.3 From 06a4c3e1c870cf37ef35c4d528fd23c66d5ca260 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:18:19 +1200 Subject: Add heredoc support to Vim Perl indent plugin This anchors lines in a Perl heredoc with no indent until it sees the terminating word. It works really well. --- vim/indent/perl.vim | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 51e8b26c..604b836b 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -10,6 +10,22 @@ let b:did_indent = 1 setlocal indentexpr=GetPerlIndent() setlocal indentkeys=o,O,0},0),0] +" Build patterns for heredoc indenting; note that we detect indented heredocs +" with tildes like <<~EOF, but we don't treat them any differently; note also +" a semicolon is required +let s:heredoc_word = '\I\i*' +let s:heredoc_open = '<<\~\?' + \ . '\(' + \ . '\\\?' . s:heredoc_word + \ . '\|' + \ . "'" . s:heredoc_word . "'" + \ . '\|' + \ . '"' . s:heredoc_word . '"' + \ . '\|' + \ . '`' . s:heredoc_word . '`' + \ . '\)' + \ . '.*\ . ';\s*$' + " Define indent function function! GetPerlIndent() @@ -19,9 +35,42 @@ function! GetPerlIndent() return 0 endif - " Get line properties + " Heredoc detection; start at top of buffer + let l:hn = 0 + while l:hn < v:lnum + let l:hl = getline(l:hn) + + " If we're not in a heredoc and not in a comment ... + if !exists('l:hw') && l:hl !~# '^\s*#' + + " Line opens with a heredoc + let l:hm = matchstr(l:hl, s:heredoc_open) + + " Store the heredoc word and make this our indent reference + if strlen(l:hm) + let l:hw = matchstr(l:hm, s:heredoc_word) + let l:pn = l:hn + endif + + " If we are in a heredoc and we found the token word, finish it + elseif exists('l:hw') && l:hl =~# '^'.l:hw.'\>' + unlet l:hw + endif + + " Bump the loop index + let l:hn = l:hn + 1 + + endwhile + + " If we ended up in a heredoc, return 0 for the indent. + if exists('l:hw') + return 0 + endif + + " Get current line properties let l:cl = getline(v:lnum) - let l:ci = indent(l:cn) + + " Get data of previous non-blank and non-heredoc line let l:pl = getline(l:pn) let l:pi = indent(l:pn) -- cgit v1.2.3 From 26a24ab136f196431ba557599d8ad139cb0be3ef Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:19:13 +1200 Subject: Adjust continued line indent for Vim Perl Don't add another two spaces if we already did on a previous line; get the "base" indent first. --- vim/indent/perl.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 604b836b..650dbb08 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -99,7 +99,7 @@ function! GetPerlIndent() " Continued line; add half 'shiftwidth' elseif l:sw >= 2 - return l:pi + l:sw / 2 + return l:pi - l:pi % l:sw + l:sw / 2 endif endfunction -- cgit v1.2.3 From 94c3ce9ad589a29e4023e76c0f342098c39d2c0c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 01:20:50 +1200 Subject: Correct end of heredoc pattern in Vim Perl indent Just a plain old syntax error. --- vim/indent/perl.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 650dbb08..71e2c440 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -24,7 +24,7 @@ let s:heredoc_open = '<<\~\?' \ . '\|' \ . '`' . s:heredoc_word . '`' \ . '\)' - \ . '.*\ . ';\s*$' + \ . '.*;\s*$' " Define indent function function! GetPerlIndent() -- cgit v1.2.3 From e726e79727de2af472d52f1d60f22be8d8387343 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 11:30:53 +1200 Subject: Committing final state of Vim Perl indent I'm not sure I actually want to use this anymore; will remove it for now in the next commit. --- vim/indent/perl.vim | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 71e2c440..01c1259b 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -79,27 +79,31 @@ function! GetPerlIndent() \ ? shiftwidth() \ : &shiftwidth + " Base indent with any fractional indent removed + let l:pb = l:pi - l:pi % l:sw + " Just follow comment indent if l:pl =~# '^\s*#' return l:pi - " Entering closing brace + " Move out with closing brace elseif l:cl =~# '^\s*[])}]' - return l:pi >= l:sw - \ ? l:pi - l:sw - l:pi % l:sw - \ : 0 + return l:pb >= l:sw ? l:pb - l:sw : 0 - " After opening brace + " Move in after opening brace elseif l:pl =~# '[{([]\s*$' - return l:pi + l:sw + return l:pb + l:sw + + " Preserve base indent after a semicolon or a hash element assignment + elseif l:pl =~# '[;,]\s*$' + \ || l:pl =~# '^\s=>.*,\s*$' + \ || l:pl =~# '^\s*sub\>.*{.*}\s+$' + return l:pb - " After a semicolon, comma, or closing brace - elseif l:pl =~# '[;,}]\s*$' - return l:pi - l:pi % l:sw + " Line-continuation: indent half a 'shiftwidth' + else + return l:pb + l:sw / 2 - " Continued line; add half 'shiftwidth' - elseif l:sw >= 2 - return l:pi - l:pi % l:sw + l:sw / 2 endif endfunction -- cgit v1.2.3 From f0b98feb769d9dfbbb0c1825b1291851795163db Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 11:31:57 +1200 Subject: Remove Vim Perl indent This one is pretty good, but I think I'll stick with the stock one for now. --- vim/indent/perl.vim | 114 ---------------------------------------------------- 1 file changed, 114 deletions(-) delete mode 100644 vim/indent/perl.vim diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim deleted file mode 100644 index 01c1259b..00000000 --- a/vim/indent/perl.vim +++ /dev/null @@ -1,114 +0,0 @@ -" Custom Vim indent file for Perl5; the stock one didn't suit me. - -" Only load this indent file when no other was loaded. -if exists('b:did_indent') || &compatible - finish -endif -let b:did_indent = 1 - -" Indent settings -setlocal indentexpr=GetPerlIndent() -setlocal indentkeys=o,O,0},0),0] - -" Build patterns for heredoc indenting; note that we detect indented heredocs -" with tildes like <<~EOF, but we don't treat them any differently; note also -" a semicolon is required -let s:heredoc_word = '\I\i*' -let s:heredoc_open = '<<\~\?' - \ . '\(' - \ . '\\\?' . s:heredoc_word - \ . '\|' - \ . "'" . s:heredoc_word . "'" - \ . '\|' - \ . '"' . s:heredoc_word . '"' - \ . '\|' - \ . '`' . s:heredoc_word . '`' - \ . '\)' - \ . '.*;\s*$' - -" Define indent function -function! GetPerlIndent() - - " Get previous line, bail if none - let l:pn = prevnonblank(v:lnum - 1) - if !l:pn - return 0 - endif - - " Heredoc detection; start at top of buffer - let l:hn = 0 - while l:hn < v:lnum - let l:hl = getline(l:hn) - - " If we're not in a heredoc and not in a comment ... - if !exists('l:hw') && l:hl !~# '^\s*#' - - " Line opens with a heredoc - let l:hm = matchstr(l:hl, s:heredoc_open) - - " Store the heredoc word and make this our indent reference - if strlen(l:hm) - let l:hw = matchstr(l:hm, s:heredoc_word) - let l:pn = l:hn - endif - - " If we are in a heredoc and we found the token word, finish it - elseif exists('l:hw') && l:hl =~# '^'.l:hw.'\>' - unlet l:hw - endif - - " Bump the loop index - let l:hn = l:hn + 1 - - endwhile - - " If we ended up in a heredoc, return 0 for the indent. - if exists('l:hw') - return 0 - endif - - " Get current line properties - let l:cl = getline(v:lnum) - - " Get data of previous non-blank and non-heredoc line - let l:pl = getline(l:pn) - let l:pi = indent(l:pn) - - " Get value of 'shiftwidth' - let l:sw = exists('*shiftwidth') - \ ? shiftwidth() - \ : &shiftwidth - - " Base indent with any fractional indent removed - let l:pb = l:pi - l:pi % l:sw - - " Just follow comment indent - if l:pl =~# '^\s*#' - return l:pi - - " Move out with closing brace - elseif l:cl =~# '^\s*[])}]' - return l:pb >= l:sw ? l:pb - l:sw : 0 - - " Move in after opening brace - elseif l:pl =~# '[{([]\s*$' - return l:pb + l:sw - - " Preserve base indent after a semicolon or a hash element assignment - elseif l:pl =~# '[;,]\s*$' - \ || l:pl =~# '^\s=>.*,\s*$' - \ || l:pl =~# '^\s*sub\>.*{.*}\s+$' - return l:pb - - " Line-continuation: indent half a 'shiftwidth' - else - return l:pb + l:sw / 2 - - endif - -endfunction - -" How to undo all of that -let b:undo_indent = '|setlocal indentexpr<' - \ . '|setlocal indentkeys<' - \ . '|delfunction GetPerlIndent' -- cgit v1.2.3 From 85d8205906685e4c555a0fba5be6af8f03eda572 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 12:23:08 +1200 Subject: Revert "Remove Vim Perl indent" This reverts commit f0b98feb769d9dfbbb0c1825b1291851795163db. I changed my mind again. --- vim/indent/perl.vim | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 vim/indent/perl.vim diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim new file mode 100644 index 00000000..01c1259b --- /dev/null +++ b/vim/indent/perl.vim @@ -0,0 +1,114 @@ +" Custom Vim indent file for Perl5; the stock one didn't suit me. + +" Only load this indent file when no other was loaded. +if exists('b:did_indent') || &compatible + finish +endif +let b:did_indent = 1 + +" Indent settings +setlocal indentexpr=GetPerlIndent() +setlocal indentkeys=o,O,0},0),0] + +" Build patterns for heredoc indenting; note that we detect indented heredocs +" with tildes like <<~EOF, but we don't treat them any differently; note also +" a semicolon is required +let s:heredoc_word = '\I\i*' +let s:heredoc_open = '<<\~\?' + \ . '\(' + \ . '\\\?' . s:heredoc_word + \ . '\|' + \ . "'" . s:heredoc_word . "'" + \ . '\|' + \ . '"' . s:heredoc_word . '"' + \ . '\|' + \ . '`' . s:heredoc_word . '`' + \ . '\)' + \ . '.*;\s*$' + +" Define indent function +function! GetPerlIndent() + + " Get previous line, bail if none + let l:pn = prevnonblank(v:lnum - 1) + if !l:pn + return 0 + endif + + " Heredoc detection; start at top of buffer + let l:hn = 0 + while l:hn < v:lnum + let l:hl = getline(l:hn) + + " If we're not in a heredoc and not in a comment ... + if !exists('l:hw') && l:hl !~# '^\s*#' + + " Line opens with a heredoc + let l:hm = matchstr(l:hl, s:heredoc_open) + + " Store the heredoc word and make this our indent reference + if strlen(l:hm) + let l:hw = matchstr(l:hm, s:heredoc_word) + let l:pn = l:hn + endif + + " If we are in a heredoc and we found the token word, finish it + elseif exists('l:hw') && l:hl =~# '^'.l:hw.'\>' + unlet l:hw + endif + + " Bump the loop index + let l:hn = l:hn + 1 + + endwhile + + " If we ended up in a heredoc, return 0 for the indent. + if exists('l:hw') + return 0 + endif + + " Get current line properties + let l:cl = getline(v:lnum) + + " Get data of previous non-blank and non-heredoc line + let l:pl = getline(l:pn) + let l:pi = indent(l:pn) + + " Get value of 'shiftwidth' + let l:sw = exists('*shiftwidth') + \ ? shiftwidth() + \ : &shiftwidth + + " Base indent with any fractional indent removed + let l:pb = l:pi - l:pi % l:sw + + " Just follow comment indent + if l:pl =~# '^\s*#' + return l:pi + + " Move out with closing brace + elseif l:cl =~# '^\s*[])}]' + return l:pb >= l:sw ? l:pb - l:sw : 0 + + " Move in after opening brace + elseif l:pl =~# '[{([]\s*$' + return l:pb + l:sw + + " Preserve base indent after a semicolon or a hash element assignment + elseif l:pl =~# '[;,]\s*$' + \ || l:pl =~# '^\s=>.*,\s*$' + \ || l:pl =~# '^\s*sub\>.*{.*}\s+$' + return l:pb + + " Line-continuation: indent half a 'shiftwidth' + else + return l:pb + l:sw / 2 + + endif + +endfunction + +" How to undo all of that +let b:undo_indent = '|setlocal indentexpr<' + \ . '|setlocal indentkeys<' + \ . '|delfunction GetPerlIndent' -- cgit v1.2.3 From 702fa2dbcc3fd3817cfa85d060ff4d3b5bb49731 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 13:21:45 +1200 Subject: Remove misplaced separator in b:undo_indent This was causing the first line of the buffer to be printed on every filetype change from Perl. --- vim/indent/perl.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 01c1259b..9a8f30e1 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -109,6 +109,6 @@ function! GetPerlIndent() endfunction " How to undo all of that -let b:undo_indent = '|setlocal indentexpr<' +let b:undo_indent = 'setlocal indentexpr<' \ . '|setlocal indentkeys<' \ . '|delfunction GetPerlIndent' -- cgit v1.2.3 From 081a9a90846c41c93f4a2a374d94dbd05921f1b5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 13:22:52 +1200 Subject: Further extension of Perl Vim line cont rules --- vim/indent/perl.vim | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 9a8f30e1..c9cfe829 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -7,8 +7,8 @@ endif let b:did_indent = 1 " Indent settings -setlocal indentexpr=GetPerlIndent() -setlocal indentkeys=o,O,0},0),0] +setlocal indentexpr=GetPerlIndent(v:lnum) +setlocal indentkeys=o,O,0=,0=},0=),0=],&,, " Build patterns for heredoc indenting; note that we detect indented heredocs " with tildes like <<~EOF, but we don't treat them any differently; note also @@ -94,16 +94,23 @@ function! GetPerlIndent() elseif l:pl =~# '[{([]\s*$' return l:pb + l:sw - " Preserve base indent after a semicolon or a hash element assignment - elseif l:pl =~# '[;,]\s*$' - \ || l:pl =~# '^\s=>.*,\s*$' - \ || l:pl =~# '^\s*sub\>.*{.*}\s+$' + " Never continue after a semicolon or a double-underscore + elseif l:pl =~# '\;\s*$' + \ || l:pl =~# '__DATA__' + \ || l:pl =~# '__END__' return l:pb - " Line-continuation: indent half a 'shiftwidth' - else + " Line continuation hints + elseif l:pl =~# '[^])},]\s*$' + \ || l:cl =~# '^\s*\(and\|or\)\>' + \ || l:cl =~# '^\s*\(&&\|||\)' + \ || l:cl =~# '^\s*=' return l:pb + l:sw / 2 + " Default to indent of previous line + else + return l:pb + endif endfunction -- cgit v1.2.3 From 056b6f78ae688f9e78fa78dad467a58af378e5a9 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 13:23:45 +1200 Subject: Pass Vim indent line into Perl function Should make testing (!) easier later on. --- vim/indent/perl.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index c9cfe829..ee8fbd68 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -27,17 +27,17 @@ let s:heredoc_open = '<<\~\?' \ . '.*;\s*$' " Define indent function -function! GetPerlIndent() +function! GetPerlIndent(lnum) " Get previous line, bail if none - let l:pn = prevnonblank(v:lnum - 1) + let l:pn = prevnonblank(a:lnum - 1) if !l:pn return 0 endif " Heredoc detection; start at top of buffer let l:hn = 0 - while l:hn < v:lnum + while l:hn < a:lnum let l:hl = getline(l:hn) " If we're not in a heredoc and not in a comment ... @@ -68,7 +68,7 @@ function! GetPerlIndent() endif " Get current line properties - let l:cl = getline(v:lnum) + let l:cl = getline(v:anum) " Get data of previous non-blank and non-heredoc line let l:pl = getline(l:pn) -- cgit v1.2.3 From 6bbeb03e06a538825f038d87d9c5548fe3546c6c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 13:24:17 +1200 Subject: Add POD rules to Vim Perl indent --- vim/indent/perl.vim | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index ee8fbd68..68ee8d34 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -35,41 +35,48 @@ function! GetPerlIndent(lnum) return 0 endif - " Heredoc detection; start at top of buffer - let l:hn = 0 - while l:hn < a:lnum - let l:hl = getline(l:hn) + " Heredoc and POD detection; start at top of buffer + let l:pod = 0 + let l:hpn = 0 + while l:hpn < a:lnum + let l:hpl = getline(l:hpn) " If we're not in a heredoc and not in a comment ... - if !exists('l:hw') && l:hl !~# '^\s*#' + if !exists('l:hpw') && l:hpl !~# '^\s*#' - " Line opens with a heredoc - let l:hm = matchstr(l:hl, s:heredoc_open) + " POD switching + if !l:pod && stridx(l:hpl, '=pod') == 0 + let l:pod = 1 + elseif l:pod && stridx(l:hpl, '=cut') == 0 + let l:pod = 0 + else + + " Line opens with a heredoc + let l:hpm = matchstr(l:hpl, s:heredoc_open) + + " Store the heredoc word and make this our indent reference + if strlen(l:hpm) + let l:hpw = matchstr(l:hpm, s:heredoc_word) + let l:pn = l:hpn + endif - " Store the heredoc word and make this our indent reference - if strlen(l:hm) - let l:hw = matchstr(l:hm, s:heredoc_word) - let l:pn = l:hn endif " If we are in a heredoc and we found the token word, finish it - elseif exists('l:hw') && l:hl =~# '^'.l:hw.'\>' - unlet l:hw + elseif exists('l:hpw') && l:hpl =~# '^'.l:hpw.'\>' + unlet l:hpw endif " Bump the loop index - let l:hn = l:hn + 1 + let l:hpn = l:hpn + 1 endwhile " If we ended up in a heredoc, return 0 for the indent. - if exists('l:hw') + if exists('l:hpw') return 0 endif - " Get current line properties - let l:cl = getline(v:anum) - " Get data of previous non-blank and non-heredoc line let l:pl = getline(l:pn) let l:pi = indent(l:pn) @@ -79,6 +86,15 @@ function! GetPerlIndent(lnum) \ ? shiftwidth() \ : &shiftwidth + " If we're in POD and the indent of the previous line was less than + " 'shiftwith', keep it there. + if l:pod && l:pi < l:sw + return l:pi + endif + + " Get current line properties + let l:cl = getline(a:lnum) + " Base indent with any fractional indent removed let l:pb = l:pi - l:pi % l:sw -- cgit v1.2.3 From 4d3ec71335a338a5362a073099e6039d72fef416 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 14:17:26 +1200 Subject: Simplify POD Vim indenting behaviour --- vim/indent/perl.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 68ee8d34..d03735a4 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -77,6 +77,11 @@ function! GetPerlIndent(lnum) return 0 endif + " If we're in POD, just autoindent; simple and good enough. + if l:pod + return indent(a:lnum - 1) + endif + " Get data of previous non-blank and non-heredoc line let l:pl = getline(l:pn) let l:pi = indent(l:pn) @@ -84,13 +89,8 @@ function! GetPerlIndent(lnum) " Get value of 'shiftwidth' let l:sw = exists('*shiftwidth') \ ? shiftwidth() - \ : &shiftwidth + \ : &shiftwidth || &tabstop - " If we're in POD and the indent of the previous line was less than - " 'shiftwith', keep it there. - if l:pod && l:pi < l:sw - return l:pi - endif " Get current line properties let l:cl = getline(a:lnum) -- cgit v1.2.3 From 376f3ff8686709c23b8fe34601b6b660005e79e0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 14:17:42 +1200 Subject: Simplify Vim Perl shiftwidth calculation This is a portable method that will work on very old Vims. --- vim/indent/perl.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index d03735a4..91cc9e17 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -87,10 +87,9 @@ function! GetPerlIndent(lnum) let l:pi = indent(l:pn) " Get value of 'shiftwidth' - let l:sw = exists('*shiftwidth') - \ ? shiftwidth() - \ : &shiftwidth || &tabstop - + let l:sw = &shiftwidth + \ ? &shiftwidth + \ : &tabstop " Get current line properties let l:cl = getline(a:lnum) -- cgit v1.2.3 From 343553c05b647cf9716eb9bd44cf023fac61fc61 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 14:18:24 +1200 Subject: Refine Perl line cont hints in Vim indent --- vim/indent/perl.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 91cc9e17..f02f2a65 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -8,7 +8,7 @@ let b:did_indent = 1 " Indent settings setlocal indentexpr=GetPerlIndent(v:lnum) -setlocal indentkeys=o,O,0=,0=},0=),0=],&,, +setlocal indentkeys=o,O,0=,0=},0=),0=],0=&&,0=\|\|,0=//,0=?,0=:, " Build patterns for heredoc indenting; note that we detect indented heredocs " with tildes like <<~EOF, but we don't treat them any differently; note also @@ -117,9 +117,9 @@ function! GetPerlIndent(lnum) " Line continuation hints elseif l:pl =~# '[^])},]\s*$' - \ || l:cl =~# '^\s*\(and\|or\)\>' - \ || l:cl =~# '^\s*\(&&\|||\)' - \ || l:cl =~# '^\s*=' + \ || l:cl =~# '^\s*\(and\|or\|xor\)' + \ || l:cl =~# '^\s*\(&&\|||\|//\)' + \ || l:cl =~# '^\s*[?:=]' return l:pb + l:sw / 2 " Default to indent of previous line -- cgit v1.2.3 From f125d0bc8b08cbb9e77bd1b64e189909821239d1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 14:34:55 +1200 Subject: Rearrange heredoc/POD indent check for speed --- vim/indent/perl.vim | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index f02f2a65..14a211f5 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -35,31 +35,32 @@ function! GetPerlIndent(lnum) return 0 endif - " Heredoc and POD detection; start at top of buffer + " Heredoc and POD detection; this is expensive, so limit it to 512 lines of + " context + let l:lim = 512 + let l:hpn = line('$') > l:lim + \ ? line('$') - l:lim + \ : 0 let l:pod = 0 - let l:hpn = 0 while l:hpn < a:lnum let l:hpl = getline(l:hpn) " If we're not in a heredoc and not in a comment ... if !exists('l:hpw') && l:hpl !~# '^\s*#' - " POD switching - if !l:pod && stridx(l:hpl, '=pod') == 0 + " POD switching; match any section so that we can handle long PODs + if !l:pod && l:hpl =~# '^=\l\+\d\?\>' let l:pod = 1 elseif l:pod && stridx(l:hpl, '=cut') == 0 let l:pod = 0 - else - " Line opens with a heredoc + " Heredoc switch on + else let l:hpm = matchstr(l:hpl, s:heredoc_open) - - " Store the heredoc word and make this our indent reference if strlen(l:hpm) let l:hpw = matchstr(l:hpm, s:heredoc_word) let l:pn = l:hpn endif - endif " If we are in a heredoc and we found the token word, finish it -- cgit v1.2.3 From 57bd8dcb1a77f7ca59b1e41a6bef175fbe90fc0a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 15:27:42 +1200 Subject: More speed refactoring for Perl Vim indent --- vim/indent/perl.vim | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 14a211f5..f4304fd2 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -10,21 +10,16 @@ let b:did_indent = 1 setlocal indentexpr=GetPerlIndent(v:lnum) setlocal indentkeys=o,O,0=,0=},0=),0=],0=&&,0=\|\|,0=//,0=?,0=:, -" Build patterns for heredoc indenting; note that we detect indented heredocs -" with tildes like <<~EOF, but we don't treat them any differently; note also -" a semicolon is required +" Build patterns for heredoc indenting. Note that we detect indented heredocs +" with tildes like <<~EOF, but we don't treat them any differently. We don't +" strictly match the quotes either, in an effort to keep this fast. let s:heredoc_word = '\I\i*' let s:heredoc_open = '<<\~\?' \ . '\(' \ . '\\\?' . s:heredoc_word \ . '\|' - \ . "'" . s:heredoc_word . "'" - \ . '\|' - \ . '"' . s:heredoc_word . '"' - \ . '\|' - \ . '`' . s:heredoc_word . '`' + \ . "['`\"]" . s:heredoc_word . "['`\"]" \ . '\)' - \ . '.*;\s*$' " Define indent function function! GetPerlIndent(lnum) @@ -35,36 +30,36 @@ function! GetPerlIndent(lnum) return 0 endif - " Heredoc and POD detection; this is expensive, so limit it to 512 lines of - " context - let l:lim = 512 - let l:hpn = line('$') > l:lim - \ ? line('$') - l:lim - \ : 0 + " Heredoc and POD flags + let l:heredoc = 0 let l:pod = 0 + + " Start loop back through up to 512 lines of context + let l:lim = 512 + let l:hpn = a:lnum > l:lim ? a:lnum - l:lim : 0 while l:hpn < a:lnum let l:hpl = getline(l:hpn) " If we're not in a heredoc and not in a comment ... - if !exists('l:hpw') && l:hpl !~# '^\s*#' + if !l:heredoc && l:hpl !~# '^\s*#' " POD switching; match any section so that we can handle long PODs - if !l:pod && l:hpl =~# '^=\l\+\d\?\>' - let l:pod = 1 - elseif l:pod && stridx(l:hpl, '=cut') == 0 - let l:pod = 0 + if stridx(l:hpl, '=') == 0 + let l:pod = stridx(l:hpl, '=cut') != 0 " Heredoc switch on else let l:hpm = matchstr(l:hpl, s:heredoc_open) if strlen(l:hpm) + let l:heredoc = 1 let l:hpw = matchstr(l:hpm, s:heredoc_word) let l:pn = l:hpn endif endif " If we are in a heredoc and we found the token word, finish it - elseif exists('l:hpw') && l:hpl =~# '^'.l:hpw.'\>' + elseif l:heredoc && l:hpl =~# '^'.l:hpw.'\>' + let l:heredoc = 0 unlet l:hpw endif @@ -73,8 +68,8 @@ function! GetPerlIndent(lnum) endwhile - " If we ended up in a heredoc, return 0 for the indent. - if exists('l:hpw') + " If we ended up in a heredoc, never indent. + if l:heredoc return 0 endif -- cgit v1.2.3 From 65bda616c2045d2c6f86e52ed053eb9eea208071 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 15:27:50 +1200 Subject: Inline ternary condition in Perl Vim indent --- vim/indent/perl.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index f4304fd2..43d64f6f 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -83,9 +83,7 @@ function! GetPerlIndent(lnum) let l:pi = indent(l:pn) " Get value of 'shiftwidth' - let l:sw = &shiftwidth - \ ? &shiftwidth - \ : &tabstop + let l:sw = &shiftwidth ? &shiftwidth : &tabstop " Get current line properties let l:cl = getline(a:lnum) -- cgit v1.2.3 From 9036f191bf0ce2279167da436123948c8f180eff Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 15:29:53 +1200 Subject: Require semicolon on same line of heredoc --- vim/indent/perl.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/vim/indent/perl.vim b/vim/indent/perl.vim index 43d64f6f..cd01f30b 100644 --- a/vim/indent/perl.vim +++ b/vim/indent/perl.vim @@ -20,6 +20,7 @@ let s:heredoc_open = '<<\~\?' \ . '\|' \ . "['`\"]" . s:heredoc_word . "['`\"]" \ . '\)' + \ . '.*;\s*$' " Define indent function function! GetPerlIndent(lnum) -- cgit v1.2.3 From 2f4db29db7805aeb27ae9600549d1ff66cc14b9b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 15:33:01 +1200 Subject: Rearrange Makefile for Neovim install --- Makefile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c64d5ce3..4556ceae 100644 --- a/Makefile +++ b/Makefile @@ -432,11 +432,6 @@ install-ncmcpp: install-mpd mkdir -p -- $(HOME)/.ncmpcpp cp -p -- ncmpcpp/config $(HOME)/.ncmpcpp -install-neovim: - make install-vim \ - VIMDIR=$${XDG_CONFIG_HOME:-"$$HOME"/.config}/nvim \ - VIMRC=$${XDF_CONFIG_HOME:="$$HOME"/.config}/init.vim - install-newsboat: mkdir -p -- $(HOME)/.config/newsboat $(HOME)/.local/share/newsboat cp -p -- newsboat/config $(HOME)/.config/newsboat @@ -497,7 +492,6 @@ install-urxvt: urxvt/ext/select find urxvt/ext -type f ! -name '*.pl' \ -exec cp -p -- {} $(HOME)/.urxvt/ext \; -# Change these at invocation to install for NeoVim; see README.md VIMDIR = $(HOME)/.vim VIMRC = $(HOME)/.vimrc @@ -511,6 +505,11 @@ install-vim: install-vim-after \ install-vim-indent \ install-vim-plugin +install-neovim: + make install-vim \ + VIMDIR=$${XDG_CONFIG_HOME:-"$$HOME"/.config}/nvim \ + VIMRC=$${XDF_CONFIG_HOME:="$$HOME"/.config}/init.vim + install-vim-after: install-vim-after-ftplugin \ install-vim-after-indent \ install-vim-after-plugin \ -- cgit v1.2.3 From 6a2bc801c6e72bdaa7f725d6c7b98b17a09c3478 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 15:34:59 +1200 Subject: Include up to 500 commit messages in merge log If I want to reduce it, I'll make Vim do it. --- git/gitconfig.mi5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/gitconfig.mi5 b/git/gitconfig.mi5 index 3c97a77d..cee0a759 100644 --- a/git/gitconfig.mi5 +++ b/git/gitconfig.mi5 @@ -40,7 +40,7 @@ [merge] ff = false - log = true + log = 500 [pager] diff = cat -- cgit v1.2.3 From bd48d967ab5406ed0dd88af9ea781a579a89bc50 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 7 Jul 2018 15:32:38 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index e1eb12fb..c55e22ec 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v1.22.0 -Wed Jul 4 12:05:13 UTC 2018 +tejr dotfiles v1.23.0 +Sat Jul 7 03:31:48 UTC 2018 -- cgit v1.2.3