Skip to content

Commit 0d865c5

Browse files
committed
Compress comments on indent code
1 parent 0a835d8 commit 0d865c5

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

Diff for: indent/clojure.vim

+11-22
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ set cpoptions&vim
1818

1919
let b:undo_indent = 'setlocal autoindent< smartindent< expandtab< softtabstop< shiftwidth< indentexpr< indentkeys< lisp<'
2020

21-
setlocal noautoindent nosmartindent nolisp
21+
setlocal noautoindent nosmartindent nolisp indentkeys=!,o,O
2222
setlocal softtabstop=2 shiftwidth=2 expandtab
23-
setlocal indentkeys=!,o,O
2423

2524
" Set a new configuration option with a default value. Assigns a script-local
2625
" version too, to be used as a default fallback if the global was "unlet".
@@ -60,9 +59,8 @@ call s:SConf('clojure_indent_rules', {
6059
\ 'delay': 0, 'future': 0, 'locking': 1, 'try': 0, 'catch': 2, 'finally': 0,
6160
\ 'reify': 1, 'proxy': 2, 'defrecord': 2, 'defprotocol': 1, 'definterface': 1,
6261
\ 'extend': 1, 'extend-protocol': 1, 'extend-type': 1,
63-
"\ (letfn) (1 ((:defn)) nil)
64-
"\ (deftype defrecord proxy) (2 nil nil (:defn))
65-
"\ (defprotocol definterface extend-protocol extend-type) (1 (:defn))
62+
"\ [letfn] [1 [[:defn]] nil] [deftype defrecord proxy] [2 nil nil [:defn]]
63+
"\ [defprotocol definterface extend-protocol extend-type] [1 [:defn]]
6664
"\ ClojureScript
6765
\ 'this-as': 1, 'specify': 1, 'specify!': 1,
6866
"\ clojure.test
@@ -159,9 +157,7 @@ function! s:InsideForm(lnum)
159157
let [line_tokens, possible_comment] = s:TokeniseLine(lnum)
160158

161159
" In case of comments, copy "tokens" so we can undo alterations.
162-
if possible_comment
163-
let prev_tokens = copy(tokens)
164-
endif
160+
if possible_comment | let prev_tokens = copy(tokens) | endif
165161

166162
" Reduce tokens from line "lnum" into "tokens".
167163
for tk in line_tokens
@@ -180,11 +176,9 @@ function! s:InsideForm(lnum)
180176
let first_string_pos = tk
181177
endif
182178
endif
183-
elseif in_string
184-
" In string: ignore other tokens.
179+
elseif in_string " In string: ignore other tokens.
185180
elseif possible_comment && tk[0] ==# ';'
186-
" Comment: undo previous token applications on
187-
" this line.
181+
" Comment: undo previous token applications on this line.
188182
let tokens = copy(prev_tokens)
189183
elseif ! empty(tokens) && get(s:pairs, tk[0], '') ==# tokens[-1][0]
190184
" Matching pair: drop the last item in tokens.
@@ -232,8 +226,7 @@ function! s:StringIndent(delim_pos)
232226
let is_regex = col > 1 && getline(a:delim_pos[0])[col - 2] ==# '#'
233227
return s:PosToCharCol(a:delim_pos) - (is_regex ? 2 : 1)
234228
endif
235-
else
236-
return -1 " Keep existing indent.
229+
else | return -1 " Keep existing indent.
237230
endif
238231
endfunction
239232

@@ -250,21 +243,18 @@ function! s:ListIndent(delim_pos)
250243
let ln = getline(a:delim_pos[0])
251244
let ln_content = ln[a:delim_pos[1]:]
252245
253-
let sym_match = -1
254-
255246
" 1. Macro/rule indentation
256247
" if starts with a symbol, extract it.
257248
" - Split namespace off symbol and #'/' syntax.
258249
" - Check against pattern rules and apply indent on match.
259250
" - Look up in rules table and apply indent on match.
260-
" else, not found, go to 2.
251+
" else: not found, go to 2.
261252

262-
" TODO: handle complex indentation (e.g. letfn) and introduce
263-
" indentation config similar to Emacs' clojure-mode and cljfmt.
264-
" Skip if "traditional" style was chosen.
253+
" TODO: handle complex indentation (e.g. letfn). Skip if "traditional" style was chosen?
265254

266255
" TODO: simplify this.
267256
let syms = split(ln_content, '[[:space:],;()\[\]{}@\\"^~`]', 1)
257+
let sym_match = -1
268258

269259
if ! empty(syms)
270260
let sym = syms[0]
@@ -290,8 +280,7 @@ function! s:ListIndent(delim_pos)
290280
" 2. Function indentation
291281
" if first operand is on the same line?
292282
" - Indent subsequent lines to align with first operand.
293-
" else
294-
" - Indent 1 or 2 spaces.
283+
" else: indent 1 or 2 spaces.
295284
let pos = s:FirstFnArgPos(a:delim_pos)
296285
if pos != [0, 0] | return s:PosToCharCol(pos) - 1 | endif
297286

0 commit comments

Comments
 (0)