+(defun find-button (name idx)
+ (nth
+ idx
+ (remove-if-not
+ (lambda (widget) (and (button-p widget) (string= (button-display-name widget) name)))
+ *current-interface*)))
+
+; With authoring, idx here needs to be looked at again.
+(defun execute-button (name &optional (idx 0))
+ "EXECUTE-BUTTON NAME &optional IDX => RESULT
+
+ARGUMENTS AND VALUES:
+
+ NAME: the name of the button
+ IDX: the instance of the button, defaults to 0
+ RESULT: undefined
+
+DESCRIPTION:
+
+ Executes the code in the button referenced by NAME and IDX.
+
+ NAME refers to the display name for the button, which is usually
+ set by the model, but sometimes defaults to the code inside.
+
+ Because NAME is not guaranteed to be unique, IDX is available
+ as a specifier. The index is in the order that the buttons are
+ loaded, and cannot be guaranteed to be stable from run to run."
+ (when *current-callback*
+ (let
+ ((button (find-button name (round idx))))
+ (cond
+ ((not button) (error "Couldn't find button with name ~A (idx: ~A)" name idx))
+ ((and (button-forever button) (find button *enabled-forever-buttons* :test #'equal))
+ (setf *enabled-forever-buttons* (remove button *enabled-forever-buttons* :test #'equal)))
+ ((button-forever button)
+ (setf *enabled-forever-buttons* (cons button *enabled-forever-buttons*))
+ (sb-thread:make-thread
+ (lambda ()
+ (loop
+ :while (find button *enabled-forever-buttons* :test #'equal)
+ ; The sleep is necessary so that it gives other threads time
+ :do (progn (clnl:run-commands (button-code button)) (sleep .001))))
+ :name (format nil "Forever button: ~A" (button-display button))))
+ (t (funcall *current-callback* (button-code button)))))))
+
+(defun forever-button-on (name &optional (idx 0))
+ "FOREVER-BUTTON-ON NAME &optional IDX => ON
+
+ARGUMENTS AND VALUES:
+
+ NAME: the name of the button
+ IDX: the instance of the button, defaults to 0
+ ON: a boolean
+
+DESCRIPTION:
+
+ Returns whether the button identified by NAME and IDX is currently on.
+
+ NAME refers to the display name for the button, which is usually
+ set by the model, but sometimes defaults to the code inside.
+
+ Because NAME is not guaranteed to be unique, IDX is available
+ as a specifier. The index is in the order that the buttons are
+ loaded, and cannot be guaranteed to be stable from run to run."
+ (and (find (find-button name (round idx)) *enabled-forever-buttons* :test #'equal) t))
+