Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It depends on your Atom config and your Emacs config, I imagine.

When I paste things into Atom or Jetbrains' Webstorm, my javascript usually gets auto-indented to The Right Place. Atom even did that when I _reordered_ lines, which was especially neat as I hadn't had Webstorm do it. This isn't something that my Emacs will do. I'd be _very_ surprised if there weren't some module, script, or Emacs configuration that I could use (or write) to get this same behavior. After all, Emacs' "Tab to The Right Indentation" was something that blew my mind years ago.

(Disclaimer: I have used Atom, but prefer Webstorm. I use Emacs, but only for Git things and the occasional quick edit.)



Not that you should have to know this, but for completeness' sake:

Out of the box in Emacs (with no config or extensions) you can simply select the pasted region and hit Tab to reindent the whole area correctly (what you called 'Tab to the Right Indentation').

So in total:

* C-SPC (Mark)

* C-y (yank/paste)

* C-x C-x (select to mark, essentially)

* Tab (indent)

(https://xkcd.com/378/)

Does what you'd like. This is all compositional, no magic here (and of course you can bind this all to one key press). Naturally lots of people make this auto-indent by default.

For me the most essential thing to know about those auto-indent modes is how to temporarily turn them off (like `:set paste` in Vim), since I so often need to bypass that behaviour for one reason or another (e.g. when resolving Git merges - trying to keep the original formatting).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: