Re: CAPI: text-input-pane-selection and more
David Fox <davef@xanalys.com> writes:
> What you need to do is subclass CAPI:EDITOR-PANE and specify your
> own input model by the :INPUT-MODEL initarg. Inspect the INPUT-MODEL
> slot after (MAKE-INSTANCE 'CAPI:EDITOR-PANE) and you will see which
> gestures need a modified action.
Thanks, that did help very much! I also noticed (after reading your
mail) that the INPUT-MODEL stuff is actually mentioned in the
docs. Shame on me... :(
> Yes. You can use editor functions to set colors in the text of an
> CAPI:EDITOR-PANE, using the Face mechanism that implements the
> syntax coloring. I think that's the portable solution you're
> after. Here's some code that should help.
>
> (defvar *red-yellow*
> (editor:make-face 'ry
> :foreground :red
> :background :yellow))
>
> (defvar *buffer* (editor:buffer-from-name "foo.txt"))
> (defvar *s* (editor:buffers-start *buffer*))
> (defvar *e* (editor:buffers-end *buffer*))
> (editor::push-region-face *red-yellow* *s* *e*)
OK, another one that helped me get further. However, this also results
in three new questions:
1. It looks like the arguments to EDITOR::PUSH-REGION-FACE have to be
of type EDITOR::POINT or EDITOR::I-POINT (which also means the
buffer is encoded therein), so in order to color an arbitrary part
of my buffer I have to create an EDITOR::POINT, right?
I found the function EDITOR::MAKE-I-POINT (IIRC) but couldn't get
it to work. What I'm currently doing is this:
(defun make-point (buffer offset)
(let ((point (editor:copy-point (editor:buffers-start buffer))))
(setf (slot-value point 'editor::offset) offset)
point))
And then, to color, say, position 3 to 7 of a certain editor-pane
of my interface I do something like this:
(editor::push-region-face *red-yellow*
(make-point (editor-pane-buffer (target-pane my-interface)) 3)
(make-point (editor-pane-buffer (target-pane my-interface)) 7)))
Is this completely stupid or am I close to how it should be done?
2. I haven't yet found out how to reset the whole pane to a
"non-colored" state. I though this one should work...
(defparameter *normal*
(editor:make-face 'bw
:foreground :black
:background :white))
(defun reset-target-region ()
(editor::push-region-face *normal*
(editor:buffers-start (editor-pane-buffer (target-pane my-interface)))
(editor:buffers-end (editor-pane-buffer (target-pane my-interface)))))
...but it doesn't. Every other combination of foreground and
background colors seems to work but black-and-white doesn't,
i.e. the *red-yellow* parts stay as they are . Why?
3. If I'm implementing my own callback for, say, (:BUTTON-1
:SECOND-PRESS), I use CAPI::MOUSE-EDITOR-CALL which gives me "raw"
x and y coordinates. I then use EDITOR::MOUSE-SET-POINT to
translate these to a point. Is that the right way to do it?
> In LispWorks4.3 (tentatively scheduled for the end of June) we will
> be including editor source code allowing you to find this
> undocumented functionality for yourself.
That's great! I'm glad to hear this. I remember being one of those to
recommend this (pointing to Digitool doing this with the source code
to Fred) and I'm happy to see that Xanalys is listening to their
customers... :)
Thanks,
Edi.