3

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?

lawlist
  • 19,106
  • 5
  • 38
  • 120
NVaughan
  • 1,481
  • 12
  • 27

2 Answers2

6

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

Constantine
  • 9,122
  • 1
  • 35
  • 50
5

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
Tikhon Jelvis
  • 6,252
  • 2
  • 28
  • 41