]> git.eshelyaron.com Git - emacs.git/commitdiff
Add: 'local' keyword
authorMatthias Schmitt <male.schmitt@posteo.de>
Sat, 14 Sep 2019 21:25:21 +0000 (23:25 +0200)
committerMatthias Schmitt <male.schmitt@posteo.de>
Sun, 10 Jul 2022 23:58:46 +0000 (01:58 +0200)
lisp/use-package/use-package-core.el

index 28bc5a50ed05e315b58975511a8dc2477de49de2..5530b6c4f89aca36fb9466e549e3c5180e7302b6 100644 (file)
     :load
     ;; This must occur almost last; the only forms which should appear after
     ;; are those that must happen directly after the config forms.
-    :config)
+    :config
+    :local)
   "The set of valid keywords, in the order they are processed in.
 The order of this list is *very important*, so it is only
 advisable to insert new keywords, never to delete or reorder
@@ -1517,6 +1518,31 @@ no keyword implies `:all'."
      (when use-package-compute-statistics
        `((use-package-statistics-gather :config ',name t))))))
 
+;;;; :local
+
+(defun use-package-normalize/:local (name keyword args)
+  (let ((first-arg-name (symbol-name (caar args))))
+    (if (not (string-suffix-p "-hook" first-arg-name))
+        (let* ((sym-name (symbol-name name))
+               (addition (if (string-suffix-p "-mode" sym-name)
+                             "-hook"
+                           "-mode-hook"))
+               (hook (intern (concat sym-name addition))))
+          `((,hook . ,(use-package-normalize-forms name keyword args))))
+      (cl-loop for (hook . code) in args
+               collect `(,hook . ,(use-package-normalize-forms name keyword code))))))
+
+(defun use-package-handler/:local (name _keyword arg rest state)
+  (let* ((body (use-package-process-keywords name rest state)))
+    (use-package-concat
+     body
+     (cl-loop for (hook . code) in arg
+              for func-name = (intern (concat "use-package-func/" (symbol-name hook)))
+              collect (progn
+                        (push 'progn code)
+                        `(defun ,func-name () ,code))
+              collect `(add-hook ',hook ',func-name)))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;
 ;;; The main macro