In this "Emacs Rocks" video relating to the library multiple-cursors ( https://github.com/magnars/multiple-cursors.el ), the author demonstrates a way of swiftly performing calculations, getting the result in the main window (not in the mini buffer). However, he does not explain what commands are being used. I haven't been able to replicate them, having consulted the available documentation.

Any ideas on how he does it?

  • 4
    He does explain what commands are being used, by the way: just look at the list under the embedded video. – Constantine Nov 19 '14 at 1:54

The idea is to evaluate some Elisp inline and replace it with the result. It looks like he did it with a custom function he defined and bound to C-x C-e.

Note that C-x C-e is bound to eval-last-sexp by default, which does something very similar. It evaluates the s-expression just before your cursor. If you call it with a prefix argument, it will paste the result into the current buffer, but it won't delete the expression. So play around with it:

(* 100 200)

Put your cursor at the end of that and do C-u C-x C-e to get:

(* 100 200)20000
  • Great. Thanks for the answer and explanation. – NVaughan Nov 19 '14 at 2:05
  • The latest version of smex causes some trouble invoking this function for all cursors, but it works fine when you bind it to a key chord. – Lenar Hoyt Nov 25 '14 at 18:09

The same Emacs Rocks page links to an implementation of eval-and-replace used to replace a sexp with its value in this episode.


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.