Function: narrow-to-region

narrow-to-region is an interactive function defined in editfns.c.

Signature

(narrow-to-region START END)

Documentation

Restrict editing in this buffer to the current region.

The rest of the text becomes temporarily invisible and untouchable but is not deleted; if you save the buffer in a file, the invisible text is included in the file. C-x n w (widen) makes all visible again. See also save-restriction.

When calling from Lisp, pass two arguments START and END: positions (integers or markers) bounding the text that should remain visible.

Probably introduced at or before Emacs version 15.

Key Bindings

Source Code

// Defined in /usr/src/emacs/src/editfns.c
{
  EMACS_INT s = fix_position (start), e = fix_position (end);

  if (e < s)
    {
      EMACS_INT tem = s; s = e; e = tem;
    }

  if (!(BEG <= s && s <= e && e <= Z))
    args_out_of_range (start, end);

  if (BEGV != s || ZV != e)
    current_buffer->clip_changed = 1;

  SET_BUF_BEGV (current_buffer, s);
  SET_BUF_ZV (current_buffer, e);
  if (PT < s)
    SET_PT (s);
  if (e < PT)
    SET_PT (e);
  /* Changing the buffer bounds invalidates any recorded current column.  */
  invalidate_current_column ();
  return Qnil;
}