Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76fe007

Browse files
committed
Use snake_case for script local function names
Only public user functions need to be capitalized; this is a useful rule as typing a bare `call lower_case()` will result in a syntax error at script evaluation time.
1 parent 1cfbf2f commit 76fe007

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

‎indent/clojure.vim

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,30 @@ if exists("*searchpairpos")
5757
let g:clojure_align_subforms = 0
5858
endif
5959

60-
function! s:SynIdName()
60+
function! s:syn_id_name()
6161
return synIDattr(synID(line("."), col("."), 0), "name")
6262
endfunction
6363

64-
function! s:CurrentChar()
64+
function! s:ignored_region()
65+
return s:syn_id_name() =~? '\vstring|regex|comment|character'
66+
endfunction
67+
68+
function! s:current_char()
6569
return getline('.')[col('.')-1]
6670
endfunction
6771

68-
function! s:CurrentWord()
72+
function! s:current_word()
6973
return getline('.')[col('.')-1 : searchpos('\v>', 'n', line('.'))[1]-2]
7074
endfunction
7175

72-
function! s:IsParen()
73-
return s:CurrentChar() =~# '\v[\(\)\[\]\{\}]' &&
74-
\ s:SynIdName() !~? '\vstring|regex|comment|character'
76+
function! s:is_paren()
77+
return s:current_char() =~# '\v[\(\)\[\]\{\}]' && !s:ignored_region()
7578
endfunction
7679

7780
" Returns 1 if string matches a pattern in 'patterns', which may be a
7881
" list of patterns, or a comma-delimited string of implicitly anchored
7982
" patterns.
80-
function! s:MatchesOne(patterns, string)
83+
function! s:match_one(patterns, string)
8184
let list = type(a:patterns) == type([])
8285
\ ? a:patterns
8386
\ : map(split(a:patterns, ','), '"^" . v:val . "$"')
@@ -86,7 +89,7 @@ if exists("*searchpairpos")
8689
endfor
8790
endfunction
8891

89-
function! s:MatchPairs(open, close, stopat)
92+
function! s:match_pairs(open, close, stopat)
9093
" Stop only on vector and map [ resp. {. Ignore the ones in strings and
9194
" comments.
9295
if a:stopat == 0
@@ -95,11 +98,11 @@ if exists("*searchpairpos")
9598
let stopat = a:stopat
9699
endif
97100

98-
let pos = searchpairpos(a:open, '', a:close, 'bWn', "!s:IsParen()", stopat)
101+
let pos = searchpairpos(a:open, '', a:close, 'bWn', "!s:is_paren()", stopat)
99102
return [pos[0], virtcol(pos)]
100103
endfunction
101104

102-
function! s:ClojureCheckForStringWorker()
105+
function! s:clojure_check_for_string_worker()
103106
" Check whether there is the last character of the previous line is
104107
" highlighted as a string. If so, we check whether it's a ". In this
105108
" case we have to check also the previous character. The " might be the
@@ -113,17 +116,17 @@ if exists("*searchpairpos")
113116

114117
call cursor(nb, 0)
115118
call cursor(0, col("$") - 1)
116-
if s:SynIdName() !~? "string"
119+
if s:syn_id_name() !~? "string"
117120
return -1
118121
endif
119122

120123
" This will not work for a " in the first column...
121-
if s:CurrentChar() == '"'
124+
if s:current_char() == '"'
122125
call cursor(0, col("$") - 2)
123-
if s:SynIdName() !~? "string"
126+
if s:syn_id_name() !~? "string"
124127
return -1
125128
endif
126-
if s:CurrentChar() != '\\'
129+
if s:current_char() != '\\'
127130
return -1
128131
endif
129132
call cursor(0, col("$") - 1)
@@ -138,51 +141,51 @@ if exists("*searchpairpos")
138141
return indent(".")
139142
endfunction
140143

141-
function! s:CheckForString()
144+
function! s:check_for_string()
142145
let pos = getpos('.')
143146
try
144-
let val = s:ClojureCheckForStringWorker()
147+
let val = s:clojure_check_for_string_worker()
145148
finally
146149
call setpos('.', pos)
147150
endtry
148151
return val
149152
endfunction
150153

151-
function! s:StripNamespaceAndMacroChars(word)
154+
function! s:strip_namespace_and_macro_chars(word)
152155
return substitute(a:word, "\\v%(.*/|[#'`~@^,]*)(.*)", '1円', '')
153156
endfunction
154157

155-
function! s:ClojureIsMethodSpecialCaseWorker(position)
158+
function! s:clojure_is_method_special_case_worker(position)
156159
" Find the next enclosing form.
157160
call search('\S', 'Wb')
158161

159162
" Special case: we are at a '(('.
160-
if s:CurrentChar() == '('
163+
if s:current_char() == '('
161164
return 0
162165
endif
163166
call cursor(a:position)
164167

165-
let nextParen = s:MatchPairs('(', ')', 0)
168+
let next_paren = s:match_pairs('(', ')', 0)
166169

167170
" Special case: we are now at toplevel.
168-
if nextParen == [0, 0]
171+
if next_paren == [0, 0]
169172
return 0
170173
endif
171-
call cursor(nextParen)
174+
call cursor(next_paren)
172175

173176
call search('\S', 'W')
174-
let w = s:StripNamespaceAndMacroChars(s:CurrentWord())
177+
let w = s:strip_namespace_and_macro_chars(s:current_word())
175178
if g:clojure_special_indent_words =~# '\V\<' . w . '\>'
176179
return 1
177180
endif
178181

179182
return 0
180183
endfunction
181184

182-
function! s:IsMethodSpecialCase(position)
185+
function! s:is_method_special_case(position)
183186
let pos = getpos('.')
184187
try
185-
let val = s:ClojureIsMethodSpecialCaseWorker(a:position)
188+
let val = s:clojure_is_method_special_case_worker(a:position)
186189
finally
187190
call setpos('.', pos)
188191
endtry
@@ -197,7 +200,7 @@ if exists("*searchpairpos")
197200

198201
" We have to apply some heuristics here to figure out, whether to use
199202
" normal lisp indenting or not.
200-
let i = s:CheckForString()
203+
let i = s:check_for_string()
201204
if i > -1
202205
return i + !!g:clojure_align_multiline_strings
203206
endif
@@ -207,9 +210,9 @@ if exists("*searchpairpos")
207210
" Find the next enclosing [ or {. We can limit the second search
208211
" to the line, where the [ was found. If no [ was there this is
209212
" zero and we search for an enclosing {.
210-
let paren = s:MatchPairs('(', ')', 0)
211-
let bracket = s:MatchPairs('\[', '\]', paren[0])
212-
let curly = s:MatchPairs('{', '}', bracket[0])
213+
let paren = s:match_pairs('(', ')', 0)
214+
let bracket = s:match_pairs('\[', '\]', paren[0])
215+
let curly = s:match_pairs('{', '}', bracket[0])
213216

214217
" In case the curly brace is on a line later then the [ or - in
215218
" case they are on the same line - in a higher column, we take the
@@ -246,7 +249,7 @@ if exists("*searchpairpos")
246249
" - In any other case we use the column of the end of the word + 2.
247250
call cursor(paren)
248251

249-
if s:IsMethodSpecialCase(paren)
252+
if s:is_method_special_case(paren)
250253
return paren[1] + &shiftwidth - 1
251254
endif
252255

@@ -257,7 +260,7 @@ if exists("*searchpairpos")
257260

258261
" In case after the paren is a whitespace, we search for the next word.
259262
call cursor(0, col('.') + 1)
260-
if s:CurrentChar() == ' '
263+
if s:current_char() == ' '
261264
call search('\v\S', 'W')
262265
endif
263266

@@ -269,7 +272,7 @@ if exists("*searchpairpos")
269272

270273
" We still have to check, whether the keyword starts with a (, [ or {.
271274
" In that case we use the ( position for indent.
272-
let w = s:CurrentWord()
275+
let w = s:current_word()
273276
if stridx('([{', w[0]) > -1
274277
return paren[1]
275278
endif
@@ -278,15 +281,15 @@ if exists("*searchpairpos")
278281
" metacharacters.
279282
"
280283
" e.g. clojure.core/defn and #'defn should both indent like defn.
281-
let ww = s:StripNamespaceAndMacroChars(w)
284+
let ww = s:strip_namespace_and_macro_chars(w)
282285

283286
if &lispwords =~# '\V\<' . ww . '\>'
284287
return paren[1] + &shiftwidth - 1
285288
endif
286289

287290
if g:clojure_fuzzy_indent
288-
\ && !s:MatchesOne(g:clojure_fuzzy_indent_blacklist, ww)
289-
\ && s:MatchesOne(g:clojure_fuzzy_indent_patterns, ww)
291+
\ && !s:match_one(g:clojure_fuzzy_indent_blacklist, ww)
292+
\ && s:match_one(g:clojure_fuzzy_indent_patterns, ww)
290293
return paren[1] + &shiftwidth - 1
291294
endif
292295

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /