[slime-devel] Readtables

Terje Norderhaug terje at in-progress.com
Fri Jan 1 05:23:10 UTC 2010


On Dec 31, 2009, at 7:45 AM, Seth Burleigh wrote:
> Is there any current support for having the REPL respect reader   
> macro characters? For example, if I define the [] pair to act like  
> parentheses the repl shouldn’t automatically send a multiline [  ]  
> form to lisp until a matching ] has been found. On command line  
> REPLs, reader macro characters aren’t evaluated until a matching ]  
> has been found.

One way to have the REPL respect reader macro characters is by making  
evaluation on swank return the index of the first character not read,  
with the client using this as the starting position for the next read.

Below is the minor required modification of swank. It assumes that  
the client uses #'swank:listener-eval to evaluate a string from the  
listener in the repl. I have implemented the functionality in MCLIDE  
and verified that it works. The small change on the client was a  
simplification as it no longer has to determine where a lisp form ends.

===========================================

(defun eval-region (string)
   "Evaluate STRING.
Return the results of the last form as a list and as secondary value the
last form, with third value indicating the index of the first  
character not read in STRING"
   (with-input-from-string (stream string)
     (let (- values)
       (loop
        (let* ((index (file-position stream))
               (form (handler-case
                       (read stream nil stream)
                       (end-of-file ()
                        (finish-output)
                        (return (values values - index))))))
          (when (eq form stream)
            (finish-output)
            (return (values values -)))
          (setq - form)
          (setq values (multiple-value-list (eval form)))
          (finish-output))))))

(defun repl-eval (string)
   (clear-user-input)
   (with-buffer-syntax ()
     (with-retry-restart (:msg "Retry SLIME REPL evaluation request.")
       (track-package
        (lambda ()
          (multiple-value-bind (values last-form index) (eval-region  
string)
            (setq *** **  ** *  * (car values)
                  /// //  // /  / values
                  +++ ++  ++ +  + last-form)
            (unless index
              (funcall *send-repl-results-function* values))
            index))))))

===================================

-- Terje Norderhaug
    terje at in-progress.com








More information about the slime-devel mailing list