anchor.diff:              (buffer (current-buffer)))
           (when (and before after)
             (if (buffer-mark-p buffer)
  -              (lem::with-point ((mark-marker (lem::buffer-mark buffer) :right-inserting))
  -                (if (point< mark-marker (lem::buffer-point buffer))
  -                    (query-replace-internal-body mark-marker
  +              (lem::with-point ((mark-point (lem::buffer-mark buffer) :right-inserting))
  +                (if (point< mark-point (lem::buffer-point buffer))
  +                    (query-replace-internal-body mark-point
                                                    (lem::buffer-point buffer)
                                                    before after)
                       (query-replace-internal-body (lem::buffer-point buffer)
  -                                                 mark-marker
  +                                                 mark-point
                                                    before after)))
                 (query-replace-internal-body (lem::buffer-point buffer)
                                              nil
  
positive.code:     (setq *replace-after-string* after)
      (list before after)))
  
  (defun query-replace-internal-body (cur-marker goal-marker before after)
    (let ((pass-through nil))
      (loop
        (when (or (not (funcall *isearch-search-forward-function* cur-marker before))
                  (and goal-marker (point< goal-marker cur-marker)))
          (when goal-marker
            (lem::move-point (current-point) goal-marker))
          (return))
        (lem::with-point ((end cur-marker))
          (isearch-update-buffer cur-marker before)
          (funcall *isearch-search-backward-function* cur-marker before)
          (lem::with-point ((start cur-marker))
            (loop :for c := (unless pass-through
                              (minibuf-read-char (format nil "Replace ~s with ~s" before after)))
                  :do (cond
                        ((or pass-through (char= c #\y))
                         (lem::delete-between-points start end)
                         (lem::insert-string-at cur-marker after)
                         (return))
                        ((char= c #\n)
                         (lem::move-point cur-marker end)
                         (return))
                        ((char= c #\!)
                         (setf pass-through t)))))))))
  
negative.code: (define-command isearch-backward () ()
    (isearch-start
     "ISearch:"
     (lambda (point str)
       (search-backward (or (lem::character-offset point (length str))
                            point)
                        str))
     #'search-forward
     #'search-backward
  