annotate runtime/indent/falcon.vim @ 3660:bdf7f3e4c763 v7.3.590

updated for version 7.3.590 Problem: The '< and '> marks cannot be set directly. Solution: Allow setting '< and '>. (Christian Brabandt)
author Bram Moolenaar <bram@vim.org>
date Fri, 06 Jul 2012 17:51:28 +0200
parents 8b8ef1fed009
children 7ffc704cb7c1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim indent file
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Language: Falcon
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 " Maintainer: Steven Oliver <oliver.steven@gmail.com>
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4 " Website: https://steveno@github.com/steveno/falconpl-vim.git
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 " Credits: Thanks to the ruby.vim authors, I borrow a lot!
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 " Previous Maintainer: Brent A. Fulgham <bfulgham@debian.org>
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 " -----------------------------------------------------------
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 " GetLatestVimScripts: 2752 1 :AutoInstall: falcon.vim
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 "======================================
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 " SETUP
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12 "======================================
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 " Only load this indent file when no other was loaded.
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 if exists("b:did_indent")
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 finish
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18 let b:did_indent = 1
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20 setlocal nosmartindent
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 " Setup indent function and when to use it
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 setlocal indentexpr=FalconGetIndent()
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 setlocal indentkeys=0{,0},0),0],!^F,o,O,e
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25 setlocal indentkeys+==~case,=~catch,=~default,=~elif,=~else,=~end,=~\"
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 " Define the appropriate indent function but only once
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 if exists("*FalconGetIndent")
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 finish
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 let s:cpo_save = &cpo
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33 set cpo&vim
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 "======================================
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 " VARIABLES
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 "======================================
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 " Regex of syntax group names that are strings AND comments
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 let s:syng_strcom = '\<falcon\%(String\|StringEscape\|Comment\)\>'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 " Regex of syntax group names that are strings
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 let s:syng_string = '\<falcon\%(String\|StringEscape\)\>'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 " Keywords to indent on
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 let s:falcon_indent_keywords = '^\s*\(case\|catch\|class\|enum\|default\|elif\|else' .
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 \ '\|for\|function\|if.*"[^"]*:.*"\|if \(\(:\)\@!.\)*$\|loop\|object\|select' .
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 \ '\|switch\|try\|while\|\w*\s*=\s*\w*([$\)'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 " Keywords to deindent on
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 let s:falcon_deindent_keywords = '^\s*\(case\|catch\|default\|elif\|else\|end\)'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 "======================================
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 " FUNCTIONS
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 "======================================
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 " Check if the character at lnum:col is inside a string
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 function s:IsInStringOrComment(lnum, col)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 endfunction
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62 "======================================
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 " INDENT ROUTINE
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 "======================================
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 function FalconGetIndent()
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 " Get the line to be indented
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 let cline = getline(v:lnum)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 " Don't reindent comments on first column
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 if cline =~ '^\/\/'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 return 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 " Find the previous non-blank line
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 let lnum = prevnonblank(v:lnum - 1)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 " Use zero indent at the top of the file
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 if lnum == 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 return 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
81 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 let prevline=getline(lnum)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 let ind = indent(lnum)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85 let chg = 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 " If we are in a multi-line string or line-comment, don't do anything
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 if s:IsInStringOrComment(v:lnum, matchend(cline, '^\s*') + 1 )
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 return indent('.')
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92 " If the start of the line equals a double quote, then indent to the
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 " previous lines first double quote
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 if cline =~? '^\s*"'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 let chg = chg + &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 " If previous line started with a double quote and this one
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 " doesn't, unindent
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 if prevline =~? '^\s*"' && cline =~? '^\s*'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 let chg = chg - &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 " Indent if proper keyword
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 if prevline =~? s:falcon_indent_keywords
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 let chg = &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 " If previous line opened a parenthesis, and did not close it, indent
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 " Make sure this isn't just a function split between two lines
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 if prevline =~ ',\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 return indent(prevnonblank(v:lnum - 1)) + &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 else
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 return match(prevline, '(.*\((.*)\|[^)]\)*.*$') + 1
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 elseif prevline =~ '^[^(]*)\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 " This line closes a parenthesis. Finds opening.
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 let curr_line = prevnonblank(lnum - 1)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 while curr_line >= 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 let str = getline(curr_line)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 if str !~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 let curr_line = prevnonblank(curr_line - 1)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122 else
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 break
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 endwhile
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 if curr_line < 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 return -1
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 let ind = indent(curr_line)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 " If previous line ends in a semi-colon reset indent to previous
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 " lines setting
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
134 if prevline =~? ';\s*$' && prevnonblank(prevline) =~? ',\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 return chg = chg - (2 * &sw)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
137
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 " If previous line ended in a comma, indent again
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 if prevline =~? ',\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 let chg = chg + &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
141 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 " If previous line ended in a =>, indent again
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 if prevline =~? '=>\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145 let chg = chg + &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 " Deindent on proper keywords
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 if cline =~? s:falcon_deindent_keywords
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 let chg = chg - &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 return ind + chg
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154 endfunction
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
155
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
156 let &cpo = s:cpo_save
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
157 unlet s:cpo_save
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
158
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
159 " vim: set sw=4 sts=4 et tw=80 :