home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / mcl / 1095 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  3.4 KB

  1. Path: sparky!uunet!olivea!apple!cambridge.apple.com!bill@cambridge.apple.com
  2. From: bill@cambridge.apple.com (Bill St. Clair)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: Knowing when a buffer is modified, when point is moved, ...
  5. Message-ID: <9207291512.AA28515@cambridge.apple.com>
  6. Date: 29 Jul 92 16:51:41 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 64
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10. Full-Name: Bill St. Clair
  11. Original-To: cornell@freya.cs.umass.edu
  12. Original-Cc: info-mcl
  13.  
  14. >Howdy. I am building a mechanism that displays editable text and
  15. >non-editable textual representations of objects in a FRED buffer. The
  16. >non-text reps show in a different font to disginguish them from
  17. >editable text. I have two issues:
  18. >
  19. >
  20. >1) To insert text in the proper style I thought I'd use
  21. >buffer-insert-with-style, which takes a style vector. However, it
  22. >seemst the only way to get a style is via buffer-get-style, which
  23. >assumes I've already set the style! I'm now using buffer-set-font-spec
  24. >then buffer-insert to simulate a buffer-insert-with-font-spec, which
  25. >is really what I want. Would someone please tell me the accepted way
  26. >to do this?
  27.  
  28. The way you're doing it is perfectly reasonable. Your code will be
  29. faster if you use buffer-set-font-codes instead of  buffer-set-font-spec.
  30. You might also consider inserting the text in the current font, then
  31. using buffer-set-font-codes with the optional start & end arguments
  32. to change the font.
  33.  
  34. Alternatively, you can cons up your own style vector. This approach
  35. may break in the future as we have not documented the form of style
  36. vectors. If you decide to go this route, I can tell you how to cons
  37. up your own style vector.
  38.  
  39. >
  40. >
  41. >2) I need *general* ways to be informed when certain editing
  42. >conditions take place:
  43. >
  44. >a) when the cursor mark is moved within a non-editable
  45. >range (which I know via start and end marks I create for each
  46. >non-editable item) so I can extend the selection to cover the entire
  47. >object.
  48. >
  49. >b) when non-editable text is deleted so I can delete the
  50. >internally-stored objects corresponding to the deleted text.
  51. >
  52. >My question here is: Are there a few functions that I can tap that
  53. >tell me when these conditions happen? I thought move-mark and
  54. >buffer-delete might be them but they're non-generic functions so I'd
  55. >have to advise them, which means my functions get called whenever they
  56. >take place (often). I'm also thinking my start and end marks'
  57. >positions might tell me if their text has been deleted. Anyone have
  58. >a good solution?
  59.  
  60. You might try writing a method on FRED-UPDATE. FRED-UPDATE is called
  61. any time anything happens that might affect the display of a Fred
  62. buffer. In particular, it is called over and over again when the
  63. mouse button is down after a click in a fred window or dialog item.
  64. The only problem with this approach is figuring out what happenned.
  65. Checking for the cursor being within one of your non-editable ranges
  66. is quite easy. Checking for one of your objects being deleted is
  67. also easy but may be too slow to do every time FRED-UPDATE is called
  68. (keep a mark to the beginning and end of each object, when both marks
  69. of a pair point at the same BUFFER-POSITION, that object has been deleted.)
  70.  
  71. (defclass my-fred-dialog-item (fred-dialog-item) ())
  72.  
  73. (defmethod fred-update :before ((self my-fred-dialog-item))
  74.   ; Figure out what happenned and maybe do something about it.
  75.   ; This is a before method so that you can extend the selection
  76.   ; before updating happens.
  77.   )
  78.