Skip to content

Commit

Permalink
feat(core): add +setq-hook! & +unsetq-hook! from Doom
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Jun 12, 2023
1 parent 61bb207 commit 5cdab26
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/me-loaddefs.el
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ If N and M = 1, there's no benefit to using this macro over `remove-hook'.
(fn HOOKS [:append :local] FUNCTIONS)" nil t)
(function-put '+remove-hook! 'lisp-indent-function 'defun)
(autoload '+setq-hook! "../elisp/+minemacs" "\
Sets buffer-local variables on HOOKS.
(fn HOOKS &rest [SYM VAL]...)" nil t)
(function-put '+setq-hook! 'lisp-indent-function 1)
(autoload '+unsetq-hook! "../elisp/+minemacs" "\
Unbind setq hooks on HOOKS for VARS.
(fn HOOKS &rest [SYM VAL]...)" nil t)
(function-put '+unsetq-hook! 'lisp-indent-function 1)
(autoload '+compile-functions "../elisp/+minemacs" "\
Queue FNS to be byte/natively-compiled after a brief delay.
Expand All @@ -446,7 +456,7 @@ Run all build functions registered with `+register-build-function!'.
(fn &optional DONT-ASK-P)" t)
(autoload 'minemacs-update "../elisp/+minemacs" "\
Update MinEmacs packages." t)
(register-definition-prefixes "../elisp/+minemacs" '("+add-hook!" "+eval-when-idle-" "+hook-once-num" "+resolve-hook-forms" "minemacs--build-functions"))
(register-definition-prefixes "../elisp/+minemacs" '("+eval-when-idle-" "+hook-once-num" "+resolve-hook-forms" "+setq-hook-fns" "minemacs--build-functions"))


;;; Generated autoloads from ../elisp/+primitives.el
Expand Down
46 changes: 46 additions & 0 deletions elisp/+minemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ list is returned as-is."
collect (cadr hook)
else collect (intern (format "%s-hook" (symbol-name hook)))))))

(defun +setq-hook-fns (hooks rest &optional singles)
(unless (or singles (= 0 (% (length rest) 2)))
(signal 'wrong-number-of-arguments (list #'evenp (length rest))))
(cl-loop with vars = (let ((args rest)
vars)
(while args
(push (if singles
(list (pop args))
(cons (pop args) (pop args)))
vars))
(nreverse vars))
for hook in (+resolve-hook-forms hooks)
for mode = (string-remove-suffix "-hook" (symbol-name hook))
append
(cl-loop for (var . val) in vars
collect
(list var val hook
(intern (format "minemacs--setq-%s-for-%s-h"
var mode))))))

;; From Doom Emacs
;;;###autoload
(defmacro +add-hook! (hooks &rest rest)
Expand Down Expand Up @@ -334,6 +354,32 @@ If N and M = 1, there's no benefit to using this macro over `remove-hook'.
(declare (indent defun) (debug t))
`(+add-hook! ,hooks :remove ,@rest))

;; From Doom Emacs
;;;###autoload
(defmacro +setq-hook! (hooks &rest var-vals)
"Sets buffer-local variables on HOOKS.
\(fn HOOKS &rest [SYM VAL]...)"
(declare (indent 1))
(macroexp-progn
(cl-loop for (var val hook fn) in (+setq-hook-fns hooks var-vals)
collect `(defun ,fn (&rest _)
,(format "%s = %s" var (pp-to-string val))
(setq-local ,var ,val))
collect `(add-hook ',hook #',fn -90))))

;; From Doom Emacs
;;;###autoload
(defmacro +unsetq-hook! (hooks &rest vars)
"Unbind setq hooks on HOOKS for VARS.
\(fn HOOKS &rest [SYM VAL]...)"
(declare (indent 1))
(macroexp-progn
(cl-loop for (_var _val hook fn)
in (+setq-hook-fns hooks vars 'singles)
collect `(remove-hook ',hook #',fn))))

;; Adapted from: Doom Emacs
;;;###autoload
(defun +compile-functions (&rest fns)
Expand Down

0 comments on commit 5cdab26

Please sign in to comment.