anchor.diff:     (%line-start-position :accessor line-start-position)
      (%line-end-position :accessor line-end-position)
      (%history-table :initarg :history-table :reader history-table)
  -   (%history-position :initarg :history-position :accessor history-position))
  +   (%history-position :initarg :history-position :accessor history-position)
  +   (%history-search-fragment :initarg :history-search-fragment :accessor history-search-fragment)
  +   (%last-command :initarg :last-command :accessor last-command))
     (:default-initargs :history-table *line-editor-history*
  -                     :history-position nil))
  +                     :history-position nil
  +                     :history-search-fragment nil
  +                     :last-command nil))
   
   (defvar *line-editor-command-table* (make-hash-table))
   
  
positive.code:            #:define-command
             #:buffer
             #:cursor-position
             #:history-table
             #:history-reset
             #:history-newest
             #:history-oldest
  
negative.code:                                       :adjustable t)
            (cursor-position stream) (length data))))
  
  (defun history-search (history-table position direction-function term)
    (loop
       (let ((next (case position
                     (:newest (history-newest history-table))
                     (:oldest (history-oldest history-table))
                     (t (funcall direction-function history-table position)))))
         (when (not next)
           (return nil))
         (let ((data (history-data history-table next)))
           (when (and (<= (length term) (length data))
                      (string= term data :end2 (length term)))
             (return (values next data))))
         (setf position next))))
  
  (defun history-search-in-progress (stream)
    (member (last-command stream) '(previous-history next-history)))
  
  (defun current-history-pattern (stream)
    (cond ((history-search-in-progress stream)
           (history-search-fragment stream))
          ((zerop (length (buffer stream)))
           nil)
          (t (copy-seq (buffer stream)))))
  
  (defun move-history (stream direction pattern)
    (setf (history-search-fragment stream) (or pattern ""))
    (let ((pos (history-search (history-table stream)
                               (or (when (history-search-in-progress stream)
                                     (history-position stream))
                                   (ecase direction
                                     (:forward :oldest)
                                     (:backward :newest)))
                               (ecase direction
                                 (:forward #'history-next)
                                 (:backward #'history-previous))
                               (history-search-fragment stream))))
      (when pos
        (let ((data (history-data (history-table stream) pos)))
          (setf (buffer stream) (make-array (length data)
                                            :element-type 'character
                                            :initial-contents data
                                            :fill-pointer t
                                            :adjustable t)
                (cursor-position stream) (length data))))
      (setf (history-position stream) pos)))
  
  (define-command previous-history (stream (#\M-P #\Up-Arrow))
    (move-history stream :backward (current-history-pattern stream)))
  
  (define-command next-history (stream (#\M-N #\Down-Arrow))
    (move-history stream :forward (current-history-pattern stream)))
  
  (define-command forward-delete-char (stream (#\Delete #\C-D))
    "Delete one character forward."
  