annotate runtime/indent/GenericIndent.vim @ 1500:ea9f418ed072 v7.1.215

updated for version 7.1-215
author vimboss
date Thu, 10 Jan 2008 21:24:39 +0000
parents 8cd729851562
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
1 " Vim indent file generic utility functions
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
2 " Language: * (various)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
3 " Maintainer: Dave Silvia <dsilvia@mchsi.com>
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
4 " Date: 6/30/2004
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
5
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
6 " SUMMARY: To use GenericIndent, indent/<your_filename>.vim would have the
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
7 " following general format:
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
8 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
9 " if exists("b:did_indent") | finish | endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
10 " let b:did_indent = 1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
11 " runtime indent/GenericIndent.vim
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
12 " let b:indentStmts=''
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
13 " let b:dedentStmts=''
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
14 " let b:allStmts=''
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
15 " setlocal indentexpr=GenericIndent()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
16 " setlocal indentkeys=<your_keys>
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
17 " call GenericIndentStmts(<your_stmts>)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
18 " call GenericDedentStmts(<your_stmts>)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
19 " call GenericAllStmts()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
20 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
21 " END SUMMARY:
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
22
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
23 " NOTE: b:indentStmts, b:dedentStmts, and b:allStmts need to be initialized
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
24 " to '' before callin the functions because 'indent.vim' explicitly
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
25 " 'unlet's b:did_indent. This means that the lists will compound if
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
26 " you change back and forth between buffers. This is true as of
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
27 " version 6.3, 6/23/2004.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
28 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
29 " NOTE: By default, GenericIndent is case sensitive.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
30 " let b:case_insensitive=1 if you want to ignore case, e.g. DOS batch files
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
31
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
32 " The function 'GenericIndent' is data driven and handles most all cases of
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
33 " indent checking if you first set up the data. To use this function follow
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
34 " the example below (taken from the file indent/MuPAD_source.vim)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
35 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
36 " Before you start, source this file in indent/<your_script>.vim to have it
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
37 " define functions for your use.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
38 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
39 "runtime indent/GenericIndent.vim
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
40 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
41 " The data is in 5 sets:
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
42 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
43 " First, set the data set 'indentexpr' to GenericIndent().
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
44 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
45 "setlocal indentexpr=GenericIndent()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
46 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
47 " Second, set the data set 'indentkeys' to the keywords/expressions that need
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
48 " to be checked for 'indenting' _as_ they typed.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
49 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
50 "setlocal indentkeys==end_proc,=else,=then,=elif,=end_if,=end_case,=until,=end_repeat,=end_domain,=end_for,=end_while,=end,o,O
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
51 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
52 " NOTE: 'o,O' at the end of the previous line says you wish to be called
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
53 " whenever a newline is placed in the buffer. This allows the previous line
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
54 " to be checked for indentation parameters.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
55 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
56 " Third, set the data set 'b:indentStmts' to the keywords/expressions that, when
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
57 " they are on a line _when_ you _press_ the _<Enter>_ key,
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
58 " you wish to have the next line indented.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
59 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
60 "call GenericIndentStmts('begin,if,then,else,elif,case,repeat,until,domain,do')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
61 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
62 " Fourth, set the data set 'b:dedentStmts' to the keywords/expressions that, when
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
63 " they are on a line you are currently typing, you wish to have that line
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
64 " 'dedented' (having already been indented because of the previous line's
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
65 " indentation).
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
66 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
67 "call GenericDedentStmts('end_proc,then,else,elif,end_if,end_case,until,end_repeat,end_domain,end_for,end_while,end')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
68 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
69 " Fifth, set the data set 'b:allStmts' to the concatenation of the third and
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
70 " fourth data sets, used for checking when more than one keyword/expression
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
71 " is on a line.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
72 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
73 "call GenericAllStmts()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
74 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
75 " NOTE: GenericIndentStmts uses two variables: 'b:indentStmtOpen' and
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
76 " 'b:indentStmtClose' which default to '\<' and '\>' respectively. You can
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
77 " set (let) these to any value you wish before calling GenericIndentStmts with
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
78 " your list. Similarly, GenericDedentStmts uses 'b:dedentStmtOpen' and
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
79 " 'b:dedentStmtClose'.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
80 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
81 " NOTE: Patterns may be used in the lists passed to Generic[In|De]dentStmts
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
82 " since each element in the list is copied verbatim.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
83 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
84 " Optionally, you can set the DEBUGGING flag within your script to have the
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
85 " debugging messages output. See below for description. This can also be set
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
86 " (let) from the command line within your editing buffer.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
87 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
88 "let b:DEBUGGING=1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
89 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
90 " See:
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
91 " :h runtime
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
92 " :set runtimepath ?
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
93 " to familiarize yourself with how this works and where you should have this
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
94 " file and your file(s) installed.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
95 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
96 " For help with setting 'indentkeys' see:
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
97 " :h indentkeys
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
98 " Also, for some good examples see 'indent/sh.vim' and 'indent/vim.vim' as
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
99 " well as files for other languages you may be familiar with.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
100 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
101 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
102 " Alternatively, if you'd rather specify yourself, you can enter
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
103 " 'b:indentStmts', 'b:dedentStmts', and 'b:allStmts' 'literally':
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
104 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
105 "let b:indentStmts='\<begin\>\|\<if\>\|\<then\>\|\<else\>\|\<elif\>\|\<case\>\|\<repeat\>\|\<until\>\|\<domain\>\|\<do\>'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
106 "let b:dedentStmts='\<end_proc\>\|\<else\>\|\<elif\>\|\<end_if\>\|\<end_case\>\|\<until\>\|\<end_repeat\>\|\<end_domain\>\|\<end_for\>\|\<end_while\>\|\<end\>'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
107 "let b:allStmts=b:indentStmts.'\|'.b:dedentStmts
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
108 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
109 " This is only useful if you have particularly different parameters for
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
110 " matching each statement.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
111
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
112 " RECAP: From indent/MuPAD_source.vim
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
113 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
114 "if exists("b:did_indent") | finish | endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
115 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
116 "let b:did_indent = 1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
117 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
118 "runtime indent/GenericIndent.vim
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
119 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
120 "setlocal indentexpr=GenericIndent()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
121 "setlocal indentkeys==end_proc,=then,=else,=elif,=end_if,=end_case,=until,=end_repeat,=end_domain,=end_for,=end_while,=end,o,O
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
122 "call GenericIndentStmts('begin,if,then,else,elif,case,repeat,until,domain,do')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
123 "call GenericDedentStmts('end_proc,then,else,elif,end_if,end_case,until,end_repeat,end_domain,end_for,end_while,end')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
124 "call GenericAllStmts()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
125 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
126 " END RECAP:
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
127
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
128 let s:hit=0
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
129 let s:lastVlnum=0
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
130 let s:myScriptName=expand("<sfile>:t")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
131
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
132 if exists("*GenericIndent")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
133 finish
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
134 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
135
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
136 function GenericAllStmts()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
137 let b:allStmts=b:indentStmts.'\|'.b:dedentStmts
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
138 call DebugGenericIndent(expand("<sfile>").": "."b:indentStmts: ".b:indentStmts.", b:dedentStmts: ".b:dedentStmts.", b:allStmts: ".b:allStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
139 endfunction
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
140
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
141 function GenericIndentStmts(stmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
142 let Stmts=a:stmts
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
143 let Comma=match(Stmts,',')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
144 if Comma == -1 || Comma == strlen(Stmts)-1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
145 echoerr "Must supply a comma separated list of at least 2 entries."
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
146 echoerr "Supplied list: <".Stmts.">"
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
147 return
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
148 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
149
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
150 if !exists("b:indentStmtOpen")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
151 let b:indentStmtOpen='\<'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
152 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
153 if !exists("b:indentStmtClose")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
154 let b:indentStmtClose='\>'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
155 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
156 if !exists("b:indentStmts")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
157 let b:indentStmts=''
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
158 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
159 if b:indentStmts != ''
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
160 let b:indentStmts=b:indentStmts.'\|'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
161 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
162 call DebugGenericIndent(expand("<sfile>").": "."b:indentStmtOpen: ".b:indentStmtOpen.", b:indentStmtClose: ".b:indentStmtClose.", b:indentStmts: ".b:indentStmts.", Stmts: ".Stmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
163 let stmtEntryBegin=0
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
164 let stmtEntryEnd=Comma
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
165 let stmtEntry=strpart(Stmts,stmtEntryBegin,stmtEntryEnd-stmtEntryBegin)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
166 let Stmts=strpart(Stmts,Comma+1)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
167 let Comma=match(Stmts,',')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
168 let b:indentStmts=b:indentStmts.b:indentStmtOpen.stmtEntry.b:indentStmtClose
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
169 while Comma != -1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
170 let stmtEntryEnd=Comma
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
171 let stmtEntry=strpart(Stmts,stmtEntryBegin,stmtEntryEnd-stmtEntryBegin)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
172 let Stmts=strpart(Stmts,Comma+1)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
173 let Comma=match(Stmts,',')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
174 let b:indentStmts=b:indentStmts.'\|'.b:indentStmtOpen.stmtEntry.b:indentStmtClose
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
175 endwhile
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
176 let stmtEntry=Stmts
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
177 let b:indentStmts=b:indentStmts.'\|'.b:indentStmtOpen.stmtEntry.b:indentStmtClose
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
178 endfunction
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
179
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
180 function GenericDedentStmts(stmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
181 let Stmts=a:stmts
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
182 let Comma=match(Stmts,',')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
183 if Comma == -1 || Comma == strlen(Stmts)-1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
184 echoerr "Must supply a comma separated list of at least 2 entries."
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
185 echoerr "Supplied list: <".Stmts.">"
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
186 return
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
187 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
188
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
189 if !exists("b:dedentStmtOpen")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
190 let b:dedentStmtOpen='\<'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
191 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
192 if !exists("b:dedentStmtClose")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
193 let b:dedentStmtClose='\>'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
194 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
195 if !exists("b:dedentStmts")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
196 let b:dedentStmts=''
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
197 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
198 if b:dedentStmts != ''
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
199 let b:dedentStmts=b:dedentStmts.'\|'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
200 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
201 call DebugGenericIndent(expand("<sfile>").": "."b:dedentStmtOpen: ".b:dedentStmtOpen.", b:dedentStmtClose: ".b:dedentStmtClose.", b:dedentStmts: ".b:dedentStmts.", Stmts: ".Stmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
202 let stmtEntryBegin=0
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
203 let stmtEntryEnd=Comma
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
204 let stmtEntry=strpart(Stmts,stmtEntryBegin,stmtEntryEnd-stmtEntryBegin)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
205 let Stmts=strpart(Stmts,Comma+1)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
206 let Comma=match(Stmts,',')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
207 let b:dedentStmts=b:dedentStmts.b:dedentStmtOpen.stmtEntry.b:dedentStmtClose
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
208 while Comma != -1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
209 let stmtEntryEnd=Comma
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
210 let stmtEntry=strpart(Stmts,stmtEntryBegin,stmtEntryEnd-stmtEntryBegin)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
211 let Stmts=strpart(Stmts,Comma+1)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
212 let Comma=match(Stmts,',')
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
213 let b:dedentStmts=b:dedentStmts.'\|'.b:dedentStmtOpen.stmtEntry.b:dedentStmtClose
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
214 endwhile
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
215 let stmtEntry=Stmts
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
216 let b:dedentStmts=b:dedentStmts.'\|'.b:dedentStmtOpen.stmtEntry.b:dedentStmtClose
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
217 endfunction
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
218
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
219 " Debugging function. Displays messages in the command area which can be
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
220 " reviewed using ':messages'. To turn it on use ':let b:DEBUGGING=1'. Once
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
221 " on, turn off by using ':let b:DEBUGGING=0. If you don't want it at all and
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
222 " feel it's slowing down your editing (you must have an _awfully_ slow
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
223 " machine!;-> ), you can just comment out the calls to it from 'GenericIndent'
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
224 " below. No need to remove the function or the calls, tho', as you never can
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
225 " tell when they might come in handy!;-)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
226 function DebugGenericIndent(msg)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
227 if exists("b:DEBUGGING") && b:DEBUGGING
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
228 echomsg '['.s:hit.']'.s:myScriptName."::".a:msg
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
229 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
230 endfunction
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
231
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
232 function GenericIndent()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
233 " save ignore case option. Have to set noignorecase for the match
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
234 " functions to do their job the way we want them to!
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
235 " NOTE: if you add a return to this function be sure you do
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
236 " if IgnoreCase | set ignorecase | endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
237 " before returning. You can just cut and paste from here.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
238 let IgnoreCase=&ignorecase
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
239 " let b:case_insensitive=1 if you want to ignore case, e.g. DOS batch files
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
240 if !exists("b:case_insensitive")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
241 set noignorecase
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
242 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
243 " this is used to let DebugGenericIndent display which invocation of the
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
244 " function goes with which messages.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
245 let s:hit=s:hit+1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
246 let lnum=v:lnum
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
247 let cline=getline(lnum)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
248 let lnum=prevnonblank(lnum)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
249 if lnum==0 | if IgnoreCase | set ignorecase | endif | return 0 | endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
250 let pline=getline(lnum)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
251 let ndnt=indent(lnum)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
252 if !exists("b:allStmts")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
253 call GenericAllStmts()
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
254 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
255
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
256 call DebugGenericIndent(expand("<sfile>").": "."cline=<".cline.">, pline=<".pline.">, lnum=".lnum.", v:lnum=".v:lnum.", ndnt=".ndnt)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
257 if lnum==v:lnum
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
258 " current line, only check dedent
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
259 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
260 " just dedented this line, don't need to do it again.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
261 " another dedentStmts was added or an end%[_*] was completed.
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
262 if s:lastVlnum==v:lnum
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
263 if IgnoreCase | set ignorecase | endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
264 return ndnt
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
265 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
266 let s:lastVlnum=v:lnum
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
267 call DebugGenericIndent(expand("<sfile>").": "."Checking dedent")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
268 let srcStr=cline
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
269 let dedentKeyBegin=match(srcStr,b:dedentStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
270 if dedentKeyBegin != -1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
271 let dedentKeyEnd=matchend(srcStr,b:dedentStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
272 let dedentKeyStr=strpart(srcStr,dedentKeyBegin,dedentKeyEnd-dedentKeyBegin)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
273 "only dedent if it's the beginning of the line
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
274 if match(srcStr,'^\s*\<'.dedentKeyStr.'\>') != -1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
275 call DebugGenericIndent(expand("<sfile>").": "."It's the beginning of the line, dedent")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
276 let ndnt=ndnt-&shiftwidth
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
277 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
278 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
279 call DebugGenericIndent(expand("<sfile>").": "."dedent - returning ndnt=".ndnt)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
280 else
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
281 " previous line, only check indent
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
282 call DebugGenericIndent(expand("<sfile>").": "."Checking indent")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
283 let srcStr=pline
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
284 let indentKeyBegin=match(srcStr,b:indentStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
285 if indentKeyBegin != -1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
286 " only indent if it's the last indentStmts in the line
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
287 let allKeyBegin=match(srcStr,b:allStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
288 let allKeyEnd=matchend(srcStr,b:allStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
289 let allKeyStr=strpart(srcStr,allKeyBegin,allKeyEnd-allKeyBegin)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
290 let srcStr=strpart(srcStr,allKeyEnd)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
291 let allKeyBegin=match(srcStr,b:allStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
292 if allKeyBegin != -1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
293 " not the end of the line, check what is and only indent if
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
294 " it's an indentStmts
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
295 call DebugGenericIndent(expand("<sfile>").": "."Multiple words in line, checking if last is indent")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
296 while allKeyBegin != -1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
297 let allKeyEnd=matchend(srcStr,b:allStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
298 let allKeyStr=strpart(srcStr,allKeyBegin,allKeyEnd-allKeyBegin)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
299 let srcStr=strpart(srcStr,allKeyEnd)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
300 let allKeyBegin=match(srcStr,b:allStmts)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
301 endwhile
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
302 if match(b:indentStmts,allKeyStr) != -1
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
303 call DebugGenericIndent(expand("<sfile>").": "."Last word in line is indent")
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
304 let ndnt=ndnt+&shiftwidth
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
305 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
306 else
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
307 " it's the last indentStmts in the line, go ahead and indent
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
308 let ndnt=ndnt+&shiftwidth
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
309 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
310 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
311 call DebugGenericIndent(expand("<sfile>").": "."indent - returning ndnt=".ndnt)
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
312 endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
313 if IgnoreCase | set ignorecase | endif
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
314 return ndnt
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
315 endfunction
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
316
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
317
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
318 " TODO: I'm open!
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
319 "
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
320 " BUGS: You tell me! Probably. I just haven't found one yet or haven't been
125e80798a85 updated for version 7.0021
vimboss
parents: 12
diff changeset
321 " told about one.
856
8cd729851562 updated for version 7.0g
vimboss
parents: 36
diff changeset
322 "