diff --git a/emacs/guix-base.el b/emacs/guix-base.el index a479f6dbf5a008cf43a55da254325a54e602245e..685e4498d8c15dbf68ab00601ac14d4b31ea2a7c 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -1134,9 +1134,12 @@ The function is called with a single argument - a command line string." (defun guix-command-output (args) "Return string with 'guix ARGS ...' output." - (guix-eval-read - (apply #'guix-make-guile-expression - 'guix-command-output args))) + (cl-multiple-value-bind (output error) + (guix-eval (apply #'guix-make-guile-expression + 'guix-command-output args)) + ;; Remove trailing new space from the error string. + (message (replace-regexp-in-string "\n\\'" "" (read error))) + (read output))) (defun guix-help-string (&optional commands) "Return string with 'guix COMMANDS ... --help' output." diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm index c9b84d36d9b270cc6542c008ff4ee5de4d5c436d..e29a0a0accf96bd1f8f9fcd0017564ccd2b12b15 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm @@ -71,6 +71,18 @@ (define-syntax-rule (first-or-false lst) (define (list-maybe obj) (if (list? obj) obj (list obj))) +(define (output+error thunk) + "Call THUNK and return 2 values: output and error output as strings." + (let ((output-port (open-output-string)) + (error-port (open-output-string))) + (with-output-to-port output-port + (lambda () (with-error-to-port error-port thunk))) + (let ((strings (list (get-output-string output-port) + (get-output-string error-port)))) + (close-output-port output-port) + (close-output-port error-port) + (apply values strings)))) + (define (full-name->name+version spec) "Given package specification SPEC with or without output, return two values: name and version. For example, for SPEC @@ -953,9 +965,11 @@ (define (guix-command . args) (const #t))) (define (guix-command-output . args) - "Return string with 'guix ARGS ...' output." - (with-output-to-string - (lambda () (apply guix-command args)))) + "Return 2 strings with 'guix ARGS ...' output and error output." + (output+error + (lambda () + (parameterize ((guix-warning-port (current-error-port))) + (apply guix-command args))))) (define (help-string . commands) "Return string with 'guix COMMANDS ... --help' output."