anchor.diff:                ;; if we're in the middle of the field, either insert or replace
                 (if (.insert-enabled win)
                     (setf inbuf (insert-nth  (- len inptr)      char inbuf))
  -                  (setf inbuf (replace-nth (- len (1+ inptr)) char inbuf)))))
  -        ;; both replacing and inserting advance the cursor
  -        (incf inptr)))
  +                  (setf inbuf (replace-nth (- len (1+ inptr)) char inbuf))))
  +          ;; both replacing and inserting advance the cursor
  +          (incf inptr))))
       ;; after were done with editing, redraw the field.
  -    (draw-field win current-field)))
  +    ;; TODO: redraw the entire field or echo one single char?
  +    (draw win current-field))
  +  (refresh win))
   
   (defun field-buffer-to-string (field)
     "Return the value of the field buffer (list of chars) as a string."
     (coerce (reverse (.buffer field)) 'string))
   
  -(defun debug-print-field-buffer (form event)
  +(defun debug-print-field-buffer (win event form)
     (declare (ignore event))
  -  (with-accessors ((current-field .current-field) (win .window)) form
  +  (with-accessors ((current-field .current-field)) form
       (with-accessors ((inbuf .buffer) (inptr .fill-pointer)) current-field
         (when (> (length inbuf) 0)
           (clear win)
  
positive.code:   (with-accessors ((pos .position) (width .width) (inbuf .buffer) (inptr .fill-pointer)) field
      (clear-field window field)
      (add-string window (coerce (reverse inbuf) 'string) :attributes '(:underline))
      (move window (car pos) (+ (cadr pos) inptr)) ))
  
  ;; we have to make window a parameter because fields do not have a window slot
  (defmethod draw (window (form form))
    "Draw the form by drawing the fields, then moving the cursor to the current field."
    (declare (ignore window))
    ;; TODO: "current" field or "active" field??
    (with-accessors ((fields .fields) (current-field-number .current-field-number) (win .window)) form
      (loop for field in fields do
        ;; TODO: do we refresh in draw-field AND here?
        (draw-field win field))
      ;; after drawing the fields, reposition the cursor to the current field
      ;; ugly, we have to find a better way to do this
      (let* ((current-field (nth current-field-number fields))
             (pos (.position current-field)))
        (move win
              (car pos)
              (+ (cadr pos)
                 (.fill-pointer current-field))))
      (refresh win)))
  
  (defun draw-field (win field)
  
negative.code: 
         (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.
  (defun select-prev-field (win event form)
    "Select the previous field in a form's field list."
    ;;(declare (special form))
    (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)
    (refresh win))
  
  (defun select-next-field (win event form)
    "Select the next field in a form's field list."
    ;;(declare (special form))
    (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)
    (refresh win))
  
  (defun move-prev-char (win event form)
    "Move the cursor to the previous char in the current field."
    (with-accessors ((current-field .current-field)) form
      (with-accessors ((inptr .fill-pointer)) current-field
        (when (> inptr 0)
          (decf inptr))))
    (update-cursor-position win form)
    (refresh win))
  
  (defun move-next-char (win event form)
    "Move the cursor to the previous char in the current field."
    (with-accessors ((current-field .current-field)) form
      (with-accessors ((inbuf .buffer) (inptr .fill-pointer)) current-field
        (when (< inptr (length inbuf))
          (incf inptr))))
    (update-cursor-position win form)
    (refresh win))
  
  ;; :backspace, delete one char to the left
  (defun delete-prev-char (win event form)
    "Delete the previous char in the current field, moving the cursor to the left."
    (with-accessors ((current-field .current-field)) form
      (with-accessors ((inbuf .buffer) (inptr .fill-pointer)) current-field
        (when (> inptr 0)
          (decf inptr)
          (setf inbuf (remove-nth (- (length inbuf) 1 inptr) inbuf))))
      ;; we dont have to redraw the complete form, just the changed field.
      (draw win current-field))
    (refresh win))
  
  ;; :dc, delete one char to the right
  (defun delete-next-char (win event form)
    "Delete the next char in the current field, not moving the cursor."
    (with-accessors ((current-field .current-field)) form
      (with-accessors ((inbuf .buffer) (inptr .fill-pointer)) current-field
        ;; we can only delete to the right if the inptr is not at the end of the inbuf.
        (when (> (length inbuf) inptr)
          (setf inbuf (remove-nth (- (length inbuf) (1+ inptr)) inbuf))))
      (draw win current-field))
    (refresh win))
  
  ;; TODO: test that char is graphic
  (defun form-add-char (win char form)
    "Add char to the current field of the form."
    (with-accessors ((current-field .current-field)) form
      (with-accessors ((width .width) (inbuf .buffer) (inptr .fill-pointer)) current-field
        (let ((len (length inbuf)))
          ;; only add chars when we haven reached the max width of the field
  