aboutsummaryrefslogtreecommitdiff
path: root/vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-12-18 17:31:08 +1300
committerTom Ryder <tom@sanctum.geek.nz>2019-12-18 17:31:08 +1300
commit5536bbccd0917e554c283b73b420c2905df28efe (patch)
tree0a8d2814c50ec7a68505c175d3fa93cc674fd1a0 /vim
parentFix indentation of a Makefile line (diff)
downloaddotfiles-5536bbccd0917e554c283b73b420c2905df28efe.tar.gz
dotfiles-5536bbccd0917e554c283b73b420c2905df28efe.zip
Refactor indent macros into autoload function
Much nicer.
Diffstat (limited to 'vim')
-rw-r--r--vim/after/indent/awk.vim2
-rw-r--r--vim/after/indent/css.vim2
-rw-r--r--vim/after/indent/html.vim2
-rw-r--r--vim/after/indent/javascript.vim2
-rw-r--r--vim/after/indent/mail.vim2
-rw-r--r--vim/after/indent/perl.vim2
-rw-r--r--vim/after/indent/php.vim2
-rw-r--r--vim/after/indent/sh.vim2
-rw-r--r--vim/after/indent/vim.vim2
-rw-r--r--vim/autoload/indent.vim32
-rw-r--r--vim/macros/indent/spaces.vim7
-rw-r--r--vim/macros/indent/spaces/2.vim3
-rw-r--r--vim/macros/indent/spaces/4.vim3
13 files changed, 41 insertions, 22 deletions
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