core: add message! & format! macros with ansi support
This commit is contained in:
parent
d4bbb7e4e6
commit
e320abaef8
2 changed files with 20 additions and 0 deletions
|
@ -5,6 +5,11 @@
|
||||||
;;
|
;;
|
||||||
(autoload 'when-let "subr-x")
|
(autoload 'when-let "subr-x")
|
||||||
(autoload 'if-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
|
;; 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
|
;; for its :commands property. I use dolists instead of mapc to avoid extra
|
||||||
|
@ -70,6 +75,20 @@
|
||||||
;; Library
|
;; 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)
|
(defmacro λ! (&rest body)
|
||||||
"A shortcut for inline interactive lambdas."
|
"A shortcut for inline interactive lambdas."
|
||||||
(declare (doc-string 1))
|
(declare (doc-string 1))
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
(package! async)
|
(package! async)
|
||||||
(package! s)
|
(package! s)
|
||||||
(package! f)
|
(package! f)
|
||||||
|
(package! ansi)
|
||||||
|
|
||||||
;; core-os.el
|
;; core-os.el
|
||||||
(when IS-MAC
|
(when IS-MAC
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue