From 3fe16419379171400533dcace8913adbbee2ea78 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 12 Sep 2022 16:13:25 +0200 Subject: [PATCH] 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. --- lisp/doom-lib.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index f35e9580a..e2113a66c 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -241,6 +241,15 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions." ((add-hook hook fn -101))) 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