3

In paredit mode, C-M-u (paredit-backward-up) is used to move the point

backward up out of the enclosing list

The point is parked at the beginning parenthesis of the enclosing list. My question is:

How to move up one level of sexp similarly but have the point parked at the ending parenthesis instead (if an enclosing parenthesis exists)?

I am asking is that sexp evaluation with C-x C-e (eval-last-sexp) happens at the ending parenthesis (instead of the beginning). And I'd like to repeatedly jump up to a position where I can evaluate using C-x C-e immediately. Ideally, I'd like to have a function that repeatedly jump out and stop at the top-level, where there is no enclosing parenthesis. e.g., given:

'(((how) are) ((you) (do|ing so)) far)

I'd like to move the cursor quickly to the ending parenthesis (I mean with one possibly repeated key combination, as I need to do this a lot).

'(((how) are) ((you) (doing so)) far)|

-- Update --

I needed more specif control of navigation than the end-of-defun suggested in the comments.

Below was a larger example I tested in a scheme-mode buffer, with point indicated by |:

(car '(a b c))
'xyz
'(((how) are) ((you) (do|ing so)) far)
'(atom turkey) 'or
(car '(a b c))

I tried C-M-x before at the above position, and it gives me

=> a

, which is not the sexp I am trying to evaluate.

Hitting C-M-e (end-of-defun) followed by C-x C-e produces the same result.

2
  • You can press C-M-e (end-of-defun) followed by C-x C-e, or press C-M-x without moving the cursor.
    – jagrg
    Sep 13, 2022 at 0:23
  • @jagrg Thanks. I just added some updates about C-M-x.
    – tinlyx
    Sep 13, 2022 at 0:56

2 Answers 2

2

Without Paredit, M-x up-list but it is not bound by default. You can also use C-M-u then C-M-f, but that's not a repeatable binding.

With Paredit, M-x paredit-forward-up is available on C-M-n.

1

What you need is this ...

(defalias 'eval-next-sexp
  (kbd "C-M-f C-x C-e C-M-b"))

(global-set-key (kbd "C-x C-y") 'eval-next-sexp)

What I have done is created a keyboard macro, named it, inserted it, and bound it to a custom key.

Since you are trying to learn elisp, I hope you will be able to fill in the gaps in my response.

Btw, if it is not clear to you, you need to keep doing C-M-u until you reach the sexp you want, and then do C-x C-y (which you have defined here). See Keyboard Macros.


I don't use paredit, and I am not sure if it re-defines vanilla C-M-u.

I know for a fact that smartparens redefines C-M-u in a manner that I don't like. So, I have disabled the overriding behaviour of C-M-u.

Remember, when people say C-M-u, it is the backward-up-list defined by vanilla Emacs, and NOT the C-M-u that paredit sets it to.

If paredit'sC-M-u leaves you in the "global" scope, then disable that behaviour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.