Index: /branches/ide-1.0/ccl/examples/cocoa-editor.lisp
===================================================================
--- /branches/ide-1.0/ccl/examples/cocoa-editor.lisp	(revision 6621)
+++ /branches/ide-1.0/ccl/examples/cocoa-editor.lisp	(revision 6622)
@@ -536,5 +536,5 @@
   #+debug
   (#_NSLog #@"Attributes at index: %d" :unsigned index)
-  #-no
+  #+no
   (let* ((buffer-cache (hemlock-buffer-string-cache (slot-value self 'string)))
 	 (buffer (buffer-cache-buffer buffer-cache))
@@ -562,5 +562,5 @@
               (pref rangeptr :<NSR>ange.length) len))
       (svref *styles* style)))
-  #+no
+  #-no
   (with-slots (cache) self
     (let* ((attrs (#/attributesAtIndex:effectiveRange: cache index rangeptr)))
@@ -1682,4 +1682,12 @@
                                         n))))
 
+(defun buffer-active-font (buffer)
+  (let* ((style 0)
+         (region (hi::buffer-active-font-region buffer)))
+    (when region
+      (let* ((start (hi::region-end region)))
+        (setq style (hi::font-mark-font start))))
+    (svref *styles* style)))
+      
 (defun hi::buffer-note-insertion (buffer mark n)
   (when (hi::bufferp buffer)
@@ -1689,16 +1697,19 @@
         (let* ((pos (mark-absolute-position mark))
                (cache (#/cache textstorage))
-               (hemlock-string (#/string textstorage)))
+               (hemlock-string (#/string textstorage))
+               (display (hemlock-buffer-string-cache hemlock-string))
+               (buffer (buffer-cache-buffer display))
+               (font (buffer-active-font buffer)))
           (unless (eq (hi::mark-%kind mark) :right-inserting)
             (decf pos n))
           #+debug
-	  (format t "~&insert: pos = ~d, n = ~d" pos n)
-          (let* ((display (hemlock-buffer-string-cache hemlock-string)))
-            ;(reset-buffer-cache display)
-            (adjust-buffer-cache-for-insertion display pos n)
-            (update-line-cache-for-index display pos))
+	  (#_NSLog #@"insert: pos = %d, n = %d" :int pos :int n)
+          ;;(reset-buffer-cache display)
+          (adjust-buffer-cache-for-insertion display pos n)
+          (update-line-cache-for-index display pos)
           (#/replaceCharactersInRange:withString:
            cache (ns:make-ns-range pos 0)
-           (#/substringWithRange: hemlock-string (ns:make-ns-range pos n))) 
+           (#/substringWithRange: hemlock-string (ns:make-ns-range pos n)))
+          (#/setAttributes:range: cache font (ns:make-ns-range pos n))
           #-all-in-cocoa-thread
           (textstorage-note-insertion-at-position textstorage pos n)
@@ -1936,6 +1947,6 @@
         (let* ((textstorage (slot-value self 'textstorage))
                (display (hemlock-buffer-string-cache (#/string textstorage))))
+          (reset-buffer-cache display) 
           (#/updateCache textstorage)
-          (reset-buffer-cache display) 
           (update-line-cache-for-index display 0)
           (textstorage-note-insertion-at-position
@@ -2100,4 +2111,9 @@
       (setq *hemlock-document-controller* (call-next-method))
       (setf (slot-value *hemlock-document-controller* 'last-encoding) 0))))
+
+(defun iana-charset-name-of-nsstringencoding (ns)
+  (#_CFStringConvertEncodingToIANACharSetName
+   (#_CFStringConvertNSStringEncodingToEncoding ns)))
+    
 
 ;;; Return a list of :<NSS>tring<E>ncodings, sorted by the
