aboutsummaryrefslogtreecommitdiff
path: root/runtime/indent
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/indent')
-rw-r--r--runtime/indent/graphql.vim92
-rw-r--r--runtime/indent/just.vim51
-rw-r--r--runtime/indent/query.lua1
-rw-r--r--runtime/indent/typst.vim5
4 files changed, 146 insertions, 3 deletions
diff --git a/runtime/indent/graphql.vim b/runtime/indent/graphql.vim
new file mode 100644
index 0000000000..dc0769b9a8
--- /dev/null
+++ b/runtime/indent/graphql.vim
@@ -0,0 +1,92 @@
+" Vim indent file
+" Language: graphql
+" Maintainer: Jon Parise <jon@indelible.org>
+" Filenames: *.graphql *.graphqls *.gql
+" URL: https://github.com/jparise/vim-graphql
+" License: MIT <https://opensource.org/license/mit>
+" Last Change: 2024 Dec 21
+
+" Set our local options if indentation hasn't already been set up.
+" This generally means we've been detected as the primary filetype.
+if !exists('b:did_indent')
+ setlocal autoindent
+ setlocal nocindent
+ setlocal nolisp
+ setlocal nosmartindent
+
+ setlocal indentexpr=GetGraphQLIndent()
+ setlocal indentkeys=0{,0},0),0[,0],0#,!^F,o,O
+
+ let b:did_indent = 1
+endif
+
+" If our indentation function already exists, we have nothing more to do.
+if exists('*GetGraphQLIndent')
+ finish
+endif
+
+let s:cpo_save = &cpoptions
+set cpoptions&vim
+
+" searchpair() skip expression that matches in comments and strings.
+let s:pair_skip_expr =
+ \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? "comment\\|string"'
+
+" Check if the character at lnum:col is inside a string.
+function s:InString(lnum, col)
+ return synIDattr(synID(a:lnum, a:col, 1), 'name') ==# 'graphqlString'
+endfunction
+
+function GetGraphQLIndent()
+ " If this is the first non-blank line, we have nothing more to do because
+ " all of our indentation rules are based on matching against earlier lines.
+ let l:prevlnum = prevnonblank(v:lnum - 1)
+ if l:prevlnum == 0
+ return 0
+ endif
+
+ " If the previous line isn't GraphQL, assume we're part of a template
+ " string and indent this new line within it.
+ let l:stack = map(synstack(l:prevlnum, 1), "synIDattr(v:val, 'name')")
+ if get(l:stack, -1) !~# '^graphql'
+ return indent(l:prevlnum) + shiftwidth()
+ endif
+
+ let l:line = getline(v:lnum)
+
+ " If this line contains just a closing bracket, find its matching opening
+ " bracket and indent the closing bracket to match.
+ let l:col = matchend(l:line, '^\s*[]})]')
+ if l:col > 0 && !s:InString(v:lnum, l:col)
+ call cursor(v:lnum, l:col)
+
+ let l:bracket = l:line[l:col - 1]
+ if l:bracket ==# '}'
+ let l:matched = searchpair('{', '', '}', 'bW', s:pair_skip_expr)
+ elseif l:bracket ==# ']'
+ let l:matched = searchpair('\[', '', '\]', 'bW', s:pair_skip_expr)
+ elseif l:bracket ==# ')'
+ let l:matched = searchpair('(', '', ')', 'bW', s:pair_skip_expr)
+ else
+ let l:matched = -1
+ endif
+
+ return l:matched > 0 ? indent(l:matched) : virtcol('.') - 1
+ endif
+
+ " If we're inside of a multiline string, continue with the same indentation.
+ if s:InString(v:lnum, matchend(l:line, '^\s*') + 1)
+ return indent(v:lnum)
+ endif
+
+ " If the previous line ended with an opening bracket, indent this line.
+ if getline(l:prevlnum) =~# '\%(#.*\)\@<![[{(]\s*$'
+ return indent(l:prevlnum) + shiftwidth()
+ endif
+
+ " Default to the existing indentation level.
+ return indent(l:prevlnum)
+endfunction
+
+let &cpoptions = s:cpo_save
+unlet s:cpo_save
diff --git a/runtime/indent/just.vim b/runtime/indent/just.vim
new file mode 100644
index 0000000000..d7f82b118f
--- /dev/null
+++ b/runtime/indent/just.vim
@@ -0,0 +1,51 @@
+" Vim indent file
+" Language: Justfile
+" Maintainer: Peter Benjamin <@pbnj>
+" Last Change: 2025 Jan 19
+" Credits: The original author, Noah Bogart <https://github.com/NoahTheDuke/vim-just/>
+
+" Only load this indent file when no other was loaded yet.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetJustfileIndent()
+setlocal indentkeys=0},0),!^F,o,O,0=''',0=\"\"\"
+
+let b:undo_indent = "setlocal indentexpr< indentkeys<"
+
+if exists("*GetJustfileIndent")
+ finish
+endif
+
+function GetJustfileIndent()
+ if v:lnum < 2
+ return 0
+ endif
+
+ let prev_line = getline(v:lnum - 1)
+ let last_indent = indent(v:lnum - 1)
+
+ if getline(v:lnum) =~ "\\v^\\s+%([})]|'''$|\"\"\"$)"
+ return last_indent - shiftwidth()
+ elseif prev_line =~ '\V#'
+ return last_indent
+ elseif prev_line =~ "\\v%([:{(]|^.*\\S.*%([^']'''|[^\"]\"\"\"))\\s*$"
+ return last_indent + shiftwidth()
+ elseif prev_line =~ '\\$'
+ if v:lnum == 2 || getline(v:lnum - 2) !~ '\\$'
+ if prev_line =~ '\v:\=@!'
+ return last_indent + shiftwidth() + shiftwidth()
+ else
+ return last_indent + shiftwidth()
+ endif
+ endif
+ elseif v:lnum > 2 && getline(v:lnum - 2) =~ '\\$'
+ return last_indent - shiftwidth()
+ elseif prev_line =~ '\v:\s*%(\h|\()' && prev_line !~ '\V:='
+ return last_indent + shiftwidth()
+ endif
+
+ return last_indent
+endfunction
diff --git a/runtime/indent/query.lua b/runtime/indent/query.lua
index c5b4f1f03d..17b8e9d2ac 100644
--- a/runtime/indent/query.lua
+++ b/runtime/indent/query.lua
@@ -1,6 +1,5 @@
-- Neovim indent file
-- Language: Treesitter query
--- Last Change: 2024 Jul 03
-- it's a lisp!
vim.cmd([[runtime! indent/lisp.vim]])
diff --git a/runtime/indent/typst.vim b/runtime/indent/typst.vim
index 6aaa04a53a..c990b968c8 100644
--- a/runtime/indent/typst.vim
+++ b/runtime/indent/typst.vim
@@ -1,7 +1,8 @@
" Vim indent file
" Language: Typst
-" Maintainer: Gregory Anders <greg@gpanders.com>
-" Last Change: 2024-07-14
+" Previous Maintainer: Gregory Anders
+" Maintainer: Luca Saccarola <github.e41mv@aleeas.com>
+" Last Change: 2024 Dec 09
" Based on: https://github.com/kaarmu/typst.vim
if exists('b:did_indent')