I tried to make it easier to transpose sexps in both directions. However, to do so, I initially had to use some functions from evil. If anyone could advise me on making this work without the functions:
- evil-a-paren
- evil-jump-item
...I would appreciate it.
(defun transpose-sexps-backward (arg &optional interactive)
"Transpose a sexp backward and position cursor to do it again."
(interactive "*p\nd") ; What does this mean?
; copied form transpose-sexps
(pcase-let* ((`(,begin ,end ,type) (evil-a-paren)))
(goto-char begin)
;;(message "arg %s interactive %s" arg interactive)
(transpose-sexps arg interactive)
(goto-char (- (point) 1))
(evil-jump-item) ; %
(backward-sexp) ; put cursor on opening paren
))
(defun transpose-sexps-forward (arg &optional interactive)
"Transpose a sexp forward and position the cursor to do it again."
(interactive "*p\nd")
(unless (eq 41 (char-before)) ; 41 = closing paren
(pcase-let* ((`(,begin ,end ,type) (evil-a-paren)))
(goto-char (+ end 1))))
(condition-case nil
(transpose-sexps arg interactive)
(user-error (message "can't go further.")))
(backward-char) ; put cursor on closing paren
)
Recommended Keybindings:
(evil-define-key '(normal visual) paredit-mode-map
(kbd "C-(") #'transpose-sexps-backward ; override paredit-backward-slurp-sexp
(kbd "C-)") #'transpose-sexps-forward ; override paredit-forward-slurp-sexp
)