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

Re: [Scheme-reports] mutable unicode strings

On 07/02/2014 04:34 PM, John Cowan wrote:
> Per Bothner scripsit:
>> When it comes to BuffersCowan, it seems reasonable enough.  One comment:
>> What is the point of point?  I.e. the concept seems redundant if you have
>> markers. In Emacs point is a special marker corresponding to the "current
>> position", but I don't think that makes sense for a Scheme library API.
> The idea of point is that it's where you can insert text into the buffer.
> This reflects a classical buffer-gap implementation, in which the buffer
> is a big array of characters, with everything before point left-justified
> in the buffer, and everything after point right-justified.

I don't believe Emacs does this.  IIRC the gap is only moved when text is
inserted/deleted, not when point is moved.

>  Therefore,
> as long as the buffer doesn't overflow, inserting at point is O(k)
> where k is the number of characters inserted, rather than O(n*k).
> The trade-off is that shifting point by k characters is also O(k).
> It is therefore optimized for inserting single characters and shifting
> by a single character, both of which are O(1).

Why would you want to treat point different from any other (advancing)
markers?  Instead of:

    (buffer-insert! buffer . strings)

you can have:

    (marker-insert! marker . strings)

If the marker is 'advancing', then this is a pure buffer operation:
Insert at the position of the marker (after moving the gap as necessary);
the marker would get automatically updated along with all the other markers.

	--Per Bothner
per@x   http://per.bothner.com/

Scheme-reports mailing list