Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On pressing backspace+Enter, keep cursor indent #98

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions indent/coffee.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -184,17 +185,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.
Expand Down Expand Up @@ -243,20 +234,18 @@ 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.
if !prevlinenum
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)

Expand Down Expand Up @@ -345,7 +334,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