[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How does one read multi-line text blocks? : The Solution



Hi,
     Yesterday I left a message asking how one could have a user
paste in and edit several lines of text and read them all in at
once. Two people suggested using a window (or a dialog box)
especially for the input, so I re-read the section on fred-windows
last night and decided to go with that solution. However, just as I
was falling asleep last night I realized there is a less-clunky way
of doing the same thing by simply comparing the buffer-size of the
front window before the user puts (types/pastes) in the text to the
buffer size after the text has been entered, and taking the
difference. This is an almost ideal solution, in the sense that it
allows for nearly normal editing of multi-line text: the only problem
(to me a minor one) remaining is that the user cannot simply type
'return' to get a new line in the middle of the text. However, s/he
can do normal editing other than that, including fully functional
cutting and pasting, even of multi-line texts. Since no one
suggested anything like this, and one person asked me to forward
solutions, I thought this code might be of general interest, and so
I have attached it below.
   Thanks to everyone who replied to my original query.

                                Chris

(defun ask-for-lots ()
  ; Asks the user for multi-line editable texts, and
  ; returns them.
  (format t "Please write a lot here now.~%>> ")
  (let
    ((PreBuffer
      (buffer-size (ask (front-window) (window-buffer)))))
    (do
      ((input (read-line) (read-line)))
      ((string-equal input "")
        (buffer-substring
        (ask (front-window) (window-buffer))
        :start PreBuffer
        :end (buffer-size
              (ask (front-window) (window-buffer))))))))


*****************************************************************
*   Chris Westbury cxea@mcgilla.ca                              *
*   Department Of Psychology, McGill University                 *
*                                                               *
*    "We dignify our stupidities when we set them up in type."  *
*                                     Michel De Montaigne       *
* ***************************************************************