It can be useful to be able to run some hook in last, so let's add an option do that. --- protocol.lisp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/protocol.lisp b/protocol.lisp index 1c2ec19..cd5ddd7 100644 --- a/protocol.lisp +++ b/protocol.lisp @@ -198,7 +198,7 @@ connection.") (defgeneric read-irc-message (connection)) (defgeneric send-irc-message (connection command &rest arguments)) (defgeneric get-hooks (connection class)) -(defgeneric add-hook (connection class hook)) +(defgeneric add-hook (connection class hook &optional last)) (defgeneric remove-hook (connection class hook)) (defgeneric remove-hooks (connection class)) (defgeneric remove-all-hooks (connection)) @@ -379,10 +379,13 @@ server, via the `connection'." (gethash class (hooks connection)))
;;applies to both irc and dcc-connections -(defmethod add-hook (connection class hook) - "Add `hook' to `class'." +(defmethod add-hook (connection class hook &optional last) + "Add `hook' to `class'. +If `last' is not nil, put this hook last." (setf (gethash class (hooks connection)) - (pushnew hook (gethash class (hooks connection))))) + (if last + (append (gethash class (hooks connection)) (list hook)) + (pushnew hook (gethash class (hooks connection))))))
(defmethod remove-hook ((connection connection) class hook) "Remove `hook' from `class'."
I think I would prefer another generic function called append-hook rather than use an optional boolean parameter.
: Daniel :
It can be useful to be able to run some hook in last, so let's add a function to do that. --- package.lisp | 1 + protocol.lisp | 6 ++++++ 2 files changed, 7 insertions(+)
diff --git a/package.lisp b/package.lisp index 311fa3e..c09537a 100644 --- a/package.lisp +++ b/package.lisp @@ -48,6 +48,7 @@ :client-stream :channels :add-hook + :append-hook :remove-hook :remove-hooks :remove-all-hooks diff --git a/protocol.lisp b/protocol.lisp index 1c2ec19..7d89530 100644 --- a/protocol.lisp +++ b/protocol.lisp @@ -199,6 +199,7 @@ connection.") (defgeneric send-irc-message (connection command &rest arguments)) (defgeneric get-hooks (connection class)) (defgeneric add-hook (connection class hook)) +(defgeneric append-hook (connection class hook)) (defgeneric remove-hook (connection class hook)) (defgeneric remove-hooks (connection class)) (defgeneric remove-all-hooks (connection)) @@ -384,6 +385,11 @@ server, via the `connection'." (setf (gethash class (hooks connection)) (pushnew hook (gethash class (hooks connection)))))
+(defmethod append-hook (connection class hook) + "Append `hook' to `class'." + (setf (gethash class (hooks connection)) + (append (gethash class (hooks connection)) (list hook)))) + (defmethod remove-hook ((connection connection) class hook) "Remove `hook' from `class'." (setf (gethash class (hooks connection))