Add remember.el (WIP)

This commit is contained in:
Case Duckworth 2022-01-12 17:40:53 -06:00
parent 125a82251c
commit caf8d7aa54
1 changed files with 43 additions and 0 deletions

43
lisp/remember.el Normal file
View File

@ -0,0 +1,43 @@
;; ABANDON ALL HOPE YE WHO ENTER HERE
(defmacro remember-set (&rest symbols)
"Setup a closure remembering symbols to apply with
`remember-reset'. The variables will be renamed using TEMPLATE.
SYMBOLS is a plist: the properties are symbols or mode names, and
their values what to set after `remember-setup'."
(let* ((template (format "remember--%s-%%s" (gensym)))
(reset-fn (intern (format template "reset" "fn")))
(list (cl-loop for sym in symbols by #'cddr
collect `(,(intern (format template sym))
,sym)
into let-list
collect (let ((val (plist-get symbols sym)))
(cond ((eq val 'enable)
`(,sym +1))
((eq val 'disable)
`(,sym -1))
(t `(setq-local ,sym ,val))))
into fn-set-list
collect (let ((val (plist-get symbols sym))
(rem (intern (format template sym))))
(cond ((memq val '(enable disable))
`(,sym (if ,rem +1 -1)))
(t `(setq-local ,sym ,rem))))
into fn-reset-list
finally return (list let-list
fn-reset-list
fn-set-list))))
`(progn
(defvar-local ,reset-fn nil
"Function to recall values from `remember-set'.")
(let ,(cl-first list)
(setf (symbol-function ',reset-fn)
(lambda ()
,@(cl-second list))))
,@(cl-third list)
',reset-fn)))
;; test
(setq fn (remember-set display-fill-column-indicator-mode disable))
(funcall fn)