robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Christian Clasonvim-patch:d3ff129ce8c67b8e582f1c

master
2.4 KiB88 linesraw
1" Vim indent file (experimental).
2" Language:    Astro
3" Author:      Wuelner Martínez <wuelner.martinez@outlook.com>
4" Maintainer:  Wuelner Martínez <wuelner.martinez@outlook.com>
5" URL:         https://github.com/wuelnerdotexe/vim-astro
6" Last Change: 2022 Aug 07
7" Based On:    Evan Lecklider's vim-svelte
8" Changes:     See https://github.com/evanleck/vim-svelte
9" Credits:     See vim-svelte on github
10
11" Only load this indent file when no other was loaded yet.
12if exists('b:did_indent')
13  finish
14endif
15
16let b:html_indent_script1 = 'inc'
17let b:html_indent_style1 = 'inc'
18
19" Embedded HTML indent.
20runtime! indent/html.vim
21let s:html_indent = &l:indentexpr
22unlet b:did_indent
23
24let b:did_indent = 1
25
26setlocal indentexpr=GetAstroIndent()
27setlocal indentkeys=<>>,/,0{,{,},0},0),0],0\,<<>,,!^F,*<Return>,o,O,e,;
28
29let b:undo_indent = 'setl inde< indk<'
30
31" Only define the function once.
32if exists('*GetAstroIndent')
33  finish
34endif
35
36let s:cpoptions_save = &cpoptions
37setlocal cpoptions&vim
38
39function! GetAstroIndent()
40  let l:current_line_number = v:lnum
41
42  if l:current_line_number == 0
43    return 0
44  endif
45
46  let l:current_line = getline(l:current_line_number)
47
48  if l:current_line =~ '^\s*</\?\(script\|style\)'
49    return 0
50  endif
51
52  let l:previous_line_number = prevnonblank(l:current_line_number - 1)
53  let l:previous_line = getline(l:previous_line_number)
54  let l:previous_line_indent = indent(l:previous_line_number)
55
56  if l:previous_line =~ '^\s*</\?\(script\|style\)'
57    return l:previous_line_indent + shiftwidth()
58  endif
59
60  execute 'let l:indent = ' . s:html_indent
61
62  if searchpair('<style>', '', '</style>', 'bW') &&
63        \ l:previous_line =~ ';$' && l:current_line !~ '}'
64    return l:previous_line_indent
65  endif
66
67  if synID(l:previous_line_number, match(
68        \   l:previous_line, '\S'
69        \ ) + 1, 0) == hlID('htmlTag') && synID(l:current_line_number, match(
70        \  l:current_line, '\S'
71        \ ) + 1, 0) != hlID('htmlEndTag')
72    let l:indents_match = l:indent == l:previous_line_indent
73    let l:previous_closes = l:previous_line =~ '/>$'
74
75    if l:indents_match &&
76          \ !l:previous_closes && l:previous_line =~ '<\(\u\|\l\+:\l\+\)'
77      return l:previous_line_indent + shiftwidth()
78    elseif !l:indents_match && l:previous_closes
79      return l:previous_line_indent
80    endif
81  endif
82
83  return l:indent
84endfunction
85
86let &cpoptions = s:cpoptions_save
87unlet s:cpoptions_save
88" vim: ts=8