codekingpro/portable-devtools
114k
1" Vim indent file2" Language: occam3" Maintainer: Mario Schweigler <ms44@kent.ac.uk> (Invalid email address)4" Doug Kearns <dougkearns@gmail.com>5" Last Change: 2022 Apr 066 7" Only load this indent file when no other was loaded.8if exists("b:did_indent")9 finish10endif11let b:did_indent = 112 13"{{{ Settings14" Set the occam indent function15setlocal indentexpr=GetOccamIndent()16" Indent after new line and after initial colon17setlocal indentkeys=o,O,0=:18"}}}19 20let b:undo_indent = "setl inde< indk<"21 22" Only define the function once23if exists("*GetOccamIndent")24 finish25endif26let s:keepcpo= &cpo27set cpo&vim28 29"{{{ Indent definitions30" Define carriage return indent31let s:FirstLevelIndent = '^\C\s*\(IF\|ALT\|PRI\s\+ALT\|PAR\|SEQ\|PRI\s\+PAR\|WHILE\|VALOF\|CLAIM\|FORKING\)\>\|\(--.*\)\@<!\(\<PROC\>\|??\|\<CASE\>\s*\(--.*\)\=\_$\)'32let s:FirstLevelNonColonEndIndent = '^\C\s*PROTOCOL\>\|\(--.*\)\@<!\<\(\(CHAN\|DATA\)\s\+TYPE\|FUNCTION\)\>'33let s:SecondLevelIndent = '^\C\s*\(IF\|ALT\|PRI\s\+ALT\)\>\|\(--.*\)\@<!?\s*\<CASE\>\s*\(--.*\)\=\_$'34let s:SecondLevelNonColonEndIndent = '\(--.*\)\@<!\<\(CHAN\|DATA\)\s\+TYPE\>'35 36" Define colon indent37let s:ColonIndent = '\(--.*\)\@<!\<PROC\>'38let s:ColonNonColonEndIndent = '^\C\s*PROTOCOL\>\|\(--.*\)\@<!\<\(\(CHAN\|DATA\)\s\+TYPE\|FUNCTION\)\>'39 40let s:ColonEnd = '\(--.*\)\@<!:\s*\(--.*\)\=$'41let s:ColonStart = '^\s*:\s*\(--.*\)\=$'42 43" Define comment44let s:CommentLine = '^\s*--'45"}}}46 47"{{{ function GetOccamIndent()48" Auxiliary function to get the correct indent for a line of occam code49function GetOccamIndent()50 51 " Ensure magic is on52 let save_magic = &magic53 setlocal magic54 55 " Get reference line number56 let linenum = prevnonblank(v:lnum - 1)57 while linenum > 0 && getline(linenum) =~ s:CommentLine58 let linenum = prevnonblank(linenum - 1)59 endwhile60 61 " Get current indent62 let curindent = indent(linenum)63 64 " Get current line65 let line = getline(linenum)66 67 " Get previous line number68 let prevlinenum = prevnonblank(linenum - 1)69 while prevlinenum > 0 && getline(prevlinenum) =~ s:CommentLine70 let prevlinenum = prevnonblank(prevlinenum - 1)71 endwhile72 73 " Get previous line74 let prevline = getline(prevlinenum)75 76 " Colon indent77 if getline(v:lnum) =~ s:ColonStart78 79 let found = 080 81 while found < 182 83 if line =~ s:ColonStart84 let found = found - 185 elseif line =~ s:ColonIndent || (line =~ s:ColonNonColonEndIndent && line !~ s:ColonEnd)86 let found = found + 187 endif88 89 if found < 190 let linenum = prevnonblank(linenum - 1)91 if linenum > 092 let line = getline(linenum)93 else94 let found = 195 endif96 endif97 98 endwhile99 100 if linenum > 0101 let curindent = indent(linenum)102 else103 let colonline = getline(v:lnum)104 let tabstr = ''105 while strlen(tabstr) < &tabstop106 let tabstr = ' ' . tabstr107 endwhile108 let colonline = substitute(colonline, '\t', tabstr, 'g')109 let curindent = match(colonline, ':')110 endif111 112 " Restore magic113 if !save_magic|setlocal nomagic|endif114 115 return curindent116 endif117 118 if getline(v:lnum) =~ '^\s*:'119 let colonline = getline(v:lnum)120 let tabstr = ''121 while strlen(tabstr) < &tabstop122 let tabstr = ' ' . tabstr123 endwhile124 let colonline = substitute(colonline, '\t', tabstr, 'g')125 let curindent = match(colonline, ':')126 127 " Restore magic128 if !save_magic|setlocal nomagic|endif129 130 return curindent131 endif132 133 " Carriage return indenat134 if line =~ s:FirstLevelIndent || (line =~ s:FirstLevelNonColonEndIndent && line !~ s:ColonEnd)135 \ || (line !~ s:ColonStart && (prevline =~ s:SecondLevelIndent136 \ || (prevline =~ s:SecondLevelNonColonEndIndent && prevline !~ s:ColonEnd)))137 let curindent = curindent + shiftwidth()138 139 " Restore magic140 if !save_magic|setlocal nomagic|endif141 142 return curindent143 endif144 145 " Commented line146 if getline(prevnonblank(v:lnum - 1)) =~ s:CommentLine147 148 " Restore magic149 if !save_magic|setlocal nomagic|endif150 151 return indent(prevnonblank(v:lnum - 1))152 endif153 154 " Look for previous second level IF / ALT / PRI ALT155 let found = 0156 157 while !found158 159 if indent(prevlinenum) == curindent - shiftwidth()160 let found = 1161 endif162 163 if !found164 let prevlinenum = prevnonblank(prevlinenum - 1)165 while prevlinenum > 0 && getline(prevlinenum) =~ s:CommentLine166 let prevlinenum = prevnonblank(prevlinenum - 1)167 endwhile168 if prevlinenum == 0169 let found = 1170 endif171 endif172 173 endwhile174 175 if prevlinenum > 0176 if getline(prevlinenum) =~ s:SecondLevelIndent177 let curindent = curindent + shiftwidth()178 endif179 endif180 181 " Restore magic182 if !save_magic|setlocal nomagic|endif183 184 return curindent185 186endfunction187"}}}188 189let &cpo = s:keepcpo190unlet s:keepcpo191 