Added missing swank-slime.lisp

Pascal J. Bourguignon [2021-03-01 06:34]
Added missing swank-slime.lisp
Filename
small-cl-pgms/irclog-prompter/swank-slime.lisp
diff --git a/small-cl-pgms/irclog-prompter/swank-slime.lisp b/small-cl-pgms/irclog-prompter/swank-slime.lisp
new file mode 100644
index 0000000..c24ee08
--- /dev/null
+++ b/small-cl-pgms/irclog-prompter/swank-slime.lisp
@@ -0,0 +1,34 @@
+(defpackage "COM.INFORMATIMAGO.SMALL-CL-PGMS.SLIME"
+  (:use "COMMON-LISP")
+  (:documentation "This package exports functions to evaluate expressions in emacs thru swank/slime.")
+  (:export "EVAL-IN-EMACS"))
+(in-package "COM.INFORMATIMAGO.SMALL-CL-PGMS.SLIME")
+
+(defparameter *emacs-readtable*
+  (let ((rt (copy-readtable)))
+
+    (setf (readtable-case rt) :preserve)
+    (set-syntax-from-char #\> #\) rt)
+    (set-dispatch-macro-character
+     #\# #\<
+     (lambda (stream subchar dispchar)
+       `(emacs-unreadable ,@(read-delimited-list #\> stream t)))
+     rt)
+    ;; Probably more readtable patching would be in order.
+    rt))
+
+
+;; We could define CLOS proxies for emacs objects for a more seamless
+;; integration. swank::eval-in-emacs process the CL form to make it
+;; "emacs" (eg. downcase symbols, etc).  It could convert CLOS proxies
+;; to emacs lisp forms returning the corresponding emacs object.
+
+(defun eval-in-emacs (form &optional nowait)
+  (let ((result #+swank (swank::eval-in-emacs `(format "%S" ,form) nowait)
+                #-swank (error "Swank not available"))
+        (*readtable* *emacs-readtable*))
+    (with-input-from-string (in result)
+      (let ((result (read in nil in)))
+        result))))
+
+;;;; THE END ;;;;
ViewGit