optimize display (see the SET_WITH_NARROWED_BEGV macro). */
ptrdiff_t narrowed_begv;
+ /* Alternate end position of the buffer that may be used to
+ optimize display. */
+ ptrdiff_t narrowed_zv;
+
/* C string to iterate over. Non-null means get characters from
this string, otherwise characters are read from current_buffer
or it->string. */
void init_iterator (struct it *, struct window *, ptrdiff_t,
ptrdiff_t, struct glyph_row *, enum face_id);
ptrdiff_t get_narrowed_begv (struct window *w);
+ptrdiff_t get_narrowed_zv (struct window *w);
void init_iterator_to_row_start (struct it *, struct window *,
struct glyph_row *);
void start_display (struct it *, struct window *, struct text_pos);
This allows the buffer's full text to be seen and edited. */)
(void)
{
+ if (!NILP (Vinhibit_widen))
+ return Qnil;
if (BEG != BEGV || Z != ZV)
current_buffer->clip_changed = 1;
BEGV = BEG;
DEFSYM (Qbuffer_access_fontify_functions, "buffer-access-fontify-functions");
DEFSYM (Qwall, "wall");
DEFSYM (Qpropertize, "propertize");
+ DEFSYM (Qinhibit_widen, "inhibit-widen");
DEFVAR_LISP ("inhibit-field-text-motion", Vinhibit_field_text_motion,
doc: /* Non-nil means text motion commands don't notice fields. */);
it to be non-nil. */);
binary_as_unsigned = false;
+ DEFVAR_LISP ("inhibit-widen", Vinhibit_widen,
+ doc: /* Non-nil inhibits the `widen' function.
+
+Do NOT set this globally to a non-nil value, as doing that will
+disable the `widen' function everywhere, including the \\[widen\]
+command. This variable is intended to be let-bound around code
+that needs to disable `widen' temporarily. */);
+ Vinhibit_widen = Qnil;
+
defsubr (&Spropertize);
defsubr (&Schar_equal);
defsubr (&Sgoto_char);
}
if (current_buffer->long_line_optimizations_p)
- it->narrowed_begv = get_narrowed_begv (w);
+ {
+ it->narrowed_begv = get_narrowed_begv (w);
+ it->narrowed_zv = get_narrowed_zv (w);
+ }
/* If a buffer position was specified, set the iterator there,
getting overlays and face properties from that position. */
CHECK_IT (it);
}
-/* Compute a suitable alternate value for BEGV that may be used
+/* Compute a suitable alternate value for BEGV and ZV that may be used
temporarily to optimize display if the buffer in window W contains
long lines. */
-ptrdiff_t
-get_narrowed_begv (struct window *w)
+static int
+get_narrowed_len (struct window *w)
{
- int len, fact; ptrdiff_t begv;
+ int fact;
/* In a character-only terminal, only one font size is used, so we
can use a smaller factor. */
fact = EQ (Fterminal_live_p (Qnil), Qt) ? 2 : 3;
- len = fact * (window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS) *
- window_body_height (w, WINDOW_BODY_IN_CANONICAL_CHARS));
+ return fact * (window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS) *
+ window_body_height (w, WINDOW_BODY_IN_CANONICAL_CHARS));
+}
+
+ptrdiff_t
+get_narrowed_begv (struct window *w)
+{
+ int len = get_narrowed_len (w);
+ ptrdiff_t begv;
begv = max ((window_point (w) / len - 1) * len, BEGV);
return begv == BEGV ? 0 : begv;
}
+ptrdiff_t
+get_narrowed_zv (struct window *w)
+{
+ int len = get_narrowed_len (w);
+ return min ((window_point (w) / len + 1) * len, ZV);
+}
+
static void
unwind_narrowed_begv (Lisp_Object point_min)
{
SET_BUF_BEGV (current_buffer, XFIXNUM (point_min));
}
+static void
+unwind_narrowed_zv (Lisp_Object point_max)
+{
+ SET_BUF_ZV (current_buffer, XFIXNUM (point_max));
+}
+
/* Set DST to EXPR. When IT indicates that BEGV should temporarily be
updated to optimize display, evaluate EXPR with an updated BEGV. */
bool old_clip_changed = current_buffer->clip_changed;
bool saved_inhibit_flag = it->f->inhibit_clear_image_cache;
+ if (it->narrowed_begv)
+ {
+ record_unwind_protect (unwind_narrowed_begv, Fpoint_min ());
+ record_unwind_protect (unwind_narrowed_zv, Fpoint_max ());
+ SET_BUF_BEGV (current_buffer, it->narrowed_begv);
+ SET_BUF_ZV (current_buffer, it->narrowed_zv);
+ specbind (Qinhibit_widen, Qt);
+ }
+
val = Vfontification_functions;
specbind (Qfontification_functions, Qnil);