2017-06-08 11:47:56 +02:00
|
|
|
;;; core/autoload/message.el -*- lexical-binding: t; -*-
|
2017-04-12 10:51:29 -04:00
|
|
|
|
2017-04-15 03:14:03 -04:00
|
|
|
(defconst doom-message-fg
|
|
|
|
'((reset . 0)
|
|
|
|
(black . 30)
|
|
|
|
(red . 31)
|
|
|
|
(green . 32)
|
|
|
|
(yellow . 33)
|
|
|
|
(blue . 34)
|
|
|
|
(magenta . 35)
|
|
|
|
(cyan . 36)
|
|
|
|
(white . 37))
|
2017-04-12 10:51:29 -04:00
|
|
|
"List of text colors.")
|
|
|
|
|
2017-04-15 03:14:03 -04:00
|
|
|
(defconst doom-message-bg
|
2017-04-12 10:51:29 -04:00
|
|
|
'((on-black . 40)
|
|
|
|
(on-red . 41)
|
|
|
|
(on-green . 42)
|
|
|
|
(on-yellow . 43)
|
|
|
|
(on-blue . 44)
|
|
|
|
(on-magenta . 45)
|
|
|
|
(on-cyan . 46)
|
|
|
|
(on-white . 47))
|
|
|
|
"List of colors to draw text on.")
|
|
|
|
|
2017-04-15 03:14:03 -04:00
|
|
|
(defconst doom-message-fx
|
2017-04-12 10:51:29 -04:00
|
|
|
'((bold . 1)
|
|
|
|
(dark . 2)
|
|
|
|
(italic . 3)
|
|
|
|
(underscore . 4)
|
|
|
|
(blink . 5)
|
|
|
|
(rapid . 6)
|
|
|
|
(contrary . 7)
|
|
|
|
(concealed . 8)
|
|
|
|
(strike . 9))
|
|
|
|
"List of styles.")
|
|
|
|
|
|
|
|
;;;###autoload
|
2017-04-15 01:29:24 -04:00
|
|
|
(defmacro format! (message &rest args)
|
2017-04-12 10:51:29 -04:00
|
|
|
"An alternative to `format' that strips out ANSI codes if used in an
|
|
|
|
interactive session."
|
|
|
|
`(cl-flet*
|
2017-06-08 11:47:56 +02:00
|
|
|
(,@(cl-loop for rule
|
|
|
|
in (append doom-message-fg doom-message-bg doom-message-fx)
|
|
|
|
collect
|
|
|
|
`(,(car rule)
|
|
|
|
(lambda (message &rest args)
|
|
|
|
(apply #'doom-ansi-apply ',(car rule) message args))))
|
2017-06-23 13:06:28 +02:00
|
|
|
(color
|
|
|
|
(lambda (code format &rest args)
|
|
|
|
(apply #'doom-ansi-apply code format args))))
|
2017-04-12 10:51:29 -04:00
|
|
|
(format ,message ,@args)))
|
|
|
|
|
|
|
|
;;;###autoload
|
2017-04-15 01:29:24 -04:00
|
|
|
(defmacro message! (message &rest args)
|
2017-04-12 10:51:29 -04:00
|
|
|
"An alternative to `message' that strips out ANSI codes if used in an
|
|
|
|
interactive session."
|
2017-04-15 03:14:03 -04:00
|
|
|
`(if noninteractive
|
|
|
|
(message (format! ,message ,@args))
|
|
|
|
(let ((buf (get-buffer-create " *doom messages*")))
|
|
|
|
(with-current-buffer buf
|
|
|
|
(goto-char (point-max))
|
|
|
|
(let ((beg (point))
|
|
|
|
end)
|
|
|
|
(insert (format! ,message ,@args))
|
2017-04-17 16:54:00 -04:00
|
|
|
(insert "\n")
|
2017-04-15 03:14:03 -04:00
|
|
|
(setq end (point))
|
|
|
|
(ansi-color-apply-on-region beg end)))
|
|
|
|
(with-selected-window (doom-popup-buffer buf)
|
|
|
|
(goto-char (point-max))))))
|
2017-04-12 10:51:29 -04:00
|
|
|
|
2017-06-21 16:09:34 +02:00
|
|
|
;;;###autoload
|
|
|
|
(defmacro debug! (message &rest args)
|
|
|
|
"Out a debug message if `doom-debug-mode' is non-nil. Otherwise, ignore this."
|
|
|
|
(when doom-debug-mode
|
|
|
|
`(message ,message ,@args)))
|
|
|
|
|
2017-04-15 01:22:29 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun doom-ansi-apply (code format &rest args)
|
2017-04-15 03:14:03 -04:00
|
|
|
(let ((rule (or (assq code doom-message-fg)
|
|
|
|
(assq code doom-message-bg)
|
|
|
|
(assq code doom-message-fx))))
|
|
|
|
(format "\e[%dm%s\e[%dm"
|
|
|
|
(cdr rule)
|
2017-04-17 02:17:10 -04:00
|
|
|
(apply #'format format args)
|
2017-04-15 03:14:03 -04:00
|
|
|
0)))
|
2017-04-12 10:51:29 -04:00
|
|
|
|