mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-12 13:33:49 -05:00
Update
This commit is contained in:
@@ -13,7 +13,7 @@ let b:did_indent = 1
|
||||
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetBladeIndent()
|
||||
setlocal indentkeys=o,O,*<Return>,<>>,!^F,=@else,=@end,=@empty
|
||||
setlocal indentkeys=o,O,*<Return>,<>>,!^F,=@else,=@end,=@empty,=@show
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetBladeIndent")
|
||||
@@ -30,17 +30,26 @@ function! GetBladeIndent()
|
||||
let cline = substitute(substitute(getline(v:lnum), '\s\+$', '', ''), '^\s\+', '', '')
|
||||
let indent = indent(lnum)
|
||||
let cindent = indent(v:lnum)
|
||||
if cline =~# '@\%(else\|elseif\|empty\|end\)'
|
||||
let indent = cindent < indent ? cindent : indent - &sw
|
||||
elseif HtmlIndent() > -1
|
||||
let indent = HtmlIndent()
|
||||
if cline =~# '@\%(else\|elseif\|empty\|end\|show\)'
|
||||
let indent = indent - &sw
|
||||
else
|
||||
if exists("*GetBladeIndentCustom")
|
||||
let hindent = GetBladeIndentCustom()
|
||||
else
|
||||
let hindent = HtmlIndent()
|
||||
endif
|
||||
if hindent > -1
|
||||
let indent = hindent
|
||||
endif
|
||||
endif
|
||||
let increase = indent + &sw
|
||||
if indent = indent(lnum)
|
||||
let indent = cindent <= indent ? -1 : increase
|
||||
endif
|
||||
|
||||
if line =~# '@\%(if\|elseif\|else\|unless\|foreach\|forelse\|for\|while\)\%(.*\s*@end\)\@!'
|
||||
if line =~# '@\%(section\)\%(.*\s*@end\)\@!' && line !~# '@\%(section\)\s*([^,]*)'
|
||||
return indent
|
||||
elseif line =~# '@\%(if\|elseif\|else\|unless\|foreach\|forelse\|for\|while\|empty\|push\|section\|can\)\%(.*\s*@end\)\@!'
|
||||
return increase
|
||||
else
|
||||
return indent
|
||||
|
||||
@@ -29,6 +29,7 @@ function! GetCucumberIndent()
|
||||
let line = getline(prevnonblank(v:lnum-1))
|
||||
let cline = getline(v:lnum)
|
||||
let nline = getline(nextnonblank(v:lnum+1))
|
||||
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||
let syn = s:syn(prevnonblank(v:lnum-1))
|
||||
let csyn = s:syn(v:lnum)
|
||||
let nsyn = s:syn(nextnonblank(v:lnum+1))
|
||||
@@ -37,38 +38,38 @@ function! GetCucumberIndent()
|
||||
return 0
|
||||
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
|
||||
" examples heading
|
||||
return 2 * &sw
|
||||
return 2 * sw
|
||||
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
||||
" background, scenario or outline heading
|
||||
return &sw
|
||||
return sw
|
||||
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
|
||||
" line after feature heading
|
||||
return &sw
|
||||
return sw
|
||||
elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
|
||||
" line after examples heading
|
||||
return 3 * &sw
|
||||
return 3 * sw
|
||||
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
|
||||
" line after background, scenario or outline heading
|
||||
return 2 * &sw
|
||||
return 2 * sw
|
||||
elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
|
||||
" tag or comment before a feature heading
|
||||
return 0
|
||||
elseif cline =~# '^\s*@'
|
||||
" other tags
|
||||
return &sw
|
||||
return sw
|
||||
elseif cline =~# '^\s*[#|]' && line =~# '^\s*|'
|
||||
" mid-table
|
||||
" preserve indent
|
||||
return indent(prevnonblank(v:lnum-1))
|
||||
elseif cline =~# '^\s*|' && line =~# '^\s*[^|]'
|
||||
" first line of a table, relative indent
|
||||
return indent(prevnonblank(v:lnum-1)) + &sw
|
||||
return indent(prevnonblank(v:lnum-1)) + sw
|
||||
elseif cline =~# '^\s*[^|]' && line =~# '^\s*|'
|
||||
" line after a table, relative unindent
|
||||
return indent(prevnonblank(v:lnum-1)) - &sw
|
||||
return indent(prevnonblank(v:lnum-1)) - sw
|
||||
elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):')
|
||||
" comments on scenarios
|
||||
return &sw
|
||||
return sw
|
||||
endif
|
||||
return indent(prevnonblank(v:lnum-1))
|
||||
endfunction
|
||||
|
||||
@@ -17,16 +17,18 @@ endif
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let s:no_colon_before = ':\@<!'
|
||||
let s:no_colon_after = ':\@!'
|
||||
let s:symbols_end = '\]\|}'
|
||||
let s:arrow = '^.*->$'
|
||||
let s:pipeline = '^\s*|>.*$'
|
||||
let s:skip_syntax = '\%(Comment\|String\)$'
|
||||
let s:block_skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '".s:skip_syntax."'"
|
||||
let s:block_start = 'do\|fn'
|
||||
let s:block_middle = 'else\|match\|elsif\|catch\|after\|rescue'
|
||||
let s:block_end = 'end'
|
||||
let s:no_colon_before = ':\@<!'
|
||||
let s:no_colon_after = ':\@!'
|
||||
let s:symbols_end = '\]\|}\|)'
|
||||
let s:symbols_start = '\[\|{\|('
|
||||
let s:arrow = '^.*->$'
|
||||
let s:skip_syntax = '\%(Comment\|String\)$'
|
||||
let s:block_skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '".s:skip_syntax."'"
|
||||
let s:block_start = '\<\%(do\|fn\)\>'
|
||||
let s:block_middle = 'else\|match\|elsif\|catch\|after\|rescue'
|
||||
let s:block_end = 'end'
|
||||
let s:starts_with_pipeline = '^\s*|>.*$'
|
||||
let s:ending_with_assignment = '=\s*$'
|
||||
|
||||
let s:indent_keywords = '\<'.s:no_colon_before.'\%('.s:block_start.'\|'.s:block_middle.'\)$'.'\|'.s:arrow
|
||||
let s:deindent_keywords = '^\s*\<\%('.s:block_end.'\|'.s:block_middle.'\)\>'.'\|'.s:arrow
|
||||
@@ -35,15 +37,21 @@ let s:pair_start = '\<\%('.s:no_colon_before.s:block_start.'\)\>'.s:no_colon_af
|
||||
let s:pair_middle = '\<\%('.s:block_middle.'\)\>'.s:no_colon_after.'\zs'
|
||||
let s:pair_end = '\<\%('.s:no_colon_before.s:block_end.'\)\>\zs'
|
||||
|
||||
let s:inside_block = 0
|
||||
|
||||
function! GetElixirIndent()
|
||||
let lnum = prevnonblank(v:lnum - 1)
|
||||
let ind = indent(lnum)
|
||||
|
||||
" At the start of the file use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
let opened_symbol = 0
|
||||
let current_line = getline(v:lnum)
|
||||
let last_line = getline(lnum)
|
||||
let ind = indent(lnum)
|
||||
|
||||
" TODO: Remove these 2 lines
|
||||
" I don't know why, but for the test on spec/indent/lists_spec.rb:24.
|
||||
" Vim is making some mess on parsing the syntax of 'end', it is being
|
||||
@@ -53,15 +61,22 @@ function! GetElixirIndent()
|
||||
syntax sync fromstart
|
||||
|
||||
if synIDattr(synID(v:lnum, 1, 1), "name") !~ s:skip_syntax
|
||||
let current_line = getline(v:lnum)
|
||||
let last_line = getline(lnum)
|
||||
|
||||
let splited_line = split(last_line, '\zs')
|
||||
let opened_symbol = 0
|
||||
let opened_symbol += count(splited_line, '[') - count(splited_line, ']')
|
||||
let opened_symbol += count(splited_line, '{') - count(splited_line, '}')
|
||||
if last_line !~ s:arrow
|
||||
let split_line = split(last_line, '\zs')
|
||||
let opened_symbol += count(split_line, '(') - count(split_line, ')')
|
||||
let opened_symbol += count(split_line, '[') - count(split_line, ']')
|
||||
let opened_symbol += count(split_line, '{') - count(split_line, '}')
|
||||
end
|
||||
|
||||
let ind += (opened_symbol * &sw)
|
||||
" if start symbol is followed by a character, indent based on the
|
||||
" whitespace after the symbol, otherwise use the default shiftwidth
|
||||
if last_line =~ '\('.s:symbols_start.'\).'
|
||||
let opened_prefix = matchlist(last_line, '\('.s:symbols_start.'\)\s*')[0]
|
||||
let ind += (opened_symbol * strlen(opened_prefix))
|
||||
else
|
||||
let ind += (opened_symbol * &sw)
|
||||
endif
|
||||
|
||||
if last_line =~ '^\s*\('.s:symbols_end.'\)' || last_line =~ s:indent_keywords
|
||||
let ind += &sw
|
||||
@@ -71,27 +86,35 @@ function! GetElixirIndent()
|
||||
let ind -= &sw
|
||||
endif
|
||||
|
||||
if last_line =~ s:ending_with_assignment && opened_symbol == 0
|
||||
let b:old_ind = indent(lnum)
|
||||
let ind += &sw
|
||||
end
|
||||
|
||||
" if line starts with pipeline
|
||||
" and last line contains pipeline(s)
|
||||
" and last line ends with a pipeline,
|
||||
" align them
|
||||
if last_line =~ '|>.*$' &&
|
||||
\ current_line =~ s:pipeline
|
||||
\ current_line =~ s:starts_with_pipeline
|
||||
let ind = float2nr(match(last_line, '|>') / &sw) * &sw
|
||||
|
||||
" if line starts with pipeline
|
||||
" and last line is an attribution
|
||||
" indents pipeline in same level as attribution
|
||||
elseif current_line =~ s:pipeline &&
|
||||
elseif current_line =~ s:starts_with_pipeline &&
|
||||
\ last_line =~ '^[^=]\+=.\+$'
|
||||
let b:old_ind = ind
|
||||
|
||||
if !exists('b:old_ind') || b:old_ind == 0
|
||||
let b:old_ind = indent(lnum)
|
||||
end
|
||||
let ind = float2nr(matchend(last_line, '=\s*[^ ]') / &sw) * &sw
|
||||
endif
|
||||
|
||||
" if last line starts with pipeline
|
||||
" and current line doesn't start with pipeline
|
||||
" returns the indentation before the pipeline
|
||||
if last_line =~ s:pipeline &&
|
||||
\ current_line !~ s:pipeline
|
||||
if last_line =~ s:starts_with_pipeline &&
|
||||
\ current_line !~ s:starts_with_pipeline
|
||||
let ind = b:old_ind
|
||||
endif
|
||||
|
||||
|
||||
@@ -22,17 +22,18 @@ if exists("*GetGitconfigIndent")
|
||||
endif
|
||||
|
||||
function! GetGitconfigIndent()
|
||||
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||
let line = getline(prevnonblank(v:lnum-1))
|
||||
let cline = getline(v:lnum)
|
||||
if line =~ '\\\@<!\%(\\\\\)*\\$'
|
||||
" odd number of slashes, in a line continuation
|
||||
return 2 * &sw
|
||||
return 2 * sw
|
||||
elseif cline =~ '^\s*\['
|
||||
return 0
|
||||
elseif cline =~ '^\s*\a'
|
||||
return &sw
|
||||
return sw
|
||||
elseif cline == '' && line =~ '^\['
|
||||
return &sw
|
||||
return sw
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
|
||||
@@ -6,4 +6,43 @@ endif
|
||||
|
||||
runtime! indent/html.vim
|
||||
|
||||
" Indent Golang HTML templates
|
||||
setlocal indentexpr=GetGoHTMLTmplIndent(v:lnum)
|
||||
setlocal indentkeys+==else,=end
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetGoHTMLTmplIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
function! GetGoHTMLTmplIndent(lnum)
|
||||
" Get HTML indent
|
||||
if exists('*HtmlIndent')
|
||||
let ind = HtmlIndent()
|
||||
else
|
||||
let ind = HtmlIndentGet(a:lnum)
|
||||
endif
|
||||
|
||||
" The value of a single shift-width
|
||||
if exists('*shiftwidth')
|
||||
let sw = shiftwidth()
|
||||
else
|
||||
let sw = &sw
|
||||
endif
|
||||
|
||||
" If need to indent based on last line
|
||||
let last_line = getline(a:lnum-1)
|
||||
if last_line =~ '^\s*{{\s*\%(if\|else\|range\|with\|define\|block\).*}}'
|
||||
let ind += sw
|
||||
endif
|
||||
|
||||
" End of FuncMap block
|
||||
let current_line = getline(a:lnum)
|
||||
if current_line =~ '^\s*{{\s*\%(else\|end\).*}}'
|
||||
let ind -= sw
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
endif
|
||||
|
||||
@@ -39,10 +39,11 @@ function! GetHamlIndent()
|
||||
let line = substitute(line,'^\s\+','','')
|
||||
let indent = indent(lnum)
|
||||
let cindent = indent(v:lnum)
|
||||
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||
if cline =~# '\v^-\s*%(elsif|else|when)>'
|
||||
let indent = cindent < indent ? cindent : indent - &sw
|
||||
let indent = cindent < indent ? cindent : indent - sw
|
||||
endif
|
||||
let increase = indent + &sw
|
||||
let increase = indent + sw
|
||||
if indent == indent(lnum)
|
||||
let indent = cindent <= indent ? -1 : increase
|
||||
endif
|
||||
|
||||
@@ -2,8 +2,6 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'haskell') == -1
|
||||
|
||||
" indentation for haskell
|
||||
"
|
||||
" Based on idris indentation
|
||||
"
|
||||
" author: raichoo (raichoo@googlemail.com)
|
||||
"
|
||||
" Modify g:haskell_indent_if and g:haskell_indent_case to
|
||||
@@ -18,7 +16,7 @@ endif
|
||||
let b:did_indent = 1
|
||||
|
||||
if !exists('g:haskell_indent_if')
|
||||
" if bool
|
||||
" if x
|
||||
" >>>then ...
|
||||
" >>>else ...
|
||||
let g:haskell_indent_if = 3
|
||||
@@ -55,96 +53,130 @@ if !exists('g:haskell_indent_in')
|
||||
let g:haskell_indent_in = 1
|
||||
endif
|
||||
|
||||
if !exists('g:haskell_indent_guard')
|
||||
" f x y
|
||||
" >>|
|
||||
let g:haskell_indent_guard = 2
|
||||
endif
|
||||
|
||||
setlocal indentexpr=GetHaskellIndent()
|
||||
setlocal indentkeys=!^F,o,O,0\|,0=where,0=in,0=let,0=deriving,0=->,0=\=>,<CR>,0}
|
||||
setlocal indentkeys=0{,0},0(,0),0[,0],!^F,o,O,0\=,0=where,0=let,0=deriving,0\,,<space>
|
||||
|
||||
function! s:isInBlock(hlstack)
|
||||
return index(a:hlstack, 'haskellParens') > -1 || index(a:hlstack, 'haskellBrackets') > -1 || index(a:hlstack, 'haskellBlock') > -1
|
||||
endfunction
|
||||
|
||||
function! s:getNesting(hlstack)
|
||||
return filter(a:hlstack, 'v:val == "haskellBlock" || v:val == "haskellBrackets" || v:val == "haskellParens"')
|
||||
endfunction
|
||||
|
||||
function! s:getHLStack()
|
||||
return map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
|
||||
endfunction
|
||||
|
||||
" indent matching character
|
||||
function! s:indentMatching(char)
|
||||
normal! 0
|
||||
call search(a:char, 'cW')
|
||||
normal! %
|
||||
return col('.') - 1
|
||||
endfunction
|
||||
|
||||
" backtrack to find guard clause
|
||||
function! s:indentGuard(pos, prevline)
|
||||
let l:l = a:prevline
|
||||
let l:c = 1
|
||||
|
||||
while v:lnum != l:c
|
||||
" empty line, stop looking
|
||||
if l:l =~ '^$'
|
||||
return a:pos
|
||||
" guard found
|
||||
elseif l:l =~ '^\s*|\s\+'
|
||||
return match(l:l, '|')
|
||||
" found less deeper indentation (not starting with `,` or `=`)
|
||||
" stop looking
|
||||
else
|
||||
let l:m = match(l:l, '\S')
|
||||
if l:l !~ '^\s*[=,]' && l:m <= a:pos
|
||||
return l:m + g:haskell_indent_guard
|
||||
endif
|
||||
endif
|
||||
let l:c += 1
|
||||
let l:l = getline(v:lnum - l:c)
|
||||
endwhile
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
function! GetHaskellIndent()
|
||||
let l:prevline = getline(v:lnum - 1)
|
||||
let l:hlstack = s:getHLStack()
|
||||
|
||||
" do not indent in strings and quasiquotes
|
||||
if index(l:hlstack, 'haskellString') > -1 || index(l:hlstack, 'haskellQuasiQuote') > -1
|
||||
return -1
|
||||
endif
|
||||
|
||||
" blockcomment handling
|
||||
if index(l:hlstack, 'haskellBlockComment') > -1
|
||||
for l:c in range(v:lnum - 1, 0, -1)
|
||||
let l:line = getline(l:c)
|
||||
if l:line =~ '{-'
|
||||
return 1 + match(l:line, '{-')
|
||||
endif
|
||||
endfor
|
||||
return 1
|
||||
endif
|
||||
|
||||
let l:prevline = getline(v:lnum - 1)
|
||||
let l:line = getline(v:lnum)
|
||||
|
||||
" reset
|
||||
if l:prevline =~ '^\s*$' && l:line !~ '^\s*\S'
|
||||
return 0
|
||||
endif
|
||||
|
||||
" comment indentation
|
||||
if l:prevline =~ '^\s*--'
|
||||
return match(l:prevline, '\S')
|
||||
endif
|
||||
|
||||
if synIDattr(synID(line("."), col("."), 1), "name") == 'haskellBlockComment'
|
||||
for l:c in range(v:lnum - 1, 0, -1)
|
||||
let l:bline = getline(l:c)
|
||||
if l:bline =~ '{-'
|
||||
return 1 + match(l:bline, '{-')
|
||||
endfor
|
||||
return 1
|
||||
endif
|
||||
|
||||
if l:prevline =~ '^\s*$'
|
||||
return 0
|
||||
endif
|
||||
|
||||
let l:line = getline(v:lnum)
|
||||
|
||||
if l:line =~ '\C^\s*\<where\>'
|
||||
let l:s = match(l:prevline, '\S')
|
||||
return l:s + &shiftwidth
|
||||
endif
|
||||
|
||||
if l:line =~ '\C^\s*\<deriving\>'
|
||||
let l:s = match(l:prevline, '\C\<\(newtype\|data\)\>')
|
||||
if l:s >= 0
|
||||
return l:s + &shiftwidth
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:line =~ '\C^\s*\<let\>'
|
||||
let l:s = match(l:prevline, '\C\<let\>')
|
||||
if l:s != 0
|
||||
return l:s
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:line =~ '\C^\s*\<in\>'
|
||||
let l:s = match(l:prevline, '\C\<let\>')
|
||||
if l:s >= 0
|
||||
return l:s + g:haskell_indent_in
|
||||
elseif match(l:prevline, '=') > 0
|
||||
let l:s = match(l:prevline, '\S')
|
||||
return l:s - (4 - g:haskell_indent_in)
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:line =~ '^\s*|'
|
||||
if match(l:prevline, '^\s*data') < 0
|
||||
if match(l:prevline, '^\s*|\s') >= 0
|
||||
return match(l:prevline, '|')
|
||||
else
|
||||
return &shiftwidth
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:line =~ '^\s*[=-]>'
|
||||
let l:s = match(l:prevline, ' :: ')
|
||||
if l:s >= 0
|
||||
return l:s + 1
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:prevline =~ '\s\+[!#$%&*+./<>?@\\^|~-]\+\s*$'
|
||||
let l:s = match(l:prevline, '\S')
|
||||
if l:s > 0
|
||||
return l:s + &shiftwidth
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:prevline =~ '[{([][^})\]]\+$'
|
||||
return match(l:prevline, '[{([]')
|
||||
" operator at end of previous line
|
||||
if l:prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" let foo =
|
||||
" >>>>>>bar
|
||||
if l:prevline =~ '\C\<let\>\s\+[^=]\+=\s*$'
|
||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let + &shiftwidth
|
||||
endif
|
||||
|
||||
if l:prevline =~ '\C\<let\>\s\+.\+\(\<in\>\)\?\s*$'
|
||||
" let x = 1 in
|
||||
" >>>>x
|
||||
if l:prevline =~ '\C\<let\>\s\+.\+\<in\>\?$' && l:line !~ '\C^\s*\<in\>'
|
||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let
|
||||
endif
|
||||
|
||||
" let x = 1
|
||||
" let y = 2
|
||||
"
|
||||
" let x = 1
|
||||
" >in x
|
||||
"
|
||||
" let x = 1
|
||||
" >>>>y = 2
|
||||
if l:prevline =~ '\C\<let\>\s\+.\+$'
|
||||
if l:line =~ '\C^\s*\<let\>'
|
||||
return match(l:prevline, '\C\<let\>')
|
||||
elseif l:line =~ '\C^\s*\<in\>'
|
||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_in
|
||||
else
|
||||
return match(l:prevline, '\C\<let\>') + g:haskell_indent_let
|
||||
endif
|
||||
endif
|
||||
|
||||
" if handling
|
||||
if l:prevline !~ '\C\<else\>'
|
||||
let l:s = match(l:prevline, '\C\<if\>.*\&.*\zs\<then\>')
|
||||
if l:s > 0
|
||||
@@ -157,30 +189,252 @@ function! GetHaskellIndent()
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:prevline =~ '\C\(\<where\>\|\<do\>\|=\|[{([]\)\s*$'
|
||||
" where
|
||||
" >>foo
|
||||
"
|
||||
" do
|
||||
" >>foo
|
||||
"
|
||||
" foo =
|
||||
" >>bar
|
||||
if l:prevline =~ '\C\(\<where\>\|\<do\>\|=\)\s*$'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
"" where foo
|
||||
"" >>>>>>bar
|
||||
if l:prevline =~ '\C\<where\>\s\+\S\+.*$'
|
||||
return match(l:prevline, '\C\<where\>') + g:haskell_indent_where
|
||||
if l:line =~ '^\s*[=-]>\s' && l:prevline =~ ' :: '
|
||||
return match(l:prevline, ':: ')
|
||||
else
|
||||
return match(l:prevline, '\C\<where\>') + g:haskell_indent_where
|
||||
endif
|
||||
endif
|
||||
|
||||
" do foo
|
||||
" >>>bar
|
||||
if l:prevline =~ '\C\<do\>\s\+\S\+.*$'
|
||||
return match(l:prevline, '\C\<do\>') + g:haskell_indent_do
|
||||
endif
|
||||
|
||||
if l:prevline =~ '\C^\s*\<data\>\s\+[^=]\+\s\+=\s\+\S\+.*$'
|
||||
if l:line =~ '^\s*|'
|
||||
return match(l:prevline, '=')
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:prevline =~ '\C\<case\>\s\+.\+\<of\>\s*$'
|
||||
" case foo of
|
||||
" >>bar -> quux
|
||||
if l:prevline =~ '\C\<case\>.\+\<of\>\s*$'
|
||||
return match(l:prevline, '\C\<case\>') + g:haskell_indent_case
|
||||
endif
|
||||
|
||||
if l:prevline =~ '\C^\s*\<\data\>\s\+\S\+\s*$'
|
||||
return match(l:prevline, '\C\<data\>') + &shiftwidth
|
||||
" newtype Foo = Foo
|
||||
" >>deriving
|
||||
if l:prevline =~ '\C\s*\<\(newtype\|data\)\>[^{]\+' && l:line =~ '\C^\s*\<deriving\>'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" foo :: Int
|
||||
" >>>>-> Int
|
||||
"
|
||||
" foo
|
||||
" :: Int
|
||||
" foo
|
||||
if l:prevline =~ '\s::\s'
|
||||
if l:line =~ '^\s*[-=]>'
|
||||
return match(l:prevline, '::\s')
|
||||
elseif match(l:prevline, '^\s\+::') > -1
|
||||
return match(l:prevline, '::\s') - &shiftwidth
|
||||
endif
|
||||
endif
|
||||
|
||||
" foo :: Int
|
||||
" -> Int
|
||||
" foo x
|
||||
"
|
||||
" foo
|
||||
" :: Int
|
||||
" -> Int
|
||||
" foo x
|
||||
if l:prevline =~ '^\s*[-=]>' && l:line !~ '^\s*[-=]>'
|
||||
if s:isInBlock(l:hlstack)
|
||||
return match(l:prevline, '[^\s-=>]')
|
||||
else
|
||||
let l:m = matchstr(l:line, '^\s*\zs\<\S\+\>\ze')
|
||||
let l:l = l:prevline
|
||||
let l:c = 1
|
||||
|
||||
while v:lnum != l:c
|
||||
" fun decl
|
||||
let l:s = match(l:l, l:m)
|
||||
if l:s >= 0
|
||||
if match(l:l, '\C^\s*\<default\>') > -1
|
||||
return l:s - 8
|
||||
else
|
||||
return l:s
|
||||
endif
|
||||
" empty line, stop looking
|
||||
elseif l:l =~ '^$'
|
||||
return 0
|
||||
endif
|
||||
let l:c += 1
|
||||
let l:l = getline(v:lnum - l:c)
|
||||
endwhile
|
||||
|
||||
return 0
|
||||
endif
|
||||
endif
|
||||
|
||||
" | otherwise = ...
|
||||
" foo
|
||||
"
|
||||
" | foo
|
||||
" >>, bar
|
||||
"
|
||||
" | foo
|
||||
" >>= bar
|
||||
"
|
||||
" | Foo
|
||||
" >>deriving
|
||||
if l:prevline =~ '^\s\+|' && !s:isInBlock(l:hlstack)
|
||||
if l:line =~ '\s*[,=]'
|
||||
return match(l:prevline, '|')
|
||||
elseif l:line =~ '\C^\s*\<deriving\>'
|
||||
return match(l:prevline, '|')
|
||||
elseif l:line !~ '^\s*|'
|
||||
return match(l:prevline, '|') - g:haskell_indent_guard
|
||||
endif
|
||||
endif
|
||||
|
||||
" foo :: ( Monad m
|
||||
" , Functor f
|
||||
" )
|
||||
">>>>>=> Int
|
||||
if l:prevline =~ '^\s*)' && l:line =~ '^\s*=>'
|
||||
let l:s = match(l:prevline, ')')
|
||||
return l:s - (&shiftwidth + 1)
|
||||
endif
|
||||
|
||||
" module Foo
|
||||
" >>( bar
|
||||
if l:prevline =~ '\C^\<module\>'
|
||||
return &shiftwidth
|
||||
endif
|
||||
|
||||
" foo
|
||||
" >>{
|
||||
if l:line =~ '^\s*{' && l:prevline !~ '^{'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" in foo
|
||||
" where bar
|
||||
if l:line =~ '\C^\s*\<where\>'
|
||||
if match(l:prevline, '\C^\s\+in\s\+') == 0
|
||||
return match(l:prevline, 'in') - g:haskell_indent_in
|
||||
endif
|
||||
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" let x = 1
|
||||
" y = 2
|
||||
" >in x + 1
|
||||
if l:line =~ '\C^\s*\<in\>'
|
||||
return match(l:prevline, '\S') - (4 - g:haskell_indent_in)
|
||||
endif
|
||||
|
||||
" data Foo
|
||||
" >>= Bar
|
||||
"
|
||||
" |
|
||||
" ...
|
||||
" >>=
|
||||
"
|
||||
" foo
|
||||
" >>=
|
||||
if l:line =~ '^\s*='
|
||||
if l:prevline =~ '\C^\<data\>\s\+[^=]\+\s*$'
|
||||
return match(l:prevline, '\C\<data\>') + &shiftwidth
|
||||
else
|
||||
let l:s = s:indentGuard(match(l:line, '='), l:prevline)
|
||||
if l:s > 0
|
||||
return l:s
|
||||
else
|
||||
return &shiftwidth
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" { foo :: Int
|
||||
" >>,
|
||||
"
|
||||
" |
|
||||
" ...
|
||||
" >>,
|
||||
if l:line =~ '^\s*,'
|
||||
if s:isInBlock(l:hlstack)
|
||||
normal! 0
|
||||
call search(',', 'cW')
|
||||
let l:n = s:getNesting(s:getHLStack())
|
||||
call search('[(\[{]', 'bW')
|
||||
|
||||
while l:n != s:getNesting(s:getHLStack())
|
||||
call search('[(\[{]', 'bW')
|
||||
endwhile
|
||||
|
||||
return col('.') - 1
|
||||
else
|
||||
let l:s = s:indentGuard(match(l:line, ','), l:prevline)
|
||||
if l:s > -1
|
||||
return l:s
|
||||
end
|
||||
endif
|
||||
endif
|
||||
|
||||
" |
|
||||
" ...
|
||||
" >>|
|
||||
"
|
||||
" data Foo = Bar
|
||||
" >>>>>>>>>|
|
||||
if l:line =~ '^\s*|\s'
|
||||
if l:prevline =~ '\C^\s*\<data\>.\+=.\+$'
|
||||
return match(l:prevline, '=')
|
||||
else
|
||||
let l:s = s:indentGuard(match(l:line, '|'), l:prevline)
|
||||
if l:s > -1
|
||||
return l:s
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" foo
|
||||
" >>:: Int
|
||||
if l:line =~ '^\s*::\s'
|
||||
return match(l:prevline, '\S') + &shiftwidth
|
||||
endif
|
||||
|
||||
" indent closing brace, paren or bracket
|
||||
if l:line =~ '^\s*}'
|
||||
return s:indentMatching('}')
|
||||
endif
|
||||
|
||||
if l:line =~ '^\s*)'
|
||||
return s:indentMatching(')')
|
||||
endif
|
||||
|
||||
if l:line =~ '^\s*]'
|
||||
return s:indentMatching(']')
|
||||
endif
|
||||
"
|
||||
" indent import
|
||||
if l:line =~ '\C^\s*import'
|
||||
return 0
|
||||
endif
|
||||
|
||||
" do not reindent indented lines
|
||||
if match(l:prevline, '\S') < match(l:line, '\S')
|
||||
return -1
|
||||
endif
|
||||
|
||||
if l:line !~ '^\s*[=-]>\s' && l:line =~ '^\s*[!#$%&*+./<>?@\\^|~-]\+'
|
||||
return -1
|
||||
endif
|
||||
|
||||
return match(l:prevline, '\S')
|
||||
|
||||
@@ -177,7 +177,24 @@ call add(s:tags, 'tr')
|
||||
call add(s:tags, 'th')
|
||||
call add(s:tags, 'td')
|
||||
|
||||
let s:no_tags = []
|
||||
|
||||
call add(s:no_tags, 'base')
|
||||
call add(s:no_tags, 'link')
|
||||
call add(s:no_tags, 'meta')
|
||||
call add(s:no_tags, 'hr')
|
||||
call add(s:no_tags, 'br')
|
||||
call add(s:no_tags, 'wbr')
|
||||
call add(s:no_tags, 'img')
|
||||
call add(s:no_tags, 'embed')
|
||||
call add(s:no_tags, 'param')
|
||||
call add(s:no_tags, 'source')
|
||||
call add(s:no_tags, 'track')
|
||||
call add(s:no_tags, 'area')
|
||||
call add(s:no_tags, 'col')
|
||||
call add(s:no_tags, 'input')
|
||||
call add(s:no_tags, 'keygen')
|
||||
call add(s:no_tags, 'menuitem')
|
||||
|
||||
let s:omittable = [
|
||||
\ ['address', 'article', 'aside', 'blockquote', 'dir', 'div', 'dl', 'fieldset', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hr', 'menu', 'nav', 'ol', 'p', 'pre', 'section', 'table', 'ul'],
|
||||
@@ -187,16 +204,21 @@ let s:omittable = [
|
||||
\ ['th', 'td'],
|
||||
\]
|
||||
|
||||
|
||||
let s:html_noindent_tags = join(s:no_tags, '\|')
|
||||
|
||||
if exists('g:html_exclude_tags')
|
||||
for tag in g:html_exclude_tags
|
||||
call remove(s:tags, index(s:tags, tag))
|
||||
endfor
|
||||
let s:html_noindent_tags = s:html_noindent_tags.'\|'.join(g:html_exclude_tags, '\|')
|
||||
endif
|
||||
let s:html_indent_tags = join(s:tags, '\|')
|
||||
let s:html_indent_tags = s:html_indent_tags.'\|\w\+\(-\w\+\)\+'
|
||||
if exists('g:html_indent_tags')
|
||||
let s:html_indent_tags = s:html_indent_tags.'\|'.g:html_indent_tags
|
||||
endif
|
||||
|
||||
" let s:html_indent_tags = join(s:tags, '\|')
|
||||
let s:html_indent_tags = '[a-z_][a-z0-9_.-]*'
|
||||
" if exists('g:html_indent_tags')
|
||||
" let s:html_indent_tags = s:html_indent_tags.'\|'.g:html_indent_tags
|
||||
" endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo-=C
|
||||
@@ -231,8 +253,8 @@ endfun
|
||||
fun! <SID>HtmlIndentSum(lnum, style)
|
||||
if a:style == match(getline(a:lnum), '^\s*</')
|
||||
if a:style == match(getline(a:lnum), '^\s*</\<\('.s:html_indent_tags.'\)\>')
|
||||
let open = <SID>HtmlIndentOpen(a:lnum, s:html_indent_tags)
|
||||
let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags)
|
||||
let open = <SID>HtmlIndentOpen(a:lnum, s:html_indent_tags) - <SID>HtmlIndentOpen(a:lnum, s:html_noindent_tags)
|
||||
let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags) - <SID>HtmlIndentClose(a:lnum, s:html_noindent_tags)
|
||||
if 0 != open || 0 != close
|
||||
return open - close
|
||||
endif
|
||||
|
||||
@@ -56,10 +56,11 @@ function! GetLiquidIndent(...)
|
||||
let line = substitute(line,'\C^\%(\s*{%\s*end\w*\s*%}\)\+','','')
|
||||
let line .= matchstr(cline,'\C^\%(\s*{%\s*end\w*\s*%}\)\+')
|
||||
let cline = substitute(cline,'\C^\%(\s*{%\s*end\w*\s*%}\)\+','','')
|
||||
let ind += &sw * s:count(line,'{%\s*\%(if\|elsif\|else\|unless\|ifchanged\|case\|when\|for\|empty\|tablerow\|capture\)\>')
|
||||
let ind -= &sw * s:count(line,'{%\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>')
|
||||
let ind -= &sw * s:count(cline,'{%\s*\%(elsif\|else\|when\|empty\)\>')
|
||||
let ind -= &sw * s:count(cline,'{%\s*end\w*$')
|
||||
let sw = exists('*shiftwidth') ? shiftwidth() : &sw
|
||||
let ind += sw * s:count(line,'{%\s*\%(if\|elsif\|else\|unless\|ifchanged\|case\|when\|for\|empty\|tablerow\|capture\)\>')
|
||||
let ind -= sw * s:count(line,'{%\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>')
|
||||
let ind -= sw * s:count(cline,'{%\s*\%(elsif\|else\|when\|empty\)\>')
|
||||
let ind -= sw * s:count(cline,'{%\s*end\w*$')
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jade') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Jade
|
||||
" Language: Pug
|
||||
" Maintainer: Joshua Borton
|
||||
" Credits: Tim Pope (vim-jade)
|
||||
" Credits: Tim Pope (vim-pug)
|
||||
" Last Change: 2010 Sep 22
|
||||
|
||||
if exists("b:did_indent")
|
||||
@@ -14,25 +14,25 @@ unlet! b:did_indent
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal autoindent
|
||||
setlocal indentexpr=GetJadeIndent()
|
||||
setlocal indentexpr=GetPugIndent()
|
||||
setlocal indentkeys=o,O,*<Return>,},],0),!^F
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetJadeIndent")
|
||||
if exists("*GetPugIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:attributes = '\%((.\{-\})\)'
|
||||
let s:tag = '\([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
|
||||
|
||||
if !exists('g:jade_self_closing_tags')
|
||||
let g:jade_self_closing_tags = 'meta|link|img|hr|br|input'
|
||||
if !exists('g:pug_self_closing_tags')
|
||||
let g:pug_self_closing_tags = 'meta|link|img|hr|br|input'
|
||||
endif
|
||||
|
||||
setlocal formatoptions+=r
|
||||
setlocal comments+=n:\|
|
||||
|
||||
function! GetJadeIndent()
|
||||
function! GetPugIndent()
|
||||
let lnum = prevnonblank(v:lnum-1)
|
||||
if lnum == 0
|
||||
return 0
|
||||
@@ -60,9 +60,9 @@ function! GetJadeIndent()
|
||||
return increase
|
||||
elseif line == '-#'
|
||||
return increase
|
||||
elseif line =~? '^\v%('.g:jade_self_closing_tags.')>'
|
||||
elseif line =~? '^\v%('.g:pug_self_closing_tags.')>'
|
||||
return indent
|
||||
elseif group =~? '\v^%(jadeAttributesDelimiter|jadeClass|jadeId|htmlTagName|htmlSpecialTagName|jadeFilter|jadeTagBlockChar)$'
|
||||
elseif group =~? '\v^%(pugAttributesDelimiter|pugClass|pugId|htmlTagName|htmlSpecialTagName|pugFilter|pugTagBlockChar)$'
|
||||
return increase
|
||||
else
|
||||
return indent
|
||||
@@ -125,7 +125,7 @@ let s:indent_access_modifier_regex = '\C^\s*\%(protected\|private\)\s*\%(#.*\)\=
|
||||
" The reason is that the pipe matches a hanging "|" operator.
|
||||
"
|
||||
let s:block_regex =
|
||||
\ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|\s*(*\s*\%([*@&]\=\h\w*,\=\s*\)\%(,\s*(*\s*[*@&]\=\h\w*\s*)*\s*\)*|\)\=\s*\%(#.*\)\=$'
|
||||
\ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|[^|]*|\)\=\s*\%(#.*\)\=$'
|
||||
|
||||
let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex
|
||||
|
||||
|
||||
@@ -31,9 +31,7 @@ function! GetSassIndent()
|
||||
let indent = indent(lnum)
|
||||
let cindent = indent(v:lnum)
|
||||
if line !~ s:property && line !~ s:extend && cline =~ s:property
|
||||
return indent + &sw
|
||||
"elseif line =~ s:property && cline !~ s:property
|
||||
"return indent - &sw
|
||||
return indent + (exists('*shiftwidth') ? shiftwidth() : &sw)
|
||||
else
|
||||
return -1
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user