Reputation: 361
How do I call an emacs lisp function programmatically from an inferior shell?
For instance, I'm in a shell that uses some characters that emacs recognizes and attempts to autoexpand, so I want to run this command (setq comint-input-autoexpand nil)
to apply it to the shell I'm in.
I can do this now by entering the text of the command in the shell and running something like eval-region
on it but I want my shell to be able to invoke this command itself.
Thanks to the people who responded but it seems my question is unclear. I can accomplish what I want by entering an elisp expression, selecting it, and calling 'eval-region' on it but this requires manual input. What I want is a way to automate this so my shell can send emacs a command to change its own settings.
The "emacsclient" suggestion seems like it's in the right direction but I'm afraid that Windows does not fully support its options and it's unclear that such a command would affect the buffer from which I invoke it since I would do so via an external "shell" command.
What I want is some sort of escape sequence that signals emacs "This elisp expression is for you". I'm guessing there might be a way to open a socket to emacs and send it commands this way but I still have the problem of selecting the buffer to which to apply the command. Again, this is probably more difficult/impossible in Windows, so I will rely on my command bound to a key sequence for now.
Upvotes: 4
Views: 836
Reputation: 66059
You can use emacsclient to do it. You'll need to have started emacs as a server, either with (server-start)
in your .emacs
or by starting emacs as a background process with --daemon
.
You can evaluate elisp code in your shell like this:
emacsclient --eval '(setq comint-input-autoexpand nil)'
Upvotes: 2
Reputation: 42020
It sounds like you are looking for M-x eval-expression
, bound by default to M-: (Alt+Colon, i.e. Alt+Shift+semicolon). The expression is evaluated in whatever context you were in when eval-expression
was invoked, so if the expression sets a buffer-local variable, it will be set for your current buffer.
Upvotes: 2