1

I've got a python script that loops indefinitely waiting for input, and then does something when the input happens. My problem is then making python tell emacs to do something. I just need some way to send emacs input and make emacs evaluate that input.

Here's some code to illustrate my problem...

while(1):

  on_off = query_lightswitch
  if on_off == 0:
      send_text_to_emacs("(setq 'lightswitch t)")

Ideally I'd send emacs a string that it evaluates in its elisp interpreter. I've tried pymacs, but it looks like pymacs is made to start stuff from emacs rather than python. When I try something like this in pymacs it locks up until the loop terminates. This looks like a problem I could solve with unix pipelines, if I knew enough. If anybody out there has any ideas on how to solve this problem I'd be much obliged, thanks.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84

1 Answers1

4

You can use gnuclient (shipped with Emacs 22) (or emacsclient for earlier Emacsen), to evaluate code from external programs and connect to a running Emacs.

Getting Emacs to evaluate code by itself would look something like this:

gnuclient -q -batch -eval "(setq 'lightswitch t)"
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229