4 ms·
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 synta
by kruhft 10y ago
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 https://www.emacswiki.org/emacs/ParEdit
- TeMPOraL 10y agoParedit 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.
- kruhft 10y agoM-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))
- sedachv 10y agoYou 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-whitespaces-in-a-region 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.
- kruhft 10y agoWhat 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.