Forrest logo
back to the emacsclient tool

emacsclient:tldr:07a3b

emacsclient: Evaluate a command, printing the output to `stdout`, and then quit.
$ emacsclient --eval '(${command})'
try on your machine

The command emacsclient --eval '(${command})' is used to evaluate a piece of elisp code within an Emacs server session.

Here's how it works:

  1. emacsclient: This command is used to connect to an existing Emacs server session or start a new one if it doesn't exist.

  2. --eval: This option tells emacsclient to evaluate the following elisp code.

  3. '(${command})': The code within the single quotes is the elisp code to be evaluated. ${command} is a placeholder for the actual command you want to execute within Emacs server.

The code within '(${command})' will be replaced by the desired elisp code before execution.

Let's say you want to evaluate the elisp code (message "Hello, world!") within an Emacs server session. You can use the following command:

emacsclient --eval '(message "Hello, world!")'

The emacsclient command will connect to the Emacs server, send the (message "Hello, world!") code for evaluation, and then exit.

The output of the code, in this case, would be the message "Hello, world!" displayed in the Emacs server's message area or as a notification depending on your Emacs configuration.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the emacsclient tool