[slime-devel] OK to move arbitrary :write-string TARGET handler into core?

Matthias Koeppe mkoeppe+slime at mail.math.uni-magdeburg.de
Tue Aug 28 16:37:56 UTC 2007


Helmut,

can I move the code to handle arbitrary :write-string TARGETs (via a
hashtable of markers) from slime-presentations into core SLIME (see
diff)?

This code is actually not related to presentations, but is for
separating out streams like *trace-output*.

Matthias

--- slime.el	28 Aug 2007 08:52:04 -0700	1.832
+++ slime.el	28 Aug 2007 09:34:05 -0700	
@@ -2970,7 +2970,52 @@
          (if (>= (marker-position slime-output-end) (point))
              ;; If the output-end marker was moved by our insertion,
              ;; set it back to the beginning of the REPL result.
-             (set-marker slime-output-end result-start)))))))
+             (set-marker slime-output-end result-start)))))
+    (t
+     (let* ((marker (slime-output-target-marker target))
+            (buffer (and marker (marker-buffer marker))))
+       (when buffer
+         (with-current-buffer buffer
+           (save-excursion 
+             ;; Insert STRING at MARKER, then move MARKER behind
+             ;; the insertion.
+             (goto-char marker)
+             (insert-before-markers string)
+             (set-marker marker (point)))))))))
+
+(defvar slime-last-output-target-id 0
+  "The last integer we used as a TARGET id.")
+
+(defvar slime-output-target-to-marker
+  (make-hash-table)
+  "Map from TARGET ids to Emacs markers that indicate where
+output should be inserted.")
+
+(defun slime-output-target-marker (target)
+  "Return a marker that indicates where output for TARGET should
+be inserted."
+  (case target
+    ((nil)
+     (with-current-buffer (slime-output-buffer)
+       slime-output-end))
+    (:repl-result
+     (with-current-buffer (slime-output-buffer)
+       slime-repl-input-start-mark))
+    (t
+     (gethash target slime-output-target-to-marker))))
+
+
+(defun slime-redirect-trace-output ()
+  "Redirect the trace output to a separate Emacs buffer."
+  (interactive)
+  (let ((buffer (get-buffer-create "*SLIME Trace Output*")))
+    (with-current-buffer buffer
+      (let ((marker (copy-marker (buffer-size)))
+            (target (incf slime-last-output-target-id)))
+        (puthash target marker slime-output-target-to-marker)
+        (slime-eval `(swank:redirect-trace-output ,target))))
+    (pop-to-buffer buffer)))
+
 
 (defun slime-switch-to-output-buffer (&optional connection)
   "Select the output buffer, preferably in a different window."



-- 
Matthias Köppe -- http://www.math.uni-magdeburg.de/~mkoeppe
(currently @math.ucdavis.edu)




More information about the slime-devel mailing list