From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikita Karetnikov Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Add ',run' and ',!' Date: Thu, 11 Apr 2013 08:05:20 +0400 Message-ID: <87fvyx4sqn.fsf@karetnikov.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1365652966 27752 80.91.229.3 (11 Apr 2013 04:02:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Apr 2013 04:02:46 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Apr 11 06:02:50 2013 Return-path: Envelope-to: guile-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 1UQ8io-0000iK-Ag for guile-devel@m.gmane.org; Thu, 11 Apr 2013 06:02:50 +0200 Original-Received: from localhost ([::1]:32816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQ8in-0000c2-TN for guile-devel@m.gmane.org; Thu, 11 Apr 2013 00:02:49 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:60651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQ8ij-0000bu-KF for guile-devel@gnu.org; Thu, 11 Apr 2013 00:02:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQ8ig-0003M9-Vs for guile-devel@gnu.org; Thu, 11 Apr 2013 00:02:45 -0400 Original-Received: from li305-5.members.linode.com ([178.79.168.5]:41279 helo=cooksoni.karetnikov.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQ8ig-0003M3-Pb for guile-devel@gnu.org; Thu, 11 Apr 2013 00:02:42 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 178.79.168.5 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16217 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= There is a neat command-line option in GHCi (i.e., :!). It allows to run programs from the interpreter. For example: $ ghci Prelude> :! echo foo foo I decided to add a similar option to Guile. I've attached my attempt. I wasn't sure which version (branch) to use; I used 2.0.7. Also, I didn't bother to really check the code; just tested it a couple of times. I'll do it before I send the output of 'git format-patch'. By the way, should I assign my copyright prior to that? (I'm OK with that, but it may take a while. And where can I get the form?) It seems to work: scheme@(guile-user)> ,run echo foo foo scheme@(guile-user)> ,run ls -lh [...] scheme@(guile-user)> ,! echo bar baz 42 bar baz 42 Also, I'll try to handle the following cases more gently: scheme@(guile-user)> ,! While executing meta-command: ERROR: Wrong number of arguments to # scheme@(guile-user)> ,! foo While executing meta-command: ERROR: In procedure system*: No such file or directory So, what do you think? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=run.diff Content-Transfer-Encoding: quoted-printable =2D-- ./guile-2.0.7/module/system/repl/command.scm 2012-07-06 20:09:10.0000= 00000 +0000 +++ /home/guile-2.0.7/guile-2.0.7/module/system/repl/command.scm 2013-04-11= 03:09:02.000000000 +0000 @@ -1,6 +1,7 @@ ;;; Repl commands =20 ;; Copyright (C) 2001, 2009, 2010, 2011 Free Software Foundation, Inc. +;; Copyright (C) 2013 Nikita Karetnikov =20 ;; This library is free software; you can redistribute it and/or ;; modify it under the terms of the GNU Lesser General Public @@ -66,7 +67,7 @@ (traps) (delete del) (disable) (enable) (registers regs)) (inspect (inspect i) (pretty-print pp)) =2D (system (gc) (statistics stat) (option o) + (system (gc) (statistics stat) (run !) (option o) (quit q continue cont)))) =20 (define *show-table* @@ -927,6 +928,14 @@ (set! (repl-tm-stats repl) this-tms) (set! (repl-gc-stats repl) this-gcs))) =20 +(define-meta-command (run repl command . args) + "run +Run a command." + (apply system* + (map (lambda (x) + (->string x)) + (cons command args)))) + (define (display-stat title flag field1 field2 unit) (let ((fmt (format #f "~~20~AA ~~10@A /~~10@A ~~A~~%" (if flag "" "@")))) (format #t fmt title field1 field2 unit))) --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIcBAEBAgAGBQJRZjaDAAoJEM+IQzI9IQ38R4MP/RdOqWwyo4rHCzRT9ehAgQ40 3Y2lHzYKWOZxEKkDjxdQ2jNwzFZ9JTDUK/ikXRhv1m6tqh/ONeTX9Rih1v2gyV5i zSqxOyBB0So0brbOUlW62xn/lccIwXIcSE6Oiu6dc7JkIF5mVZ85TNIiFNNm+PwE y20mbCrBv+fT5yvrL8GQSHeblsj3m20PGj7hV+PeAHJTO3oqJQQLiqdettRRsuLe +B5nCsakSyWhaEZDJoe/hPz27w7quBHhi0GfMBWOBsd3UXTmJfEi5LSetGxryNq6 Fk5g2rdn4w8ECuAbiT0YzKmjKQMNLZQTniiaJz+cKFFlfCBUs+YeeKNZqSn+RRZn KrVjdYOgACopEKkGozOti6SIVN3aH/QgC1V/agySxPyc7p6hUIA3lX4jeEI/uJ6F T8JkOKeoMmjoRxaYkWqp7YFYMQnl2dP11BS0R0n3C+DT1qj038RqXzLdUcbou7C3 hDm6ojqXLyhIRFfxHXA/1WAL6gPQBWpN0WvnTRRRyPfroknaRqhiF+wkqwYYIvo1 YqkC+drIaMzC64Jx1UDHmwK0BogxIs7/K4jUxfbGr2aG4LCREXsrKNTsVovYI3cd KyorEY/r6D535FcVBZksfiJATnysYWNSeL1ClmUcZuxEViN1vCciNjAYXdi/B3Wd fwLk7/sayMJLMfGmnNVT =ci5n -----END PGP SIGNATURE----- --==-=-=--