atlas-engineer / nhooks

MIT License
18 stars 5 forks source link

nhooks.lisp: Fix append behaviour. #15

Closed vvcarvalho closed 2 years ago

vvcarvalho commented 2 years ago

Using the nhooks system from quicklisp there is a bug while using the :append key on add-hook. My use case depends on preserving the order handlers are added to hooks.

Before the patch, using add-hooks without :append works as intended:

CL-USER> (progn
           (defun bar () (print "Running bar"))
           (defun foo () (print "Running foo"))
           (let ((foo-hook (make-instance 'nhooks:hook)))
             (nhooks:add-hook foo-hook 'foo)
             (nhooks:add-hook foo-hook 'bar)
             (nhooks:run-hook foo-hook)))
"Running bar"
"Running foo"

But using :append t results in an error:

CL-USER> (progn
           (defun bar () (print "Running bar"))
           (defun foo () (print "Running foo"))
           (let ((foo-hook (make-instance 'nhooks:hook)))
             (nhooks:add-hook foo-hook 'foo :append t)
             (nhooks:add-hook foo-hook 'bar :append t)
             (nhooks:run-hook foo-hook)))

The value
  #<NHOOKS:HOOK {1001635CE3}>
is not of type
  SYMBOL

With the patch, the expected ordering occurs.

Note: the rest of the is patch basically indented code for legibility (automatic), so feel free to reject it.

aartaka commented 2 years ago

Yes, this looks most sane.

I'm merging. A note for next time: please, separate commits that add/change functionality, and those that change the style/indentation.