Fix arg-less color functions in print!/format!

This commit is contained in:
Henrik Lissner 2019-04-24 18:07:37 -04:00
parent 88406bb11a
commit 1ab8dac872
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 8 additions and 6 deletions

View file

@ -68,23 +68,25 @@ Accepts 'ansi and 'text-properties. nil means don't render colors.")
In a noninteractive session, this wraps the result in ansi color codes. In a noninteractive session, this wraps the result in ansi color codes.
Otherwise, it maps colors to a term-color-* face." Otherwise, it maps colors to a term-color-* face."
(let ((code (car (cdr (assq style doom-ansi-alist))))) (let ((code (car (cdr (assq style doom-ansi-alist))))
(message (if args (apply #'format text args) text)))
(pcase doom-message-backend (pcase doom-message-backend
(`ansi (`ansi
(format "\e[%dm%s\e[%dm" (format "\e[%dm%s\e[%dm"
(car (cdr (assq style doom-ansi-alist))) (car (cdr (assq style doom-ansi-alist)))
(apply #'format text args) 0)) message 0))
(`text-properties (`text-properties
(require 'term) ; piggyback on term's color faces (require 'term) ; piggyback on term's color faces
(propertize (propertize
(apply #'format text args) 'face message
'face
(append (get-text-property 0 'face text) (append (get-text-property 0 'face text)
(cond ((>= code 40) (cond ((>= code 40)
`(:background ,(caddr (assq style doom-ansi-alist)))) `(:background ,(caddr (assq style doom-ansi-alist))))
((>= code 30) ((>= code 30)
`(:foreground ,(face-foreground (caddr (assq style doom-ansi-alist))))) `(:foreground ,(face-foreground (caddr (assq style doom-ansi-alist)))))
((cddr (assq style doom-ansi-alist))))))) ((cddr (assq style doom-ansi-alist)))))))
(_ (apply #'format text args))))) (_ message))))
(defun doom--short-color-replace (forms) (defun doom--short-color-replace (forms)
"Replace color-name functions with calls to `doom-color-apply'." "Replace color-name functions with calls to `doom-color-apply'."
@ -121,7 +123,7 @@ Can be colored using (color ...) blocks:
(print! \"Hello %s\" (bold (blue \"How are you?\"))) (print! \"Hello %s\" (bold (blue \"How are you?\")))
(print! \"Hello %s\" (red \"World\")) (print! \"Hello %s\" (red \"World\"))
(print! (green \"Great %s!\") \"success\") (print! (green \"Great %s!\" \"success\"))
Uses faces in interactive sessions and ANSI codes otherwise." Uses faces in interactive sessions and ANSI codes otherwise."
`(progn (princ (format! ,message ,@args)) `(progn (princ (format! ,message ,@args))

View file

@ -39,7 +39,7 @@ commands like `doom-packages-install', `doom-packages-update' and
omitted, show all available commands, their aliases and brief descriptions." omitted, show all available commands, their aliases and brief descriptions."
(if command (if command
(princ (doom--dispatch-format desc)) (princ (doom--dispatch-format desc))
(print! (bold "%-10s\t%s\t%s") "Command:" "Alias" "Description") (print! (bold "%-10s\t%s\t%s" "Command:" "Alias" "Description"))
(dolist (spec (cl-sort doom--dispatch-command-alist #'string-lessp (dolist (spec (cl-sort doom--dispatch-command-alist #'string-lessp
:key #'car)) :key #'car))
(cl-destructuring-bind (command &key desc _body) spec (cl-destructuring-bind (command &key desc _body) spec