- ;; When running in Slime we need to hook into the Swank server
- ;; to handle events asynchronously.
- (unless (and
- (find-package "SWANK")
- (let ((connection (symbol-value (find-symbol "*EMACS-CONNECTION*" "SWANK"))))
- (when connection
- (let ((read-from-emacs (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK")))
- (stream (funcall (find-symbol "CONNECTION.SOCKET-IO" "SWANK") connection)))
- (multiple-value-bind (sec usec)
- (decompose-time *event-polling-interval*)
- (setf
- (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK"))
- #'(lambda ()
- (loop
- (case (socket-status (cons stream :input) sec usec)
- ((:input :eof) (return (funcall read-from-emacs)))
- (otherwise (main-iterate-all)))))))))))
- #-(and clisp readline)
- (warn "Asynchronous event handling not supported on this platform. An explicit main loop has to be started."))
+ ;; When running in CLISP or certain versions of SBCL in Slime we need
+ ;; to hook into the Swank server to handle events asynchronously.
+ (cond
+ ((and (find-package "SWANK") (find-symbol "CHECK-SLIME-INTERRUPTS" "SWANK"))
+ (let ((check-slime-interrupts
+ (symbol-function (find-symbol "CHECK-SLIME-INTERRUPTS" "SWANK"))))
+ (setf
+ (symbol-function (find-symbol "CHECK-SLIME-INTERRUPTS" "SWANK"))
+ #'(lambda ()
+ (main-iterate-all)
+ (funcall check-slime-interrupts)))))
+ ((and (find-package "SWANK")
+ (find-symbol "READ-FROM-EMACS" "SWANK")
+ (find-symbol "*EMACS-CONNECTION*" "SWANK")
+ (find-symbol "CONNECTION.SOCKET-IO" "SWANK"))
+ (let ((connection (symbol-value (find-symbol "*EMACS-CONNECTION*" "SWANK"))))
+ (when connection
+ (let ((read-from-emacs (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK")))
+ (stream (funcall (find-symbol "CONNECTION.SOCKET-IO" "SWANK") connection)))
+ (multiple-value-bind (sec usec)
+ (decompose-time *event-polling-interval*)
+ (setf (symbol-function (find-symbol "READ-FROM-EMACS" "SWANK"))
+ #'(lambda ()
+ (loop
+ (case (socket-status (cons stream :input) sec usec)
+ ((:input :eof) (return (funcall read-from-emacs)))
+ (otherwise (main-iterate-all)))))))))))
+ ((flet ((warn-main-loop ()
+ (warn "Asynchronous event handling not supported on this platform. An explicit main loop has to be started.")))
+ #+(and clisp readline)
+ (if (find-package "SWANK")
+ (warn-main-loop) ; assuming we're running in SLIME
+ ;; Readline will call the event hook at most ten times per second
+ (setf readline:event-hook #'main-iterate-all))
+ #-(and clisp readline)(warn-main-loop))))