branch: externals/setup
commit 682172f38a91baafe70dce166965b23149faf2aa
Author: Earl Hyatt <oka...@protonmail.com>
Commit: Philip Kaludercic <phil...@posteo.net>

    Add `:with-function` and document how `:with-` macros effect expansion.
    
    - Expand on how setting a "feature" sets hooks and maps.
    
    - Add a `:with-function` sub-macro.  Setting the mode sets the function.  
For
      now, this function is used by `:hook-into`.
---
 setup.el | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/setup.el b/setup.el
index dccd06ea1a..66976a7a28 100644
--- a/setup.el
+++ b/setup.el
@@ -366,6 +366,7 @@ VAL into one s-expression."
                     (setup-bind body
                       (feature feature)
                       (mode (or (get features 'setup-mode) mode))
+                      (func (or (get features 'setup-func) mode))
                       (hook (or (get features 'setup-hook)
                                 (get mode 'setup-hook)
                                 (intern (format "%s-hook" mode))))
@@ -381,6 +382,7 @@ This macro also:
   FEATURE, unless it already ends with \"-mode\"
 - Declares a current hook by appending \"-hook\" to the mode
 - Declares a current map by appending \"-map\" to the mode
+- Declares a current function that has the same name as the mode
 If FEATURE is a list, apply BODY to all elements of FEATURE."
   :debug '([&or ([&rest sexp]) sexp] setup)
   :indent 1)
@@ -391,6 +393,8 @@ If FEATURE is a list, apply BODY to all elements of 
FEATURE."
       (dolist (mode (if (listp modes) modes (list modes)))
         (push (setup-bind body
                 (mode mode)
+                (func (or (get mode 'setup-func)
+                          mode))
                 (hook (or (get mode 'setup-hook)
                           (intern (format "%s-hook" mode))))
                 (map (or (get mode 'setup-map)
@@ -401,7 +405,8 @@ If FEATURE is a list, apply BODY to all elements of 
FEATURE."
 If MODE is a list, apply BODY to all elements of MODE.
 This macro also:
 - Declares a current hook by appending \"-hook\" to the mode
-- Declares a current map by appending \"-map\" to the mode"
+- Declares a current map by appending \"-map\" to the mode
+- Declares a current function that has the same name as the mode"
   :debug '([&or ([&rest sexp]) sexp] setup)
   :indent 1)
 
@@ -429,6 +434,21 @@ If HOOK is a list, apply BODY to all elements of HOOK."
   :debug '([&or ([&rest sexp]) sexp] setup)
   :indent 1)
 
+(setup-define :with-function
+  (lambda (functions &rest body)
+    (let (bodies)
+      (dolist (func (if (listp functions) functions (list functions)))
+        (let ((fn (if (memq (car-safe func) '(quote function))
+                      (cadr func)
+                    func)))
+          (push (setup-bind body (func fn))
+                bodies)))
+      (macroexp-progn (nreverse bodies))))
+  :documentation "Change the FUNCTION that BODY will use.
+If FUNCTION is a list, apply BODY to all elements of FUNCTION."
+  :debug '(sexp setup)
+  :indent 1)
+
 (setup-define :package
   (lambda (package)
     `(unless (package-installed-p ',package)
@@ -510,8 +530,8 @@ The arguments REST are handled as by `:bind'."
                    (if (string-match-p "-hook\\'" name)
                        mode
                      (intern (concat name "-hook"))))
-               #',(setup-get 'mode)))
-  :documentation "Add current mode to HOOK."
+               #',(setup-get 'func)))
+  :documentation "Add current function to HOOK."
   :repeatable t)
 
 (setup-define :option

Reply via email to