Hello.
I'm using swank for a school project, so that, in Emacs, I can use Common Lisp to do database related operations. The thing is that Emacs Lisp doesn't have any good package to do database operations (DDL and DML API, socket connection to a database, ACID properties, etc). I've used, as a first try, sql-mode to fire a mysql client process and did all sql operations from there. However it doesn't support some desired properties (rollbacks, etc), the program would be strongly tied to the specific output of mysql client process (I had to parse the output to get the results) and it was a nightmare to make the select queries synchronous (the function would receive a select query string and block while the mysql process outputs the result - and then parse).
I chosed CL-SQL as a engine to do DB related operations, and now I need a way to comunicate between Emacs and Common Lisp. I don't know if it is the best way to do it, but I'm using swank as the "bridge" between both.
However I don't know, neither can't find documented, the protocol to communicate with swank. Can you help me?
Thats all I did until now:
I've fired swank in a SBCL console:
(require 'swank) (swank::create-swank-server 4006 :spawn #'swank::simple-announce-function t)
And then I connect in Emacs:
(open-network-stream "swank-process" "swank-buffer" "localhost" 4006)
I find "swank-buffer" which reads:
000025(:open-dedicated-output-stream 46912)
Then I connect to 46912:
(open-network-stream "swank-output" "swank-output-buffer" "localhost" 46912)
However as I try to communicate with "swank-process", using (process-send-string), the connection exits abnormally with code 256. In the SBCL console it shows:
;; Swank started at port: 4006.
4006 * ;; Event history start: WRITE: (:open-dedicated-output-stream 46912) ;; Event history end. ;; Connection to Emacs lost. [ ;; condition: junk in string "(+ 2 2" ;; type: SWANK::SLIME-PROTOCOL-ERROR ;; encoding: :ISO-LATIN-1-UNIX style: :SPAWN dedicated: T]
debugger invoked on a SIMPLE-ERROR in thread #<THREAD "auto-flush-thread" {B096EE1}>: #<SB-SYS:FD-STREAM for "a constant string" {AF7E3A9}> is closed.
+ "José Fernandes" josemataf@gmail.com:
| However I don't know, neither can't find documented, the protocol to | communicate with swank. Can you help me?
I asked the same sort of question of the list back in February:
http://common-lisp.net/pipermail/slime-devel/2006-February/004608.html http://common-lisp.net/pipermail/slime-devel/2006-February/004609.html http://common-lisp.net/pipermail/slime-devel/2006-February/004610.html
Maybe that helps.
- Harald
+ Harald Hanche-Olsen hanche@math.ntnu.no:
| I asked the same sort of question of the list back in February: | | http://common-lisp.net/pipermail/slime-devel/2006-February/004608.html | http://common-lisp.net/pipermail/slime-devel/2006-February/004609.html | http://common-lisp.net/pipermail/slime-devel/2006-February/004610.html | | Maybe that helps.
I might add that you need to be careful with swank::eval-in-emacs.
It's OK if it causes an emacs error, e.g., (swank::eval-in-emacs '(barf)) produces the emacs message "Error in process filter" and in the slime-repl buffer you'll get ; Evaluation aborted. But if evaluation of the form in emacs returns a value that the Lisp reader cannot handle, that's a protocol error, and slime loses the connection to the backend lisp.
For example, the following naive function does not work, because it will return a buffer, which prints as #<buffer name>, and that does not fly with the Lisp reader. So the correct version needs to arrange for the emacs form to return something else, like the filename or t.
(defun edit (file) (swank::eval-in-emacs `(find-file-other-window ,(namestring file))))
(This should use some functions meant to translate filenames between the slime view and the backend Lisp view, but I haven't gotten around to learning about those yet.)
- Harald