summaryrefslogtreecommitdiffstats
path: root/runtime/indent
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--runtime/indent/arduino.vim16
-rw-r--r--runtime/indent/asm.vim29
-rw-r--r--runtime/indent/hare.vim31
-rw-r--r--runtime/indent/kdl.vim30
-rw-r--r--runtime/indent/stylus.vim121
-rw-r--r--runtime/indent/testdir/vb.in52
-rw-r--r--runtime/indent/testdir/vb.ok58
-rw-r--r--runtime/indent/vb.vim252
8 files changed, 427 insertions, 162 deletions
diff --git a/runtime/indent/arduino.vim b/runtime/indent/arduino.vim
new file mode 100644
index 0000000..88717ac
--- /dev/null
+++ b/runtime/indent/arduino.vim
@@ -0,0 +1,16 @@
+" Vim indent file
+" Language: Arduino
+" Maintainer: The Vim Project <https://github.com/vim/vim>
+" Ken Takata <https://github.com/k-takata>
+" Last Change: 2024 Apr 03
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+" Use C indenting.
+setlocal cindent
+
+let b:undo_indent = "setl cin<"
diff --git a/runtime/indent/asm.vim b/runtime/indent/asm.vim
deleted file mode 100644
index 4efa766..0000000
--- a/runtime/indent/asm.vim
+++ /dev/null
@@ -1,29 +0,0 @@
-" Vim indent file
-" Language: asm
-" Maintainer: Philip Jones <philj56@gmail.com>
-" Upstream: https://github.com/philj56/vim-asm-indent
-" Last Change: 2017-Jul-01
-" 2024 Apr 25 by Vim Project (undo_indent)
-
-if exists("b:did_indent")
- finish
-endif
-let b:did_indent = 1
-
-setlocal indentexpr=s:getAsmIndent()
-setlocal indentkeys=<:>,!^F,o,O
-
-let b:undo_indent = "indentexpr< indentkeys<"
-
-function! s:getAsmIndent()
- let line = getline(v:lnum)
- let ind = shiftwidth()
-
- " If the line is a label (starts with ':' terminated keyword),
- " then don't indent
- if line =~ '^\s*\k\+:'
- let ind = 0
- endif
-
- return ind
-endfunction
diff --git a/runtime/indent/hare.vim b/runtime/indent/hare.vim
index 0a9d8da..1b51d1e 100644
--- a/runtime/indent/hare.vim
+++ b/runtime/indent/hare.vim
@@ -1,19 +1,16 @@
" Vim indent file
-" Language: Hare
-" Maintainer: Amelia Clarke <me@rsaihe.dev>
-" Last Change: 2022 Sep 22
-" 2023 Aug 28 by Vim Project (undo_indent)
+" Language: Hare
+" Maintainer: Amelia Clarke <selene@perilune.dev>
+" Last Change: 2024-04-14
+" Upstream: https://git.sr.ht/~sircmpwn/hare.vim
-if exists("b:did_indent")
+if exists('b:did_indent')
finish
endif
let b:did_indent = 1
-if !has("cindent") || !has("eval")
- finish
-endif
-
-setlocal cindent
+let s:cpo_save = &cpo
+set cpo&vim
" L0 -> don't deindent labels
" (s -> use one indent after a trailing (
@@ -41,7 +38,11 @@ setlocal cinwords=if,else,for,switch,match
setlocal indentexpr=GetHareIndent()
-let b:undo_indent = "setl cin< cino< cinw< inde< indk<"
+let b:undo_indent = 'setl cino< cinw< inde< indk<'
+
+if exists('*GetHareIndent()')
+ finish
+endif
function! FloorCindent(lnum)
return cindent(a:lnum) / shiftwidth() * shiftwidth()
@@ -122,7 +123,8 @@ function! GetHareIndent()
" Indent the body of a case.
" If the previous line ended in a semicolon and the line before that was a
" case, don't do any special indenting.
- if prevline =~# '\v;\s*(//.*)?$' && prevprevline =~# '\v\=\>\s*(//.*)?$' && line !~# '\v^\s*}'
+ if prevline =~# '\v;\s*(//.*)?$' && prevprevline =~# '\v\=\>\s*(//.*)?$'
+ \ && line !~# '\v^\s*}'
return indent(prevlnum)
endif
@@ -138,4 +140,7 @@ function! GetHareIndent()
return l:indent
endfunction
-" vim: tabstop=2 shiftwidth=2 expandtab
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
+" vim: et sw=2 sts=2 ts=8
diff --git a/runtime/indent/kdl.vim b/runtime/indent/kdl.vim
new file mode 100644
index 0000000..b0a6bd9
--- /dev/null
+++ b/runtime/indent/kdl.vim
@@ -0,0 +1,30 @@
+" Vim indent file
+" Language: KDL
+" Author: Aram Drevekenin <aram@poor.dev>
+" Maintainer: Yinzuo Jiang <jiangyinzuo@foxmail.com>
+" Last Change: 2024-06-16
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=KdlIndent()
+let b:undo_indent = "setlocal indentexpr<"
+
+function! KdlIndent(...)
+ let line = substitute(getline(v:lnum), '//.*$', '', '')
+ let previousNum = prevnonblank(v:lnum - 1)
+ let previous = substitute(getline(previousNum), '//.*$', '', '')
+
+ let l:indent = indent(previousNum)
+ if previous =~ "{" && previous !~ "}"
+ let l:indent += shiftwidth()
+ endif
+ if line =~ "}" && line !~ "{"
+ let l:indent -= shiftwidth()
+ endif
+ return l:indent
+endfunction
+" vim: sw=2 sts=2 et
diff --git a/runtime/indent/stylus.vim b/runtime/indent/stylus.vim
new file mode 100644
index 0000000..89634f0
--- /dev/null
+++ b/runtime/indent/stylus.vim
@@ -0,0 +1,121 @@
+" Vim indent file
+" Language: Stylus
+" Maintainer: Marc Harter
+" Last Change: 2010 May 21
+" Based On: sass.vim from Tim Pope
+"
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal indentexpr=GetStylusIndent()
+setlocal indentkeys=o,O,*<Return>,},],0),!^F
+let b:undo_indent = "setl indentexpr< indentkeys<"
+
+if exists("*GetStylusIndent") " only define once
+ finish
+endif
+
+function s:prevnonblanknoncomment(lnum)
+ let lnum = a:lnum
+ while lnum > 1
+ let lnum = prevnonblank(lnum)
+ let line = getline(lnum)
+ if line =~ '\*/'
+ while lnum > 1 && line !~ '/\*'
+ let lnum -= 1
+ endwhile
+ if line =~ '^\s*/\*'
+ let lnum -= 1
+ else
+ break
+ endif
+ else
+ break
+ endif
+ endwhile
+ return lnum
+endfunction
+
+function s:count_braces(lnum, count_open)
+ let n_open = 0
+ let n_close = 0
+ let line = getline(a:lnum)
+ let pattern = '[{}]'
+ let i = match(line, pattern)
+ while i != -1
+ if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'css\%(Comment\|StringQ\{1,2}\)'
+ if line[i] == '{'
+ let n_open += 1
+ elseif line[i] == '}'
+ if n_open > 0
+ let n_open -= 1
+ else
+ let n_close += 1
+ endif
+ endif
+ endif
+ let i = match(line, pattern, i + 1)
+ endwhile
+ return a:count_open ? n_open : n_close
+endfunction
+
+" function CheckCSSIndent()
+" let line = getline(v:lnum)
+" if line =~ '^\s*\*'
+" return cindent(v:lnum)
+" endif
+"
+" let pnum = s:prevnonblanknoncomment(v:lnum - 1)
+" if pnum == 0
+" return 0
+" endif
+
+function! GetStylusIndent()
+ let line = getline(v:lnum)
+ if line =~ '^\s*\*'
+ return cindent(v:lnum)
+ endif
+
+ let pnum = s:prevnonblanknoncomment(v:lnum - 1)
+ if pnum == 0
+ return 0
+ endif
+
+ let lnum = prevnonblank(v:lnum-1)
+ if lnum == 0
+ return 0
+ endif
+
+ let pline = getline(pnum)
+
+ if pline =~ '[}{]'
+ return indent(pnum) + s:count_braces(pnum, 1) * &sw - s:count_braces(v:lnum, 0) * &sw
+ endif
+
+ let line = substitute(getline(lnum),'[\s()]\+$','','') " get last line strip ending whitespace
+ let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','') " get current line, trimmed
+ let lastcol = strlen(line) " get last col in prev line
+ let line = substitute(line,'^\s\+','','') " then remove preceeding whitespace
+ let indent = indent(lnum) " get indent on prev line
+ let cindent = indent(v:lnum) " get indent on current line
+ let increase = indent + &sw " increase indent by the shift width
+ if indent == indent(lnum)
+ let indent = cindent <= indent ? indent : increase
+ endif
+
+ let group = synIDattr(synID(lnum,lastcol,1),'name')
+
+ " if group !~? 'css.*' && line =~? ')\s*$' " match user functions
+ " return increase
+ if group =~? '\v^%(cssTagName|cssClassName|cssIdentifier|cssSelectorOp|cssSelectorOp2|cssBraces|cssAttributeSelector|cssPseudo|stylusId|stylusClass)$'
+ return increase
+ elseif (group == 'stylusUserFunction') && (indent(lnum) == '0') " mixin definition
+ return increase
+ else
+ return indent
+ endif
+endfunction
+
+" vim:set sw=2;
diff --git a/runtime/indent/testdir/vb.in b/runtime/indent/testdir/vb.in
index 1653ae6..cb964f7 100644
--- a/runtime/indent/testdir/vb.in
+++ b/runtime/indent/testdir/vb.in
@@ -1,6 +1,16 @@
' vim: filetype=vb shiftwidth=4 expandtab
'
' START_INDENT
+#Const Debug = False
+
+#If Win64 Then
+' Win64=true, Win32=true, Win16=false
+#ElseIf Win32 Then
+' Win32=true, Win16=false
+#Else
+' Win16=true
+#End If
+
Public Type GEmployeeRecord ' Create user-defined type.
ID As Integer ' Define elements of data type.
Name As String * 20
@@ -95,6 +105,9 @@ Public Sub TestMultiline (cellAddr As String, rowNbr As Long)
Dim rng As Range
Set rng = Range(cellAddr)
+
+' Line continuation is implemented as a two-character sequence-
+' whitespace followed by underscore.
With rng
.Cells(1,1).Value = _
"Line 1 of multiline string; " & _
@@ -102,14 +115,25 @@ With rng
"Line 3 of multiline string"
End With
-' The following lines have whitespace after the underscore character
-' and therefore do not form a valid multiline statement. The indent
-' script correctly treats them as four single line statements contrary
-' to the author's obvious indent.
-rng..Cells(1,1).Value = _
+' This code block omits the leading whitespace character and so
+' the trailing underscore will not be treated as line continuation.
+With rng
+.Cells(1,1).Value =_
+"Line 1 of multiline string; " &_
+"Line 2 of multiline string; " &_
+"Line 3 of multiline string"
+End With
+
+' The following lines have whitespace after the underscore character.
+' This is contrary to Microsoft documentation but it is reported that
+' some Microsoft editors allow it and will still treat the statement
+' as line-continued.
+With rng
+rng.Cells(1,1).Value = _
"Line 1 of multiline string; " & _
"Line 2 of multiline string; " & _
"Line 3 of multiline string"
+End With
End Sub
@@ -121,6 +145,18 @@ stmtLabel:
End Sub
+Public Static Function TestStatic(addend As Integer)
+Dim Integer accumulator
+accumulator = accumulator + addend
+TestStatic = accumulator
+End Function
+
+Friend Function TestFriend(addend As Integer)
+Static Integer accumulator
+accumulator = accumulator + addend
+TestFriend = accumulator
+End Function
+
Sub TestTypeKeyword()
Type EmployeeRecord ' Create user-defined type.
ID As Integer ' Define elements of data type.
@@ -131,4 +167,10 @@ HireDate As Date
End Type
Dim varType As EmployeeRecord
End Sub
+
+Sub TestDateLiteralAfterLineContinuation
+Dim birthday as Date
+birthday = _
+#January 1, 1901#
+End Sub
' END_INDENT
diff --git a/runtime/indent/testdir/vb.ok b/runtime/indent/testdir/vb.ok
index 143c688..01a1a4c 100644
--- a/runtime/indent/testdir/vb.ok
+++ b/runtime/indent/testdir/vb.ok
@@ -1,6 +1,16 @@
' vim: filetype=vb shiftwidth=4 expandtab
'
' START_INDENT
+#Const Debug = False
+
+#If Win64 Then
+' Win64=true, Win32=true, Win16=false
+#ElseIf Win32 Then
+' Win32=true, Win16=false
+#Else
+' Win16=true
+#End If
+
Public Type GEmployeeRecord ' Create user-defined type.
ID As Integer ' Define elements of data type.
Name As String * 20
@@ -95,6 +105,9 @@ Public Sub TestMultiline (cellAddr As String, rowNbr As Long)
Dim rng As Range
Set rng = Range(cellAddr)
+
+ ' Line continuation is implemented as a two-character sequence-
+ ' whitespace followed by underscore.
With rng
.Cells(1,1).Value = _
"Line 1 of multiline string; " & _
@@ -102,14 +115,25 @@ Public Sub TestMultiline (cellAddr As String, rowNbr As Long)
"Line 3 of multiline string"
End With
- ' The following lines have whitespace after the underscore character
- ' and therefore do not form a valid multiline statement. The indent
- ' script correctly treats them as four single line statements contrary
- ' to the author's obvious indent.
- rng..Cells(1,1).Value = _
- "Line 1 of multiline string; " & _
- "Line 2 of multiline string; " & _
- "Line 3 of multiline string"
+ ' This code block omits the leading whitespace character and so
+ ' the trailing underscore will not be treated as line continuation.
+ With rng
+ .Cells(1,1).Value =_
+ "Line 1 of multiline string; " &_
+ "Line 2 of multiline string; " &_
+ "Line 3 of multiline string"
+ End With
+
+ ' The following lines have whitespace after the underscore character.
+ ' This is contrary to Microsoft documentation but it is reported that
+ ' some Microsoft editors allow it and will still treat the statement
+ ' as line-continued.
+ With rng
+ rng.Cells(1,1).Value = _
+ "Line 1 of multiline string; " & _
+ "Line 2 of multiline string; " & _
+ "Line 3 of multiline string"
+ End With
End Sub
@@ -121,6 +145,18 @@ stmtLabel:
End Sub
+Public Static Function TestStatic(addend As Integer)
+ Dim Integer accumulator
+ accumulator = accumulator + addend
+ TestStatic = accumulator
+End Function
+
+Friend Function TestFriend(addend As Integer)
+ Static Integer accumulator
+ accumulator = accumulator + addend
+ TestFriend = accumulator
+End Function
+
Sub TestTypeKeyword()
Type EmployeeRecord ' Create user-defined type.
ID As Integer ' Define elements of data type.
@@ -131,4 +167,10 @@ Sub TestTypeKeyword()
End Type
Dim varType As EmployeeRecord
End Sub
+
+Sub TestDateLiteralAfterLineContinuation
+ Dim birthday as Date
+ birthday = _
+ #January 1, 1901#
+End Sub
' END_INDENT
diff --git a/runtime/indent/vb.vim b/runtime/indent/vb.vim
index bc7142f..a2a8185 100644
--- a/runtime/indent/vb.vim
+++ b/runtime/indent/vb.vim
@@ -1,155 +1,193 @@
-" Vim indent file
-" Language: VisualBasic (ft=vb) / Basic (ft=basic) / SaxBasic (ft=vb)
-" Author: Johannes Zellner <johannes@zellner.org>
-" Maintainer: Michael Soyka (mssr953@gmail.com)
-" Last Change: Fri, 18 Jun 2004 07:22:42 CEST
-" Small update 2010 Jul 28 by Maxim Kim
-" 2022/12/15: add support for multiline statements.
-" 2022/12/21: move VbGetIndent from global to script-local scope
-" 2022/12/26: recognize "Type" keyword
+vim9script
+
+# Vim indent file
+# Language: VisualBasic (ft=vb) / Basic (ft=basic) / SaxBasic (ft=vb)
+# Author: Johannes Zellner <johannes@zellner.org>
+# Maintainer: Michael Soyka (mssr953@gmail.com)
+# Contributors: Doug Kearns (dougkearns@gmail.com)
+# Last Change: Fri, 18 Jun 2004 07:22:42 CEST
+# Small update 2010 Jul 28 by Maxim Kim
+# 2022/12/15: add support for multiline statements.
+# 2022/12/21: move VbGetIndent from global to script-local scope
+# 2022/12/26: recognize "Type" keyword
+# 2023/07/13: correct/extend line continuation pattern (Doug Kearns)
+# 2023/07/14: add more keywords; various optimizations (Doug Kearns)
+# 2023/07/20: convert to Vim9 script
+# 2023/07/23: improve detection of preproc directives (Doug Kearns)
if exists("b:did_indent")
finish
endif
-let b:did_indent = 1
+b:did_indent = v:true
setlocal autoindent
-setlocal indentexpr=s:VbGetIndent(v:lnum)
+setlocal indentexpr=VbGetIndent()
setlocal indentkeys&
setlocal indentkeys+==~else,=~elseif,=~end,=~wend,=~case,=~next,=~select,=~loop
-let b:undo_indent = "set ai< indentexpr< indentkeys<"
+b:undo_indent = "setlocal autoindent< indentexpr< indentkeys<"
-" Only define the function once.
-if exists("*s:VbGetIndent")
+# Only define the function once.
+if exists("*VbGetIndent")
finish
endif
-function s:VbGetIndent(lnum)
- let this_lnum = a:lnum
- let this_line = getline(this_lnum)
+# These regular expressions identify statement labels and preprocessor
+# directives.
+#
+const RE_LABEL: string = '^\s*\k\+:\s*$'
+const RE_PREPROC: string =
+ '^\s*#\%(const\|if\|elseif\|else\|end\|region\|enable\|disable\)\>'
+
+# Microsoft documentation states that line continuation is indicated by a
+# two-character sequence at end-of-line: a space character followed by an
+# underscore. Nonetheless, it has been reported that additional
+# whitespace after the underscore is also allowed. We will support both.
+# However, VB 16.0 also permits a comment after the underscore which,
+# for simplicity, we do not support.
+#
+const RE_LINE_CONTINUATION: string = '\s_\s*$'
+
+# The following regular expressions are used to increase the indent
+# after statements that open a new scope.
+#
+const RE_INCR_INDENT_1: string =
+ '^\s*\%(begin\|select\|case\|default\|if\|else\|elseif\|do\|for\|while\|with\)\>'
+const RE_INCR_INDENT_2: string =
+ '^\s*\%(\%(private\|public\|friend\)\s\+\)\=\%(static\s\+\)\=\%(function\|sub\|property\)\>'
+const RE_INCR_INDENT_3: string =
+ '^\s*\%(\%(private\|public\)\s\+\)\=\%(enum\|type\)\>'
- " labels and preprocessor get zero indent immediately
- let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
- if this_line =~? LABELS_OR_PREPROC
- return 0
+def VbGetIndent(): number
+ var this_lnum: number = v:lnum
+ var this_line: string = getline(this_lnum)
+ var this_indent: number = 0
+
+ # labels and preprocessor statements get zero indent immediately
+ if (this_line =~? RE_LABEL) || (this_line =~? RE_PREPROC)
+ return this_indent
endif
-
- " Get the current value of "shiftwidth"
- let bShiftwidth = shiftwidth()
- " Find a non-blank line above the current line.
- " Skip over labels and preprocessor directives.
- let lnum = this_lnum
+ # Get the current value of 'shiftwidth'
+ const SHIFTWIDTH: number = shiftwidth()
+
+ # Find a non-blank line above the current line.
+ # Skip over labels and preprocessor directives.
+ var lnum: number = this_lnum
+ var previous_line: string
while lnum > 0
- let lnum = prevnonblank(lnum - 1)
- let previous_line = getline(lnum)
- if previous_line !~? LABELS_OR_PREPROC
+ lnum = prevnonblank(lnum - 1)
+ previous_line = getline(lnum)
+ if (previous_line !~? RE_LABEL) || (previous_line !~? RE_PREPROC)
break
endif
endwhile
- " Hit the start of the file, use zero indent.
+ # Hit the start of the file, use zero indent.
if lnum == 0
- return 0
+ return this_indent
endif
- " Variable "previous_line" now contains the text in buffer line "lnum".
-
- " Multi-line statements have the underscore character at end-of-line:
- "
- " object.method(arguments, _
- " arguments, _
- " arguments)
- "
- " and require extra logic to determine the correct indentation.
- "
- " Case 1: Line "lnum" is the first line of a multiline statement.
- " Line "lnum" will have a trailing underscore character
- " but the preceding non-blank line does not.
- " Line "this_lnum" will be indented relative to "lnum".
- "
- " Case 2: Line "lnum" is the last line of a multiline statement.
- " Line "lnum" will not have a trailing underscore character
- " but the preceding non-blank line will.
- " Line "this_lnum" will have the same indentation as the starting
- " line of the multiline statement.
- "
- " Case 3: Line "lnum" is neither the first nor last line.
- " Lines "lnum" and "lnum-1" will have a trailing underscore
- " character.
- " Line "this_lnum" will have the same indentation as the preceding
- " line.
- "
- " No matter which case it is, the starting line of the statement must be
- " found. It will be assumed that multiline statements cannot have
- " intermingled comments, statement labels, preprocessor directives or
- " blank lines.
- "
- let lnum_is_continued = (previous_line =~ '_$')
+ # Variable "previous_line" now contains the text in buffer line "lnum".
+
+ # Multi-line statements have the underscore character at end-of-line:
+ #
+ # object.method(arguments, _
+ # arguments, _
+ # arguments)
+ #
+ # and require extra logic to determine the correct indentation.
+ #
+ # Case 1: Line "lnum" is the first line of a multiline statement.
+ # Line "lnum" will have a trailing underscore character
+ # but the preceding non-blank line does not.
+ # Line "this_lnum" will be indented relative to "lnum".
+ #
+ # Case 2: Line "lnum" is the last line of a multiline statement.
+ # Line "lnum" will not have a trailing underscore character
+ # but the preceding non-blank line will.
+ # Line "this_lnum" will have the same indentation as the starting
+ # line of the multiline statement.
+ #
+ # Case 3: Line "lnum" is neither the first nor last line.
+ # Lines "lnum" and "lnum-1" will have a trailing underscore
+ # character.
+ # Line "this_lnum" will have the same indentation as the preceding
+ # line.
+ #
+ # No matter which case it is, the starting line of the statement must be
+ # found. It will be assumed that multiline statements cannot have
+ # intermingled comments, statement labels, preprocessor directives or
+ # blank lines.
+ #
+ var lnum_is_continued: bool = (previous_line =~? RE_LINE_CONTINUATION)
+ var before_lnum: number
+ var before_previous_line: string
if lnum > 1
- let before_lnum = prevnonblank(lnum-1)
- let before_previous_line = getline(before_lnum)
+ before_lnum = prevnonblank(lnum - 1)
+ before_previous_line = getline(before_lnum)
else
- let before_lnum = 0
- let before_previous_line = ""
+ before_lnum = 0
+ before_previous_line = ""
endif
- if before_previous_line !~ '_$'
- " Variable "previous_line" contains the start of a statement.
- "
- let ind = indent(lnum)
+ if before_previous_line !~? RE_LINE_CONTINUATION
+ # Variable "previous_line" contains the start of a statement.
+ #
+ this_indent = indent(lnum)
if lnum_is_continued
- let ind += bShiftwidth
+ this_indent += SHIFTWIDTH
endif
elseif ! lnum_is_continued
- " Line "lnum" contains the last line of a multiline statement.
- " Need to find where this multiline statement begins
- "
+ # Line "lnum" contains the last line of a multiline statement.
+ # Need to find where this multiline statement begins
+ #
while before_lnum > 0
- let before_lnum -= 1
- if getline(before_lnum) !~ '_$'
- let before_lnum += 1
+ before_lnum -= 1
+ if getline(before_lnum) !~? RE_LINE_CONTINUATION
+ before_lnum += 1
break
endif
endwhile
if before_lnum == 0
- let before_lnum = 1
+ before_lnum = 1
endif
- let previous_line = getline(before_lnum)
- let ind = indent(before_lnum)
+ previous_line = getline(before_lnum)
+ this_indent = indent(before_lnum)
else
- " Line "lnum" is not the first or last line of a multiline statement.
- "
- let ind = indent(lnum)
+ # Line "lnum" is not the first or last line of a multiline statement.
+ #
+ this_indent = indent(lnum)
endif
- " Add
- if previous_line =~? '^\s*\<\(begin\|\%(\%(private\|public\|friend\)\s\+\)\=\%(function\|sub\|property\|enum\|type\)\|select\|case\|default\|if\|else\|elseif\|do\|for\|while\|with\)\>'
- let ind = ind + bShiftwidth
+ # Increment indent
+ if (previous_line =~? RE_INCR_INDENT_1) ||
+ (previous_line =~? RE_INCR_INDENT_2) ||
+ (previous_line =~? RE_INCR_INDENT_3)
+ this_indent += SHIFTWIDTH
endif
- " Subtract
- if this_line =~? '^\s*\<end\>\s\+\<select\>'
- if previous_line !~? '^\s*\<select\>'
- let ind = ind - 2 * bShiftwidth
+ # Decrement indent
+ if this_line =~? '^\s*end\s\+select\>'
+ if previous_line !~? '^\s*select\>'
+ this_indent -= 2 * SHIFTWIDTH
else
- " this case is for an empty 'select' -- 'end select'
- " (w/o any case statements) like:
- "
- " select case readwrite
- " end select
- let ind = ind - bShiftwidth
+ # this case is for an empty 'select' -- 'end select'
+ # (w/o any case statements) like:
+ #
+ # select case readwrite
+ # end select
+ this_indent -= SHIFTWIDTH
endif
- elseif this_line =~? '^\s*\<\(end\|else\|elseif\|until\|loop\|next\|wend\)\>'
- let ind = ind - bShiftwidth
- elseif this_line =~? '^\s*\<\(case\|default\)\>'
- if previous_line !~? '^\s*\<select\>'
- let ind = ind - bShiftwidth
+ elseif this_line =~? '^\s*\%(end\|else\|elseif\|until\|loop\|next\|wend\)\>'
+ this_indent -= SHIFTWIDTH
+ elseif this_line =~? '^\s*\%(case\|default\)\>'
+ if previous_line !~? '^\s*select\>'
+ this_indent -= SHIFTWIDTH
endif
endif
- return ind
-endfunction
+ return this_indent
+enddef
-" vim:sw=4
+# vim:sw=4