[Openmcl-devel] format to a
Gary Byers
gb at clozure.com
Thu Feb 2 18:11:03 PST 2012
Sorry for not responding earlier (and I still haven't looked at your
test case in any detail.)
A Hemlock buffer in the IDE is (usually/always/almost always) associated
with a Cocoa text view; from the point of view of the text view, the
Hemlock buffer implements the view's text storage.
Modifying an NSTextStorage object safely and sanely requires that a
certain protocol be observed; that protocol involves telling the text
system that editing (if the storage object) is in progress, informing
it of what ranges of text are affected by insertions/deletions/etc,
and telling the text system that a sequence of editing operations has
been completed and the view should redisplay affected areas.
When a Hemlock command runs (usually in response to some key event),
it (a) runs on the main Cocoa event thread and (b) observes this protocol;
it can call HI::INSERT-CHARACTER and HI::INSERT-STRING (or have FORMAT
do that), and these things mean that modification on the buffer/textstorage
is synchronised with redisplay of the containing view. Nothing really
enforces the first constraint (that everything's happening on a single
thread) except for the fact that trying to modify the buffer from some
other thread will probably lead to display and other problems.)
It'd be nice if there was some protocol that allowed arbitrary code
(running in an arbitrary thread) to modify Hemlock buffers in thread-safe
ways and to ensure that those modifications were made in accordance with
Cocoa constraints. That protocol doesn't exist.
Like I said, I haven't really looked at this but I suspect you'll find
that FORMAT modified the buffer as expected but (a) the text view doesn't
know that and (b) it's possible that other code running concurrently
was also modifying the buffer in some ways while FORMAT was.
On Thu, 2 Feb 2012, Arthur Cater wrote:
> Thanks Glen.
>
> I've never looked at the innards of Format, but I assumed it bottoms out in calls
> to stream-write-char, stream-write-string, and perhaps stream-terpri.
> And these all turn into hi::insert-character and hi::insert-string.
> So I'm puzzled about what does foul up the insertion point.
>
> Arthur
>
>
> On 2 Feb 2012, at 09:49, Glen Foy wrote:
>
>> Arthur,
>>
>> If you can't find a solution to the stream/format approach (which I like), you might try using hi::insert-string.
>>
>> It accepts a :charprops parameter and will not foul up the insertion point.
>>
>> -- Glen
>>
>>
>> On Feb 1, 2012, at 10:36 AM, Arthur Cater wrote:
>>
>>> I am having trouble with cursor position in a programmatic Hemlock view.
>>> The attached (also enclosed) code makes a Hemlock view, creates a stream
>>> to write to it, and writes a few lines using format.
>>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>
>
More information about the Openmcl-devel
mailing list