From 8aecf5d104fa69e24585540da9607054999b66f0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 30 May 2020 19:31:16 +1200 Subject: Spin detect_indent.vim out into its own plugin --- .gitmodules | 3 ++ vim/autoload/detect_indent.vim | 108 ----------------------------------------- vim/bundle/detect_indent | 1 + vim/plugin/detect_indent.vim | 23 --------- 4 files changed, 4 insertions(+), 131 deletions(-) delete mode 100644 vim/autoload/detect_indent.vim create mode 160000 vim/bundle/detect_indent delete mode 100644 vim/plugin/detect_indent.vim diff --git a/.gitmodules b/.gitmodules index 6a023a9b..41920514 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,6 +14,9 @@ [submodule "vim/bundle/cursorline_current"] path = vim/bundle/cursorline_current url = https://sanctum.geek.nz/code/vim-cursorline-current.git +[submodule "vim/bundle/detect_indent"] + path = vim/bundle/detect_indent + url = https://sanctum.geek.nz/code/vim-detect-indent.git [submodule "vim/bundle/digraph_search"] path = vim/bundle/digraph_search url = https://sanctum.geek.nz/code/vim-digraph-search.git diff --git a/vim/autoload/detect_indent.vim b/vim/autoload/detect_indent.vim deleted file mode 100644 index 71a43e87..00000000 --- a/vim/autoload/detect_indent.vim +++ /dev/null @@ -1,108 +0,0 @@ -" Numeric comparison function to sort in a Vim v7.0 compatible way -function! s:CompareNumeric(a, b) abort - return a:a > a:b ? 1 : -1 -endfunction - -" Entry point for plugin -function! detect_indent#() abort - - " For spaces, we count both the total space-indented lines, and also the - " count of lines indexed by space count, so that if we need to, we can - " figure out a good 'shiftwidth' setting; for tabs, we just count the - " indented lines, since we won't need to set 'shiftwidth' for that. - " - let tabs = 0 - let spaces = { - \ 'hist': {}, - \ 'total': 0, - \} - - " Figure out how many lines we'll check; cap this to 1,024, or whatever the - " user configured - let total = max([line('$'), get(g:, 'detect_indent_limit', 1024)]) - - " Iterate through the lines - for line in getline(1, total) - - " If there are leading tabs, we'll call this a tab-indented line; bump the - " appropriate count, and skip the rest of the loop. - " - if matchstr(line, '^\t*') !=# '' - let tabs += 1 - continue - endif - - " Figure out count of space indenting; skip to the next line if it's zero - let indent = strlen(matchstr(line, '^ *')) - if indent == 0 - continue - endif - - " Increment the count of space-indented lines - let spaces['total'] += 1 - - " Create a dictionary entry in the histogram for this indent if necessary, - " and increment that counter - " - if !has_key(spaces['hist'], indent) - let spaces['hist'][indent] = 0 - endif - let spaces['hist'][indent] += 1 - - endfor - - " If the value for 'expandtab' as determined by the user's configuration - " matches the expected dominance of space-indented lines over tab-indented - " lines, we're already using the right setting, and we stop here - " - if &expandtab == (spaces['total'] >= tabs) - return - endif - - " If 'expandtab' is set, we need to unset it and switch to pure tab - " indenting; that's straightforward, we just need to make sure 'shiftwidth' - " matches 'tabstop', and that 'softtabstop' is off. - " - if &expandtab - setlocal noexpandtab softtabstop=0 - let &l:shiftwidth = &tabstop - - " If 'expandtab' is not set, we need to set it, and guess an appropriate - " 'shiftwidth'. - else - setlocal expandtab - - " Iterate through the keys of the histogram from smallest to largest. - " We'll accept as our 'shiftwidth' the smallest indent level that - " constitutes more than 5% of the total lines, configurable by the user. - " This is just an heuristic, but it seems to work pretty well. - " - let shiftwidth = 0 - let indents = keys(spaces['hist']) - call map(indents, 'str2nr(v:val)') " Coerce the string keys to numeric - call sort(indents, 's:CompareNumeric') " Force numeric sort - for shiftwidth in indents - if spaces['hist'][shiftwidth] * 100 / spaces['total'] - \ >= get(g:, 'detect_indent_confidence', 5) - break - endif - endfor - - " We have our 'shiftwidth'; set it, with 'softtabstop' set to match - let &l:shiftwidth = shiftwidth - let &l:softtabstop = shiftwidth - - endif - - " Since we just messed with indent settings, stack up a command to revert - " the changes when the indent plugin is unloaded, as if we ourselves were - " a single filetype indent plugin. - " - let undo_indent = 'setlocal expandtab< shiftwidth< softtabstop<' - if exists('b:undo_indent') - let b:undo_indent .= '|' . undo_indent - else - let b:undo_indent = undo_indent - endif - -endfunction diff --git a/vim/bundle/detect_indent b/vim/bundle/detect_indent new file mode 160000 index 00000000..4b364f09 --- /dev/null +++ b/vim/bundle/detect_indent @@ -0,0 +1 @@ +Subproject commit 4b364f096f9c5ad06daa99f5d302e0b07424f0bf diff --git a/vim/plugin/detect_indent.vim b/vim/plugin/detect_indent.vim deleted file mode 100644 index e75324ac..00000000 --- a/vim/plugin/detect_indent.vim +++ /dev/null @@ -1,23 +0,0 @@ -" -" detect_indent.vim: If 'expandtab' doesn't match the shape of the buffer's -" indents, switch it over, including a guess at 'shiftwidth' if switching it -" on. -" -" Author: Tom Ryder -" License: Same as Vim itself -" -if exists('loaded_detect_indent') || &compatible || v:version < 700 - finish -endif -let loaded_detect_indent = 1 - -" Set up a user command in case the user wants to set this manually -command! -bar DetectIndent - \ call detect_indent#() - -" Add hook for FileType event; this should load *after* filetype plugins -augroup detect_indent - autocmd! - autocmd FileType * - \ DetectIndent -augroup END -- cgit v1.2.3 From 6650e817307ba95294c650ac836a429285cc788e Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 30 May 2020 19:31:51 +1200 Subject: Update squeeze_repeat_blanks.vim to v0.7.0 --- vim/bundle/squeeze_repeat_blanks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vim/bundle/squeeze_repeat_blanks b/vim/bundle/squeeze_repeat_blanks index d80bc373..27dd1b58 160000 --- a/vim/bundle/squeeze_repeat_blanks +++ b/vim/bundle/squeeze_repeat_blanks @@ -1 +1 @@ -Subproject commit d80bc3733cf19eb72111171bee269306222d67bb +Subproject commit 27dd1b5858b4839b34249c106d2b3963a3da4161 -- cgit v1.2.3 From e7a7e40654a0879ed60131905f991eafdd3499c6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 30 May 2020 19:32:19 +1200 Subject: Bump VERSION --- VERSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 32ca21a7..51a17591 100644 --- a/VERSION +++ b/VERSION @@ -1,2 +1,2 @@ -tejr dotfiles v9.11.0 -Fri, 29 May 2020 13:33:26 +0000 +tejr dotfiles v9.12.0 +Sat, 30 May 2020 07:32:19 +0000 -- cgit v1.2.3