Skip to content

Commit

Permalink
Questions asked.
Browse files Browse the repository at this point in the history
  • Loading branch information
phmarek committed Nov 26, 2020
1 parent 5233421 commit d9d8374
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -111,3 +111,7 @@ doc-%:
doc: doc-help

.PHONY: clean elpa compile check doc dist

.PHONY: json
json:
cat json.txt - | nc localhost 4490
13 changes: 13 additions & 0 deletions README-JSON.md
@@ -0,0 +1,13 @@


- change the DEFSTRUCT CONNECTION to a class, to enable CHANGE-CLASS?
- need a *CONNECTION*... or use *EMACS-CONNECTION*?
- Why the (if (EQ *EMACS-CONNECTION* connection) in WITH-CONNECTION?

- Why is *EMACS-CONNECTION* not bound for all related threads?

- Should we just look for ":keyword" or "pkg::sym" to convert strings, or should these have some prefix, like "§pkg::sym"?
- have prefix

- should READ-MESSAGE etc. autodetect JSON or S-EXPR?

26 changes: 18 additions & 8 deletions swank.lisp
Expand Up @@ -723,7 +723,8 @@ If PACKAGE is not specified, the home package of SYMBOL is used."
(dont-close *dont-close*))
"Start the server and write the listen port number to PORT-FILE.
This is the entry point for Emacs."
(setup-server 0
(setup-server (or (ignore-errors (parse-integer (sb-posix:getenv "JS_SWANK_PORT")))
0)
(lambda (port) (announce-server-port port-file port))
style dont-close nil))

Expand Down Expand Up @@ -864,20 +865,25 @@ if the file doesn't exist; otherwise the first line of the file."
;;;;; Event Decoding/Encoding

;; TODO: pass connection or decoder in?
(defun decode-message (stream)
"Read an S-expression from STREAM using the SLIME protocol."
(log-event "decode-message~%")
(defun decode-message (stream) ;; =PM
"Read an expression from STREAM."
#+(or)
(format *trace-output* "conn ~a, dec ~a ~%"
*emacs-connection*
(connection.form-decoder *emacs-connection*))
(without-slime-interrupts
(handler-bind ((error #'signal-swank-error))
(handler-case (read-message stream
*swank-io-package*
(connection.form-decoder *emacs-connection*))
; =PM
; Are we using the right *emacs-connection* here??
(swank-reader-error (c)
`(:reader-error ,(swank-reader-error.packet c)
,(swank-reader-error.cause c)))))))

(defun encode-message (message stream)
"Write an S-expression to STREAM using the SLIME protocol."
"Write an S-expression to STREAM."
(log-event "encode-message~%")
(without-slime-interrupts
(handler-bind ((error #'signal-swank-error))
Expand Down Expand Up @@ -973,6 +979,10 @@ The processing is done in the extent of the toplevel restart."
(let ((input-stream (connection.socket-io connection))
(control-thread (mconn.control-thread connection)))
(with-swank-error-handler (connection)
;; PM
;; Auto-guess communication protocol (S-expr or JSON)
;; (let ((ch (peek-char input-stream nil nil)))
;; (when (eql ch #\[)))
(loop (send control-thread (decode-message input-stream))))))

(defun dispatch-loop (connection)
Expand Down Expand Up @@ -2118,7 +2128,7 @@ after Emacs causes a restart to be invoked."
"The initial number of backtrace frames to send to Emacs.")

(defvar *sldb-restarts* nil
"The list of currenlty active restarts.")
"The list of currently active restarts.")

(defvar *sldb-stepping-p* nil
"True during execution of a step command.")
Expand Down Expand Up @@ -2260,7 +2270,7 @@ where
restart ::= (name description)
stack-frame ::= (number description [plist])
extra ::= (:references and other random things)
cont ::= continutation
cont ::= continuation
plist ::= (:restartable {nil | t | :unknown})
condition---a pair of strings: message, and type. If show-source is
Expand All @@ -2271,7 +2281,7 @@ restart---a pair of strings: restart name, and description.
stack-frame---a number from zero (the top), and a printed
representation of the frame's call.
continutation---the id of a pending Emacs continuation.
continuation---the id of a pending Emacs continuation.
Below is an example return value. In this case the condition was a
division by zero (multi-line description), and only one frame is being
Expand Down
9 changes: 7 additions & 2 deletions swank/rpc.lisp
Expand Up @@ -21,8 +21,12 @@

(defun read-message (stream package &optional decoder)
(let ((packet (read-packet stream)))
(handler-case (values (funcall (or decoder
#'read-form)
#+(or)
(format *trace-output* "packet is ~s~%" packet)
(handler-case (values (funcall
(if (eql (aref packet 0) #\[)
(find-symbol "RECOVER-SYMBOLS" (find-package :vlime))
#'read-form)
packet package))
(reader-error (c)
(error 'swank-reader-error
Expand All @@ -42,6 +46,7 @@
(loop for code across (etypecase packet
(string (map 'vector #'char-code packet))
(vector packet))
; =PM TODO ignore § ?
do (cond ((<= code #x7f) (write-char (code-char code)))
(t (format t "\\x~x" code))))))

Expand Down

0 comments on commit d9d8374

Please sign in to comment.