From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.devel Subject: towards sh-like 1> and 2> emulation: emacs-exit-messages Date: Tue, 31 Jul 2012 23:24:40 +0200 Message-ID: <87sjc71v53.fsf@zigzag.favinet> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: dough.gmane.org 1343769897 17161 80.91.229.3 (31 Jul 2012 21:24:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 31 Jul 2012 21:24:57 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 31 23:24:58 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SwJw1-0002Nw-Gl for ged-emacs-devel@m.gmane.org; Tue, 31 Jul 2012 23:24:57 +0200 Original-Received: from localhost ([::1]:41682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwJw0-0006B9-Ny for ged-emacs-devel@m.gmane.org; Tue, 31 Jul 2012 17:24:56 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwJvy-0006B4-7S for emacs-devel@gnu.org; Tue, 31 Jul 2012 17:24:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SwJvw-0007C1-Qi for emacs-devel@gnu.org; Tue, 31 Jul 2012 17:24:54 -0400 Original-Received: from smtp208.alice.it ([82.57.200.104]:58544) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwJvw-0007Bt-CL for emacs-devel@gnu.org; Tue, 31 Jul 2012 17:24:52 -0400 Original-Received: from zigzag.favinet (82.56.5.125) by smtp208.alice.it (8.6.023.02) id 500F3F9401786862 for emacs-devel@gnu.org; Tue, 31 Jul 2012 23:24:51 +0200 Original-Received: from ttn by zigzag.favinet with local (Exim 4.72) (envelope-from ) id 1SwJw2-0002v5-H9 for emacs-devel@gnu.org; Tue, 31 Jul 2012 23:24:58 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 82.57.200.104 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152048 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On another (explicitly unnamed) mailing list, there is discussion of replacing the standalone info reader w/ a specially-dumped (purpose built) Emacs. Reuben Thomas posted a workable sketch that exposes two problems (i.e., "code enhancement opportunities" as was known in some circles): - forced async operation of =E2=80=98man=E2=80=99 workaround: zonk =E2=80=98start-process=E2=80=99 - reliance on /bin/sh to display a message to stderr =20=20=20 The first can be addressed purely in Lisp, and is not the subject of this message (i trust someone will DTRT). The second is part of a more general infelicity in using Emacs in batch (or "semi-batch") mode. The global var =E2=80=98noninteractive=E2=80=99 is much too crude a switch for = such cases. So, refinement is indicated. But where? At first, i tried mucking w/ src/print.c func =E2=80=98strout=E2=80=99, int= erpreting a small-integer (file-descriptor-ish) =E2=80=98printcharfun=E2=80=99 as a spe= cification for stdout (1) or stderr (2) in another =E2=80=98else if=E2=80=99 clause. = This failed to produce output, and i didn't investigate. Was i too hasty? The second approach is attached (caveat: just a sketch; no multibyte, locale, bidi awareness; poor error handling) here: --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=emacs-exit-messages.diff Content-Transfer-Encoding: quoted-printable commit bb69d9879f9ff7ed0659a8e7505479275affd9b9 Author: Thien-Thi Nguyen Date: 2012-07-31 22:18:28 +0200 Add var =E2=80=98emacs-exit-messages=E2=80=99 and handle it during shut= down. * emacs.c (shut_down_emacs): After resetting the tty, display any strings specified by =E2=80=98emacs-exit-messages=E2=80=99 to stder= r/stdout. (syms_of_emacs Vemacs_exit_messages): New DEFVAR_LISP. =2D-- src/emacs.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index 2194cfe..210c5a5 100644 =2D-- a/src/emacs.c +++ b/src/emacs.c @@ -2051,6 +2051,30 @@ shut_down_emacs (int sig, int no_x, Lisp_Object stuf= f) reset_all_sys_modes (); #endif + /* If there are any messages, display them now. + Silently ignore ill-formed data, which is a latent bug. */ + while (CONSP (Vemacs_exit_messages)) + { + Lisp_Object msg =3D Fcar (Vemacs_exit_messages); + FILE *to =3D stderr; + + if (CONSP (msg) && INTEGERP (Fcar (msg))) + { + if (1 =3D=3D XINT (Fcar (msg))) + to =3D stdout; + msg =3D Fcdr (msg); + } + if (STRINGP (msg)) + { + size_t expected =3D SBYTES (msg); + size_t actually =3D fwrite (SDATA (msg), 1, expected, to); + + if (expected > actually) + abort (); + } + Vemacs_exit_messages =3D Fcdr (Vemacs_exit_messages); + } + stuff_buffered_input (stuff); inhibit_sentinels =3D 1; @@ -2438,6 +2462,14 @@ Before Emacs 24.1, the hook was not run in batch mod= e, i.e., if `noninteractive' was non-nil. */); Vkill_emacs_hook =3D Qnil; + DEFVAR_LISP ("emacs-exit-messages", Vemacs_exit_messages, + doc: /* List of strings to display to stderr at exit. +These are output as-is, so you need to include a newline. +Each element may also have form (FD . STRING), where FD is +a small integer: 1 for standard output, 2 for standard error. +All other FD values are taken as 2. */); + Vemacs_exit_messages =3D Qnil; + DEFVAR_LISP ("path-separator", Vpath_separator, doc: /* String containing the character that separates directories= in search paths, such as PATH and other similar environment variables. */); --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable OT1H, this is still relatively crude; saving output to the end is both inelegant and suboptimal (but perhaps i repeat myself). OTOH, it does the job: Emacs can effect sh-like =E2=80=981>=E2=80=99 and =E2=80=982>=E2= =80=99 control to fellow and parent processes, finally. Anyway, w/ that patch applied, the following program, slightly modified From=20the original, works fine (look ma, no /bin/sh!) w/ invocations: $ /tmp/info cat # interactive, "(coreutils) cat invocation" $ /tmp/info emacs # interactive, "(emacs) Top" $ /tmp/info zow # noninteractive, exit 1, msg on stderr To play, save to /tmp/info, chmod +x, and frob "bloody-emacs" to taste. --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=info Content-Transfer-Encoding: base64 IjoiIDsgZXhlYyBibG9vZHktZW1hY3MgLXEgLS1uby1zcGxhc2ggLS1sb2FkICQwICIkQCIKOzs7 IGluZm8gLS0tIFVzZSBlbWFjcyBhcyBhIHN0YW5kYWxvbmUgaW5mbyAmIG1hbiByZWFkZXIKCjs7 IEF1dGhvcjogUmV1YmVuIFRob21hcwo7OyAgICAgIFRoaWVuLVRoaSBOZ3V5ZW4KOzsgTGFzdC1N b2RpZmllZDogMjAxMi0wNy0zMQoKOzs7IENvbW1lbnRhcnk6Cgo7OyBVc2FnZTogaW5mbyBUT1BJ Qwo7Owo7OyBNaW1pYyB0aGUgc3RhbmRhbG9uZSBpbmZvLCBzZWFyY2hpbmcgZm9yIGluZm8gZm9y bWF0IGRvY3VtZW50YXRpb24KOzsgZm9yIFRPUElDLCBhbmQgZmFsbGluZyBiYWNrIHRvIG1hbnBh Z2UuICBJZiBuZWl0aGVyIG1ldGhvZCBzdWNjZWVkcywKOzsgZGlzcGxheSBhIG1lc3NhZ2UgdG8g c3RkZXJyIGFuZCBleGl0IGZhaWx1cmVmdWxseS4KCjs7OyBDb2Rl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hcmdzLWxlZnQpKSkKICAoc2V0LWZyYW1lLXBhcmFtZXRlciBuaWwgJ3RpdGxl IChmb3JtYXQgImluZm86ICVzIiB0b3BpYykpCiAgKGNvbmRpdGlvbi1jYXNlIGllcnIgKGluZm8t b3ItbWFuIHRvcGljKQogICAgKGVycm9yIChwdXNoCiAgICAgICAgICAgIDs7IE5COiBOYWtlZCDi gJhTVFJJTkfigJkgaXMgdGhlIHNhbWUgYXMg4oCYKDIgLiBTVFJJTkcp4oCZLgogICAgICAgICAg ICA7OyAgICAgVGhpcyBpcyBmb3IgZGVtb25zdHJhdGlvbiBwdXJwb3Nlcy4KICAgICAgICAgICAg KGNvbnMgMiAoZm9ybWF0ICJpbmZvOiBObyBzdWNoIGluZm8gb3IgbWFuIHBhZ2U6ICVzXG4iCiAg ICAgICAgICAgICAgICAgICAgICAgICAgICB0b3BpYykpCiAgICAgICAgICAgIGVtYWNzLWV4aXQt bWVzc2FnZXMpCiAgICAgICAgICAgKGtpbGwtZW1hY3MgMSkpKSkKCjs7OyBMb2NhbCB2YXJpYWJs ZXM6Cjs7OyBtb2RlOiBlbWFjcy1saXNwCjs7OyBFbmQ6Cgo7OzsgaW5mbyBlbmRzIGhlcmUK --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Now just watch: Someone will tell me this is already doable... :-/ =2D-=20 Thien-Thi Nguyen ..................................... GPG key: 4C807502 . NB: ttn at glug dot org is not me . . (and has not been since 2007 or so) . . ACCEPT NO SUBSTITUTES . ........... please send technical questions to mailing lists ........... --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAlAYTR8ACgkQZwMiJEyAdQJJVQCfXk2dx/IUHbg95veF1s5S/5FE N+EAoJOoZJCnktp/Y7oXyqTVJyQuoPpv =rCr2 -----END PGP SIGNATURE----- --==-=-=--