While writing Clojure code, I often end up with spaces between the last expression and the closing brackets. Something like
(defn myfunction
[arg]
(do
(expr1)
(expr2)|
))
where | is the position of the cursor. Is there a shortcut in Emacs to delete the spaces between (expr2) and the final brackets? The goal is to end up with
(defn myfunction
[arg]
(do
(expr1)
(expr2)))
M-^
(command delete-indentation
) already does what you requested, at least in the example you gave (and similar). See (elisp) User-Level Deletion
.
Send the prefix argument to M-^:
C-u M-^
Without the prefix, M-^ joins the current line with the previous.
With the prefix (the C-u), M-^ joins the next line with the current.
Improving on @wvxvw's comment above, you can add the following to your .emacs
file. Then, C-z m
(or any other key combination that you select) will do what you want. In fact, it will work if you're at any point of the line containing (expr1)
.
(global-set-key "\C-zm" 'join-lines-removing-spaces)
(defun join-lines-removing-spaces ()
"Join the current line with the next, removing all whitespace at this point."
(move-end-of-line nil)
(kill-line)
(delete-horizontal-space))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With