aboutsummaryrefslogtreecommitdiff
path: root/runtime/indent
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-11-25 19:15:05 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-11-25 19:27:38 +0000
commitc5d770d311841ea5230426cc4c868e8db27300a8 (patch)
treedd21f70127b4b8b5f109baefc8ecc5016f507c91 /runtime/indent
parent9be89f131f87608f224f0ee06d199fcd09d32176 (diff)
parent081beb3659bd6d8efc3e977a160b1e72becbd8a2 (diff)
downloadrneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.gz
rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.bz2
rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'runtime/indent')
-rw-r--r--runtime/indent/idris2.vim183
-rw-r--r--runtime/indent/racket.vim12
-rw-r--r--runtime/indent/sh.vim6
-rw-r--r--runtime/indent/testdir/bash.in22
-rw-r--r--runtime/indent/testdir/bash.ok22
5 files changed, 243 insertions, 2 deletions
diff --git a/runtime/indent/idris2.vim b/runtime/indent/idris2.vim
new file mode 100644
index 0000000000..d3c306e0a1
--- /dev/null
+++ b/runtime/indent/idris2.vim
@@ -0,0 +1,183 @@
+" Vim indent file
+" Language: Idris 2
+" Maintainer: Idris Hackers (https://github.com/edwinb/idris2-vim), Serhii Khoma <srghma@gmail.com>
+" Author: raichoo <raichoo@googlemail.com>
+" Last Change: 2024 Nov 05
+" License: Vim (see :h license)
+" Repository: https://github.com/ShinKage/idris2-nvim
+"
+" indentation for idris (idris-lang.org)
+"
+" Based on haskell indentation by motemen <motemen@gmail.com>
+"
+" Indentation configuration variables:
+"
+" g:idris2_indent_if (default: 3)
+" Controls indentation after 'if' statements
+" Example:
+" if condition
+" >>>then expr
+" >>>else expr
+"
+" g:idris2_indent_case (default: 5)
+" Controls indentation of case expressions
+" Example:
+" case x of
+" >>>>>Left y => ...
+" >>>>>Right z => ...
+"
+" g:idris2_indent_let (default: 4)
+" Controls indentation after 'let' bindings
+" Example:
+" let x = expr in
+" >>>>body
+"
+" g:idris2_indent_rewrite (default: 8)
+" Controls indentation after 'rewrite' expressions
+" Example:
+" rewrite proof in
+" >>>>>>>>expr
+"
+" g:idris2_indent_where (default: 6)
+" Controls indentation of 'where' blocks
+" Example:
+" function args
+" >>>>>>where helper = expr
+"
+" g:idris2_indent_do (default: 3)
+" Controls indentation in 'do' blocks
+" Example:
+" do x <- action
+" >>>y <- action
+"
+" Example configuration in .vimrc:
+" let g:idris2_indent_if = 2
+
+if exists('b:did_indent')
+ finish
+endif
+
+setlocal indentexpr=GetIdrisIndent()
+setlocal indentkeys=!^F,o,O,}
+
+let b:did_indent = 1
+let b:undo_indent = "setlocal indentexpr< indentkeys<"
+
+" we want to use line continuations (\) BEGINNING
+let s:cpo_save = &cpo
+set cpo&vim
+
+" Define defaults for indent configuration
+let s:indent_defaults = {
+ \ 'idris2_indent_if': 3,
+ \ 'idris2_indent_case': 5,
+ \ 'idris2_indent_let': 4,
+ \ 'idris2_indent_rewrite': 8,
+ \ 'idris2_indent_where': 6,
+ \ 'idris2_indent_do': 3
+ \ }
+
+" we want to use line continuations (\) END
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
+" Set up indent settings with user overrides
+for [key, default] in items(s:indent_defaults)
+ let varname = 'g:' . key
+ if !exists(varname)
+ execute 'let' varname '=' default
+ endif
+endfor
+
+if exists("*GetIdrisIndent")
+ finish
+endif
+
+function! GetIdrisIndent()
+ let prevline = getline(v:lnum - 1)
+
+ if prevline =~ '\s\+(\s*.\+\s\+:\s\+.\+\s*)\s\+->\s*$'
+ return match(prevline, '(')
+ elseif prevline =~ '\s\+{\s*.\+\s\+:\s\+.\+\s*}\s\+->\s*$'
+ return match(prevline, '{')
+ endif
+
+ if prevline =~ '[!#$%&*+./<>?@\\^|~-]\s*$'
+ let s = match(prevline, '[:=]')
+ if s > 0
+ return s + 2
+ else
+ return match(prevline, '\S')
+ endif
+ endif
+
+ if prevline =~ '[{([][^})\]]\+$'
+ return match(prevline, '[{([]')
+ endif
+
+ if prevline =~ '\<let\>\s\+.\+\<in\>\s*$'
+ return match(prevline, '\<let\>') + g:idris2_indent_let
+ endif
+
+ if prevline =~ '\<rewrite\>\s\+.\+\<in\>\s*$'
+ return match(prevline, '\<rewrite\>') + g:idris2_indent_rewrite
+ endif
+
+ if prevline !~ '\<else\>'
+ let s = match(prevline, '\<if\>.*\&.*\zs\<then\>')
+ if s > 0
+ return s
+ endif
+
+ let s = match(prevline, '\<if\>')
+ if s > 0
+ return s + g:idris2_indent_if
+ endif
+ endif
+
+ if prevline =~ '\(\<where\>\|\<do\>\|=\|[{([]\)\s*$'
+ return match(prevline, '\S') + &shiftwidth
+ endif
+
+ if prevline =~ '\<where\>\s\+\S\+.*$'
+ return match(prevline, '\<where\>') + g:idris2_indent_where
+ endif
+
+ if prevline =~ '\<do\>\s\+\S\+.*$'
+ return match(prevline, '\<do\>') + g:idris2_indent_do
+ endif
+
+ if prevline =~ '^\s*\<\(co\)\?data\>\s\+[^=]\+\s\+=\s\+\S\+.*$'
+ return match(prevline, '=')
+ endif
+
+ if prevline =~ '\<with\>\s\+([^)]*)\s*$'
+ return match(prevline, '\S') + &shiftwidth
+ endif
+
+ if prevline =~ '\<case\>\s\+.\+\<of\>\s*$'
+ return match(prevline, '\<case\>') + g:idris2_indent_case
+ endif
+
+ if prevline =~ '^\s*\(\<namespace\>\|\<\(co\)\?data\>\)\s\+\S\+\s*$'
+ return match(prevline, '\(\<namespace\>\|\<\(co\)\?data\>\)') + &shiftwidth
+ endif
+
+ if prevline =~ '^\s*\(\<using\>\|\<parameters\>\)\s*([^(]*)\s*$'
+ return match(prevline, '\(\<using\>\|\<parameters\>\)') + &shiftwidth
+ endif
+
+ if prevline =~ '^\s*\<mutual\>\s*$'
+ return match(prevline, '\<mutual\>') + &shiftwidth
+ endif
+
+ let line = getline(v:lnum)
+
+ if (line =~ '^\s*}\s*' && prevline !~ '^\s*;')
+ return match(prevline, '\S') - &shiftwidth
+ endif
+
+ return match(prevline, '\S')
+endfunction
+
+" vim:et:sw=2:sts=2
diff --git a/runtime/indent/racket.vim b/runtime/indent/racket.vim
index d301cd64f9..2bab3f3bed 100644
--- a/runtime/indent/racket.vim
+++ b/runtime/indent/racket.vim
@@ -3,7 +3,7 @@
" Maintainer: D. Ben Knoble <ben.knoble+github@gmail.com>
" Previous Maintainer: Will Langstroth <will@langstroth.com>
" URL: https://github.com/benknoble/vim-racket
-" Last Change: 2024 Jan 31
+" Last Change: 2024 Nov 12
if exists("b:did_indent")
finish
@@ -21,6 +21,7 @@ setlocal lispwords+=λ
setlocal lispwords+=with-handlers
setlocal lispwords+=define-values,opt-lambda,case-lambda,syntax-rules,with-syntax,syntax-case,syntax-parse
setlocal lispwords+=define-for-syntax,define-syntax-parser,define-syntax-parse-rule,define-syntax-class,define-splicing-syntax-class
+setlocal lispwords+=syntax/loc,quasisyntax/loc
setlocal lispwords+=define-syntax-parameter,syntax-parameterize
setlocal lispwords+=define-signature,unit,unit/sig,compund-unit/sig,define-values/invoke-unit/sig
setlocal lispwords+=define-opt/c,define-syntax-rule
@@ -30,6 +31,11 @@ setlocal lispwords+=with-input-from-file,with-output-to-file
setlocal lispwords+=begin,begin0
setlocal lispwords+=place
setlocal lispwords+=cond
+" Racket style indents if like a function application:
+" (if test
+" then
+" else)
+setlocal lispwords-=if
" Racket OOP
" TODO missing a lot of define-like forms here (e.g., define/augment, etc.)
@@ -50,6 +56,7 @@ setlocal lispwords+=for/set,for*/set
setlocal lispwords+=for/first,for*/first
setlocal lispwords+=for/last,for*/last
setlocal lispwords+=for/stream,for*/stream
+setlocal lispwords+=for/lists,for*/lists
setlocal lispwords+=match,match*,match/values,define/match,match-lambda,match-lambda*,match-lambda**
setlocal lispwords+=match-let,match-let*,match-let-values,match-let*-values
@@ -66,4 +73,7 @@ setlocal lispwords+=if-view,case-view,cond-view,list-view,dyn-view
setlocal lispwords+=case/dep
setlocal lispwords+=define/obs
+" rackunit
+setlocal lispwords+=define-simple-check,define-binary-check,define-check,with-check-info
+
let b:undo_indent = "setlocal lisp< ai< si< lw<" .. (has('vim9script') ? ' indentexpr< lispoptions<' : '')
diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim
index aa47c6d1bd..184e829873 100644
--- a/runtime/indent/sh.vim
+++ b/runtime/indent/sh.vim
@@ -7,6 +7,8 @@
" License: Vim (see :h license)
" Repository: https://github.com/chrisbra/vim-sh-indent
" Changelog:
+" 20241411 - Detect dash character in function keyword for
+" bash mode (issue #16049)
" 20190726 - Correctly skip if keywords in syntax comments
" (issue #17)
" 20190603 - Do not indent in zsh filetypes with an `if` in comments
@@ -195,7 +197,9 @@ endfunction
function! s:is_function_definition(line)
return a:line =~ '^\s*\<\k\+\>\s*()\s*{' ||
\ a:line =~ '^\s*{' ||
- \ a:line =~ '^\s*function\s*\k\+\s*\%(()\)\?\s*{'
+ \ a:line =~ '^\s*function\s*\k\+\s*\%(()\)\?\s*{' ||
+ \ ((&ft is# 'zsh' || s:is_bash()) &&
+ \ a:line =~ '^\s*function\s*\S\+\s*\%(()\)\?\s*{' )
endfunction
function! s:is_array(line)
diff --git a/runtime/indent/testdir/bash.in b/runtime/indent/testdir/bash.in
new file mode 100644
index 0000000000..7ffcfc7a9d
--- /dev/null
+++ b/runtime/indent/testdir/bash.in
@@ -0,0 +1,22 @@
+#!/bin/bash
+# vim: set ft=bash sw=2 noet:
+
+# START_INDENT
+a = 10
+b = 20
+
+function add() {
+c = $((a + b))
+}
+
+function print {
+# do nothing
+}
+
+if [[ $c -ge 15 ]];
+then
+print("ok")
+else
+print("not ok")
+fi
+# END_INDENT
diff --git a/runtime/indent/testdir/bash.ok b/runtime/indent/testdir/bash.ok
new file mode 100644
index 0000000000..93d5b33c38
--- /dev/null
+++ b/runtime/indent/testdir/bash.ok
@@ -0,0 +1,22 @@
+#!/bin/bash
+# vim: set ft=bash sw=2 noet:
+
+# START_INDENT
+a = 10
+b = 20
+
+function add() {
+ c = $((a + b))
+}
+
+function print {
+ # do nothing
+}
+
+if [[ $c -ge 15 ]];
+then
+ print("ok")
+else
+ print("not ok")
+fi
+# END_INDENT