feat(lib): add doom-compile-function

To be used in some autoloaded libraries, in case they haven't been
byte-compiled and contain especially expensive functions.
This commit is contained in:
Henrik Lissner 2022-09-12 16:13:25 +02:00
parent a18ea683d2
commit 3fe1641937
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -241,6 +241,15 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions."
((add-hook hook fn -101))) ((add-hook hook fn -101)))
fn))) fn)))
(defun doom-compile-function (fn &optional level)
"Compile FN, and natively, if possible."
(if (featurep 'native-compile)
(let ((native-comp-speed (or level native-comp-speed)))
(unless (subr-native-elisp-p (symbol-function fn))
(native-compile fn)))
(unless (byte-code-function-p (symbol-function fn))
(with-no-warnings (byte-compile fn)))))
;; ;;
;;; Sugars ;;; Sugars