Short version: yes
Instead of C-x C-e to evaluate the expression, give it a prefix
argument. C-u C-x C-e will print the output to the buffer.
How I found this information
You can investigate how Emacs does these things by looking in
or asking Emacs itself.
To see what a particular keybinding does, you can use C-h k
(describe-key). You were ...
Simply use (progn ). This should address your question:
emacs --eval "(progn (toggle-frame-maximized) (sr-speedbar-toggle))"
Please note that this does not execute the commands simultaneously (as you requested). It executes one command after another.
Bind this to some key.
(defun foo ()
"Replace sexp before point by result of its evaluation."
(let ((result (pp-to-string (eval (pp-last-sexp) lexical-binding))))
(delete-region (save-excursion (backward-sexp) (point)) (point))
use C-u M-: insert the result into current buffer instead of printing it in the echo area.
(eval-expression EXP &optional INSERT-VALUE)
Evaluate EXP and print value in the echo area.
When called interactively, read an Emacs Lisp expression and evaluate it.
Value is also consed on to front of the variable ‘values’.
If the resulting value is an integer, ...
These are alternative representations of an integer with their reader literals for octal, hexadecimal and char notation. In other words, evaluating the octal number #o4, hexadecimal number #x4 or char ?\C-d yields 4.
edit: FWIW, this behaviour seems to be a bug and should be fixed on master (and hopefully become part of the upcoming 25.1 release).
The emacs way is to ask emacs:
C-h k C-x C-e
C-x C-e runs the command eval-last-sexp (found in global-map), which
is an interactive compiled Lisp function in `elisp-mode.el'.
It is bound to C-x C-e.
Probably introduced at or before Emacs version 24.4.
Evaluate sexp before point; print value in the echo area.
Two possibilities that I am aware of.
In the package crux https://github.com/bbatsov/crux there is a function crux-eval-and-replace which does exactly what you are asking for. If you don't want to use the whole package you can just take this function.
(defun crux-eval-and-replace ()
"Replace the preceding sexp with its value."
The savehist library is the general option for persisting variable values across sessions.
Simply enabling savehist-mode ensures that most minibuffer histories will persist, but you can also tell it to do likewise for any other variable, by adding it to savehist-additional-variables:
'(add-to-list 'savehist-additional-variables ...
You can override eval-expression-print-format to return "" or nil:
(defun eval-expression-print-format (value)
; return an empty string
See the answer by @Harald Hanche-Olsen for a way to override it temporarily.
I guess you mean M-x eval-expression, because eval is not
interactive function (command).
You can either:
define temporary function in *scratch* and then call it or
write everything you need in *scratch*, kill it and yank into minibuffer
of eval-expression or
use C-q C-j to insert new lines in minibuffer.
If you want to do an arithmetic operation and insert the value into the buffer, but don't care where you do the operation, then you can also do C-u M-: and type the operation info the minibuffer.
This blog has
(defun eval-and-replace (value)
"Evaluate the sexp at point and replace it with its value"
(interactive (list (eval-last-sexp nil)))
You might also use calc's embedded mode if you intent to replace an expression with its result in the current buffer. C-u C-x * e when your formula / expression is on it's own on a separate line.
Otherwise mark it and type C-0 C-x * e
(Update: thanks to Dodgie, forgot to mention that) When you are finished with your mathematical manipulations type C-x * e ...
IELM allows you to set another the current buffer, take a look at your Mode Line to see which buffer your IELM is running on, I guess you changed the current buffer. You can change it back with C-c C-b (ielm-change-working-buffer). To learn more info about IELM, type C-h m (describe-mode) as usual.
I assume that the code you want to run is
(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 ...
If you don't want a permanent change, you can arrange things with a bit of advice:
(defvar mute-eval-expression-print-format nil
"Set to t to mute eval-expression-print-format")
(defun mute-eval-expression-print-format (orig-fun value)
(funcall orig-fun value)))
For file history, if you enable ido-mode and customize ido-use-virtual-buffers to t, even closed buffers remain in the ido history. This persists across desktop.el sessions.
C-k during an ido-switch-buffer removes the selected buffer from the history, if you need to get it out of your way.
When you evaluate (insert "qwerty") the lisp reader creates a string object with the literal value "qwerty". No input method functionality is able to intervene there.
The input method has already done its work by the time a character is inserted into a buffer, such that (using your example) typing q would result in (insert "a"), not (insert "q").
You can use select-frame-set-input-focus to give focus to a given frame:
emacsclient --eval '(progn
But, if you only want to open a file, don't use --eval:
emacsclient -c file.txt
To use rainbow-mode in clojure-mode only under a certain directory, add a .dir-locals.el file to the directory, containing:
((clojure-mode . ((eval . (rainbow-mode 1)))))
You can also use M-x add-dir-local-variable to create/edit the file.
Note that eval is a pseudo-variable used to evaluate elisp.
Alternatively, with the file in the project root:
It seems it's intended:
(setq helm-debug nil)
thus whenever a helm session ends, helm-debug will be reset to nil. I guess it's because the log buffer can grow too quickly.
Instead of changing helm-debug directly, according to helm's own help (you can get it by type C-h m within any helm session, I have ...
Sort-of solution: emacsclient -a '' ...
Looking at the automatic links appearing at the right of the question, I saw a question not seen before: emacsclient - Opening frames from emacs-daemon - Emacs Stack Exchange. User there uses emacsclient -a '' ... which incidentally solves the issue.
I guess it allows emacsclient to assume that callee is a real ...
I'm not sure if I understand your question correctly but if you just want to have a command to delete the comments you can take the code from your referenced answer and wrap it in a function like this:
(defun delete-comments ()
(comment-kill (count-lines (point-min) (...
I will take a look to see what, if anything, I think might be done as an improvement.
C-h f icicle-pp-eval-expression tells you how to do without that function:
By default, Icicle mode remaps all key sequences that are normally
bound to `eval-expression` or `pp-eval-expression` to
`icicle-pp-eval-expression`. If you do not want this remapping, then
Try this for line 7:
(defun x (y z) (eval `(,y ',z)))
That is, ensure that the second argument is quoted in the expansion. When you call (x :m `(8)), in your version the body of x ends up as:
(eval '(:m (8)))
which obviously implies a call to the function 8. With the extra quote in the definition of x, it would try this instead:
(eval '(:m '(8)))