+ enable lexical-scope everywhere (lexical-binding = t): ~5-10% faster startup; ~5-20% general boost + reduce consing, function calls & garbage collection by preferring cl-loop & dolist over lambda closures (for mapc[ar], add-hook, and various cl-lib filter/map/reduce functions) -- where possible + prefer functions with dedicated opcodes, like assq (see byte-defop's in bytecomp.el for more) + prefer pcase & cond (faster) over cl-case + general refactor for code readability + ensure naming & style conventions are adhered to + appease byte-compiler by marking unused variables with underscore + defer minor mode activation to after-init, emacs-startup or window-setup hooks; a customization opportunity for users + ensures custom functionality won't interfere with startup.
79 lines
2.2 KiB
EmacsLisp
79 lines
2.2 KiB
EmacsLisp
;;; core/autoload/message.el -*- lexical-binding: t; -*-
|
|
|
|
(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-message-bg
|
|
'((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.")
|
|
|
|
(defconst doom-message-fx
|
|
'((bold . 1)
|
|
(dark . 2)
|
|
(italic . 3)
|
|
(underscore . 4)
|
|
(blink . 5)
|
|
(rapid . 6)
|
|
(contrary . 7)
|
|
(concealed . 8)
|
|
(strike . 9))
|
|
"List of styles.")
|
|
|
|
;;;###autoload
|
|
(defmacro format! (message &rest args)
|
|
"An alternative to `format' that strips out ANSI codes if used in an
|
|
interactive session."
|
|
`(cl-flet*
|
|
(,@(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))))
|
|
(color (symbol-function 'doom-ansi-apply)))
|
|
(format ,message ,@args)))
|
|
|
|
;;;###autoload
|
|
(defmacro message! (message &rest args)
|
|
"An alternative to `message' that strips out ANSI codes if used in an
|
|
interactive session."
|
|
`(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))
|
|
(insert "\n")
|
|
(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)
|
|
(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)))
|
|
|