diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index 8e0adc99e..91b6d215c 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -838,5 +838,18 @@ The previous values will be be restored upon exit." collect `(setenv ,(car var) ,(cadr var))) ,@body)) +;; Introduced in Emacs 29+ +(defbackport! defmacro with-memoization (place &rest code) + "Return the value of CODE and stash it in PLACE. +If PLACE's value is non-nil, then don't bother evaluating CODE +and return the value found in PLACE instead." + (declare (indent 1) (debug (gv-place body))) + (gv-letplace (getter setter) place + `(or ,getter + ,(macroexp-let2 nil val (macroexp-progn code) + `(progn + ,(funcall setter val) + ,val))))) + (provide 'doom-lib) ;;; doom-lib.el ends here