unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* kill-emacs and returning values
@ 2009-02-14 13:51 Mathias Dahl
  2009-02-14 17:17 ` Mathias Megyei
  0 siblings, 1 reply; 5+ messages in thread
From: Mathias Dahl @ 2009-02-14 13:51 UTC (permalink / raw)
  To: emacs-devel

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.

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

Let's see what we got:

  mathias@klibb:~$ echo $returnvariable

  $

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

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

  mathias@klibb:~$ 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.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-02-14 22:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-14 13:51 kill-emacs and returning values Mathias Dahl
2009-02-14 17:17 ` Mathias Megyei
2009-02-14 20:23   ` Mathias Dahl
2009-02-14 21:47     ` Mathias Megyei
2009-02-14 22:01       ` Mathias Dahl

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).