wip(emacs): Abstract strategy-running

- Show docs and goto def are confirmed working
This commit is contained in:
Madeleine Sydney
2025-02-15 16:26:19 -07:00
parent 753f0c2dd9
commit a0495c6df3
3 changed files with 115 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
;; syd-strategies.el -*- lexical-binding: t; -*-
(require 'syd-text)
;; :documentation : Identifier -> Marker
(defvar-local syd-strat--strategies nil)
(defun syd-strat-try-functions-wrapped (wrapper fns &rest args)
"For each FN in FNS, call WRAPPER with the arguments FN followed by ARGS,
until a FN returns non-nil."
(cl-loop for fn in fns
with r = nil
do (setq r (apply wrapper fn args))
until r
finally return r))
(defun syd-strat--set-strategies (category strategies)
(cl-loop for ref in-ref syd-strat--strategies
until (eq category (car ref))
finally do (pp ref)))
(defun syd-set-strategies (modes &rest args)
(dolist (mode (ensure-list modes))
(let ((hook (intern (format "%s-hook" mode)))
(fn-name (intern (format "syd-strat--init-for-%s-h" mode))))
(unless (cl-evenp (length args))
(signal 'wrong-number-of-arguments args))
;; We use this `defalias' incantation instead of a raw `fset' because the
;; former will properly associate a source location to the definition.
(defalias fn-name
(function
(lambda ()
(cl-loop for (category strategies) on args by (lambda (x) (-drop 2 x))
do (syd-strat--set-strategies category strategies)))))
(add-hook hook fn-name))))
(provide 'syd-strategies)