feat(lib): backport with-memoization from 29

Ref: emacs-mirror/emacs@3c972723e4
This commit is contained in:
Henrik Lissner 2022-09-06 19:04:48 +02:00
parent edaa887bd9
commit 2b01166d1d
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -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