summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-04-10 10:26:39 +0200
committerLudovic Courtès <ludo@gnu.org>2019-04-10 12:40:59 +0200
commitcc3697d5438a861f78a1e5ed57f592ea9ee327be (patch)
treea5df8be83ee9c461e8af802c7db3d21ee64ad191
parent26a2021a1f7951818539353531d56d2e8338966e (diff)
downloadguix-cc3697d5438a861f78a1e5ed57f592ea9ee327be.tar.gz
ui: Factorize 'print-diagnostic-prefix'.
* guix/ui.scm (define-diagnostic): Emit call to 'print-diagnostic-prefix'.
(print-diagnostic-prefix): New procedure.
-rw-r--r--guix/ui.scm16
1 files changed, 10 insertions, 6 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index 953cf9ea7f..8893cc8eee 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -136,9 +136,7 @@ messages."
             (and (string? (syntax->datum #'fmt))
                  (free-identifier=? #'underscore #'G_))
             #'(begin
-                (format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
-                        (program-name) (program-name)
-                        (gettext prefix %gettext-domain))
+                (print-diagnostic-prefix prefix)
                 (format (guix-warning-port) (gettext fmt %gettext-domain)
                         args (... ...))))
            ((name (N-underscore singular plural n) args (... ...))
@@ -146,9 +144,7 @@ messages."
                  (string? (syntax->datum #'plural))
                  (free-identifier=? #'N-underscore #'N_))
             #'(begin
-                (format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
-                        (program-name) (program-name)
-                        (gettext prefix %gettext-domain))
+                (print-diagnostic-prefix prefix)
                 (format (guix-warning-port)
                         (ngettext singular plural n %gettext-domain)
                         args (... ...))))))))))
@@ -166,6 +162,14 @@ messages."
     (report-error args ...)
     (exit 1)))
 
+(define (print-diagnostic-prefix prefix)
+  "Print PREFIX as a diagnostic line prefix."
+  (format (guix-warning-port) "~:[~*~;guix ~a: ~]~a"
+          (program-name) (program-name)
+          (if (string-null? prefix)
+              prefix
+              (gettext prefix %gettext-domain))))
+
 (define (print-unbound-variable-error port key args default-printer)
   ;; Print unbound variable errors more nicely, and in the right language.
   (match args