Function: insert-buffer-substring

insert-buffer-substring is a function defined in editfns.c.

Signature

(insert-buffer-substring BUFFER &optional START END)

Documentation

Insert before point a substring of the contents of BUFFER.

BUFFER may be a buffer or a buffer name. Arguments START and END are character positions specifying the substring. They default to the values of (point-min) and (point-max) in BUFFER.

Point and markers are relocated as in the function insert.

If the current buffer is multibyte and BUFFER is unibyte, or vice versa, strings are converted from unibyte to multibyte or vice versa using string-make-multibyte or string-make-unibyte, which see.

View in manual

Probably introduced at or before Emacs version 18.

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  register EMACS_INT b, e, temp;
  register struct buffer *bp, *obuf;
  Lisp_Object buf;

  buf = Fget_buffer (buffer);
  if (NILP (buf))
    nsberror (buffer);
  bp = XBUFFER (buf);
  if (!BUFFER_LIVE_P (bp))
    error ("Selecting deleted buffer");

  b = !NILP (start) ? fix_position (start) : BUF_BEGV (bp);
  e = !NILP (end) ? fix_position (end) : BUF_ZV (bp);
  if (b > e)
    temp = b, b = e, e = temp;

  if (!(BUF_BEGV (bp) <= b && e <= BUF_ZV (bp)))
    args_out_of_range (start, end);

  obuf = current_buffer;
  set_buffer_internal_1 (bp);
  update_buffer_properties (b, e);
  set_buffer_internal_1 (obuf);

  insert_from_buffer (bp, b, e - b, 0);
  return Qnil;
}