I assume that the code you want to run is
(goto-char (point-min)) (let (kill-ring) (comment-kill (count-lines (point-min) (point-max))))
Actually, the problem is not that the Lisp code contains multiple lines — that would work just fine — but that the Lisp code consists of multiple expressions that need to be executed in sequence.
M-x eval-expression requires a single expression. If you want to evaluate two expressions successively, the simplest solution, cognitively speaking, is to call M-x eval-expression twice.
M-x eval-expression RET (goto-char (point-min)) RET M-x (let (kill-ring) (comment-kill (count-lines (point-min) (point-max)))) RET
Since whitespace isn't significant in Lisp, you can put a space instead of the newline if you're typing the code. If you're copy-pasting, keeping the pasted newline is fine too.
From a Lisp perspective, the “right” solution would be to put the two expressions into a progn form. A progn expression runs each expression in sequence (and returns the value of the last one).
M-x eval-expression RET (progn (goto-char (point-min)) (let (kill-ring) (comment-kill (count-lines (point-min) (point-max))))) RET
In this particular case, there are other solutions that are simpler but don't generalize:
- Instead of running
(goto-char (point-min)), use key bindings to move to the beginning of the buffer (C-home or M-<). Since let itself allows multiple expressions (let is like progn, but first binds some variables), you could write that code
(let (kill-ring) (goto-char (point-min)) (comment-kill (count-lines (point-min) (point-max))))
Another approach would be to copy the code into the buffer you want to modify, select it, run M-x eval-region, and finally remove the code. That only works if the code you want to run wouldn't affect itself, and if the buffer is a normal, non-read-only text edition buffer.
If you're going to use that code more than once, make it a function and define it in your init file.
M-x eval-expressiongiven below isM-: