-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Define commentstring for vim plugin * Define comments for vim plugin * Correct commentstring * Update vim Makefile to handle ftplugin directory * Rough indentation plugin implementation * Set indent level of first line * Improve indentation inside sections * Indent keywords * Tidy echoes and comments * Handle indent plugin in Makefile * Add 'Stage' keyword * Tidy comments * Add handling of apptest section Co-authored-by: Vanessasaurus <814322+vsoch@users.noreply.github.com> Co-authored-by: Vanessasaurus <814322+vsoch@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
" Singularity indent file | ||
|
||
" Only load this script if no other indent script has been loaded | ||
if exists("b:did_indent") | ||
finish | ||
endif | ||
let b:did_indent=1 | ||
|
||
" Configure other indent options | ||
setlocal nocindent | ||
setlocal nosmartindent | ||
setlocal autoindent | ||
|
||
" Declare function to determine indent level | ||
setlocal indentexpr=GetSingularityIndent(v:lnum) | ||
|
||
" Declare which keys trigger the indentation function | ||
setlocal indentkeys=!^F,o,O,0%,<:> | ||
|
||
" Indentation level function | ||
" Returns the level of indentation as an integer | ||
" -1 means to retain the current indentation level | ||
function! GetSingularityIndent(lnum) | ||
let lnum = a:lnum | ||
|
||
" The first line is at indent level 0 | ||
if lnum == 1 | ||
return 0 | ||
endif | ||
|
||
let this_line = getline(lnum) | ||
|
||
" Catch indentation triggered when typing %, for section headings set | ||
" indent to level 0 | ||
if this_line =~ '^\s*%' | ||
return 0 | ||
endif | ||
|
||
" Trigger indentation when typing :, if line matches a keyword set indent | ||
" to level 0 | ||
if this_line =~ '^\s*\(Bootstrap\|From\|Stage\|OSVersion\|MirrorURL\|Library\|Registry\|Namespace\|IncludeCmd\|Include\):' | ||
return 0 | ||
endif | ||
|
||
|
||
" Search backwards for the section lnum belongs to | ||
let clnum = lnum - 1 | ||
while clnum > 0 | ||
let current_line = getline(clnum) | ||
|
||
" If parent section is one of | ||
" %setup,%files,%post,%test,%environment,%startscript,%runscript,%labels,%help | ||
" increase indent one step | ||
if current_line =~ '^%\(setup\|files\|post\|test\|environment\|startscript\|runscript\|labels\|help\)' | ||
return indent(clnum) + &shiftwidth | ||
endif | ||
|
||
" If parent section is one of | ||
" %apprun *,%applabels *,%appinstall *,%appenv *,%apphelp *,%appfiles * | ||
" increase indent one step | ||
if current_line =~ '^%\(apprun\|applabels\|appinstall\|appenv\|apphelp\|appfiles\|apptest\)\s*[a-zA-Z]*' | ||
return indent(clnum) + &shiftwidth | ||
endif | ||
|
||
let clnum = clnum - 1 | ||
endwhile | ||
|
||
" Otherwise return same indent level | ||
return -1 | ||
endfunction |