emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

kill-emacs and returning values


From: Mathias Dahl
Subject: kill-emacs and returning values
Date: Sat, 14 Feb 2009 14:51:16 +0100

I am trying to use emacs interactively as part of a shell script and
want to return a value that I can use in the script.

How is the optional string parameter to `kill-emacs' supposed to be
used? The docstring says:

===
kill-emacs is an interactive built-in function in `C source code'.

(kill-emacs &optional arg)

Exit the Emacs job and kill it.
If arg is an integer, return arg as the exit program code.
If arg is a string, stuff it as keyboard input.
===

Okay, sounds promising. I did a small test:

  $ cat ke.el
  ;; Interactive stuff goes here...

  ;; In the end, kill emacs and return a value to the script running in
  ;; the shell
  (kill-emacs "This is the return value.")

Testing it:

  $ emacs -Q -nw -l ke.el
  This is the return value.

So far so good. Now I want to save this value in a variable.

  address@hidden:~$ emacs -Q -nw -l ke.el; read returnvariable
  This is the return value.

Let's see what we got:

  address@hidden:~$ echo $returnvariable

  $

Nothing? Okay... A pipe must be used, of course, Next try:

  address@hidden:~$ emacs -Q -nw -l ke.el | read returnvariable
  This is the return value.

  address@hidden:~$ echo $returnvariable

  $

I see now that "as keyboard input" does not mean what I thought; it is
not something returned to stdout.

How is this supposed to be used? It would seem more natural to return
things to stdout, but I am sure there is a good reason for it to work
the way it does, it's just that I don't understand it.

Please note that I do not want to use emacs in batch mode. Emacs must
be responsive because I am building a UI for file selection in it.

Thanks!

/Mathias

PS. Of course I can use write-region and write what I want to a file
and then read the result from there, but that seems like a less
elegant solution to me.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]