From e320abaef8a046e8edab55dc51fb07cbbdf1390c Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 12 Apr 2017 08:52:12 -0400 Subject: [PATCH] core: add message! & format! macros with ansi support --- core/core-lib.el | 19 +++++++++++++++++++ core/packages.el | 1 + 2 files changed, 20 insertions(+) diff --git a/core/core-lib.el b/core/core-lib.el index d7f22c6c7..b747f6c91 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -5,6 +5,11 @@ ;; (autoload 'when-let "subr-x") (autoload 'if-let "subr-x") +;; +(if noninteractive + (require 'ansi) + (autoload 'with-ansi "ansi") + (autoload 'ansi-apply "ansi")) ;; I don't use use-package for these to save on the `fboundp' lookups it does ;; for its :commands property. I use dolists instead of mapc to avoid extra @@ -70,6 +75,20 @@ ;; Library ;; +(defmacro format! (message &rest args) + "An alternative to `format' that strips out ANSI codes if used in an +interactive session." + `(with-ansi + ,(if noninteractive + `(format ,message ,@args) + `(cl-letf (((symbol-function 'ansi-apply) (lambda (_ &rest args) (apply 'format args)))) + (format ,message ,@args))))) + +(defmacro message! (message &rest args) + "An alternative to `message' that strips out ANSI codes if used in an +interactive session." + `(message (format! ,message ,@args))) + (defmacro λ! (&rest body) "A shortcut for inline interactive lambdas." (declare (doc-string 1)) diff --git a/core/packages.el b/core/packages.el index b0e5ee22b..235761a89 100644 --- a/core/packages.el +++ b/core/packages.el @@ -5,6 +5,7 @@ (package! async) (package! s) (package! f) +(package! ansi) ;; core-os.el (when IS-MAC