Autoload format library

If you byte-compile your config, the expanded forms of this library's
macros (like print! or format!) will use internal functions that aren't
autoloaded (like `doom--format`, mentioned in #1768), causing
void-function errors.
This commit is contained in:
Henrik Lissner 2019-09-09 13:59:13 -04:00
parent 4045827d61
commit 9d775ca798
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -91,6 +91,7 @@ Accepts 'ansi and 'text-properties. nil means don't render colors.")
;;
;;; Library
;;;###autoload
(defun doom--format (output)
(if (string-empty-p (string-trim output))
""
@ -99,6 +100,7 @@ Accepts 'ansi and 'text-properties. nil means don't render colors.")
"\n" (concat "\n" (make-string doom-format-indent 32))
output t t))))
;;;###autoload
(defun doom--format-print (output)
(unless (string-empty-p output)
(if (not noninteractive)
@ -107,6 +109,7 @@ Accepts 'ansi and 'text-properties. nil means don't render colors.")
(terpri)) ; newline
t))
;;;###autoload
(defun doom--format-indent (width text &optional prefix)
"Indent TEXT by WIDTH spaces. If ARGS, format TEXT with them."
(with-temp-buffer
@ -121,6 +124,7 @@ Accepts 'ansi and 'text-properties. nil means don't render colors.")
(insert prefix)))
(buffer-string)))
;;;###autoload
(defun doom--format-autofill (&rest msgs)
"Ensure MSG is split into lines no longer than `fill-column'."
(with-temp-buffer
@ -131,6 +135,7 @@ Accepts 'ansi and 'text-properties. nil means don't render colors.")
(fill-region (point-min) (point-max))
(buffer-string))))
;;;###autoload
(defun doom--format-color (style format &rest args)
"Apply STYLE to formatted MESSAGE with ARGS.
@ -159,6 +164,7 @@ Otherwise, it maps colors to a term-color-* face."
((cddr (assq style doom-format-ansi-alist)))))))
(_ message))))
;;;###autoload
(defun doom--format-class (class format &rest args)
"Apply CLASS to formatted format with ARGS.
@ -172,6 +178,7 @@ transformative logic."
(args (apply #'format format args))
(format))))
;;;###autoload
(defun doom--format-apply (forms &optional sub)
"Replace color-name functions with calls to `doom--format-color'."
(cond ((null forms) nil)