anchor.diff:        (cons element (cdr list))
         (cons (car list) (replace-nth (1- n) element (cdr list)))))
   
  -;; TODO: rename to clear, make clear a method specialized on fields
  +;; TODO: rename to clear, make clear a method specialized on fields, forms and windows.
  +;; TODO: (defmethod clear (win (field field)))
   (defun clear-field (win field)
     "Do what (clear win) does, but for a single field.
   
   clear = write space combined with the background char."
     (with-accessors ((pos .position) (width .width)) field
       (setf (.cursor-position win) pos)
  +    ;; TODO: overwrite the field with the background char, not just with a space.
       (add-char win #\space :n width)
       (setf (.cursor-position win) pos)
       ;; this is the only place we set the attribute for the whole field
       (change-attributes win width '(:underline))))
   
  -;; TODO: do we need to refresh here?
  -(defun update-cursor-position (win object)
  -  "Update the cursor position of object, which can be a form or a single field."
  -  (typecase object
  -    (field
  -     (with-accessors ((pos .position) (inptr .fill-pointer)) object
  -       (move win
  -             (car pos)
  -             (+ (cadr pos) inptr))))
  -    (form
  -     (with-accessors ((current-field .current-field)) object
  -       (update-cursor-position win current-field)))))
  +(defgeneric update-cursor-position (window object)
  +  (:documentation "Update the cursor position of a form or a field."))
  +
  +(defmethod update-cursor-position (win (field field))
  +  "Update the cursor position of a field."
  +  (with-accessors ((pos .position) (inptr .fill-pointer)) field
  +    (move win
  +          (car pos)
  +          (+ (cadr pos) inptr))))
  +
  +(defmethod update-cursor-position (win (form form))
  +  "Update the cursor position of the current field of the form."
  +  (update-cursor-position win (.current-field form)))
   
   (defgeneric draw (window object)
     (:documentation "Draw forms and their elements like fields and buttons."))
  
positive.code:   (with-accessors ((fields .fields) (current-field-number .current-field-number) (current-field .current-field)) form
      ;; use mod to cycle the field list.
      (setf current-field-number (mod (- current-field-number 1) (length fields)))
      ;; TODO: before we can set the prev current field, we have to setf the first current field.
      (setf current-field (nth current-field-number fields)))
    ;; after we switched the field number, we also have to move the cursor.
    (update-cursor-position win form)
  
negative.code:     ;;#\newline  'debug-print-field-buffer
      :default   'form-add-char))
  
  ;; keymap used for editing single fields which are not part of a form.
  (add-keymap :field-default-keymap
    (make-keymap
  
      ;; Use C-a ^A #\soh 1 to exit the edit loop.
      ;; TODO: what should the exit return?
      #\soh      'exit-event-loop
     
      :left      'move-prev-char
      :right     'move-next-char
      :backspace 'delete-prev-char
      :dc        'delete-next-char
  
      :ic        (lambda (win event form)
                   ;; If an optional argument like form is passed to run-event-loop,
                   ;; the handler functions have to handle it.  
                   (setf (.insert-enabled win) (not (.insert-enabled win))))
  
      ;;#\newline  'debug-print-field-buffer
      :default   'field-add-char))
  
  (defun edit (window object)
    "Allow the used to edit fields or forms."
    (draw window object)
  
    (let ((default-keymap (typecase object
                            (field :field-default-keymap)
                            (form  :form-default-keymap))))
    
      ;; if the user didnt add any event handlers, add the default keymap.
      (with-accessors ((event-handlers .event-handlers)) window
        (unless event-handlers
          (setf event-handlers (get-keymap default-keymap)))))
  
    ;; the optional arg form will be passed by run-event-loop to the
    ;; event handler functions along with win and event.
    (run-event-loop window object))
  