anchor.diff:      (loop for field in fields do
         (draw win field))
       ;; after drawing the fields, reposition the cursor to the current field
  -    ;; ugly, we have to find a better way to do this
       (update-cursor-position win form)
       (refresh win)))
  -
  -(defun draw-field (win field)
  -  "Clear and redraw the field and its contents and background."
  -  (with-accessors ((pos .position) (width .width) (inbuf .buffer) (inptr .fill-pointer)) field
  -    (clear-field win field)
  -    (add-string win (coerce (reverse inbuf) 'string) :attributes '(:underline))
  -    (move win (car pos) (+ (cadr pos) inptr))
  -    (refresh win)))
  -
  -;; TODO: delete, replaced by (draw win form)
  -(defun draw-form (win form)
  -  "Draw the form by drawing the fields, then moving the cursor to the current field."
  -  ;; TODO: "current" field or "active" field??
  -  (loop for field in (.fields form) do
  -       (draw-field win field))
  -  ;; after drawing the fields, reposition the cursor
  -  ;; ugly, we have to find a better way to do this
  -  (let* ((field (nth (.current-field-number form) (.fields form)))
  -         (pos (.position field)))
  -    (move win
  -          (car pos)
  -          (+ (cadr pos)
  -             (.fill-pointer field))))
  -  (refresh win))
  -
  -;; we have to merge edit-form and edit(-field) because we have to
  -;; catch #\soh, tab and all other field-switching events in one single event loop.
  -(defun edit-field (win field)
  -  "Let the user edit the field, then return the contents."
  -  ;; declaring the field special lets the object keep its contents after the edit functions returns
  -  (declare (special field))
  -  (with-accessors ((pos .position) (width .width) (inbuf .buffer) (inptr .fill-pointer)) field
  -    (draw-field win field)
  -    (event-case (win event)
  -      ;; TODO: use some other key for exiting the edit loop, maybe C-something.
  -      ;; C-a ^A #\soh 1          
  -      (#\soh (return-from event-case inbuf))
  -      
  -      (:left
  -       (when (> inptr 0) (decf inptr))
  -       (move win (car pos) (+ (cadr pos) inptr)))
  -
  -      (:right
  -       (when (< inptr (length inbuf)) (incf inptr))
  -       (move win (car pos) (+ (cadr pos) inptr)))
  -      
  -      ;; for debugging, return prints the content of the buffer and then deletes the buffer
  -      (#\newline
  -       (when (> (length inbuf) 0)
  -         (clear win)
  -         (format t "~A~%" (coerce (reverse inbuf) 'string)) (refresh win)
  -         (setf inbuf nil inptr 0)
  -         (draw-field win field)))
  -
  -      ;; delete one char to the right
  -      (:dc
  -       (when (> (length inbuf) inptr)
  -         (setf inbuf (remove-nth (- (length inbuf) (1+ inptr)) inbuf))
  -         (draw-field win field) ))
  -
  -      ;; delete one char to the left
  -      (:backspace
  -       ;; we can use it only until the first char.
  -       (when (> inptr 0)
  -         (decf inptr)
  -         (setf inbuf (remove-nth (- (length inbuf) 1 inptr) inbuf))
  -         (draw-field win field) ))
  -
  -      ;; toggle insert/overwrite mode
  -      (:ic (setf (.insert-enabled win) (not (.insert-enabled win))))
  -
  -      ;; display every other character
  -      ;; TODO: limit handling to displayable graphic characters only
  -      (otherwise
  -       (let ((len (length inbuf)))
  -         ;; only add chars when we haven reached the max width of the field
  -         (unless (= len width)
  -           ;; if we're at the end of the inbuf
  -           (if (= inptr len)
  -               ;; just add another char to the inbuf
  -               (setf inbuf (cons event inbuf))
  -               ;; if we're in the middle of the field, either insert or replace
  -               (if (.insert-enabled win)
  -                   ;; if we're somewhere in the middle, either insert or replace.
  -                   (setf inbuf (insert-nth  (- len inptr)      event inbuf))
  -                   (setf inbuf (replace-nth (- len (1+ inptr)) event inbuf))))
  -           ;; both replacing and inserting advance the cursor
  -           (incf inptr)))
  -
  -       (draw-field win field)) )))
   
   ;; prev-field and next-field are the only two elements where the current-field-number is changed.
   ;; here also current-field has to be set.
  
positive.code:       (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
  (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)
      (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 draw (window object)
    (:documentation "Draw forms and their elements like fields and buttons."))
  
negative.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)))
      (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)
  