feat(lib): backport with-memoization from 29
Ref: emacs-mirror/emacs@3c972723e4
This commit is contained in:
parent
edaa887bd9
commit
2b01166d1d
1 changed files with 13 additions and 0 deletions
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue