1

In scratch file I has:

(* 60 10)
(* 50 100)
(* 50 200)

I want to use my custom function replace-last-sexp (C-c C-l)

(defun replace-last-sexp ()
(interactive)
(let ((value (eval (preceding-sexp))))
  (kill-sexp -1)
  (insert (format "%S" value))))

To do this I use multiple-cursors package - https://github.com/magnars/multiple-cursors.el

After I press C-c C-l in multiple-cursors mode I get this:

600
(* 50 100)
(* 50 200)

enter image description here

Why not calculate another lines?

3
  • Where does eval-replace-last-sexp come from? I don't have it in my emacs. If I do C-x C-e (i.e. eval-last-sexp) all three expressions get evaluated (with the results in the echo area). – NickD Dec 1 '20 at 20:39
  • I found a replace-last-sexp, bound it to C-c r and tried it: it asked me whether I wanted to apply it to all the cursors, I said "yes" and it worked. I have subsequently applied it again without having to answer any questions. – NickD Dec 1 '20 at 22:18
  • @NickD replace-last-sexp not ask me about apply to all cursors. Just replace first line – a_subscriber Dec 1 '20 at 23:16
2

I have the same issue as you. And I'm not asked if I want to apply this function to other cursors ... strange, becuase I did expect this question. Maybe there are some changes in multiple-cursors recently?

I also can't answer your "why" question.

But here is some source code, to make it do, what you expect.

(defun replace-last-sexp--internal ()
  (interactive)
  (let ((value (eval (preceding-sexp))))
    (kill-sexp -1)
    (insert (format "%S" value))))

(defun replace-last-sexp ()
  (interactive)
  (if (functionp 'mc/execute-command-for-all-cursors)
      (mc/execute-command-for-all-cursors #'replace-last-sexp--internal)
    (replace-last-sexp--internal)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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