Index: /trunk/ccl/examples/cocoa-editor.lisp
===================================================================
--- /trunk/ccl/examples/cocoa-editor.lisp	(revision 720)
+++ /trunk/ccl/examples/cocoa-editor.lisp	(revision 721)
@@ -49,9 +49,12 @@
 (defun make-hemlock-buffer (&rest args)
   (let* ((buf (apply #'hi::make-buffer args)))
-    (or buf
-	(progn
-	  (format t "~& couldn't make hemlock buffer with args ~s" args)
-	  (dbg)
-	  nil))))
+    (if buf
+      (progn
+	(setf (hi::buffer-gap-context buf) (hi::make-buffer-gap-context))
+	buf)
+      (progn
+	(format t "~& couldn't make hemlock buffer with args ~s" args)
+	(dbg)
+	nil))))
 	 
 ;;; Define some key event modifiers.
@@ -342,5 +345,8 @@
           :edited #$NSTextStorageEditedCharacters
           :range (ns-make-range pos n)
-          :change-in-length (- n))))
+          :change-in-length (- n))
+    (let* ((display (hemlock-buffer-string-cache (send self 'string))))
+            (reset-buffer-cache display) 
+            (update-line-cache-for-index display pos))))
 
 (define-objc-method ((:void :note-modification params) hemlock-text-storage)
@@ -386,6 +392,4 @@
 ;;; hemlock-buffer-string.)
 (defun make-textstorage-for-hemlock-buffer (buffer)
-  (unless (hi::buffer-gap-context buffer)
-    (setf (hi::buffer-gap-context buffer) (hi::make-buffer-gap-context)))
   (make-objc-instance 'hemlock-text-storage
 		      :with-string
@@ -998,5 +1002,6 @@
 
 (defun nsstring-to-buffer (nsstring buffer)
-  (let* ((document (hi::buffer-document buffer)))
+  (let* ((document (hi::buffer-document buffer))
+	 (hi::*buffer-gap-context* (hi::buffer-gap-context buffer)))
     (setf (hi::buffer-document buffer) nil)
     (unwind-protect
@@ -1284,5 +1289,4 @@
 	(setf (slot-value doc 'textstorage)
 	      (make-textstorage-for-hemlock-buffer buffer)
-	      (hi::buffer-gap-context buffer) (hi::make-buffer-gap-context)
 	      (hi::buffer-document buffer) doc)))
     doc))
@@ -1300,8 +1304,7 @@
 		    (setf (hi::buffer-pathname b) pathname)
 		    (setf (slot-value self 'textstorage)
-			  (make-textstorage-for-hemlock-buffer b)
-			  (hi::buffer-gap-context b)
-			  (hi::make-buffer-gap-context))
+			  (make-textstorage-for-hemlock-buffer b))
 		    b)))
+	 (hi::*buffer-gap-context* (hi::buffer-gap-context buffer))
 	 (data (make-objc-instance 'ns:ns-data
 				   :with-contents-of-file filename))
@@ -1365,4 +1368,6 @@
   
 (define-objc-method ((:void make-window-controllers) hemlock-editor-document)
+  #+debug
+  (#_NSLog #@"Make window controllers")
   (let* ((controller (make-objc-instance
 		      'hemlock-editor-window-controller
