anchor.diff:       ,@body))
   
   (defun display-buffer (buffer fb x y w h)
  -  (sys.int::%bitset h w #xFF000000 fb y x)
  +  (sys.graphics::bitset h w (sys.graphics::make-colour sys.graphics::*default-background-colour*) fb y x)
     (do ((lines-written 0)
          (line (buffer-first-line buffer)))
         ((or (>= lines-written h)
   	   (null line)))
       (let ((contents (slot-value line 'contents))
  -          (next (slot-value line 'next)))
  +          (next (slot-value line 'next))
  +          (text-colour (sys.graphics::make-colour sys.graphics::*default-foreground-colour*)))
         (do ((i 0 (1+ i))
   	   (ofs 0))
   	  ((or (>= i (length contents))
  
positive.code: 	     (draw-cursor fb (+ x ofs) (+ y lines-written) (eql *buffer* buffer))))
  	(let* ((ch (char contents i))
                 (width (if (eql ch #\Space) 8 (sys.int::unifont-glyph-width ch))))
            (unless (>= (+ ofs width) w)
              (if (eql ch #\Space)
                  (sys.int::%bitset 16 8 #xFF000000 fb (+ y lines-written) (+ x ofs))
                  (sys.int::render-char-at ch fb (+ x ofs) (+ y lines-written))))
  	  (when (with-current-buffer buffer
                    (and (eql (point-line) line)
                         (eql (point-character) i)))
  
negative.code:            (funcall fn))
           (setf *last-command* fn)))))
  
  (defclass editor-window (sys.graphics::window-with-chrome)
    ((input-buffer :initarg :input-buffer)
     (process :reader window-process))
    (:default-initargs :input-buffer (sys.graphics::make-fifo 500 'character)))
  
  (defmethod initialize-instance :after ((instance editor-window))
    (unless *buffer*
      (set-buffer (get-buffer-create "*scratch*"))
      (setf *main-screen-buffer* (get-buffer-create "*scratch*"))
      (setf *minibuffer* (get-buffer-create " *minibuffer*")
            (buffer-key *minibuffer* #\Newline) 'exit-minibuffer))
    (let ((process (make-instance 'sys.int::process :name "Edit")))
      (setf (slot-value instance 'process) process)
      (sys.int::process-preset process 'editor-top-level instance)
      (sys.int::process-enable process)))
  
  (defmethod sys.graphics::window-close-event :before ((window editor-window))
    (sys.int::process-arrest-reason (window-process window) :window-closed))
  
  (defmethod sys.graphics::key-press-event ((window editor-window) character)
    (sys.graphics::fifo-push character (slot-value window 'input-buffer)))
  
  (defmethod sys.graphics::window-redraw ((window editor-window))
    (let* ((fb (sys.graphics::window-backbuffer window))
           (dims (array-dimensions fb))
           (width (second dims))
           (height (first dims))
           (text-colour (sys.graphics::make-colour sys.graphics::*default-foreground-colour*)))
      (multiple-value-bind (left right top bottom)
          (sys.graphics::compute-window-margins window)
        (display-buffer *main-screen-buffer* fb
                        left top
                        (- width left right) (- height 16 16 2 top bottom))
        (display-buffer *minibuffer* fb
                        left (- height 16 bottom)
                        (- width left right) 16)
        (sys.graphics::bitset 16 (- width left right)
                              (sys.graphics::make-colour sys.graphics::*default-background-darker-colour*)
                              fb
                              (- height 16 16 1 bottom) left)
        (let ((name (buffer-name *main-screen-buffer*))
              (ofs left))
          (dotimes (i (length name))
            (let* ((ch (char name i))
                   (char-width (if (eql ch #\Space) 8 (sys.int::unifont-glyph-width ch)))
                   (glyph (sys.int::map-unifont-2d ch)))
              (when (and (< (+ ofs char-width) width)
                         (not (eql ch #\Space))
                         glyph)
                (sys.graphics::bitset-argb-xrgb-mask-1 16 char-width text-colour
                                                       glyph 0 0
                                                       fb (- height 16 16 1 bottom) ofs))
              (incf ofs char-width))))
        (sys.graphics::bitset 1 (- width left right) #xFFD0D0D0 fb (- height 16 1 bottom) left)
        (sys.graphics::bitset 1 (- width left right) #xFFD0D0D0 fb (- height 16 16 2 bottom) left))))
  
  (defun read-editor-character ()
    (loop
       (let ((char (sys.graphics::fifo-pop (slot-value *frame* 'input-buffer))))
         (when char (return char)))
       (sys.int::process-wait "User input"
                              (lambda (frame)
                                (not (sys.graphics::fifo-emptyp (slot-value frame 'input-buffer))))
                              *frame*)))
  
  (defun editor-top-level (window)
    (let ((*buffer* (get-buffer-create "*scratch*"))
          (*last-key-pressed* nil)
          (*frame* window))
      (unwind-protect
           (handler-case (editor-loop)
             (exit-editor ()))
        (sys.graphics::close-window window))))
  
  (defun ed (&optional thing)
    (unless *editor-window*
      (setf *editor-window* (sys.graphics::make-window "Edit.com" 600 600 'editor-window)))
    (sys.graphics::window-set-visibility *editor-window* t))
  (defun create-or-show-editor-window ()
    (unless *editor-window*
      (setf *editor-window* (sys.graphics::make-window "Edit.com" 600 600 'editor-window)))
    (sys.graphics::window-set-visibility *editor-window* t))
  (defun create-or-show-editor-window ()
    (let ((win (sys.graphics::make-window "Edit" 600 600 'editor-window)))
      (sys.graphics::window-set-visibility win t)))
  
  (setf (gethash (name-char "F6") sys.graphics::*global-keybindings*) 'create-or-show-editor-window)
  (setf (gethash (name-char "M-F6") sys.graphics::*global-keybindings*) 'create-editor-window)
  