diff --git a/runtime/compiler/cabal.vim b/runtime/compiler/cabal.vim index 02d4d9b8e1..3590e93e31 100644 --- a/runtime/compiler/cabal.vim +++ b/runtime/compiler/cabal.vim @@ -33,7 +33,8 @@ CompilerSet errorformat= \%E%f:%l:%c:\ %trror:%m, \%E%f:%l:%c:\ %trror:, \%Z\ %\\+\|%.%#, - \%C%m + \%C%m, + \%-G%.%# let &cpo = s:save_cpo unlet s:save_cpo diff --git a/runtime/ftplugin/cabal.vim b/runtime/ftplugin/cabal.vim index e7e4ab18a9..91b9298930 100644 --- a/runtime/ftplugin/cabal.vim +++ b/runtime/ftplugin/cabal.vim @@ -3,16 +3,16 @@ " Maintainer: Riley Bruins " Last Change: 2024 Jul 06 " 2026 Jan 13 by Vim project: set compiler #19152 +" 2026 Jun 26 by Vim project: set expandtab #20623 if exists('b:did_ftplugin') finish endif let b:did_ftplugin = 1 +setlocal expandtab +setlocal comments=:-- commentstring=--\ %s + compiler cabal -let b:undo_ftplugin = 'compiler make' - -setl comments=:-- commentstring=--\ %s - -let b:undo_ftplugin .= '| setl com< cms<' +let b:undo_ftplugin = 'compiler make | setlocal com< cms< et<' diff --git a/runtime/indent/cabal.vim b/runtime/indent/cabal.vim new file mode 100644 index 0000000000..3faaa6def8 --- /dev/null +++ b/runtime/indent/cabal.vim @@ -0,0 +1,100 @@ +" Vim indent file +" Language: Haskell Cabal Build file +" Maintainer: Mateo Gjika <@mateoxh> + +if exists('b:did_indent') + finish +endif + +let b:did_indent = 1 + +setlocal indentexpr=GetCabalIndent() +setlocal indentkeys=!^F,o,O,e,0=elif,<:> + +let b:undo_indent = 'setlocal inde< indk<' + +let s:save_cpo = &cpo +set cpo&vim + +function! GetCabalIndent() abort + let categories = '\v\c^<(executable|(foreign-)?library|flag|source-repository|test-suite|benchmark|common|custom-setup)>' + let line = getline(v:lnum) + let prevline = getline(v:lnum - 1) + + if line =~# categories + return 0 + endif + + if line =~# '^\s*--' + return -1 + endif + + if line =~# '^\s*}' + let [lnum, col] = s:searchpairpos('{','','}','bnW') + if [lnum, col] == [0, 0] + return -1 + else + return indent(lnum) + endif + endif + + if line =~# '^\s*||' + if prevline =~# '^\s*||' + return indent(v:lnum - 1) + else + return indent(v:lnum - 1) + 1 + endif + endif + + if line =~# '\v^\s*' + let [lnum, col] = s:searchpairpos('\v', '', '\v\zs', 'bnW') + return col - 1 + elseif line =~# '\v^\s*' + let [lnum, col] = s:searchpairpos('\v', '\v', '\v\zs', 'bnW') + return col - 1 + endif + + if prevline =~# '\v^\s*<(if|elif|else)>' + return indent(v:lnum - 1) + shiftwidth() + endif + + if prevline =~# categories + return indent(v:lnum - 1) + shiftwidth() + endif + + if empty(prevline) || line =~# '\v^\s*\S+:' + call cursor(v:lnum, 1) + let prevCond = search('\v^\s*<(if|elif|else)>', 'bnW', 0, 0, + \ "synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment'") + let prevCat = search(categories, 'bnW', 0, 0, + \ "synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment'") + if prevCond > prevCat + return indent(v:lnum) > indent(prevCond) + \ ? indent(prevCond) + shiftwidth() + \ : indent(prevCond) + elseif prevCat > 0 + return indent(prevCat) + shiftwidth() + else + return 0 + endif + endif + + if line !~# '\v^\s*(|--)' + if prevline =~# '\v^\s*\S+:$' + return indent(v:lnum - 1) + shiftwidth() + endif + if prevline =~# '\v^\s*\S+:\s*\S' + return match(prevline, '\v^\s*\S+:\s*\zs') + endif + endif + + return indent(prevnonblank(v:lnum - 1)) +endfunction + +function! s:searchpairpos(start, middle, end, flags) abort + return searchpairpos(a:start, a:middle, a:end, a:flags, + \ "synIDattr(synID(line('.'),col('.'),1),'name') =~? 'comment'") +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/runtime/syntax/cabal.vim b/runtime/syntax/cabal.vim index ddc905615b..fffc0c7752 100644 --- a/runtime/syntax/cabal.vim +++ b/runtime/syntax/cabal.vim @@ -8,6 +8,7 @@ " " 2026 Apr 29 by Léana: add missing haskell language editions " 2026 Apr 20 by Vim project: remove wrong oneline keyword #20018 +" 2026 Jun 26 by Vim project: add elif keyword #20623 " " v1.6: Added support for foreign-libraries " Added highlighting for various fields @@ -53,7 +54,7 @@ syn iskeyword @,48-57,192-255,- " Case sensitive matches syn case match -syn keyword cabalConditional if else +syn keyword cabalConditional if elif else syn keyword cabalFunction os arche impl flag syn match cabalComment /--.*$/