source: trunk/source/cocoa-ide/swank-ccl-ide.el @ 12214

Last change on this file since 12214 was 12214, checked in by mikel, 11 years ago

lots more errors get caught now. repeatedly using the emacs utility to request a swank load and connection correctly creates multiple swank connections. It's possible to disconnect from and reconnect to a CCl using a swank server loaded by the load request. It's possible to kill CCL and relaunch it, and reconnect to the new CCL using the emacs request.

the handshake is hairy enough that additional uncaught errors probably remain.

File size: 2.1 KB
Line 
1;;;; ***********************************************************************
2;;;; FILE IDENTIFICATION
3;;;;
4;;;; Name:          swank-ccl-ide.el
5;;;; Project:       CCL IDE
6;;;; Purpose:       swank extensions for use with the CCL IDE
7;;;;
8;;;; ***********************************************************************
9
10;;; ABOUT
11;;; ------------------------------------------------------------------------
12
13;;; this file implements an extension to SLIME that talks to CCL's
14;;; Cocoa app
15;;; it provides utilities that:
16;;; 1. tell CCL to find and load the swank-loader currently in use by
17;;;    the running Emacs
18;;; 2.  start a swank server on a specified port.
19;;; 3. tell SLIME to connect to swank on the specified port
20
21(defun swank-loader-path () (concat slime-path "swank-loader.lisp"))
22
23(defvar *ccl-swank-listener-host* "127.0.0.1")
24(defvar *ccl-swank-listener-port* 4884)
25(defvar *ccl-swank-listener-proc* nil)
26
27(defvar *ccl-swank-output* nil)
28
29(defun slime-ccl-swank-filter (process string)
30  (let* ((status (read string))
31         (active? (plist-get status :active)))
32    (setq *ccl-swank-output* status)
33    (if active?
34        (let ((port (plist-get status :port)))
35          (slime-connect *ccl-swank-listener-host* port))
36        (error "CCL failed to start the swank server. The reason it gave was: '%s'"
37               (plist-get status :message)))))
38
39(defvar $emacs-ccl-swank-request-marker "[emacs-ccl-swank-request]")
40
41(defun request-ccl-load-swank (&optional host listener-port connection-port loader-path)
42  (let* ((host (or host *ccl-swank-listener-host*))
43         (listener-port (or listener-port *ccl-swank-listener-port*))
44         (connection-port (or connection-port slime-port))
45         (loader-path (or loader-path (swank-loader-path)))
46         (ping (concat $emacs-ccl-swank-request-marker (format "%d" connection-port) ":" loader-path "\n"))
47         (ccl-proc (open-network-stream "SLIME CCL Swank" nil host listener-port)))
48    (setq *ccl-swank-listener-proc* ccl-proc)
49    (set-process-filter ccl-proc 'slime-ccl-swank-filter)
50    ;; send ping
51    (process-send-string ccl-proc ping)
52    ccl-proc))
53
Note: See TracBrowser for help on using the repository browser.