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

indent: default to the result of GetYAMLIndent; always return the def… #127

Merged
merged 1 commit into from Nov 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions indent/ansible.vim
Expand Up @@ -18,6 +18,7 @@ let s:named_module_entry = '\v^\s*-\s*(name|hosts|role):\s*\S' " - name: 'do stu
let s:dictionary_entry = '\v^\s*[^:-]+:\s*$' " with_items:
let s:key_value = '\v^\s*[^:-]+:\s*\S' " apt: name=package
let s:scalar_value = '\v:\s*[>|\|]\s*$' " shell: >
let s:blank = '\v^\s*$' " line with only spaces

if exists('*GetAnsibleIndent')
finish
Expand All @@ -33,26 +34,29 @@ function GetAnsibleIndent(lnum)
endif
endif
let prevlnum = prevnonblank(a:lnum - 1)
let maintain = indent(prevlnum)
let increase = maintain + &sw
let default = GetYAMLIndent(a:lnum)
let increase = indent(prevlnum) + &sw

let line = getline(prevlnum)
if line =~ s:array_entry
if line =~ s:named_module_entry
let prevline = getline(prevlnum)
let line = getline(a:lnum)
if line !~ s:blank
return default " we only special case blank lines
elseif prevline =~ s:array_entry
if prevline =~ s:named_module_entry
return increase
else
return maintain
return default
endif
elseif line =~ s:dictionary_entry
elseif prevline =~ s:dictionary_entry
return increase
elseif line =~ s:key_value
if line =~ s:scalar_value
elseif prevline =~ s:key_value
if prevline =~ s:scalar_value
return increase
else
return maintain
return default
endif
else
return maintain
return default
endif
endfunction

Expand Down