summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre A. Gomes <andremegafone@gmail.com>2024-01-15 09:45:37 +0200
committerAndre A. Gomes <andremegafone@gmail.com>2024-01-22 11:45:37 +0200
commit5f3d1c599c45febb998944b3c7f0c65f6fbf4792 (patch)
tree6261c35b4429bb73ab76e6512d8425bd38b1ae2f
parent2d21d63adcd4d31c1818ec4f4a91083613807f74 (diff)
command-commands: Refactor {enable,disable}-hook-handler commands.
-rw-r--r--source/command-commands.lisp34
1 files changed, 16 insertions, 18 deletions
diff --git a/source/command-commands.lisp b/source/command-commands.lisp
index 92ba4b9ef..b6206bb95 100644
--- a/source/command-commands.lisp
+++ b/source/command-commands.lisp
@@ -322,25 +322,23 @@ User input is evaluated Lisp."
(define-class disabled-handler-source (handler-source)
((prompter:constructor (lambda (source) (hooks:disabled-handlers (hook source))))))
+(defun manage-hook-handler (action)
+ (let ((hook (prompt1 :prompt "Hook"
+ :sources 'hook-source)))
+ (funcall (case action
+ (:enable #'hooks:enable-hook)
+ (:disable #'hooks:disable-hook))
+ hook
+ (prompt1 :prompt "Handler"
+ :sources (make-instance (case action
+ (:enable 'disabled-handler-source)
+ (:disable 'handler-source))
+ :hook hook)))))
(define-command-global disable-hook-handler ()
- "Remove handler(s) from a hook."
- (let* ((hook-desc (prompt1
- :prompt "Hook where to disable handler"
- :sources 'hook-source))
- (handler (prompt1
- :prompt (format nil "Disable handler from ~a" (name hook-desc))
- :sources (make-instance 'handler-source
- :hook (value hook-desc)))))
- (hooks:disable-hook (value hook-desc) handler)))
+ "Remove handler of a hook."
+ (manage-hook-handler :disable))
(define-command-global enable-hook-handler ()
- "Enable handler(s) from a hook."
- (let* ((hook-desc (prompt1
- :prompt "Hook where to enable handler"
- :sources 'hook-source))
- (handler (prompt1
- :prompt (format nil "Enable handler from ~a" (name hook-desc))
- :sources (make-instance 'disabled-handler-source
- :hook (value hook-desc)))))
- (hooks:enable-hook (value hook-desc) handler)))
+ "Add handler of a hook."
+ (manage-hook-handler :enable))