mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
feat(lib): backport with-memoization from 29
Ref: emacs-mirror/emacs@3c972723e4
This commit is contained in:
@ -838,5 +838,18 @@ The previous values will be be restored upon exit."
|
|||||||
collect `(setenv ,(car var) ,(cadr var)))
|
collect `(setenv ,(car var) ,(cadr var)))
|
||||||
,@body))
|
,@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)
|
(provide 'doom-lib)
|
||||||
;;; doom-lib.el ends here
|
;;; doom-lib.el ends here
|
||||||
|
Reference in New Issue
Block a user