How can I execute elisp in the currently running emacs from the command line?

The following command echoes 'hi' but doesn't set 'abc in the emacs instance.

emacsclient --no-wait --eval '(message "hi") (setq abc)'

Is there a way to modify emacs from the command line?

My specific use case is to revert all buffers with a shell command.


You can either wrap your two forms in a progn:

emacsclient --no-wait --eval '(progn (message "hi") (setq abc 123))'

Or you can send them separately:

emacsclient --no-wait --eval '(message "hi")' '(setq def 456)'
  • I don't think the quoting matters. Either way, abc is not defined in emacs. The goal is for abc to be defined in the currently open emacs. – Joe Aug 3 '16 at 3:55
  • 1
    I just tried it and both of the options listed work on my machine. You're sure you've got the server running? – Dan Aug 3 '16 at 13:34
  • Ah, I had a zombie emacs process that was intercepting emacsclient. It now works like a charm – Joe Aug 4 '16 at 3:13

Your Answer

