From 4ee53150fa2eb61f3420b46a2e4937ad335c8e0c Mon Sep 17 00:00:00 2001 From: Mateo Gjika <104777599+mateoxh@users.noreply.github.com> Date: Tue, 4 Mar 2025 15:57:56 +0100 Subject: [PATCH 1/3] Add options to configure indentation These options override the default behavior of auto indenting to the first non-space character: `g:haskell_indent_do` do >>foo `g:haskell_indent_if` if foo >>then bar >>else baz `g:haskell_indent_case` case foo of >>bar -> baz --- indent/haskell.vim | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/indent/haskell.vim b/indent/haskell.vim index eaff0c9..bbc5335 100644 --- a/indent/haskell.vim +++ b/indent/haskell.vim @@ -124,7 +124,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 +133,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 +149,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 +471,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 From 8babd5e85dfb880fcb3c94b7ffadba2a12135602 Mon Sep 17 00:00:00 2001 From: Mateo Gjika <104777599+mateoxh@users.noreply.github.com> Date: Sat, 8 Mar 2025 19:19:44 +0100 Subject: [PATCH 2/3] Add option for indenting `in` `g:haskell_indent_in` let x = 1 >>in x --- indent/haskell.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/indent/haskell.vim b/indent/haskell.vim index bbc5335..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 " = From 671390103dd8033f453ed6350010c90151aba06a Mon Sep 17 00:00:00 2001 From: Mateo Gjika <104777599+mateoxh@users.noreply.github.com> Date: Sat, 8 Mar 2025 19:34:51 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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)