overlay.el bug, incompatable overlays-in

Stephen J. Turnbull stephen at xemacs.org
Wed Feb 27 03:33:06 EST 2008


It's me FKtPp ;) writes:

 > +(defsubst overlay-validate-begin-end-buffer ()

I prefer the name "overlay-normalize-begin-end-buffer".  Validate is
OK, but for example in XML processing a "validating process" will give
a fatal error on invalid XML; it won't fix it up.

 > +  "validte the value of BEG, END and BUFFER
 > +
 > +If BUFFER is nil, set to current buffer.  If BEG is
 > +greater than END, exchange their value.  If either
 > +BEG or END is out of buffer boundary, set their
 > +value to corresponding boundary-value."

  "Normalize the BEG, END, and BUFFER arguments.

BUFFER must be a buffer or nil, meaning the current buffer.
BEG and END must be integers.  They are sorted and truncated to values
legal in BUFFER so that 1 <= BEG <= END <= \(1+ \(length BUFFER))."

 > +  (if (null buffer)
 > +      (setq buffer (current-buffer))
 > +    (check-argument-type 'bufferp buffer))

 > +  (when (> beg end)
 > +    (setq beg (prog1 end (setq end beg))))
 > +
 > +  (setq beg (max beg 1)
 > +	end (min end (1+ (buffer-size))))
 > +  t)

I would write these as

  (when (< beg 1)
    (setq beg 1))
  (when (> end (1+ (buffer-size buffer)))
    (setq end (1+ (buffer-size buffer))))

 > +
 >  (defun make-overlay (beg end &optional buffer front-advance rear-advance)
 >    "Create a new overlay with range BEG to END in BUFFER.
 >  If omitted, BUFFER defaults to the current buffer.
 > @@ -76,13 +95,15 @@
 >  The fourth arg FRONT-ADVANCE, if non-nil, makes the
 >  front delimiter advance when text is inserted there.
 >  The fifth arg REAR-ADVANCE, if non-nil, makes the
 > -rear delimiter advance when text is inserted there."
 > -  (if (null buffer)
 > -      (setq buffer (current-buffer))
 > -    (check-argument-type 'bufferp buffer))
 > -  (when (> beg end)
 > -    (setq beg (prog1 end (setq end beg))))
 > +rear delimiter advance when text is inserted there.
 >  
 > +BEG and END's value will be exchanged if END is less
 > +than BEG.  And if BEG or END is out of buffer
 > +boundary the corresponding boundary-value will
 > +be used."

How about

BEG and END will be normalized so 1 <= BEG <= END <= \(1+ \(length BUFFER)).

and similarly below.

 > +
 > +  (overlay-validate-begin-end-buffer)
 > +
 >    (let ((overlay (make-extent beg end buffer)))
 >      (set-extent-property overlay 'overlay t)
 >      (if front-advance
 > @@ -98,12 +119,19 @@
 >    "Set the endpoints of OVERLAY to BEG and END in BUFFER.
 >  If BUFFER is omitted, leave OVERLAY in the same buffer it inhabits now.
 >  If BUFFER is omitted, and OVERLAY is in no buffer, put it in the current
 > -buffer."
 > +buffer.
 > +
 > +BEG and END's value will be exchanged if END is less
 > +than BEG.  And if BEG or END is out of buffer
 > +boundary the corresponding boundary-value will
 > +be used."
 > +
 >    (check-argument-type 'overlayp overlay)
 >    (if (null buffer)
 >        (setq buffer (extent-object overlay)))
 > -  (if (null buffer)
 > -      (setq buffer (current-buffer)))
 > +
 > +  (overlay-validate-begin-end-buffer)
 > +
 >    (check-argument-type 'bufferp buffer)
 >    (and (= beg end)
 >         (extent-property overlay 'evaporate)
 > @@ -150,15 +178,32 @@
 >  Overlap means that at least one character is contained within the overlay
 >  and also contained within the specified region.
 >  Empty overlays are included in the result if they are located at BEG
 > -or between BEG and END."
 > +or between BEG and END.
 > +
 > +If BEG or END is out of buffer boundary the
 > +corresponding boundary-value will be used."
 > +
 > +  (setq beg (max beg 1)
 > +	end (min end (1+ (buffer-size))))
 > +
 >    (mapcar-extents #'identity nil nil beg end
 >  		  'all-extents-closed-open 'overlay))
 >  
 > +(defsubst overlay-validate-pos ()
 > +  "validate the pos parameter, set it to the corresponding
 > +boundary-value if it was out of buffer boundary"
 > +  (setq pos (max pos 1)
 > +	pos (min pos (1+ (buffer-size)))))
 > +
 >  (defun next-overlay-change (pos)
 >    "Return the next position after POS where an overlay starts or ends.
 > -If there are no more overlay boundaries after POS, return (point-max)."
 > +If there are no more overlay boundaries after POS, return (point-max).
 > +
 > +POS will be checked, its value will be set to corresponding
 > +boundary-value if it was out of buffer boundary."
 >    (let ((next (point-max))
 >  	tmp)
 > +    (overlay-validate-pos)
 >      (map-extents
 >       (lambda (overlay ignore)
 >  	    (when (or (and (< (setq tmp (extent-start-position overlay)) next)
 > @@ -172,9 +217,13 @@
 >  
 >  (defun previous-overlay-change (pos)
 >    "Return the previous position before POS where an overlay starts or ends.
 > -If there are no more overlay boundaries before POS, return (point-min)."
 > +If there are no more overlay boundaries before POS, return (point-min).
 > +
 > +POS will be checked, its value will be set to corresponding
 > +boundary-value if it was out of buffer boundary."
 >    (let ((prev (point-min))
 >  	tmp)
 > +    (overlay-validate-pos)
 >      (map-extents
 >       (lambda (overlay ignore)
 >         (when (or (and (> (setq tmp (extent-end-position overlay)) prev)
 > @@ -206,7 +255,11 @@
 >      (cons (nreverse before) (nreverse after))))
 >  
 >  (defun overlay-recenter (pos)
 > -  "Recenter the overlays of the current buffer around position POS."
 > +  "Recenter the overlays of the current buffer around position POS.
 > +
 > +POS will be checked, its value will be set to corresponding
 > +boundary-value if it was out of buffer boundary."
 > +  (overlay-validate-pos)
 >    (set (make-local-variable 'xemacs-internal-overlay-center-pos) pos))
 >  
 >  (defun overlay-get (overlay prop)



More information about the XEmacs-Patches mailing list