annotate runtime/indent/falcon.vim @ 4863:c4d4f0fc12b9 v7.3.1178

updated for version 7.3.1178 Problem: Can't put all Vim config files together in one directory. Solution: Load ~/.vim/vimrc if ~/.vimrc does not exist. (Lech Lorens)
author Bram Moolenaar <bram@vim.org>
date Wed, 12 Jun 2013 20:35:58 +0200
parents 7ffc704cb7c1
children a5352e73dc00
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
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 " SETUP
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 "======================================
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 " Only load this indent file when no other was loaded.
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 if exists("b:did_indent")
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 finish
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 let b:did_indent = 1
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 setlocal nosmartindent
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 " Setup indent function and when to use it
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 setlocal indentexpr=FalconGetIndent()
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 setlocal indentkeys=0{,0},0),0],!^F,o,O,e
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 setlocal indentkeys+==~case,=~catch,=~default,=~elif,=~else,=~end,=~\"
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 " Define the appropriate indent function but only once
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 if exists("*FalconGetIndent")
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 finish
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 let s:cpo_save = &cpo
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 set cpo&vim
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33
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 " VARIABLES
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 "======================================
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 " Regex of syntax group names that are strings AND comments
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 let s:syng_strcom = '\<falcon\%(String\|StringEscape\|Comment\)\>'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 " Regex of syntax group names that are strings
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 let s:syng_string = '\<falcon\%(String\|StringEscape\)\>'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44 " Keywords to indent on
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 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
46 \ '\|for\|function\|if.*"[^"]*:.*"\|if \(\(:\)\@!.\)*$\|loop\|object\|select' .
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 \ '\|switch\|try\|while\|\w*\s*=\s*\w*([$\)'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 " Keywords to deindent on
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 let s:falcon_deindent_keywords = '^\s*\(case\|catch\|default\|elif\|else\|end\)'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51
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 " FUNCTIONS
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 "======================================
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 " Check if the character at lnum:col is inside a string
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57 function s:IsInStringOrComment(lnum, col)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 endfunction
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60
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 " INDENT ROUTINE
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 "======================================
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 function FalconGetIndent()
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 " Get the line to be indented
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 let cline = getline(v:lnum)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 " Don't reindent comments on first column
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 if cline =~ '^\/\/'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 return 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74 " Find the previous non-blank line
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 let lnum = prevnonblank(v:lnum - 1)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 " Use zero indent at the top of the file
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 if lnum == 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 return 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
81
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82 let prevline=getline(lnum)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 let ind = indent(lnum)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 let chg = 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86 " 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
87 if s:IsInStringOrComment(v:lnum, matchend(cline, '^\s*') + 1 )
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 return indent('.')
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91 " 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
92 " previous lines first double quote
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 if cline =~? '^\s*"'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 let chg = chg + &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 " If previous line started with a double quote and this one
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 " doesn't, unindent
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 if prevline =~? '^\s*"' && cline =~? '^\s*'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 let chg = chg - &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 " Indent if proper keyword
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 if prevline =~? s:falcon_indent_keywords
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 let chg = &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 " If previous line opened a parenthesis, and did not close it, indent
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 " Make sure this isn't just a function split between two lines
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 if prevline =~ ',\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 return indent(prevnonblank(v:lnum - 1)) + &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 else
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 return match(prevline, '(.*\((.*)\|[^)]\)*.*$') + 1
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 elseif prevline =~ '^[^(]*)\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 " This line closes a parenthesis. Finds opening.
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 let curr_line = prevnonblank(lnum - 1)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 while curr_line >= 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 let str = getline(curr_line)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 if str !~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 let curr_line = prevnonblank(curr_line - 1)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 else
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122 break
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 endwhile
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 if curr_line < 0
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 return -1
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 let ind = indent(curr_line)
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131 " If previous line ends in a semi-colon reset indent to previous
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 " lines setting
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
133 if prevline =~? ';\s*$' && prevnonblank(prevline) =~? ',\s*$'
4186
7ffc704cb7c1 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
134 let chg = chg - (2 * &sw)
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
135 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
137 " If previous line ended in a comma, indent again
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 if prevline =~? ',\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 let chg = chg + &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
141
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
142 " If previous line ended in a =>, indent again
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
143 if prevline =~? '=>\s*$'
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
144 let chg = chg + &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
145 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
146
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
147 " Deindent on proper keywords
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
148 if cline =~? s:falcon_deindent_keywords
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
149 let chg = chg - &sw
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
150 endif
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
151
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
152 return ind + chg
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
153 endfunction
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
154
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
155 let &cpo = s:cpo_save
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
156 unlet s:cpo_save
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2596
diff changeset
157
2596
fae782ef63dd Runtime file updates.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
158 " vim: set sw=4 sts=4 et tw=80 :