Hacker News new | past | comments | ask | show | jobs | submit login

Paredit[1] is (almost) from the gods as an AST editor. The only issue I have is that it doesn't automatically reformat your code so it is not only always syntactically correct, but also properly formatted at the same time.

[1] https://www.emacswiki.org/emacs/ParEdit




Paredit does try and keep the subtree you're editing correctly indented. Moreover, it has a paredit-reindent-defun command (bound to M-q), which reindents the whole tree you're editing. Bind it to whatever auto-reindent facility Emacs has (Electric keys? I don't know - I never had a need to configure it for myself.), and there you go. Personally, I'm fine with manual M-q on code if I see the identation got messed up.


M-q is useful, but something more useful IMO would be the same feature but one that removes unneeded white space within the sexpr between expressions and keep everything indented. A contrived example:

   (defun   x ()   
   (+ x   x)) => (defun x () 
                     (+ x x))


You can write an interactive function that runs fill-paragraph (or whatever M-q is bound to in the mode you are using), then deletes multiple spaces (something like http://stackoverflow.com/questions/8674912/how-to-collapse-w...).

That would not be a good default because some people, like me, like to align their code in columns (for example, things like let clauses).

What I would like to see come as an Emacs default is just-one-space working on regions with the behavior you describe.


What I've noticed after using paredit is that I'm doing a lot less paren matching (well none) and a lot more white space clean up, so I think such a function would be very useful to run as a hook on insert char. Since the program is always syntactically correct, it might almost work...

And @sedachv, thanks for Parenscript. It makes Javascript almost...well, now I can work it it :) Much appreciated.




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

Search: