anchor.diff:    (unless (buffer-mark-p (current-buffer))
       (editor-error "Not mark in this buffer")))
   
  -(defun set-current-mark (marker)
  -  (let ((buffer (point-buffer marker)))
  +(defun set-current-mark (point)
  +  (let ((buffer (point-buffer point)))
       (cond ((buffer-mark-p buffer)
              (move-point (buffer-mark buffer)
  -                       marker))
  +                       point))
             (t
              (setf (buffer-mark-p buffer) t)
              (setf (buffer-mark buffer)
  -                 (copy-point marker :right-inserting)))))
  -  marker)
  +                 (copy-point point :right-inserting)))))
  +  point)
   
   (defun current-line-string ()
     (line-string-at (current-point)))
  
positive.code:           region-end
            apply-region-lines))
  
  (defun first-line-p (marker)
    (<= (point-linum marker) 1))
  
  (defun last-line-p (marker)
    (<= (buffer-nlines (point-buffer marker))
        (point-linum marker)))
  
  (defun start-line-p (marker)
    (zerop (point-charpos marker)))
  
  (defun end-line-p (marker)
    (= (point-charpos marker)
       (buffer-line-length (point-buffer marker)
                           (point-linum marker))))
  
  (defun start-buffer-p (marker)
    (and (first-line-p marker)
         (start-line-p marker)))
  
  (defun end-buffer-p (marker)
    (and (last-line-p marker)
         (end-line-p marker)))
  
  (defun line-start (marker)
    (setf (point-charpos marker) 0)
    marker)
  
  (defun line-end (marker)
    (setf (point-charpos marker)
          (buffer-line-length (point-buffer marker)
                              (point-linum marker)))
    marker)
  
  (defun buffer-start (marker)
    (move-point marker (buffers-start (point-buffer marker))))
  
  (defun buffer-end (marker)
    (move-point marker (buffers-end (point-buffer marker))))
  
  (defun move-point (marker new-marker)
    (let ((buffer (point-buffer marker)))
      (setf (point-linum marker)
            (min (point-linum new-marker)
                 (buffer-nlines buffer)))
      (setf (point-charpos marker)
            (min (buffer-line-length buffer (point-linum marker))
                 (point-charpos new-marker))))
    marker)
  
  (defun same-line-p (marker1 marker2)
    (assert (eq (point-buffer marker1)
                (point-buffer marker2)))
    (= (point-linum marker1)
       (point-linum marker2)))
  
  (defun line-offset (marker n &optional (charpos 0))
    (let ((linum (point-linum marker)))
      (if (plusp n)
          (dotimes (_ n)
            (when (<= (buffer-nlines (point-buffer marker)) linum)
              (return-from line-offset nil))
            (incf linum))
          (dotimes (_ (- n))
            (when (= linum 1)
              (return-from line-offset nil))
            (decf linum)))
      (setf (point-linum marker) linum))
    (setf (point-charpos marker)
          (if (< 0 charpos)
              (min charpos
                   (length (line-string-at marker)))
              0))
    marker)
  
  (defun %character-offset-positive (marker n)
    (let ((charpos (point-charpos marker))
          (linum (point-linum marker)))
      (loop
        (when (minusp n)
          (setf (point-charpos marker) charpos)
          (setf (point-linum marker) linum)
          (return nil))
        (let* ((length (1+ (buffer-line-length (point-buffer marker)
                                               (point-linum marker))))
               (w (- length (point-charpos marker))))
          (when (< n w)
            (incf (point-charpos marker) n)
            (return marker))
          (decf n w)
          (unless (line-offset marker 1)
            (setf (point-charpos marker) charpos)
            (setf (point-linum marker) linum)
            (return nil))))))
  
  (defun %character-offset-negative (marker n)
    (let ((charpos (point-charpos marker))
          (linum (point-linum marker)))
      (loop
        (when (minusp n)
          (setf (point-charpos marker) charpos)
          (setf (point-linum marker) linum)
          (return nil))
        (when (<= n (point-charpos marker))
          (decf (point-charpos marker) n)
          (return marker))
        (decf n (1+ (point-charpos marker)))
        (cond ((first-line-p marker)
               (setf (point-charpos marker) charpos)
               (setf (point-linum marker) linum)
               (return nil))
              (t
               (line-offset marker -1)
               (line-end marker))))))
  
  (defun character-offset (marker n)
    (if (plusp n)
        (%character-offset-positive marker n)
        (%character-offset-negative marker (- n))))
  
  (defun character-at (marker &optional (offset 0))
    (if (zerop offset)
        (buffer-get-char (point-buffer marker)
                         (point-linum marker)
                         (point-charpos marker))
        (with-point ((temp-marker marker))
          (when (character-offset temp-marker offset)
            (character-at temp-marker 0)))))
  
  (defun insert-char-at (marker char &optional (n 1))
    (loop :repeat n :do (insert-char/marker marker char))
    t)
  
  (defun insert-string-at (marker string)
    (cond ((lem.text-property:text-property-p string)
           (let ((str (lem.text-property:text-property-string string)))
             (with-point ((start-marker marker))
               (insert-string/marker marker str)
               (let ((end-marker (character-offset (copy-point start-marker :temporary)
                                                   (length str))))
                 (loop :for (k v) :on (lem.text-property:text-property-plist string) :by #'cddr
                       :do (put-text-property start-marker end-marker k v))))))
          (t
           (insert-string/marker marker string)))
    t)
  
  (defun delete-char-at (marker &optional (n 1) killp)
    (when (minusp n)
      (unless (character-offset marker n)
        (return-from delete-char-at nil))
      (setf n (- n)))
    (unless (end-buffer-p marker)
      (let ((string (delete-char/marker marker n)))
        (when killp
          (kill-push string))
        t)))
  
negative.code:                                            end)
                                         key))))
  
  (defun next-single-property-change (point property-name &optional limit-point)
    (let ((first-value (text-property-at point property-name))
          (start-point (copy-point point :temporary)))
      (loop
        (unless (character-offset point 1)
          (move-point point start-point)
          (return nil))
        (unless (eq first-value (text-property-at point property-name))
          (return point))
        (when (and limit-point (point<= limit-point point))
          (move-point point start-point)
          (return nil)))))
  
  (defun previous-single-property-change (point property-name &optional limit-point)
    (let ((first-value (text-property-at point property-name -1))
          (start-point (copy-point point :temporary)))
      (loop
        (unless (eq first-value (text-property-at point property-name -1))
          (return point))
        (unless (character-offset point -1)
          (move-point point start-point)
          (return nil))
        (when (and limit-point (point>= limit-point point))
          (move-point point start-point)
          (return nil)))))
  
  (defun line-string-at (point)
    (buffer-line-string (point-buffer point)
                        (point-linum point)))
  
  (defun point-column (point)
    (string-width (line-string-at point)
                  0
                  (point-charpos point)))
  
  (defun move-to-column (point column &optional force)
    (line-end point)
    (let ((cur-column (point-column point)))
      (cond ((< column cur-column)
             (setf (point-charpos point)
                   (wide-index (line-string-at point) column))
             point)
            (force
             (insert-char-at point #\space (- column cur-column))
             (line-end point))
            (t
             (line-end point)))))
  
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  