CLIM mail archive


help for editing text.

> I would like to have a little text editor, so I can accept a few (more than
> one) line of text. I think that question is somewhat connected with 1.

Here's what works for me...

(defun edit-obj (obj associated-window &optional pkg)
  (let* ((*package* (if (symbolp obj)
		        (symbol-package obj)
		        *package*))  ;; just so package prefix is not printed.
	 (df (with-output-to-string (s) (pprint obj s))))
    (clim::with-menu (str associated-window) 
      (clim::clear-input str)
      ;; set to some arbitrary "nice" size, LUCID comes up with a very
      ;; small one by default.
      (clim::window-set-inside-size str 700 300)
      (setf (clim::stream-text-margin str) (clim::window-inside-width str))
      (clim::window-expose str)

      ;; just to make sure pointer is in the window...
      (clim::stream-set-pointer-position* str 100 100)
      (clim::with-input-editing (str :initial-contents df)
	#+excl (mp::process-run-function "OLD KLUDGE" #'bloody-kludge str)
	#+lcl (lcl::make-process :name "OLD KLUDGE" :function #'bloody-kludge
                                 :args (list str))
	(read str)))))

(defun bloody-kludge (str)
  ;;; AAAAAAAARGH, MAJOR KLUDGERY to get text displayed
  (sleep 1) (clim::window-refresh str))

This works on a SUN with either Allegro or Lucid CL.  Also, I think
for LUCID, you need to be careful about the argument to
:initial-contents, if it is a well-formed (expr) list, it may return
immediately, so you may want to do something like (subseq obj 0 (1-
(length obj))) after you've converted obj into a string.
Unfortunately you won't get a cursor.  Since this is really primitive,
if you have something that is more than one line long, you'll prolly
have to write something that breaks it up reasonably.

Hope this helps.



Main Index | Thread Index