Skip to content

Commit d944c79

Browse files
committed
Add coffee_indent_keep_current (#98)
1 parent 0f0307b commit d944c79

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,23 @@ This is the full list of configuration variables available, with example
380380
settings and default values. Use these in your vimrc to control the default
381381
behavior.
382382

383+
#### coffee\_indent\_keep\_current
384+
385+
By default, the indent function matches the indent of the previous line if it
386+
doesn't find a reason to indent or outdent. To change this behavior so it
387+
instead keeps the [current indent of the cursor][98], use
388+
389+
let coffee_indent_keep_current = 1
390+
391+
[98]: https://github.com/kchmck/vim-coffee-script/pull/98
392+
393+
*Default*: `unlet coffee_indent_keep_current`
394+
395+
Note that if you change this after a coffee file has been loaded, you'll have to
396+
reload the indent script for the change to take effect:
397+
398+
unlet b:did_indent | runtime indent/coffee.vim
399+
383400
#### coffee\_compiler
384401

385402
Path to the `coffee` executable used by the `Coffee` commands:

indent/coffee.vim

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ setlocal indentexpr=GetCoffeeIndent(v:lnum)
1515
" indented or outdented.
1616
setlocal indentkeys+=0],0),0.,=else,=when,=catch,=finally
1717

18+
" If no indenting or outdenting is needed, either keep the indent of the cursor
19+
" or match the indent of the previous line.
20+
if exists('g:coffee_indent_keep_current')
21+
let s:DEFAULT_LEVEL = '-1'
22+
else
23+
let s:DEFAULT_LEVEL = 'previndent'
24+
endif
25+
1826
" Only define the function once.
1927
if exists('*GetCoffeeIndent')
2028
finish
@@ -345,7 +353,6 @@ function! GetCoffeeIndent(curlinenum)
345353
endif
346354
endif
347355

348-
" If no indent or outdent is needed, keep the indent level of the previous
349-
" line.
350-
return previndent
356+
" No indenting or outdenting is needed so use the default policy.
357+
exec 'return' s:DEFAULT_LEVEL
351358
endfunction

0 commit comments

Comments
 (0)