Function: move-overlay

move-overlay is a function defined in buffer.c.

Signature

(move-overlay OVERLAY BEG END &optional BUFFER)

Documentation

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.

Other relevant functions are documented in the overlay group.

View in manual

Shortdoc

;; overlay
(move-overlay foo 5 20)
    e.g. => #<overlay from 5 to 20 in *foo*>

Aliases

semantic-overlay-move (obsolete since 27.1) reftex-move-overlay (obsolete since 28.1) viper-move-overlay (obsolete since 27.1)

Source Code

// Defined in /usr/src/emacs/src/buffer.c
{
  struct buffer *b, *ob = 0;
  Lisp_Object obuffer;
  specpdl_ref count = SPECPDL_INDEX ();
  ptrdiff_t o_beg UNINIT, o_end UNINIT;

  CHECK_OVERLAY (overlay);
  if (NILP (buffer))
    buffer = Foverlay_buffer (overlay);
  if (NILP (buffer))
    XSETBUFFER (buffer, current_buffer);
  CHECK_BUFFER (buffer);

  if (NILP (Fbuffer_live_p (buffer)))
    error ("Attempt to move overlay to a dead buffer");

  if (MARKERP (beg) && !BASE_EQ (Fmarker_buffer (beg), buffer))
    signal_error ("Marker points into wrong buffer", beg);
  if (MARKERP (end) && !BASE_EQ (Fmarker_buffer (end), buffer))
    signal_error ("Marker points into wrong buffer", end);

  CHECK_FIXNUM_COERCE_MARKER (beg);
  CHECK_FIXNUM_COERCE_MARKER (end);

  if (XFIXNUM (beg) > XFIXNUM (end))
    {
      Lisp_Object temp;
      temp = beg; beg = end; end = temp;
    }

  specbind (Qinhibit_quit, Qt); /* FIXME: Why?  */

  obuffer = Foverlay_buffer (overlay);
  b = XBUFFER (buffer);

  ptrdiff_t n_beg = clip_to_bounds (BUF_BEG (b), XFIXNUM (beg), BUF_Z (b));
  ptrdiff_t n_end = clip_to_bounds (n_beg, XFIXNUM (end), BUF_Z (b));

  if (!NILP (obuffer))
    {
      ob = XBUFFER (obuffer);

      o_beg = OVERLAY_START (overlay);
      o_end = OVERLAY_END (overlay);
    }

  if (! BASE_EQ (buffer, obuffer))
    {
      if (! NILP (obuffer))
        remove_buffer_overlay (XBUFFER (obuffer), XOVERLAY (overlay));
      add_buffer_overlay (XBUFFER (buffer), XOVERLAY (overlay), n_beg, n_end);
    }
  else
    itree_node_set_region (b->overlays, XOVERLAY (overlay)->interval,
                              n_beg, n_end);

  /* If the overlay has changed buffers, do a thorough redisplay.  */
  if (!BASE_EQ (buffer, obuffer))
    {
      /* Redisplay where the overlay was.  */
      if (ob)
        modify_overlay (ob, o_beg, o_end);

      /* Redisplay where the overlay is going to be.  */
      modify_overlay (b, n_beg, n_end);
    }
  else
    /* Redisplay the area the overlay has just left, or just enclosed.  */
    {
      if (o_beg == n_beg)
	modify_overlay (b, o_end, n_end);
      else if (o_end == n_end)
	modify_overlay (b, o_beg, n_beg);
      else
	modify_overlay (b, min (o_beg, n_beg), max (o_end, n_end));
    }

  /* Delete the overlay if it is empty after clipping and has the
     evaporate property.  */
  if (n_beg == n_end && !NILP (Foverlay_get (overlay, Qevaporate)))
    { /* We used to call `Fdelete_overlay' here, but it causes problems:
         - At this stage, `overlay' is not included in its buffer's lists
           of overlays (the data-structure is in an inconsistent state),
           contrary to `Fdelete_overlay's assumptions.
         - Most of the work done by Fdelete_overlay has already been done
           here for other reasons.  */
      drop_overlay (XOVERLAY (overlay));
      return unbind_to (count, overlay);
    }

  return unbind_to (count, overlay);
}