From: Mathias Dahl <mathias.dahl@gmail.com>
To: emacs-devel@gnu.org
Subject: kill-emacs and returning values
Date: Sat, 14 Feb 2009 14:51:16 +0100 [thread overview]
Message-ID: <7dbe73ed0902140551w7a85d043n54e451896d99279e@mail.gmail.com> (raw)
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.
next reply other threads:[~2009-02-14 13:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-14 13:51 Mathias Dahl [this message]
2009-02-14 17:17 ` kill-emacs and returning values Mathias Megyei
2009-02-14 20:23 ` Mathias Dahl
2009-02-14 21:47 ` Mathias Megyei
2009-02-14 22:01 ` Mathias Dahl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7dbe73ed0902140551w7a85d043n54e451896d99279e@mail.gmail.com \
--to=mathias.dahl@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).