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

Re: Scrolling windows with word wrap...



>> Can't seem to find an easy way to do this in MACL 2.0 - anyone know
>> how or where to find code that does it?

Here is a program I modified from someone else's program for word-wrap.  (Sorry, I cannot  
remember the original program to give credit to.)  It works  in fred-windows and  
scrolling-fred-dialog-items.

(defconstant *wsp&cr* #.(let ((str (make-string 7)))
                          (set-schar str 0 #\Space)
                          (set-schar str 1 #\^M)
                          (set-schar str 2 #\^I)
                          (set-schar str 3 #\^L)
                          (set-schar str 4 #\^@)
                          (set-schar str 5 #\^J)
                          (set-schar str 6 (%code-char #xCA))
                          str))

(defun word-wrap (w fill-length)  ; w is the window; fill-length is the line length for word-wrap
  (let* ((buf (fred-buffer w))
         (end-pos (buffer-position buf))
         (end-column (buffer-column buf end-pos)))

    (when (> end-column fill-length)               

      (do ((break-pos (buffer-char-pos buf *wsp&cr* 

                                       :start 0 

                                       :end fill-length
                                       :from-end t)
                      (buffer-char-pos buf *wsp&cr* 

                                       :start break-pos 

                                       :end (+ break-pos fill-length)
                                       :from-end t)))
          ((or (null break-pos) 

               (>= (+ break-pos fill-length) end-pos) )
           (buffer-char-replace buf #\return break-pos))
        (buffer-char-replace buf #\return break-pos)
                       

        ))))

Sheldon Shen