Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial auto-indent support #95

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions indent/just.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
" Vim indent file
" Language: Justfile
" Maintainer: Noah Bogart <[email protected]>
" URL: https://github.com/NoahTheDuke/vim-just.git
" Last Change: 2024 Jan 19

" 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