Rewrite doom-doctor
- Use message library instead of reinventing the wheel - Fix -d/--debug support for `bin/doom doctor` - Add indent and autofill support to print! and format! - Add doom-message-backend for forcing format! to use a specific backend - Phase out anaphoric when! macro in doctor scripts, it was hardly used
This commit is contained in:
parent
51a28249bd
commit
9bea168cc1
5 changed files with 144 additions and 103 deletions
|
@ -31,27 +31,60 @@
|
|||
(on-white 47 term-color-white))
|
||||
"TODO")
|
||||
|
||||
(defvar doom-message-backend
|
||||
(if noninteractive 'ansi 'text-properties)
|
||||
"Determines whether to print colors with ANSI codes or with text properties.
|
||||
|
||||
Accepts 'ansi and 'text-properties. nil means don't render colors.")
|
||||
|
||||
;;;###autoload
|
||||
(defun doom-color-apply (style text)
|
||||
(defun doom-message-indent (width text &rest args)
|
||||
(with-temp-buffer
|
||||
(insert (apply #'format text args))
|
||||
(let ((fill-column 80))
|
||||
(fill-region (point-min) (point-max))
|
||||
(indent-rigidly (point-min) (point-max) width))
|
||||
(when (> width 2)
|
||||
(goto-char (point-min))
|
||||
(beginning-of-line-text)
|
||||
(delete-char -2)
|
||||
(insert "> "))
|
||||
(buffer-string)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom-message-autofill (&rest msgs)
|
||||
(with-temp-buffer
|
||||
(let ((fill-column 70))
|
||||
(dolist (line msgs)
|
||||
(when line
|
||||
(insert line)))
|
||||
(fill-region (point-min) (point-max))
|
||||
(buffer-string))))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom-color-apply (style text &rest args)
|
||||
"Apply CODE to formatted MESSAGE with ARGS. CODE is derived from any of
|
||||
`doom-message-fg', `doom-message-bg' or `doom-message-fx'.
|
||||
|
||||
In a noninteractive session, this wraps the result in ansi color codes.
|
||||
Otherwise, it maps colors to a term-color-* face."
|
||||
(let ((code (cadr (assq style doom-ansi-alist))))
|
||||
(if noninteractive
|
||||
(format "\e[%dm%s\e[%dm"
|
||||
(cadr (assq style doom-ansi-alist))
|
||||
text 0)
|
||||
(require 'term) ; piggyback on term's color faces
|
||||
(propertize
|
||||
text 'face
|
||||
(append (get-text-property 0 'face text)
|
||||
(cond ((>= code 40)
|
||||
`(:background ,(caddr (assq style doom-ansi-alist))))
|
||||
((>= code 30)
|
||||
`(:foreground ,(face-foreground (caddr (assq style doom-ansi-alist)))))
|
||||
((cddr (assq style doom-ansi-alist)))))))))
|
||||
(let ((code (car (cdr (assq style doom-ansi-alist)))))
|
||||
(pcase doom-message-backend
|
||||
(`ansi
|
||||
(format "\e[%dm%s\e[%dm"
|
||||
(car (cdr (assq style doom-ansi-alist)))
|
||||
(apply #'format text args) 0))
|
||||
(`text-properties
|
||||
(require 'term) ; piggyback on term's color faces
|
||||
(propertize
|
||||
(apply #'format text args) 'face
|
||||
(append (get-text-property 0 'face text)
|
||||
(cond ((>= code 40)
|
||||
`(:background ,(caddr (assq style doom-ansi-alist))))
|
||||
((>= code 30)
|
||||
`(:foreground ,(face-foreground (caddr (assq style doom-ansi-alist)))))
|
||||
((cddr (assq style doom-ansi-alist)))))))
|
||||
(_ (apply #'format text args)))))
|
||||
|
||||
(defun doom--short-color-replace (forms)
|
||||
"Replace color-name functions with calls to `doom-color-apply'."
|
||||
|
@ -64,6 +97,10 @@ Otherwise, it maps colors to a term-color-* face."
|
|||
((eq (car forms) 'color)
|
||||
(pop forms)
|
||||
`(doom-color-apply ,(car forms)))
|
||||
((memq (car forms) '(indent autofill))
|
||||
(let ((fn (pop forms)))
|
||||
`(,(intern (format "doom-message-%s" fn))
|
||||
,(car forms))))
|
||||
((list (car forms))))
|
||||
(doom--short-color-replace (cdr forms))
|
||||
nil))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue