From: bill@cambridge.apple.com (Bill St. Clair)
Newsgroups: comp.lang.lisp.mcl
Subject: Re: Knowing when a buffer is modified, when point is moved, ...
Date: 29 Jul 92 16:51:41 GMT
Full-Name: Bill St. Clair
Original-To: cornell@freya.cs.umass.edu
Original-Cc: info-mcl

>Howdy. I am building a mechanism that displays editable text and
>non-editable textual representations of objects in a FRED buffer. The
>non-text reps show in a different font to disginguish them from
>editable text. I have two issues:
>
>
>1) To insert text in the proper style I thought I'd use
>buffer-insert-with-style, which takes a style vector. However, it
>seemst the only way to get a style is via buffer-get-style, which
>assumes I've already set the style! I'm now using buffer-set-font-spec
>then buffer-insert to simulate a buffer-insert-with-font-spec, which
>is really what I want. Would someone please tell me the accepted way
>to do this?

The way you're doing it is perfectly reasonable. Your code will be
faster if you use buffer-set-font-codes instead of  buffer-set-font-spec.
You might also consider inserting the text in the current font, then
using buffer-set-font-codes with the optional start & end arguments
to change the font.

Alternatively, you can cons up your own style vector. This approach
may break in the future as we have not documented the form of style
vectors. If you decide to go this route, I can tell you how to cons
up your own style vector.

>
>
>2) I need *general* ways to be informed when certain editing
>conditions take place:
>
>a) when the cursor mark is moved within a non-editable
>range (which I know via start and end marks I create for each
>non-editable item) so I can extend the selection to cover the entire
>object.
>
>b) when non-editable text is deleted so I can delete the
>internally-stored objects corresponding to the deleted text.
>
>My question here is: Are there a few functions that I can tap that
>tell me when these conditions happen? I thought move-mark and
>buffer-delete might be them but they're non-generic functions so I'd
>have to advise them, which means my functions get called whenever they
>take place (often). I'm also thinking my start and end marks'
>positions might tell me if their text has been deleted. Anyone have
>a good solution?

You might try writing a method on FRED-UPDATE. FRED-UPDATE is called
any time anything happens that might affect the display of a Fred
buffer. In particular, it is called over and over again when the
mouse button is down after a click in a fred window or dialog item.
The only problem with this approach is figuring out what happenned.
Checking for the cursor being within one of your non-editable ranges
is quite easy. Checking for one of your objects being deleted is
also easy but may be too slow to do every time FRED-UPDATE is called
(keep a mark to the beginning and end of each object, when both marks
of a pair point at the same BUFFER-POSITION, that object has been deleted.)

(defclass my-fred-dialog-item (fred-dialog-item) ())

(defmethod fred-update :before ((self my-fred-dialog-item))
  ; Figure out what happenned and maybe do something about it.
  ; This is a before method so that you can extend the selection
  ; before updating happens.
  )