(sigil hooks)
(sigil hooks) - Emacs-Style Hook System
Hooks are lists of functions called when specific events occur. Multiple handlers can be registered for each hook and are called in order of registration.
Basic Usage
(import (sigil hooks))
(define my-hook (make-hook))
(add-hook! my-hook (lambda () (display "First\n")))
(add-hook! my-hook (lambda () (display "Second\n")))
(run-hook my-hook)
; prints: First
; SecondPassing Arguments
(define on-file-save (make-hook))
(add-hook! on-file-save
(lambda (filename)
(display "Saved: ")
(display filename)))
(run-hook-with-args on-file-save "document.txt")Exports
make-hookprocedureCreate a new empty hook.
(define my-hook (make-hook))hook?procedureCheck if a value is a hook.
(hook? my-hook) ; => #t
(hook? '()) ; => #fhook-empty?procedureCheck if a hook has no handlers.
(hook-empty? (make-hook)) ; => #tadd-hook!procedureAdd a function to a hook.
Functions are called in the order they are added.
(add-hook! my-hook (lambda () (display "Called!")))remove-hook!procedureRemove a function from a hook.
The function is matched by identity (eq?).
(define my-fn (lambda () ...))
(add-hook! my-hook my-fn)
(remove-hook! my-hook my-fn)clear-hook!procedureRemove all handlers from a hook.
(clear-hook! my-hook)run-hookprocedureRun a hook with no arguments.
Calls each handler function in order.
(run-hook my-hook)run-hook-with-argsprocedureRun a hook with arguments.
Each handler receives the same arguments.
(run-hook-with-args on-save-hook filename buffer)