1

Suppose I have this structure:

((1 2 3)
 (4 5 6)
 (7 8))

I can move backward and forward sexp-by-sexp (one-by-one) with backward-sexp and forward-sexp.

However, I often have dozens of sexps to navigate, and I am looking for a command that takes me directly to the last (or first) sexp at that level. A command that takes me to the beginning or end of the enclosing sexp also works.

To illustrate using the example above, pretend I have the cursor positions start-a, end-a, start-b, and end-b.

What I want is to jump from start-a to end-a, and from start-b to end-b.

(start-a (start-b 1 2 3 end-b)
 (4 5 6)
 (7 8) end-a)

1 Answer 1

2

If it doesn't exist a ready-made function, you can create one:

(defun jump-to-last-sexp()
  "Jump to the last sexp of a sexp at current level"
   (interactive)
  (let ((pt(point)) (fwpt (progn(thing-at-point--end-of-sexp)(point))))
    (while(not(eq pt fwpt))
      (setq pt fwpt fwpt(progn(thing-at-point--end-of-sexp)(point))))))

and bind it to a keystroke

(bind-key "C-c C-e" #'jump-to-last-sexp)

or any key you like.

Your Answer

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

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