Generalize message! & format! (interactive vs noninteractive)
This commit is contained in:
parent
e48c6c5381
commit
fedfa1ffad
3 changed files with 41 additions and 36 deletions
|
@ -1,18 +1,18 @@
|
|||
;;; message.el
|
||||
|
||||
(defconst doom-ansi-fg
|
||||
'((reset . 0)
|
||||
(black . 30)
|
||||
(red . 31)
|
||||
(green . 32)
|
||||
(yellow . 33)
|
||||
(blue . 34)
|
||||
(magenta . 35)
|
||||
(cyan . 36)
|
||||
(white . 37))
|
||||
(defconst doom-message-fg
|
||||
'((reset . 0)
|
||||
(black . 30)
|
||||
(red . 31)
|
||||
(green . 32)
|
||||
(yellow . 33)
|
||||
(blue . 34)
|
||||
(magenta . 35)
|
||||
(cyan . 36)
|
||||
(white . 37))
|
||||
"List of text colors.")
|
||||
|
||||
(defconst doom-ansi-bg
|
||||
(defconst doom-message-bg
|
||||
'((on-black . 40)
|
||||
(on-red . 41)
|
||||
(on-green . 42)
|
||||
|
@ -23,7 +23,7 @@
|
|||
(on-white . 47))
|
||||
"List of colors to draw text on.")
|
||||
|
||||
(defconst doom-ansi-fx
|
||||
(defconst doom-message-fx
|
||||
'((bold . 1)
|
||||
(dark . 2)
|
||||
(italic . 3)
|
||||
|
@ -41,11 +41,11 @@
|
|||
interactive session."
|
||||
`(cl-flet*
|
||||
(,@(mapcar
|
||||
(lambda (ansi)
|
||||
`(,(car ansi)
|
||||
(lambda (rule)
|
||||
`(,(car rule)
|
||||
(lambda (message &rest args)
|
||||
(apply 'doom-ansi-apply ,(cdr ansi) message args))))
|
||||
(append doom-ansi-fg doom-ansi-bg doom-ansi-fx))
|
||||
(apply 'doom-ansi-apply ',(car rule) message args))))
|
||||
(append doom-message-fg doom-message-bg doom-message-fx))
|
||||
(color (symbol-function 'doom-ansi-apply)))
|
||||
(format ,message ,@args)))
|
||||
|
||||
|
@ -53,22 +53,26 @@ interactive session."
|
|||
(defmacro message! (message &rest args)
|
||||
"An alternative to `message' that strips out ANSI codes if used in an
|
||||
interactive session."
|
||||
`(message (format! ,message ,@args)))
|
||||
`(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))
|
||||
(setq end (point))
|
||||
(ansi-color-apply-on-region beg end)))
|
||||
(with-selected-window (doom-popup-buffer buf)
|
||||
(goto-char (point-max))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom-ansi-apply (code format &rest args)
|
||||
(if noninteractive
|
||||
(format "\e[%dm%s\e[%sm"
|
||||
(if (numberp code)
|
||||
code
|
||||
(cdr (or (assq code doom-ansi-fg)
|
||||
(assq code doom-ansi-bg)
|
||||
(assq code doom-ansi-fx))))
|
||||
(apply 'format format args) 0)
|
||||
(apply 'format format args)))
|
||||
(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)
|
||||
(apply 'format format args)
|
||||
0)))
|
||||
|
||||
|
||||
;; --- DOOM message buffer -----------------------------------------------------
|
||||
|
||||
;; TODO
|
||||
;; (defun doom-message (message &rest args) (interactive))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue