Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
idris2.vim184 linesDownload Raw Back to indent
1" Vim indent file2" Language:            Idris 23" Maintainer:          Idris Hackers (https://github.com/edwinb/idris2-vim), Serhii Khoma <srghma@gmail.com>4" Author:              raichoo <raichoo@googlemail.com>5" Last Change:         2024 Nov 056" License:             Vim (see :h license)7" Repository:          https://github.com/ShinKage/idris2-nvim8"9" indentation for idris (idris-lang.org)10"11" Based on haskell indentation by motemen <motemen@gmail.com>12"13" Indentation configuration variables:14"15" g:idris2_indent_if (default: 3)16"   Controls indentation after 'if' statements17"   Example:18"     if condition19"     >>>then expr20"     >>>else expr21"22" g:idris2_indent_case (default: 5)23"   Controls indentation of case expressions24"   Example:25"     case x of26"     >>>>>Left y => ...27"     >>>>>Right z => ...28"29" g:idris2_indent_let (default: 4)30"   Controls indentation after 'let' bindings31"   Example:32"     let x = expr in33"     >>>>body34"35" g:idris2_indent_rewrite (default: 8)36"   Controls indentation after 'rewrite' expressions37"   Example:38"     rewrite proof in39"     >>>>>>>>expr40"41" g:idris2_indent_where (default: 6)42"   Controls indentation of 'where' blocks43"   Example:44"     function args45"     >>>>>>where helper = expr46"47" g:idris2_indent_do (default: 3)48"   Controls indentation in 'do' blocks49"   Example:50"     do x <- action51"     >>>y <- action52"53" Example configuration in .vimrc:54" let g:idris2_indent_if = 255 56if exists('b:did_indent')57  finish58endif59 60setlocal indentexpr=GetIdrisIndent()61setlocal indentkeys=!^F,o,O,}62 63let b:did_indent = 164let b:undo_indent = "setlocal indentexpr< indentkeys<"65 66" we want to use line continuations (\) BEGINNING67let s:cpo_save = &cpo68set cpo&vim69 70" Define defaults for indent configuration71let s:indent_defaults = {72  \ 'idris2_indent_if': 3,73  \ 'idris2_indent_case': 5,74  \ 'idris2_indent_let': 4,75  \ 'idris2_indent_rewrite': 8,76  \ 'idris2_indent_where': 6,77  \ 'idris2_indent_do': 378  \ }79 80" we want to use line continuations (\) END81let &cpo = s:cpo_save82unlet s:cpo_save83 84" Set up indent settings with user overrides85for [key, default] in items(s:indent_defaults)86  let varname = 'g:' . key87  if !exists(varname)88    execute 'let' varname '=' default89  endif90endfor91 92if exists("*GetIdrisIndent")93  finish94endif95 96function! GetIdrisIndent()97  let prevline = getline(v:lnum - 1)98 99  if prevline =~ '\s\+(\s*.\+\s\+:\s\+.\+\s*)\s\+->\s*$'100    return match(prevline, '(')101  elseif prevline =~ '\s\+{\s*.\+\s\+:\s\+.\+\s*}\s\+->\s*$'102    return match(prevline, '{')103  endif104 105  if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'106    let s = match(prevline, '[:=]')107    if s > 0108      return s + 2109    else110      return match(prevline, '\S')111    endif112  endif113 114  if prevline =~ '[{([][^})\]]\+$'115    return match(prevline, '[{([]')116  endif117 118  if prevline =~ '\<let\>\s\+.\+\<in\>\s*$'119    return match(prevline, '\<let\>') + g:idris2_indent_let120  endif121 122  if prevline =~ '\<rewrite\>\s\+.\+\<in\>\s*$'123    return match(prevline, '\<rewrite\>') + g:idris2_indent_rewrite124  endif125 126  if prevline !~ '\<else\>'127    let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')128    if s > 0129      return s130    endif131 132    let s = match(prevline, '\<if\>')133    if s > 0134      return s + g:idris2_indent_if135    endif136  endif137 138  if prevline =~ '\(\<where\>\|\<do\>\|=\|[{([]\)\s*$'139    return match(prevline, '\S') + &shiftwidth140  endif141 142  if prevline =~ '\<where\>\s\+\S\+.*$'143    return match(prevline, '\<where\>') + g:idris2_indent_where144  endif145 146  if prevline =~ '\<do\>\s\+\S\+.*$'147    return match(prevline, '\<do\>') + g:idris2_indent_do148  endif149 150  if prevline =~ '^\s*\<\(co\)\?data\>\s\+[^=]\+\s\+=\s\+\S\+.*$'151    return match(prevline, '=')152  endif153 154  if prevline =~ '\<with\>\s\+([^)]*)\s*$'155    return match(prevline, '\S') + &shiftwidth156  endif157 158  if prevline =~ '\<case\>\s\+.\+\<of\>\s*$'159    return match(prevline, '\<case\>') + g:idris2_indent_case160  endif161 162  if prevline =~ '^\s*\(\<namespace\>\|\<\(co\)\?data\>\)\s\+\S\+\s*$'163    return match(prevline, '\(\<namespace\>\|\<\(co\)\?data\>\)') + &shiftwidth164  endif165 166  if prevline =~ '^\s*\(\<using\>\|\<parameters\>\)\s*([^(]*)\s*$'167    return match(prevline, '\(\<using\>\|\<parameters\>\)') + &shiftwidth168  endif169 170  if prevline =~ '^\s*\<mutual\>\s*$'171    return match(prevline, '\<mutual\>') + &shiftwidth172  endif173 174  let line = getline(v:lnum)175 176  if (line =~ '^\s*}\s*' && prevline !~ '^\s*;')177    return match(prevline, '\S') - &shiftwidth178  endif179 180  return match(prevline, '\S')181endfunction182 183" vim:et:sw=2:sts=2184 
codekingpro/portable-devtools · Team Ai