Skip to content

Commit

Permalink
Retain indentation level of previous line.
Browse files Browse the repository at this point in the history
Before, if GetCoffeeIndent didn't detect the need to indent / outdent,
it would return -1. Now it returns the indentation level of the previous
line if it exists. This makes for more convenient behavior when typing
'cc' on an empty line below an indented line, and matches how other
vim extensions such as javascript behave.
  • Loading branch information
nathansobo committed Jan 12, 2012
1 parent 2591fef commit 2a691d9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions indent/coffee.vim
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,12 @@ function! s:GetCoffeeIndent(curlinenum)
endif
endif

" Keep the current indent.
return -1
" If no indent / outdent is needed, keep the indentation level of the previous line if possible
if previndent
return previndent
else
return -1
endif
endfunction

" Wrap s:GetCoffeeIndent to keep the cursor position.
Expand Down

2 comments on commit 2a691d9

@mgutz
Copy link

@mgutz mgutz commented on 2a691d9 Jan 29, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduced an annoying side-effect. When you add or open a line in a comment block the new line is indented. Example

# four score
  # and seven years ago

@kchmck
Copy link
Owner

@kchmck kchmck commented on 2a691d9 Jan 30, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know. I'm working on a fix.

Please sign in to comment.