Skip to content

Commit

Permalink
Add coffee_indent_keep_current (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
kchmck committed Aug 30, 2013
1 parent 0f0307b commit d944c79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
17 changes: 17 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,23 @@ This is the full list of configuration variables available, with example
settings and default values. Use these in your vimrc to control the default
behavior.

#### coffee\_indent\_keep\_current

By default, the indent function matches the indent of the previous line if it
doesn't find a reason to indent or outdent. To change this behavior so it
instead keeps the [current indent of the cursor][98], use

let coffee_indent_keep_current = 1

[98]: https://github.com/kchmck/vim-coffee-script/pull/98

*Default*: `unlet coffee_indent_keep_current`

Note that if you change this after a coffee file has been loaded, you'll have to
reload the indent script for the change to take effect:

unlet b:did_indent | runtime indent/coffee.vim

#### coffee\_compiler

Path to the `coffee` executable used by the `Coffee` commands:
Expand Down
13 changes: 10 additions & 3 deletions indent/coffee.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ setlocal indentexpr=GetCoffeeIndent(v:lnum)
" indented or outdented.
setlocal indentkeys+=0],0),0.,=else,=when,=catch,=finally

" If no indenting or outdenting is needed, either keep the indent of the cursor
" or match the indent of the previous line.
if exists('g:coffee_indent_keep_current')
let s:DEFAULT_LEVEL = '-1'
else
let s:DEFAULT_LEVEL = 'previndent'
endif

" Only define the function once.
if exists('*GetCoffeeIndent')
finish
Expand Down Expand Up @@ -345,7 +353,6 @@ function! GetCoffeeIndent(curlinenum)
endif
endif

" If no indent or outdent is needed, keep the indent level of the previous
" line.
return previndent
" No indenting or outdenting is needed so use the default policy.
exec 'return' s:DEFAULT_LEVEL
endfunction

0 comments on commit d944c79

Please sign in to comment.