core: add message! & format! macros with ansi support

This commit is contained in:
Henrik Lissner 2017-04-12 08:52:12 -04:00
parent d4bbb7e4e6
commit e320abaef8
2 changed files with 20 additions and 0 deletions

View File

@ -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))

View File

@ -5,6 +5,7 @@
(package! async)
(package! s)
(package! f)
(package! ansi)
;; core-os.el
(when IS-MAC