guix-commits
[Top][All Lists]
Advanced

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

09/12: emacs: Add code for executing guix commands in REPL.


From: Alex Kost
Subject: 09/12: emacs: Add code for executing guix commands in REPL.
Date: Fri, 14 Aug 2015 08:18:17 +0000

alezost pushed a commit to branch wip-emacs-popup-ui
in repository guix.

commit e0aef413437024d460b6c62e0402d663a356e8e4
Author: Alex Kost <address@hidden>
Date:   Thu Aug 13 10:51:31 2015 +0300

    emacs: Add code for executing guix commands in REPL.
    
    * emacs/guix-base.el (guix-execute-command, guix-help-string): New 
functions.
    * emacs/guix-main.scm (with-quit-catch): New macro.
      (guix-command, help-string): New procedures.
---
 emacs/guix-base.el  |   11 +++++++++++
 emacs/guix-main.scm |   35 +++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/emacs/guix-base.el b/emacs/guix-base.el
index 6505c63..e01c85d 100644
--- a/emacs/guix-base.el
+++ b/emacs/guix-base.el
@@ -1094,6 +1094,17 @@ FILE.  With a prefix argument, also prompt for PROFILE."
      operation-buffer)))
 
 
+;;; Executing guix commands
+
+(defun guix-execute-command (args)
+  "Execute 'guix ARGS ...' command in Guix REPL."
+  (guix-eval-in-repl (guix-make-guile-expression 'guix-command args)))
+
+(defun guix-help-string (&optional commands)
+  "Return string with 'guix COMMANDS ... --help' output."
+  (guix-eval-read (guix-make-guile-expression 'help-string commands)))
+
+
 ;;; Pull
 
 (defcustom guix-update-after-pull t
diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm
index b0ce34f..c76ee9f 100644
--- a/emacs/guix-main.scm
+++ b/emacs/guix-main.scm
@@ -62,6 +62,11 @@
  (guix scripts pull)
  (gnu packages))
 
+(define-syntax-rule (with-quit-catch body ...)
+  (catch 'quit
+    (lambda () body ...)
+    (const #t)))
+
 (define-syntax-rule (first-or-false lst)
   (and (not (null? lst))
        (first lst)))
@@ -930,6 +935,36 @@ GENERATIONS is a list of generation numbers."
                 (package-source-derivation->store-path derivation))))))
 
 
+;;; Executing guix commands
+
+(define (guix-command args)
+  "Run 'guix ARGS ...' command.
+ARGS is a list of strings."
+  (with-quit-catch
+    (apply guix-main "guix" args)))
+
+(define (help-string commands)
+  "Return string with 'guix COMMANDS ... --help' output.
+COMMANDS is a list of strings."
+  (with-output-to-string
+    (lambda ()
+      ;; FIXME Using 'guix-main' won't work because 'setvbuf' (from
+      ;; 'initialize-guix') doesn't like string ports.
+
+      ;; (guix-command `(,@commands "--help"))
+
+      ;; So use the following variant.  Should 'show-guix-help' be
+      ;; exported from (guix ui)?
+      (with-quit-catch
+       (match commands
+         (()
+          ((@@ (guix ui) show-guix-help)))
+         ((command actions ...)
+          (apply run-guix-command
+                 (string->symbol command)
+                 `(,@actions "--help"))))))))
+
+
 ;;; Lists of packages, lint checkers, etc.
 
 (define (lint-checker-names)



reply via email to

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