summaryrefslogtreecommitdiff
path: root/src/indent.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2017-07-02 18:01:39 +0300
committerEli Zaretskii <eliz@gnu.org>2017-07-02 18:01:39 +0300
commit4c9353a5840b285631a86a5bad2b48ea6276abf3 (patch)
treecab569e2b2ed396ca5258c33a5b29ecf20fee73c /src/indent.c
parentb5ce3100a8549df519d6f2b577fe7c3acf90cb40 (diff)
downloademacs-4c9353a5840b285631a86a5bad2b48ea6276abf3.tar.gz
emacs-4c9353a5840b285631a86a5bad2b48ea6276abf3.tar.bz2
emacs-4c9353a5840b285631a86a5bad2b48ea6276abf3.zip
Avoid off-by-one errors in column C-n/C-p calculations
* src/indent.c (Fvertical_motion): Help C-n/C-p estimate correctly the width used up by line numbers by looking near the window-start point.
Diffstat (limited to 'src/indent.c')
-rw-r--r--src/indent.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/indent.c b/src/indent.c
index adecc3622a8..2cacfbbe3c0 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -2068,9 +2068,26 @@ whether or not it is currently displayed in some window. */)
start_x = window_column_x (w, window, start_col, cur_col);
}
- itdata = bidi_shelve_cache ();
+ /* When displaying line numbers, we need to prime IT's
+ lnum_width with the value calculated at window's start, since
+ that's what normal window redisplay does. Otherwise C-n/C-p
+ will sometimes err by one column. */
+ int lnum_width = 0;
+ if (!NILP (Vdisplay_line_numbers)
+ && !EQ (Vdisplay_line_numbers, Qvisual))
+ {
+ struct text_pos wstart;
+ SET_TEXT_POS_FROM_MARKER (wstart, w->start);
+ itdata = bidi_shelve_cache ();
+ start_display (&it, w, wstart);
+ move_it_by_lines (&it, 1);
+ lnum_width = it.lnum_width;
+ bidi_unshelve_cache (itdata, 0);
+ }
SET_TEXT_POS (pt, PT, PT_BYTE);
+ itdata = bidi_shelve_cache ();
start_display (&it, w, pt);
+ it.lnum_width = lnum_width;
first_x = it.first_visible_x;
it_start = IT_CHARPOS (it);