From d944c79848a29ac58cc1e435e81a795bb6d16c18 Mon Sep 17 00:00:00 2001 From: Mick Koch Date: Fri, 30 Aug 2013 15:24:09 -0400 Subject: [PATCH] Add coffee_indent_keep_current (#98) --- Readme.md | 17 +++++++++++++++++ indent/coffee.vim | 13 ++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 0e119c0..1cc404a 100644 --- a/Readme.md +++ b/Readme.md @@ -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: diff --git a/indent/coffee.vim b/indent/coffee.vim index 9be5fa6..8464742 100644 --- a/indent/coffee.vim +++ b/indent/coffee.vim @@ -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 @@ -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