2

Is there any way to enable the following behavior. Let's say i have some code:

def main(args: List[String]): Unit = {

}

Of cause the blank line between braces is indented, but when i move cursor to that position i need to hit tab to place it on the proper column according to my indentation settings, can i enable such behavior by default? E.g in the given example, if i move cursor up or down, the cursor would be in this position:

def main(args: List[String]): Unit = {
|    
}

But i want it to be in this:

def main(args: List[String]): Unit = {
  |    
}
2

The command back-to-indentation (bound to M-m by default) moves point to the first non-whitespace character on the current line.

Arranging for it to be called whenever you move the cursor is a matter of advising the correct function. For example, the following will cause back-to-indentation to be called whenever you move up:

(advice-add 'previous-line :after #'back-to-indentation)


However, I strongly advise against such a customization: you most probably want to go to the indentation only in a limited set of occasions (maybe for whitespace-only lines?). Most of the time, you probably expect your cursor to stay on the same column when moving up or down.

  • The wrinkle is that back-to-indentation will not work on a whitespace-only line precisely because it moves to the first non-whitespace character on the line -- of which there are none. – Dan Nov 15 '14 at 23:28
  • @Dan Well, I tested that before posting and it seems to work on my setup (i.e. in whitespace-only lines, back-to-indentation moves to end of line). Doesn't it work that way in your setup? – ffevotte Nov 16 '14 at 9:50
  • you're right! It turns out that what I observed is a quirk of evil-mode rather than a quirk in back-to-indentation. – Dan Nov 16 '14 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.