annotate runtime/indent/ishd.vim @ 10151:0be17a56e65f v7.4.2346

commit https://github.com/vim/vim/commit/f18c4dbbe545757ce93563b25380e6f010340b4e Author: Bram Moolenaar <Bram@vim.org> Date: Thu Sep 8 22:10:06 2016 +0200 patch 7.4.2346 Problem: Autocommand test fails when run directly, passes when run as part of test_alot. Solution: Add command to make the cursor move. Close a tab page.
author Christian Brabandt <cb@256bit.org>
date Thu, 08 Sep 2016 22:15:06 +0200
parents a686fd6c8beb
children 63b0b7b79b25
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Description: InstallShield indenter
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Author: Johannes Zellner <johannes@zellner.org>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Last Change: Tue, 27 Apr 2004 14:54:59 CEST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10
234
a686fd6c8beb updated for version 7.0065
vimboss
parents: 7
diff changeset
11 setlocal autoindent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 setlocal indentexpr=GetIshdIndent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 setlocal indentkeys&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 setlocal indentkeys+==else,=elseif,=endif,=end,=begin,<:>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " setlocal indentkeys-=0#
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
234
a686fd6c8beb updated for version 7.0065
vimboss
parents: 7
diff changeset
17 let b:undo_indent = "setl ai< indentexpr< indentkeys<"
a686fd6c8beb updated for version 7.0065
vimboss
parents: 7
diff changeset
18
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 if exists("*GetIshdIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 fun! GetIshdIndent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 " labels and preprocessor get zero indent immediately
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let this_line = getline(a:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 let LABELS_OR_PREPROC = '^\s*\(\<\k\+\>:\s*$\|#.*\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 let LABELS_OR_PREPROC_EXCEPT = '^\s*\<default\+\>:'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 if this_line =~ LABELS_OR_PREPROC && this_line !~ LABELS_OR_PREPROC_EXCEPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 " Find a non-blank line above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 " Skip over labels and preprocessor directives.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let lnum = a:lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 while lnum > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let lnum = prevnonblank(lnum - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let previous_line = getline(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 if previous_line !~ LABELS_OR_PREPROC || previous_line =~ LABELS_OR_PREPROC_EXCEPT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 " Hit the start of the file, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 if lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 let ind = indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 " Add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 if previous_line =~ '^\s*\<\(function\|begin\|switch\|case\|default\|if.\{-}then\|else\|elseif\|while\|repeat\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 let ind = ind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 " Subtract
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 if this_line =~ '^\s*\<endswitch\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 let ind = ind - 2 * &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 elseif this_line =~ '^\s*\<\(begin\|end\|endif\|endwhile\|else\|elseif\|until\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 elseif this_line =~ '^\s*\<\(case\|default\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 if previous_line !~ '^\s*\<switch\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 let ind = ind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 return ind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 endfun