On pressing backspace+Enter, keep cursor indent #98

Closed
wants to merge 4 commits into
from

Projects

None yet

5 participants

@AndrewRadev

When I want to "exit" a block of code while writing it, I press <backspace>. For example, I'm writing this:

if foo
  bar
  # cursor

When I press backspace, I'll get something like this:

if foo
  bar
# cursor

But then, I want to leave some space after the block, so I hit <enter>. The result is that the indent of the new line is set to the one of the last non-blank line:

if foo
  bar

  # cursor

While this seems to be a minor issue, it trips me up all the time. I suppose I should get used to leaving the space first with an <enter>, but I can't seem to do so :). In python, the behaviour is exactly as I want it to be, so I took a cue from that indent file and I tweaked this one to work like that.

I understand there may be some specific reason to have it this way. If so, I have no complaints to rejecting this PR outright.

@mattsacks
Contributor

trips me up all the time too

👍

@AndrewRadev AndrewRadev 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".
04bad86
@AndrewRadev

I also pushed a commit that makes the same behaviour work if the above line is a comment. To do that, I removed special handling of comment indentation. Everything seems to work okay after a few quick tests, but if someone notices any problems, please let me know.

@raine
raine commented Aug 18, 2012

Should this happen when I press o for new line + insert mode and type a #?

edit: found this, http://stackoverflow.com/a/2323728/303712

@AndrewRadev AndrewRadev set nosmartindent
Smart indent seems to be useful for C, but not necessary in this case.
9741798
@AndrewRadev

Seems like smartindent is meant for C -- it probably indents the # over there because it considers it a preprocessor directive. I've pushed a commit that unsets smartindent in coffeescript buffers.

@AndrewRadev AndrewRadev Handle comments
In the end, there has to be an explicit check for comments, or they get
indented just like normal code.
a1e8d3a
@summivox
summivox commented Nov 7, 2012

👍

@kchmck kchmck added a commit that referenced this pull request Aug 30, 2013
@kchmck Add coffee_indent_keep_current (#98) d944c79
@kchmck
Owner
kchmck commented Aug 30, 2013

Looking back at the history, this was actually the original behavior before 2a691d9/#69. I prefer the current behavior, but obviously it's a subjective thing, so at long last I've added a config knob coffee_indent_keep_current if you prefer it to work this way.

@kchmck kchmck closed this Aug 30, 2013
@AndrewRadev AndrewRadev deleted the AndrewRadev:improve-backspacing branch Sep 4, 2013
@AndrewRadev

Thanks, this seems like it should please both camps.

@lcharlick lcharlick added a commit to lcharlick/vim-coffee-script that referenced this pull request Feb 21, 2014
@kchmck @lcharlick + lcharlick Add coffee_indent_keep_current (#98) 711373f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment