From caf8d7aa54a5e8fca9ffd6fdceccfb4fa58169dd Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 12 Jan 2022 17:40:53 -0600 Subject: Add remember.el (WIP) --- lisp/remember.el | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lisp/remember.el (limited to 'lisp') diff --git a/lisp/remember.el b/lisp/remember.el new file mode 100644 index 0000000..39476d1 --- /dev/null +++ b/lisp/remember.el @@ -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) -- cgit 1.4.1-21-gabe81