bset_begv_marker (b, Qnil);
bset_zv_marker (b, Qnil);
+ bset_begh_marker (b, Qnil);
+ bset_zh_marker (b, Qnil);
+
name = Fcopy_sequence (buffer_or_name);
set_string_intervals (name, NULL);
bset_name (b, name);
bset_pt_marker (b, build_marker (b, b->pt, b->pt_byte));
bset_begv_marker (b, build_marker (b, b->begv, b->begv_byte));
bset_zv_marker (b, build_marker (b, b->zv, b->zv_byte));
+
XMARKER (BVAR (b, zv_marker))->insertion_type = 1;
}
else
so the buffer is truly empty after this. */)
(void)
{
- Fwiden ();
+ Fwiden (Qnil);
- del_range (BEG, Z);
+ del_range (BEGV, ZV);
current_buffer->last_window_start = 1;
/* Prevent warnings, or suspension of auto saving, that would happen
swapfield_ (pt_marker, Lisp_Object);
swapfield_ (begv_marker, Lisp_Object);
swapfield_ (zv_marker, Lisp_Object);
+ swapfield_ (begh_marker, Lisp_Object);
+ swapfield_ (zh_marker, Lisp_Object);
bset_point_before_scroll (current_buffer, Qnil);
bset_point_before_scroll (other_buffer, Qnil);
}
}
if (narrowed)
- Fnarrow_to_region (make_number (begv), make_number (zv));
+ Fnarrow_to_region (make_number (begv), make_number (zv), Qnil);
}
else
{
TEMP_SET_PT (pt);
if (narrowed)
- Fnarrow_to_region (make_number (begv), make_number (zv));
+ Fnarrow_to_region (make_number (begv), make_number (zv), Qnil);
/* Do this first, so that chars_in_text asks the right question.
set_intervals_multibyte needs it too. */
bset_pt_marker (&buffer_local_flags, make_number (0));
bset_begv_marker (&buffer_local_flags, make_number (0));
bset_zv_marker (&buffer_local_flags, make_number (0));
+ bset_begh_marker (&buffer_local_flags, make_number (0));
+ bset_zh_marker (&buffer_local_flags, make_number (0));
bset_last_selected_window (&buffer_local_flags, make_number (0));
idx = 1;
#define BUF_FETCH_BYTE(buf, n) \
*(BUF_BYTE_ADDRESS ((buf), (n)))
+
+\f
+/* Macros for setting and accessing hard-narrow markers */
+
+/* Position of beginning of hard-narrowed range of buffer. */
+#define BEGH (BUF_BEGH (current_buffer))
+#define BUF_BEGH(buf) \
+ ((NILP (BVAR (buf, begh_marker))) ? BUF_BEG (buf) \
+ : marker_position (BVAR (buf, begh_marker)))
+#define SET_BUF_BEGH(buf, charpos) \
+ (bset_begh_marker (buf, build_marker(buf, charpos, buf_charpos_to_bytepos(buf, charpos))))
+
+/* Position of end of hard-narrowed range of buffer. */
+#define ZH (BUF_ZH(current_buffer))
+#define BUF_ZH(buf) \
+ ((NILP (BVAR (buf, zh_marker))) ? BUF_Z (buf) \
+ : marker_position (BVAR (buf, zh_marker)))
+#define SET_BUF_ZH(buf, charpos) \
+ (bset_zh_marker (buf, build_marker(buf, charpos, buf_charpos_to_bytepos(buf, charpos))))
+
\f
/* Define the actual buffer data structures. */
ZV for this buffer when the buffer is not current. */
Lisp_Object zv_marker_;
+ /* Lower hard limit of the buffer.*/
+ Lisp_Object begh_marker_;
+
+ /* Upper hard limit of the buffer.*/
+ Lisp_Object zh_marker_;
+
/* This holds the point value before the last scroll operation.
Explicitly setting point sets this to nil. */
Lisp_Object point_before_scroll_;
{
b->width_table_ = val;
}
+INLINE void
+bset_begh_marker (struct buffer *b, Lisp_Object val)
+{
+ b->begh_marker_ = val;
+}
+INLINE void
+bset_zh_marker (struct buffer *b, Lisp_Object val)
+{
+ b->zh_marker_ = val;
+}
/* Number of Lisp_Objects at the beginning of struct buffer.
If you add, remove, or reorder Lisp_Objects within buffer
CASE (Bnarrow_to_region):
{
- Lisp_Object v1;
+ Lisp_Object v1, v2;
BEFORE_POTENTIAL_GC ();
v1 = POP;
- TOP = Fnarrow_to_region (TOP, v1);
+ v2 = POP;
+ TOP = Fnarrow_to_region (TOP, v2, v1);
AFTER_POTENTIAL_GC ();
NEXT;
}
CASE (Bwiden):
BEFORE_POTENTIAL_GC ();
- PUSH (Fwiden ());
+ TOP = Fwiden (TOP);
AFTER_POTENTIAL_GC ();
NEXT;
return empty_unibyte_string;
return del_range_1 (XINT (start), XINT (end), 1, 1);
}
+
\f
-DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
+DEFUN ("widen", Fwiden, Swiden, 0, 1, "",
doc: /* Remove restrictions (narrowing) from current buffer.
-This allows the buffer's full text to be seen and edited. */)
- (void)
+If HARD is non-nil, remove the hard restriction imposed by a previous
+call to \\[narrow-to-region]. If HARD is nil, remove visual
+restriction up to the previously imposed hard limit (if any). */)
+ (Lisp_Object hard)
{
- if (BEG != BEGV || Z != ZV)
- current_buffer->clip_changed = 1;
- BEGV = BEG;
- BEGV_BYTE = BEG_BYTE;
- SET_BUF_ZV_BOTH (current_buffer, Z, Z_BYTE);
- /* Changing the buffer bounds invalidates any recorded current column. */
- invalidate_current_column ();
+
+ if(!NILP (hard))
+ {
+ bset_begh_marker(current_buffer, Qnil);
+ bset_zh_marker(current_buffer, Qnil);
+ }
+ else
+ {
+ if (BEG != BEGV || Z != ZV)
+ current_buffer->clip_changed = 1;
+ BEGV = BEG;
+ BEGV_BYTE = BEG_BYTE;
+ SET_BUF_ZV_BOTH (current_buffer, Z, Z_BYTE);
+ /* Changing the buffer bounds invalidates any recorded current column. */
+ invalidate_current_column ();
+ }
+
return Qnil;
}
-DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r",
- doc: /* 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. \\[widen] makes all visible again.
-See also `save-restriction'.
+DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 3, "r",
+ doc: /* Restrict editing in this buffer to the current
+region. START and END are positions (integers or markers) bounding the
+text that should restricted. There can be two types of restrictions,
+visual and hard. If HARD is nil, impose visual restriction, otherwise
+a hard one.
-When calling from a program, pass two arguments; positions (integers
-or markers) bounding the text that should remain visible. */)
- (register Lisp_Object start, Lisp_Object end)
+When visual restriction is in place, the rest of the text is invisible
+and untouchable but is not deleted; if you save the buffer in a file,
+the invisible text is included in the file. \\[widen] with nil
+optional argument makes it all visible again.
+
+When hard restriction is in place, invocations of (visual) \\[widen]
+with nil argument removes visual narrowing up to the hard
+restriction. In order to lift hard restriction, call \\[widen] with
+non-nil HARD argument. */)
+ (register Lisp_Object start, Lisp_Object end, Lisp_Object hard)
{
+
CHECK_NUMBER_COERCE_MARKER (start);
CHECK_NUMBER_COERCE_MARKER (end);
if (!(BEG <= XINT (start) && XINT (start) <= XINT (end) && XINT (end) <= Z))
args_out_of_range (start, end);
+ if (!NILP (hard))
+ {
+ SET_BUF_BEGH (current_buffer, XFASTINT (start));
+ SET_BUF_ZH (current_buffer, XFASTINT (end));
+ if (BEGV >= XFASTINT (start) && ZV <= XFASTINT (end))
+ /* Visual narrowing within hard limits. */
+ return Qnil;
+ }
+
if (BEGV != XFASTINT (start) || ZV != XFASTINT (end))
current_buffer->clip_changed = 1;
return Qnil;
}
+
Lisp_Object
save_restriction_save (void)
{
This is useful in tar-mode. --Stef
XSETFASTINT (start, BEG);
XSETFASTINT (end, Z); */
- Fwiden ();
+ Fwiden (Qnil);
}
record_unwind_protect (build_annotations_unwind,
/* Set point and ZV around stuff to be read. */
Fgoto_char (start);
if (!NILP (end))
- Fnarrow_to_region (make_number (BEGV), end);
+ Fnarrow_to_region (make_number (BEGV), end, Qnil);
/* Just for cleanliness, convert END to a marker
if it is an integer. */
/* If the output marker is outside of the visible region, save
the restriction and widen. */
if (! (BEGV <= PT && PT <= ZV))
- Fwiden ();
+ Fwiden (Qnil);
/* Adjust the multibyteness of TEXT to that of the buffer. */
if (NILP (BVAR (current_buffer, enable_multibyte_characters))
/* If the restriction isn't what it should be, set it. */
if (old_begv != BEGV || old_zv != ZV)
- Fnarrow_to_region (make_number (old_begv), make_number (old_zv));
+ Fnarrow_to_region (make_number (old_begv), make_number (old_zv), Qnil);
bset_read_only (current_buffer, old_read_only);
SET_PT_BOTH (opoint, opoint_byte);