diff --git a/README.md b/README.md index ecdca46..c89f211 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,32 @@ ## Installation Install with your favorite plugin manager. +## Options +If you don't like the default indentation you can easily change it by creating the following variables. + +Here are some examples: + +* `let g:haskell_indent_do = 3` + + do + >>>foo + +* `let g:haskell_indent_if = 2` + + if foo + >>then bar + >>else baz + +* `let g:haskell_indent_case = 2` + + case foo of + >>bar -> baz + +* `let g:haskell_indent_in = 1` + + let x = 1 + >in x + ## Author itchyny (https://github.com/itchyny) diff --git a/indent/haskell.vim b/indent/haskell.vim index eaff0c9..d2ca5ab 100644 --- a/indent/haskell.vim +++ b/indent/haskell.vim @@ -72,7 +72,9 @@ function! GetHaskellIndent() abort " in if line =~# '\v^\s*' - return s:indent('\v^\s*', '\v^.*\s*\zs', 0, -1) + return exists('g:haskell_indent_in') + \ ? s:indent('\v^\s*', '\v^.*\zs', 0, -1) + g:haskell_indent_in + \ : s:indent('\v^\s*', '\v^.*\s*\zs', 0, -1) endif " = @@ -124,7 +126,7 @@ function! GetHaskellIndent() abort endif if nonblankline =~# '\v\s*%(--.*)?$' - return match(nonblankline, '\v^\s*%(|.*)?\s*\zs') + &shiftwidth + return match(nonblankline, '\v^\s*%(|.*)?\s*\zs') + get(g:, 'haskell_indent_do', &shiftwidth) endif if nonblankline =~# '\v\s*[[:alnum:](]' @@ -133,7 +135,9 @@ function! GetHaskellIndent() abort if line =~# '\v' && line !~# '\v^\s*#' if line !~# '\v' - return match(line, '\v.*\s*\zs') + return exists('g:haskell_indent_if') + \ ? match(line, '\v.*\zs') + g:haskell_indent_if + \ : match(line, '\v.*\s*\zs') elseif line !~# '\v' return match(line, '\v.*\zs') endif @@ -147,9 +151,13 @@ function! GetHaskellIndent() abort return indent(s:prevnonblank(v:lnum - 1)) + &shiftwidth endif else - return line =~# '\v.*\s*([[:alnum:](\"''\[]|-\d)' - \ ? match(line, '\v.*\s*\zs\S') - \ : match(line, '\v.*\s*\zs') + if line =~# '\v.*\s*([[:alnum:](\"''\[]|-\d)' + return match(line, '\v.*\s*\zs') + else + return exists('g:haskell_indent_case') + \ ? match(line, '\v.*\zs') + g:haskell_indent_case + \ : match(line, '\v.*\s*\zs') + endif endif endif @@ -465,8 +473,9 @@ function! s:indent_then() abort if lnum == 0 && col == 0 return -1 else - " consider adding option to decide where to indent 'then' - return match(getline(lnum)[col - 1:], '\v\s*\zs') + col - 1 + return exists('g:haskell_indent_if') + \ ? g:haskell_indent_if + col - 1 + \ : match(getline(lnum)[col - 1:], '\v\s*\zs') + col - 1 endif endfunction