From 5536bbccd0917e554c283b73b420c2905df28efe Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 18 Dec 2019 17:31:08 +1300 Subject: Refactor indent macros into autoload function Much nicer. --- Makefile | 11 +---------- vim/after/indent/awk.vim | 2 +- vim/after/indent/css.vim | 2 +- vim/after/indent/html.vim | 2 +- vim/after/indent/javascript.vim | 2 +- vim/after/indent/mail.vim | 2 +- vim/after/indent/perl.vim | 2 +- vim/after/indent/php.vim | 2 +- vim/after/indent/sh.vim | 2 +- vim/after/indent/vim.vim | 2 +- vim/autoload/indent.vim | 32 ++++++++++++++++++++++++++++++++ vim/macros/indent/spaces.vim | 7 ------- vim/macros/indent/spaces/2.vim | 3 --- vim/macros/indent/spaces/4.vim | 3 --- 14 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 vim/autoload/indent.vim delete mode 100644 vim/macros/indent/spaces.vim delete mode 100644 vim/macros/indent/spaces/2.vim delete mode 100644 vim/macros/indent/spaces/4.vim diff --git a/Makefile b/Makefile index c9019eea..0b562f8e 100644 --- a/Makefile +++ b/Makefile @@ -546,7 +546,6 @@ install-vim: install-vim-after \ install-vim-filetype \ install-vim-ftplugin \ install-vim-indent \ - install-vim-macros \ install-vim-plugin \ install-vim-syntax @@ -559,7 +558,7 @@ install-vim-after-ftplugin: install-vim-compiler mkdir -p $(VIMDIR)/after/ftplugin cp -p -- vim/after/ftplugin/*.vim $(VIMDIR)/after/ftplugin -install-vim-after-indent: install-vim-macros +install-vim-after-indent: install-vim-autoload mkdir -p $(VIMDIR)/after/indent cp -p -- vim/after/indent/*.vim $(VIMDIR)/after/indent @@ -619,14 +618,6 @@ install-vim-indent: mkdir -p -- $(VIMDIR)/indent cp -p -- vim/indent/*.vim $(VIMDIR)/indent -install-vim-macros: - find vim/macros \ - -type d -exec sh -c \ - 'mkdir -p -- $(VIMDIR)/"$${1#vim/}"' _ {} \; \ - -o \ - -type f -exec sh -c \ - 'cp -p -- "$$1" $(VIMDIR)/"$${1#vim/}"' _ {} \; - install-vim-plugin: install-vim-autoload mkdir -p -- $(VIMDIR)/plugin cp -p -- vim/plugin/*.vim $(VIMDIR)/plugin diff --git a/vim/after/indent/awk.vim b/vim/after/indent/awk.vim index 951c830a..61f09a1e 100644 --- a/vim/after/indent/awk.vim +++ b/vim/after/indent/awk.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -runtime macros/indent/spaces/4.vim +call indent#spaces(4) diff --git a/vim/after/indent/css.vim b/vim/after/indent/css.vim index 951c830a..61f09a1e 100644 --- a/vim/after/indent/css.vim +++ b/vim/after/indent/css.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -runtime macros/indent/spaces/4.vim +call indent#spaces(4) diff --git a/vim/after/indent/html.vim b/vim/after/indent/html.vim index fb7f4127..c043f620 100644 --- a/vim/after/indent/html.vim +++ b/vim/after/indent/html.vim @@ -1,5 +1,5 @@ " Use four spaces for indentation -runtime macros/indent/spaces/4.vim +call indent#spaces(4) " Clear away the flag we set to indent after paragraphs unlet html_indent_inctags diff --git a/vim/after/indent/javascript.vim b/vim/after/indent/javascript.vim index 951c830a..61f09a1e 100644 --- a/vim/after/indent/javascript.vim +++ b/vim/after/indent/javascript.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -runtime macros/indent/spaces/4.vim +call indent#spaces(4) diff --git a/vim/after/indent/mail.vim b/vim/after/indent/mail.vim index 951c830a..61f09a1e 100644 --- a/vim/after/indent/mail.vim +++ b/vim/after/indent/mail.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -runtime macros/indent/spaces/4.vim +call indent#spaces(4) diff --git a/vim/after/indent/perl.vim b/vim/after/indent/perl.vim index 951c830a..61f09a1e 100644 --- a/vim/after/indent/perl.vim +++ b/vim/after/indent/perl.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -runtime macros/indent/spaces/4.vim +call indent#spaces(4) diff --git a/vim/after/indent/php.vim b/vim/after/indent/php.vim index 951c830a..61f09a1e 100644 --- a/vim/after/indent/php.vim +++ b/vim/after/indent/php.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -runtime macros/indent/spaces/4.vim +call indent#spaces(4) diff --git a/vim/after/indent/sh.vim b/vim/after/indent/sh.vim index 951c830a..61f09a1e 100644 --- a/vim/after/indent/sh.vim +++ b/vim/after/indent/sh.vim @@ -1,2 +1,2 @@ " Use four spaces for indentation -runtime macros/indent/spaces/4.vim +call indent#spaces(4) diff --git a/vim/after/indent/vim.vim b/vim/after/indent/vim.vim index 59179225..ce99f713 100644 --- a/vim/after/indent/vim.vim +++ b/vim/after/indent/vim.vim @@ -1,5 +1,5 @@ " Use two (not four!) spaces for indentation, per convention -runtime macros/indent/spaces/2.vim +call indent#spaces(2) " Remove inapplicable defaults from 'indentkeys'; we should only need to undo " this if the stock plugin didn't already arrange that (before v7.3.539) diff --git a/vim/autoload/indent.vim b/vim/autoload/indent.vim new file mode 100644 index 00000000..3e850c63 --- /dev/null +++ b/vim/autoload/indent.vim @@ -0,0 +1,32 @@ +function! indent#spaces(...) abort + setlocal expandtab + let &l:shiftwidth = a:0 + \ ? a:1 + \ : 0 + let &l:softtabstop = has#('patch-7.3.693') + \ ? -1 + \ : &l:shiftwidth + call indent#undo() +endfunction + +function! indent#tabs() abort + setlocal noexpandtab shiftwidth< softtabstop< + call indent#undo() +endfunction + +function! indent#undo() abort + if exists('b:undo_indent_set') + return + endif + let l:undo = 'call indent#reset()' + if exists('b:undo_indent') + let b:undo_indent .= '|'.l:undo + else + let b:undo_indent = l:undo + endif + let b:undo_indent_set = 1 +endfunction + +function! indent#reset() abort + setlocal expandtab< shiftwidth< softtabstop< tabstop< +endfunction diff --git a/vim/macros/indent/spaces.vim b/vim/macros/indent/spaces.vim deleted file mode 100644 index d4b36afe..00000000 --- a/vim/macros/indent/spaces.vim +++ /dev/null @@ -1,7 +0,0 @@ -" Use spaces for current buffer's indentation (set 'shiftwidth' first) -setlocal expandtab -let b:undo_ftplugin .= '|setlocal expandtab< shiftwidth<' -if &l:softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_ftplugin .= '|setlocal softtabstop<' -endif diff --git a/vim/macros/indent/spaces/2.vim b/vim/macros/indent/spaces/2.vim deleted file mode 100644 index a0f847ae..00000000 --- a/vim/macros/indent/spaces/2.vim +++ /dev/null @@ -1,3 +0,0 @@ -" Use two spaces for current buffer's indentation -setlocal shiftwidth=2 -runtime macros/indent/spaces.vim diff --git a/vim/macros/indent/spaces/4.vim b/vim/macros/indent/spaces/4.vim deleted file mode 100644 index 13ac5258..00000000 --- a/vim/macros/indent/spaces/4.vim +++ /dev/null @@ -1,3 +0,0 @@ -" Use four spaces for current buffer's indentation -setlocal shiftwidth=4 -runtime macros/indent/spaces.vim -- cgit v1.2.3