I wanted to jump to the end of the current top-level S-expression as described in this question: How to move up to the ending parenthesis of the enclosing list (if it exists)?. The goal is to position the point in a location such that the current
top-level S-expression can be evaluated with
C-x C-e (and then evaluate it). Based on the answers linked above, I have the following shortcut key sequence:
(defalias 'eval-next-sexp ;; (kbd "M-m C-f C-u C-M-n C-x C-e") (kbd "M-m C-f C-u C-M-n") ) (global-set-key (kbd "C-x C-y") 'eval-next-sexp)
As I am using paredit mode,
M-m moves the cursor to the first non-whitespace position,
C-f moves one letter into the S-expression,
C-u C-M-n repeatedly moves up the hierarchy of parentheses (
paredit-forward-up) until it cannot move any further.
So far this has been (mostly) successful in moving the point to where it needs to be, and a subsequent
C-x C-e evaluates the expression.
The problem is that when I tried to combine the move and the evaluation, as shown in the commented line:
(kbd "M-m C-f C-u C-M-n C-x C-e"), the evaluation doesn't happen because the movement command generates an error when stopping:
After 0 kbd macro iterations: Scan error: "Unbalanced parentheses", 1647, 12558
My guess is that
C-u C-M-n reached top and generates an error.
The question is:
How can errors from previous commands as above be ignored and the subsequent key strokes be executed?
Additionally, is it possible to repeat a key combination/command (
C-M-n here) until an error happens? (If so, the going up can be implemented more reliably)