From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: [PATCH 1/3] emacs: Display guix command errors in the minibuffer. Date: Sun, 13 Sep 2015 22:39:19 +0300 Message-ID: <1442173161-527-2-git-send-email-alezost@gmail.com> References: <1442173161-527-1-git-send-email-alezost@gmail.com> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58351) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZbD8T-0003oO-BN for guix-devel@gnu.org; Sun, 13 Sep 2015 15:40:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZbD8P-0000fa-0H for guix-devel@gnu.org; Sun, 13 Sep 2015 15:40:25 -0400 In-Reply-To: <1442173161-527-1-git-send-email-alezost@gmail.com> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org * emacs/guix-main.scm (output+error): New procedure. (guix-command-output): Use it. * emacs/guix-base.el (guix-command-output): Display error output in the minibuffer. --- emacs/guix-base.el | 9 ++++++--- emacs/guix-main.scm | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/emacs/guix-base.el b/emacs/guix-base.el index 3bee910..8d14095 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -1129,9 +1129,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 c9b84d3..10165c1 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm @@ -71,6 +71,18 @@ (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 @@ GENERATIONS is a list of generation numbers." (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 () + (guix-warning-port (current-error-port)) + (apply guix-command args)))) (define (help-string . commands) "Return string with 'guix COMMANDS ... --help' output." -- 2.5.1