aboutsummaryrefslogtreecommitdiff
path: root/runtime/indent
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
committerJosh Rahm <joshuarahm@gmail.com>2024-05-24 19:18:11 +0000
commitff7ed8f586589d620a806c3758fac4a47a8e7e15 (patch)
tree729bbcb92231538fa61dab6c3d890b025484b7f5 /runtime/indent
parent376914f419eb08fdf4c1a63a77e1f035898a0f10 (diff)
parent28c04948a1c887a1cc0cb64de79fa32631700466 (diff)
downloadrneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.gz
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.tar.bz2
rneovim-ff7ed8f586589d620a806c3758fac4a47a8e7e15.zip
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'runtime/indent')
-rw-r--r--runtime/indent/arduino.vim16
-rw-r--r--runtime/indent/asm.vim29
-rw-r--r--runtime/indent/astro.vim88
-rw-r--r--runtime/indent/json5.vim11
-rw-r--r--runtime/indent/stylus.vim121
5 files changed, 265 insertions, 0 deletions
diff --git a/runtime/indent/arduino.vim b/runtime/indent/arduino.vim
new file mode 100644
index 0000000000..88717ac00d
--- /dev/null
+++ b/runtime/indent/arduino.vim
@@ -0,0 +1,16 @@
+" Vim indent file
+" Language: Arduino
+" Maintainer: The Vim Project <https://github.com/vim/vim>
+" Ken Takata <https://github.com/k-takata>
+" Last Change: 2024 Apr 03
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+" Use C indenting.
+setlocal cindent
+
+let b:undo_indent = "setl cin<"
diff --git a/runtime/indent/asm.vim b/runtime/indent/asm.vim
new file mode 100644
index 0000000000..054612b9d6
--- /dev/null
+++ b/runtime/indent/asm.vim
@@ -0,0 +1,29 @@
+" Vim indent file
+" Language: asm
+" Maintainer: Philip Jones <philj56@gmail.com>
+" Upstream: https://github.com/philj56/vim-asm-indent
+" Last Change: 2017-Jul-01
+" 2024 Apr 25 by Vim Project (undo_indent)
+
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=s:getAsmIndent()
+setlocal indentkeys=<:>,!^F,o,O
+
+let b:undo_indent = "setlocal indentexpr< indentkeys<"
+
+function! s:getAsmIndent()
+ let line = getline(v:lnum)
+ let ind = shiftwidth()
+
+ " If the line is a label (starts with ':' terminated keyword),
+ " then don't indent
+ if line =~ '^\s*\k\+:'
+ let ind = 0
+ endif
+
+ return ind
+endfunction
diff --git a/runtime/indent/astro.vim b/runtime/indent/astro.vim
new file mode 100644
index 0000000000..25a2aa0c29
--- /dev/null
+++ b/runtime/indent/astro.vim
@@ -0,0 +1,88 @@
+" Vim indent file (experimental).
+" Language: Astro
+" Author: Wuelner Martínez <wuelner.martinez@outlook.com>
+" Maintainer: Wuelner Martínez <wuelner.martinez@outlook.com>
+" URL: https://github.com/wuelnerdotexe/vim-astro
+" Last Change: 2022 Aug 07
+" Based On: Evan Lecklider's vim-svelte
+" Changes: See https://github.com/evanleck/vim-svelte
+" Credits: See vim-svelte on github
+
+" Only load this indent file when no other was loaded yet.
+if exists('b:did_indent')
+ finish
+endif
+
+let b:html_indent_script1 = 'inc'
+let b:html_indent_style1 = 'inc'
+
+" Embedded HTML indent.
+runtime! indent/html.vim
+let s:html_indent = &l:indentexpr
+unlet b:did_indent
+
+let b:did_indent = 1
+
+setlocal indentexpr=GetAstroIndent()
+setlocal indentkeys=<>>,/,0{,{,},0},0),0],0\,<<>,,!^F,*<Return>,o,O,e,;
+
+let b:undo_indent = 'setl inde< indk<'
+
+" Only define the function once.
+if exists('*GetAstroIndent')
+ finish
+endif
+
+let s:cpoptions_save = &cpoptions
+setlocal cpoptions&vim
+
+function! GetAstroIndent()
+ let l:current_line_number = v:lnum
+
+ if l:current_line_number == 0
+ return 0
+ endif
+
+ let l:current_line = getline(l:current_line_number)
+
+ if l:current_line =~ '^\s*</\?\(script\|style\)'
+ return 0
+ endif
+
+ let l:previous_line_number = prevnonblank(l:current_line_number - 1)
+ let l:previous_line = getline(l:previous_line_number)
+ let l:previous_line_indent = indent(l:previous_line_number)
+
+ if l:previous_line =~ '^\s*</\?\(script\|style\)'
+ return l:previous_line_indent + shiftwidth()
+ endif
+
+ execute 'let l:indent = ' . s:html_indent
+
+ if searchpair('<style>', '', '</style>', 'bW') &&
+ \ l:previous_line =~ ';$' && l:current_line !~ '}'
+ return l:previous_line_indent
+ endif
+
+ if synID(l:previous_line_number, match(
+ \ l:previous_line, '\S'
+ \ ) + 1, 0) == hlID('htmlTag') && synID(l:current_line_number, match(
+ \ l:current_line, '\S'
+ \ ) + 1, 0) != hlID('htmlEndTag')
+ let l:indents_match = l:indent == l:previous_line_indent
+ let l:previous_closes = l:previous_line =~ '/>$'
+
+ if l:indents_match &&
+ \ !l:previous_closes && l:previous_line =~ '<\(\u\|\l\+:\l\+\)'
+ return l:previous_line_indent + shiftwidth()
+ elseif !l:indents_match && l:previous_closes
+ return l:previous_line_indent
+ endif
+ endif
+
+ return l:indent
+endfunction
+
+let &cpoptions = s:cpoptions_save
+unlet s:cpoptions_save
+" vim: ts=8
diff --git a/runtime/indent/json5.vim b/runtime/indent/json5.vim
new file mode 100644
index 0000000000..5977a4b912
--- /dev/null
+++ b/runtime/indent/json5.vim
@@ -0,0 +1,11 @@
+" Vim indent file
+" Language: JSON5
+" Maintainer: The Vim Project <https://github.com/vim/vim>
+" Last Change: 2024-03-26
+
+if exists("b:did_indent")
+ finish
+endif
+
+" Same as jsonc indenting for now
+runtime! indent/jsonc.vim
diff --git a/runtime/indent/stylus.vim b/runtime/indent/stylus.vim
new file mode 100644
index 0000000000..89634f0914
--- /dev/null
+++ b/runtime/indent/stylus.vim
@@ -0,0 +1,121 @@
+" Vim indent file
+" Language: Stylus
+" Maintainer: Marc Harter
+" Last Change: 2010 May 21
+" Based On: sass.vim from Tim Pope
+"
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetStylusIndent()
+setlocal indentkeys=o,O,*<Return>,},],0),!^F
+let b:undo_indent = "setl indentexpr< indentkeys<"
+
+if exists("*GetStylusIndent") " only define once
+ finish
+endif
+
+function s:prevnonblanknoncomment(lnum)
+ let lnum = a:lnum
+ while lnum > 1
+ let lnum = prevnonblank(lnum)
+ let line = getline(lnum)
+ if line =~ '\*/'
+ while lnum > 1 && line !~ '/\*'
+ let lnum -= 1
+ endwhile
+ if line =~ '^\s*/\*'
+ let lnum -= 1
+ else
+ break
+ endif
+ else
+ break
+ endif
+ endwhile
+ return lnum
+endfunction
+
+function s:count_braces(lnum, count_open)
+ let n_open = 0
+ let n_close = 0
+ let line = getline(a:lnum)
+ let pattern = '[{}]'
+ let i = match(line, pattern)
+ while i != -1
+ if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'css\%(Comment\|StringQ\{1,2}\)'
+ if line[i] == '{'
+ let n_open += 1
+ elseif line[i] == '}'
+ if n_open > 0
+ let n_open -= 1
+ else
+ let n_close += 1
+ endif
+ endif
+ endif
+ let i = match(line, pattern, i + 1)
+ endwhile
+ return a:count_open ? n_open : n_close
+endfunction
+
+" function CheckCSSIndent()
+" let line = getline(v:lnum)
+" if line =~ '^\s*\*'
+" return cindent(v:lnum)
+" endif
+"
+" let pnum = s:prevnonblanknoncomment(v:lnum - 1)
+" if pnum == 0
+" return 0
+" endif
+
+function! GetStylusIndent()
+ let line = getline(v:lnum)
+ if line =~ '^\s*\*'
+ return cindent(v:lnum)
+ endif
+
+ let pnum = s:prevnonblanknoncomment(v:lnum - 1)
+ if pnum == 0
+ return 0
+ endif
+
+ let lnum = prevnonblank(v:lnum-1)
+ if lnum == 0
+ return 0
+ endif
+
+ let pline = getline(pnum)
+
+ if pline =~ '[}{]'
+ return indent(pnum) + s:count_braces(pnum, 1) * &sw - s:count_braces(v:lnum, 0) * &sw
+ endif
+
+ let line = substitute(getline(lnum),'[\s()]\+$','','') " get last line strip ending whitespace
+ let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','') " get current line, trimmed
+ let lastcol = strlen(line) " get last col in prev line
+ let line = substitute(line,'^\s\+','','') " then remove preceeding whitespace
+ let indent = indent(lnum) " get indent on prev line
+ let cindent = indent(v:lnum) " get indent on current line
+ let increase = indent + &sw " increase indent by the shift width
+ if indent == indent(lnum)
+ let indent = cindent <= indent ? indent : increase
+ endif
+
+ let group = synIDattr(synID(lnum,lastcol,1),'name')
+
+ " if group !~? 'css.*' && line =~? ')\s*$' " match user functions
+ " return increase
+ if group =~? '\v^%(cssTagName|cssClassName|cssIdentifier|cssSelectorOp|cssSelectorOp2|cssBraces|cssAttributeSelector|cssPseudo|stylusId|stylusClass)$'
+ return increase
+ elseif (group == 'stylusUserFunction') && (indent(lnum) == '0') " mixin definition
+ return increase
+ else
+ return indent
+ endif
+endfunction
+
+" vim:set sw=2;