Commit3009f09aRecorded25 Feb 2026Repositorysigil-hooks
Add procedure specs to args, ansi, process, and hooks modules
Message
sigil-args: 5 specs (parse-args, run-command, generate-help, print-help, find-subcommand)
sigil-ansi: 43 specs (16 foreground colors, 8 background colors, 9 text styles, 12 cursor/screen controls, strip-ansi, ansi-enabled?, with-ansi-disabled)
sigil process: 17 specs (14 native, 3 Scheme utilities)
sigil-hooks: 8 specs (make-hook, hook?, hook-empty?, add-hook!, remove-hook!, clear-hook!, run-hook, run-hook-with-args)
Changed
src/sigil/hooks.sgl | 8 ++++++++
1 file changed, 8 insertions(+)Diff
src/sigil/hooks.sglmodified
@@ -54,6 +54,7 @@
54
;;; (define my-hook (make-hook)) 55
;;; ``` 56
(define (make-hook)+57
(: -> hook?) 58
(vector 'hook '())) 59
60
;;; Check if a value is a hook.@@ -63,6 +64,7 @@
64
;;; (hook? '()) ; => #f 65
;;; ``` 66
(define (hook? obj)+67
(: any? -> boolean?) 68
(and (vector? obj) 69
(> (vector-length obj) 0) 70
(eq? (vector-ref obj 0) 'hook)))@@ -81,6 +83,7 @@
83
;;; (hook-empty? (make-hook)) ; => #t 84
;;; ``` 85
(define (hook-empty? hook)+86
(: hook? -> boolean?) 87
(null? (hook-handlers hook))) 88
89
;;; Add a function to a hook.@@ -91,6 +94,7 @@
94
;;; (add-hook! my-hook (lambda () (display "Called!"))) 95
;;; ``` 96
(define (add-hook! hook func)+97
(: hook? procedure? -> void?) 98
(hook-handlers-set! hook 99
(append (hook-handlers hook) (list func)))) 100
@@ -104,6 +108,7 @@
108
;;; (remove-hook! my-hook my-fn) 109
;;; ``` 110
(define (remove-hook! hook func)+111
(: hook? procedure? -> void?) 112
(hook-handlers-set! hook 113
(filter (lambda (f) (not (eq? f func))) 114
(hook-handlers hook))))@@ -114,6 +119,7 @@
119
;;; (clear-hook! my-hook) 120
;;; ``` 121
(define (clear-hook! hook)+122
(: hook? -> void?) 123
(hook-handlers-set! hook '())) 124
125
;;; Run a hook with no arguments.@@ -124,6 +130,7 @@
130
;;; (run-hook my-hook) 131
;;; ``` 132
(define (run-hook hook)+133
(: hook? -> void?) 134
(for-each (lambda (f) (f)) (hook-handlers hook))) 135
136
;;; Run a hook with arguments.@@ -134,6 +141,7 @@
141
;;; (run-hook-with-args on-save-hook filename buffer) 142
;;; ``` 143
(define (run-hook-with-args hook . args)+144
(: hook? any? ... -> void?) 145
(for-each (lambda (f) (apply f args)) 146
(hook-handlers hook))) 147