Hello! I have a rather noob question: suppose I have code like this:
(let [x (->>
[1 2 3 4]
(map inc))])
I'd like to add another function to end of the threading macro. What's the easiest way to do this in emacs? I've found I can navigate the right paren (the closing for threading macro) and press enter to land in the right spot, but that's tedious if there's a lot of parens at the end of the line.
emacs won't let the cursor to be at the position without text, so I can't just C-n at the right position. I wonder if there's a command that would let me put the point at (map opening paren there, and do what I intend to. Could you help me please?
UP: the result I'm looking for is something like
(let [x (->>
[1 2 3 4]
(map inc)
(filter odd?))])I put my cursor on that line and then go to the beginning of the line which would be before the opening parent at map. Then forward one sexp then press enter and I have my new line which is correctly indented
Thanks @dpsutton, I guess that's what I need - sexp forward/backward
forward-sexp is the solution and depending where you are you can use whatever else. Like I sometimes just go left from the end but in your case there's many parens. It would be really easy to record this as a macro and bind to keys if you do it often
An alternate solution that sometimes works better. Just write the sexp at (map and then use transpose-sexps to move them to the correct order.
Thank you, @macroz!
If using Evil package, then % key toggles between open and closed parens.
Or use smartparens / paredit to jump around.
When using parinfer package the new expression can be typed under the last expression and parinfer takes care of balancing the parens.
I'm using parinfer-rust, and indeed that's true -- the only problem is that I have to pad stuff with whitespace so I can type right under the last expression.
It's alright though, @dpsutton’s suggestion on forward-sexp/backward-sexp usage works like a charm. 🙂 Thank you for replying @jr0cket!
avy to jump to the closing parenthesis of (map inc), then, electric-pair-mode to insert both ( and ) with one key, I don't think it's possible to optimize it more
The problem is to determine which paren is the closing one, if there's something like )))])]) 🙂 . rainbow-parenthesis mode doesn't help much to be honest. Turns out, navigating to the opening paren (maybe with avy) then to closing one with forward-sexp is less mentally taxing
sure, although if there's something like )))])]), refactoring is probably needed in the first place 🙂
😄 come on, I haven't finished my first take and you're already talking about refactoring 🙂
But yeah, it's not ideal ofc.
avy works for beginning of sexp, not the end so much
Also on this meeting, @mb will discuss configuring Emacs for Clojure with https://github.com/licht1stein/babashka.el and https://github.com/licht1stein/context-transient.el.