summaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2020-10-14 23:01:53 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2020-10-14 23:01:53 +0200
commitbbee246aaeb7fb689c7a2ae2bb911e34cabe7b00 (patch)
tree7fb14a8cb7d7fb1579e46f79ff7c43838dcfbadb /indent
parent3da600ac3070976142f81025b53dda44d99d44e4 (diff)
downloadvim-polyglot-bbee246aaeb7fb689c7a2ae2bb911e34cabe7b00.tar.gz
vim-polyglot-bbee246aaeb7fb689c7a2ae2bb911e34cabe7b00.zip
Add and fix tests from upstream vim
Diffstat (limited to 'indent')
-rw-r--r--indent/Dockerfile.vim27
-rw-r--r--indent/make.vim120
-rw-r--r--indent/xf86conf.vim41
3 files changed, 161 insertions, 27 deletions
diff --git a/indent/Dockerfile.vim b/indent/Dockerfile.vim
deleted file mode 100644
index 18db33d1..00000000
--- a/indent/Dockerfile.vim
+++ /dev/null
@@ -1,27 +0,0 @@
-if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'dockerfile') == -1
-
-if exists('b:did_indent') | finish | endif
-let b:did_indent = 1
-
-
-function! DockerfileIndent(line)
- let prev_line = getline(a:line - 1)
- if a:line > 1 && prev_line =~ '\\\s*$'
- let i = indent(a:line - 1)
- if i == 0
- let i += &l:shiftwidth
- if &l:expandtab && prev_line =~# '^RUN\s'
- " Overindent past RUN
- let i = 4 + &l:shiftwidth
- endif
- endif
- return i
- endif
-
- return -1
-endfunction
-
-
-set indentexpr=DockerfileIndent(v:lnum)
-
-endif
diff --git a/indent/make.vim b/indent/make.vim
new file mode 100644
index 00000000..07436042
--- /dev/null
+++ b/indent/make.vim
@@ -0,0 +1,120 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'make') == -1
+
+" Vim indent file
+" Language: Makefile
+" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
+" Latest Revision: 2007-05-07
+
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetMakeIndent()
+setlocal indentkeys=!^F,o,O,<:>,=else,=endif
+setlocal nosmartindent
+
+if exists("*GetMakeIndent")
+ finish
+endif
+
+let s:comment_rx = '^\s*#'
+let s:rule_rx = '^[^ \t#:][^#:]*:\{1,2}\%([^=:]\|$\)'
+let s:continued_rule_rx = '^[^#:]*:\{1,2}\%([^=:]\|$\)'
+let s:continuation_rx = '\\$'
+let s:assignment_rx = '^\s*\h\w*\s*[+?]\==\s*\zs.*\\$'
+let s:folded_assignment_rx = '^\s*\h\w*\s*[+?]\=='
+" TODO: This needs to be a lot more restrictive in what it matches.
+let s:just_inserted_rule_rx = '^\s*[^#:]\+:\{1,2}$'
+let s:conditional_directive_rx = '^ *\%(ifn\=\%(eq\|def\)\|else\)\>'
+let s:end_conditional_directive_rx = '^\s*\%(else\|endif\)\>'
+
+function s:remove_continuation(line)
+ return substitute(a:line, s:continuation_rx, "", "")
+endfunction
+
+function GetMakeIndent()
+ " TODO: Should this perhaps be v:lnum -1?
+" let prev_lnum = prevnonblank(v:lnum - 1)
+ let prev_lnum = v:lnum - 1
+ if prev_lnum == 0
+ return 0
+ endif
+ let prev_line = getline(prev_lnum)
+
+ let prev_prev_lnum = prev_lnum - 1
+ let prev_prev_line = prev_prev_lnum != 0 ? getline(prev_prev_lnum) : ""
+
+ " TODO: Deal with comments. In comments, continuations aren't interesting.
+ if prev_line =~ s:continuation_rx
+ if prev_prev_line =~ s:continuation_rx
+ return indent(prev_lnum)
+ elseif prev_line =~ s:rule_rx
+ return shiftwidth()
+ elseif prev_line =~ s:assignment_rx
+ call cursor(prev_lnum, 1)
+ if search(s:assignment_rx, 'W') != 0
+ return virtcol('.') - 1
+ else
+ " TODO: ?
+ return shiftwidth()
+ endif
+ else
+ " TODO: OK, this might be a continued shell command, so perhaps indent
+ " properly here? Leave this out for now, but in the next release this
+ " should be using indent/sh.vim somehow.
+ "if prev_line =~ '^\t' " s:rule_command_rx
+ " if prev_line =~ '^\s\+[@-]\%(if\)\>'
+ " return indent(prev_lnum) + 2
+ " endif
+ "endif
+ return indent(prev_lnum) + shiftwidth()
+ endif
+ elseif prev_prev_line =~ s:continuation_rx
+ let folded_line = s:remove_continuation(prev_prev_line) . ' ' . s:remove_continuation(prev_line)
+ let lnum = prev_prev_lnum - 1
+ let line = getline(lnum)
+ while line =~ s:continuation_rx
+ let folded_line = s:remove_continuation(line) . ' ' . folded_line
+ let lnum -= 1
+ let line = getline(lnum)
+ endwhile
+ let folded_lnum = lnum + 1
+ if folded_line =~ s:rule_rx
+ if getline(v:lnum) =~ s:rule_rx
+ return 0
+ else
+ return &ts
+ endif
+ else
+" elseif folded_line =~ s:folded_assignment_rx
+ if getline(v:lnum) =~ s:rule_rx
+ return 0
+ else
+ return indent(folded_lnum)
+ endif
+" else
+" " TODO: ?
+" return indent(prev_lnum)
+ endif
+ elseif prev_line =~ s:rule_rx
+ if getline(v:lnum) =~ s:rule_rx
+ return 0
+ else
+ return &ts
+ endif
+ elseif prev_line =~ s:conditional_directive_rx
+ return shiftwidth()
+ else
+ let line = getline(v:lnum)
+ if line =~ s:just_inserted_rule_rx
+ return 0
+ elseif line =~ s:end_conditional_directive_rx
+ return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) - shiftwidth()
+ else
+ return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1)
+ endif
+ endif
+endfunction
+
+endif
diff --git a/indent/xf86conf.vim b/indent/xf86conf.vim
new file mode 100644
index 00000000..261c4416
--- /dev/null
+++ b/indent/xf86conf.vim
@@ -0,0 +1,41 @@
+if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'xf86conf') == -1
+
+" Vim indent file
+" Language: XFree86 Configuration File
+" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
+" Latest Revision: 2006-12-20
+
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetXF86ConfIndent()
+setlocal indentkeys=!^F,o,O,=End
+setlocal nosmartindent
+
+if exists("*GetXF86ConfIndent")
+ finish
+endif
+
+function GetXF86ConfIndent()
+ let lnum = prevnonblank(v:lnum - 1)
+
+ if lnum == 0
+ return 0
+ endif
+
+ let ind = indent(lnum)
+
+ if getline(lnum) =~? '^\s*\(Sub\)\=Section\>'
+ let ind = ind + shiftwidth()
+ endif
+
+ if getline(v:lnum) =~? '^\s*End\(Sub\)\=Section\>'
+ let ind = ind - shiftwidth()
+ endif
+
+ return ind
+endfunction
+
+endif