This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: printed representation -> C string


> If so, it would be very groovy to have a kind of Guile I/O port that
> reads/writes to a Gtk text widget.

Co-incidentally, I have been working on something similar for Kawa.
At this point, I think it is quite neat.  It may provide help and
ideas for anyone trying to implement something similar using Gtk
and Guile.  I was inspired by the Lisp interaction windows of Emacs.

See the latest snapshot in ftp://ftp.cygnus.com/pub/bothner/kawa-1.5.94.tar.gz.
(This requires a Java environment with JDK 1.1 functionality.)

Some of the features provided include:
* Uses standard AWT TextArea widget (which is somewhat primitive.)
* Provides text editing using standard TextArea bindings.
* Hitting Enter causes "current line" to be sent to reader.
* Can create multiple windows, which can either share or have separate
top-level environments.
* A prompt is emitted, with a line number.
* Multi-line commands work. A prompt is emitted for each line,
but the prompt is modified to show it is a continuation line.
* Conversely, if you type multiple commands on a line, you only get
one prompt!
* If you paste multi-line text (and then hit enter), only the first
line is sent to the reader.  The "output cursor" is set to before
the remaining lines.  Thus output (including the next prompt) is
inserted in the right place.  When the reader asks for the next
line, it calls the prompt procedure, which inserts the prompt, and
reads the next line of the pasted text.
* If when you hit enter, the curser is after the output marker
(or on the same line), then only text text after the output marker
is sent to the reader.  This automatically avoids problems with the
prompt, without needing a "prompt regexp" (as in Emacs).
* If when you hit enter, the cursor is *before* the line containing
the output marker, then the cursor line is inserted at the output marker
and then sent to the reader.  This matches Emacs inferior-Lisp and
inferior-Shell behavior.  However, there is a problem recognizing
the prompt.  I reduce that problem by making the default prompt
have the form of a comment.  But see below for a better solution.

Unfortunately, the TextArea wident is rather primitive, and does not
support styled (multi-font) text.  Also, it does not directly support
Emacs-style "markers", though they can be implemented with some hacking.
(I did something like it to simulate the "output position marker",
though I'm not sure how robust it is.)  At some point, I'll rewrite
it to use the new Swing widgets.

Assuming the corresponding Gtk widget supports multi-style text,
there are some nice things you can do.  One neat idea is to put
the prompt in a special style.  Then when you hit enter in an "old"
line, it is easy to skip any text that has the prompt style.
That solves the problem I mentioned before, without needing
Emacs's non-robust "prompt-regexp".  You could also strip out
text in the prompt style when cutting-and-pasting text.

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner