void redisplay_preserve_echo_area (int);
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);
+ptrdiff_t get_narrowed_begv (struct window *);
+ptrdiff_t get_narrowed_zv (struct window *);
+ptrdiff_t get_closer_narrowed_begv (struct window *, ptrdiff_t);
void init_iterator_to_row_start (struct it *, struct window *,
struct glyph_row *);
void start_display (struct it *, struct window *, struct text_pos);
long lines. */
static int
-get_narrowed_len (struct window *w)
+get_narrowed_width (struct window *w)
{
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;
- return 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);
+}
+
+static int
+get_narrowed_len (struct window *w)
+{
+ return get_narrowed_width (w) *
+ window_body_height (w, WINDOW_BODY_IN_CANONICAL_CHARS);
}
ptrdiff_t
return min ((window_point (w) / len + 1) * len, ZV);
}
+ptrdiff_t
+get_closer_narrowed_begv (struct window *w, ptrdiff_t pos)
+{
+ int len = get_narrowed_width (w);
+ return max ((pos / len - 1) * len, BEGV);
+}
+
static void
unwind_narrowed_begv (Lisp_Object point_min)
{
}
/* Set DST to EXPR. When IT indicates that BEGV should temporarily be
- updated to optimize display, evaluate EXPR with an updated BEGV. */
+ updated to optimize display, evaluate EXPR with BEGV set to BV. */
-#define SET_WITH_NARROWED_BEGV(IT,DST,EXPR) \
+#define SET_WITH_NARROWED_BEGV(IT,DST,EXPR,BV) \
do { \
if (IT->narrowed_begv) \
{ \
specpdl_ref count = SPECPDL_INDEX (); \
record_unwind_protect (unwind_narrowed_begv, Fpoint_min ()); \
- SET_BUF_BEGV (current_buffer, IT->narrowed_begv); \
+ SET_BUF_BEGV (current_buffer, BV); \
DST = EXPR; \
unbind_to (count, Qnil); \
} \
dec_both (&cp, &bp);
SET_WITH_NARROWED_BEGV (it, IT_CHARPOS (*it),
- find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it)));
+ find_newline_no_quit (cp, bp, -1, &IT_BYTEPOS (*it)),
+ get_closer_narrowed_begv (it->w, IT_CHARPOS (*it)));
}
SET_WITH_NARROWED_BEGV (it, bob,
string_p ? 0 :
- IT_BYTEPOS (*it) < BEGV ? obegv : BEGV);
+ IT_BYTEPOS (*it) < BEGV ? obegv : BEGV,
+ it->narrowed_begv);
if (STRINGP (it->string))
{
SET_WITH_NARROWED_BEGV (it, it->bidi_it.charpos,
find_newline_no_quit (IT_CHARPOS (*it),
IT_BYTEPOS (*it), -1,
- &it->bidi_it.bytepos));
+ &it->bidi_it.bytepos),
+ it->narrowed_begv);
bidi_paragraph_init (it->paragraph_embedding, &it->bidi_it, true);
do
{
dec_both (&cp, &bp);
SET_WITH_NARROWED_BEGV (it, cp,
- find_newline_no_quit (cp, bp, -1, NULL));
+ find_newline_no_quit (cp, bp, -1, NULL),
+ it->narrowed_begv);
move_it_to (it, cp, -1, -1, -1, MOVE_TO_POS);
}
bidi_unshelve_cache (it3data, true);