From 0461bc53f022fb53dc0afbf0d74b96b95f0142fd Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Fri, 15 Jun 2012 16:42:48 +0300 Subject: [PATCH 1/4] On pressing backspace+Enter, keep cursor indent --- indent/coffee.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/indent/coffee.vim b/indent/coffee.vim index 6e58d5e..86a397a 100644 --- a/indent/coffee.vim +++ b/indent/coffee.vim @@ -345,7 +345,6 @@ function! GetCoffeeIndent(curlinenum) endif endif - " If no indent or outdent is needed, keep the indent level of the previous - " line. - return previndent + " If no indent or outdent is needed, keep the indent level of the cursor + return -1 endfunction From 04bad864035c14679976db7d7efaa016c85067b0 Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Sat, 4 Aug 2012 14:04:37 +0300 Subject: [PATCH 2/4] Remove special comment handling Comments seem to be handled fine without it, except their behaviour matches the new backspacing behaviour -- when the user backspaces after a comment line, their indentation is preserved when they hit "Enter". --- indent/coffee.vim | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/indent/coffee.vim b/indent/coffee.vim index 86a397a..988e739 100644 --- a/indent/coffee.vim +++ b/indent/coffee.vim @@ -184,17 +184,7 @@ endfunction " Get the nearest previous line that isn't a comment. function! s:GetPrevNormalLine(startlinenum) - let curlinenum = a:startlinenum - - while curlinenum - let curlinenum = prevnonblank(curlinenum - 1) - - if !s:IsCommentLine(curlinenum) - return curlinenum - endif - endwhile - - return 0 + return prevnonblank(a:startlinenum - 1) endfunction " Try to find a comment in a line. @@ -243,13 +233,6 @@ function! GetCoffeeIndent(curlinenum) return -1 endif - let prevlinenum = a:curlinenum - 1 - - " If continuing a comment, keep the indent level. - if s:IsCommentLine(prevlinenum) - return indent(prevlinenum) - endif - let prevlinenum = s:GetPrevNormalLine(a:curlinenum) " Don't do anything if there's no code before. From 97417981aa550f7fc1c95875a5fd7a7e4953102a Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Mon, 20 Aug 2012 14:21:50 +0300 Subject: [PATCH 3/4] set nosmartindent Smart indent seems to be useful for C, but not necessary in this case. --- indent/coffee.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/indent/coffee.vim b/indent/coffee.vim index 988e739..9cc839d 100644 --- a/indent/coffee.vim +++ b/indent/coffee.vim @@ -10,6 +10,7 @@ endif let b:did_indent = 1 setlocal autoindent +setlocal nosmartindent setlocal indentexpr=GetCoffeeIndent(v:lnum) " Make sure GetCoffeeIndent is run when these are typed so they can be " indented or outdented. From a1e8d3a1319a8c1ded021caa41df11738afaae5e Mon Sep 17 00:00:00 2001 From: Andrew Radev Date: Thu, 4 Oct 2012 16:37:06 +0300 Subject: [PATCH 4/4] Handle comments In the end, there has to be an explicit check for comments, or they get indented just like normal code. --- indent/coffee.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/indent/coffee.vim b/indent/coffee.vim index 9cc839d..12e2f3a 100644 --- a/indent/coffee.vim +++ b/indent/coffee.vim @@ -241,6 +241,11 @@ function! GetCoffeeIndent(curlinenum) return -1 endif + " If continuing a comment, keep the indent level. + if s:IsCommentLine(prevlinenum) + return -1 + endif + " Indent based on the current line. let curline = s:GetTrimmedLine(a:curlinenum)