From 4a4341936d2911820abddd67882f9b867496abbb Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 18 Dec 2019 17:05:08 +1300 Subject: Put common indent setting patterns in macros --- Makefile | 11 ++++++++++- vim/after/indent/awk.vim | 8 +------- vim/after/indent/css.vim | 8 +------- vim/after/indent/html.vim | 12 +++--------- vim/after/indent/javascript.vim | 8 +------- vim/after/indent/mail.vim | 8 +------- vim/after/indent/perl.vim | 8 +------- vim/after/indent/php.vim | 8 +------- vim/after/indent/sh.vim | 8 +------- vim/after/indent/vim.vim | 12 +++--------- vim/macros/indent/spaces.vim | 7 +++++++ vim/macros/indent/spaces/2.vim | 3 +++ vim/macros/indent/spaces/4.vim | 3 +++ 13 files changed, 36 insertions(+), 68 deletions(-) create mode 100644 vim/macros/indent/spaces.vim create mode 100644 vim/macros/indent/spaces/2.vim create mode 100644 vim/macros/indent/spaces/4.vim diff --git a/Makefile b/Makefile index bdd6b1d4..77199b14 100644 --- a/Makefile +++ b/Makefile @@ -546,6 +546,7 @@ install-vim: install-vim-after \ install-vim-filetype \ install-vim-ftplugin \ install-vim-indent \ + install-vim-macros \ install-vim-plugin \ install-vim-syntax @@ -558,7 +559,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-after-indent: install-vim-macros mkdir -p $(VIMDIR)/after/indent cp -p -- vim/after/indent/*.vim $(VIMDIR)/after/indent @@ -618,6 +619,14 @@ 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 ba6dfdeb..951c830a 100644 --- a/vim/after/indent/awk.vim +++ b/vim/after/indent/awk.vim @@ -1,8 +1,2 @@ " Use four spaces for indentation -setlocal expandtab -setlocal shiftwidth=4 -let b:undo_ftplugin .= '|setlocal expandtab< shiftwidth<' -if &l:softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_ftplugin .= '|setlocal softtabstop<' -endif +runtime macros/indent/spaces/4.vim diff --git a/vim/after/indent/css.vim b/vim/after/indent/css.vim index ba6dfdeb..951c830a 100644 --- a/vim/after/indent/css.vim +++ b/vim/after/indent/css.vim @@ -1,8 +1,2 @@ " Use four spaces for indentation -setlocal expandtab -setlocal shiftwidth=4 -let b:undo_ftplugin .= '|setlocal expandtab< shiftwidth<' -if &l:softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_ftplugin .= '|setlocal softtabstop<' -endif +runtime macros/indent/spaces/4.vim diff --git a/vim/after/indent/html.vim b/vim/after/indent/html.vim index 72c92d21..fb7f4127 100644 --- a/vim/after/indent/html.vim +++ b/vim/after/indent/html.vim @@ -1,15 +1,9 @@ +" Use four spaces for indentation +runtime macros/indent/spaces/4.vim + " Clear away the flag we set to indent after paragraphs unlet html_indent_inctags " Don't re-indent lines on right-angle-bracket or enter setlocal indentkeys-=<>>, let b:undo_ftplugin .= '|setlocal indentkeys<' - -" Use four spaces for indentation -setlocal expandtab -setlocal shiftwidth=4 -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/after/indent/javascript.vim b/vim/after/indent/javascript.vim index ba6dfdeb..951c830a 100644 --- a/vim/after/indent/javascript.vim +++ b/vim/after/indent/javascript.vim @@ -1,8 +1,2 @@ " Use four spaces for indentation -setlocal expandtab -setlocal shiftwidth=4 -let b:undo_ftplugin .= '|setlocal expandtab< shiftwidth<' -if &l:softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_ftplugin .= '|setlocal softtabstop<' -endif +runtime macros/indent/spaces/4.vim diff --git a/vim/after/indent/mail.vim b/vim/after/indent/mail.vim index ba6dfdeb..951c830a 100644 --- a/vim/after/indent/mail.vim +++ b/vim/after/indent/mail.vim @@ -1,8 +1,2 @@ " Use four spaces for indentation -setlocal expandtab -setlocal shiftwidth=4 -let b:undo_ftplugin .= '|setlocal expandtab< shiftwidth<' -if &l:softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_ftplugin .= '|setlocal softtabstop<' -endif +runtime macros/indent/spaces/4.vim diff --git a/vim/after/indent/perl.vim b/vim/after/indent/perl.vim index ba6dfdeb..951c830a 100644 --- a/vim/after/indent/perl.vim +++ b/vim/after/indent/perl.vim @@ -1,8 +1,2 @@ " Use four spaces for indentation -setlocal expandtab -setlocal shiftwidth=4 -let b:undo_ftplugin .= '|setlocal expandtab< shiftwidth<' -if &l:softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_ftplugin .= '|setlocal softtabstop<' -endif +runtime macros/indent/spaces/4.vim diff --git a/vim/after/indent/php.vim b/vim/after/indent/php.vim index ba6dfdeb..951c830a 100644 --- a/vim/after/indent/php.vim +++ b/vim/after/indent/php.vim @@ -1,8 +1,2 @@ " Use four spaces for indentation -setlocal expandtab -setlocal shiftwidth=4 -let b:undo_ftplugin .= '|setlocal expandtab< shiftwidth<' -if &l:softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_ftplugin .= '|setlocal softtabstop<' -endif +runtime macros/indent/spaces/4.vim diff --git a/vim/after/indent/sh.vim b/vim/after/indent/sh.vim index ba6dfdeb..951c830a 100644 --- a/vim/after/indent/sh.vim +++ b/vim/after/indent/sh.vim @@ -1,8 +1,2 @@ " Use four spaces for indentation -setlocal expandtab -setlocal shiftwidth=4 -let b:undo_ftplugin .= '|setlocal expandtab< shiftwidth<' -if &l:softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_ftplugin .= '|setlocal softtabstop<' -endif +runtime macros/indent/spaces/4.vim diff --git a/vim/after/indent/vim.vim b/vim/after/indent/vim.vim index 320e5d7d..59179225 100644 --- a/vim/after/indent/vim.vim +++ b/vim/after/indent/vim.vim @@ -1,15 +1,9 @@ +" Use two (not four!) spaces for indentation, per convention +runtime macros/indent/spaces/2.vim + " 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) setlocal indentkeys-=0#,0{,0},0),: if !exists('b:undo_indent') let b:undo_indent = 'setlocal indentkeys<' endif - -" Observe VimL conventions for two-space indents -setlocal expandtab -setlocal shiftwidth=2 -let b:undo_indent .= '|setlocal expandtab< shiftwidth<' -if &softtabstop != -1 - let &l:softtabstop = &l:shiftwidth - let b:undo_indent .= '|setlocal softtabstop<' -endif diff --git a/vim/macros/indent/spaces.vim b/vim/macros/indent/spaces.vim new file mode 100644 index 00000000..d4b36afe --- /dev/null +++ b/vim/macros/indent/spaces.vim @@ -0,0 +1,7 @@ +" 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 new file mode 100644 index 00000000..a0f847ae --- /dev/null +++ b/vim/macros/indent/spaces/2.vim @@ -0,0 +1,3 @@ +" 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 new file mode 100644 index 00000000..13ac5258 --- /dev/null +++ b/vim/macros/indent/spaces/4.vim @@ -0,0 +1,3 @@ +" Use four spaces for current buffer's indentation +setlocal shiftwidth=4 +runtime macros/indent/spaces.vim -- cgit v1.2.3