- /* Temporarily disable selective display so we don't move too far */
- oselective = it.selective;
- it.selective = 0;
- move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
- it.selective = oselective;
-
- /* Move back if we got too far. This may happen if
- truncate-lines is on and PT is beyond right margin.
- Don't go back if the overshoot is expected (see above). */
- if (IT_CHARPOS (it) > it_start && XINT (lines) > 0
- && (!it_overshoot_expected
- || (it_overshoot_expected < 0
- && it.method == GET_FROM_BUFFER
- && it.c == '\n')))
- move_it_by_lines (&it, -1, 0);
-
- it.vpos = 0;
- /* Do this even if LINES is 0, so that we move back
- to the beginning of the current line as we ought. */
- if (XINT (lines) >= 0 || IT_CHARPOS (it) > 0)
- move_it_by_lines (&it, XINT (lines), 0);
+ if (IT_CHARPOS (it) != PT)
+ /* We used to temporarily disable selective display here; the
+ comment said this is "so we don't move too far" (2005-01-19
+ checkin by kfs). But this does nothing useful that I can
+ tell, and it causes Bug#2694 . -- cyd */
+ move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
+
+ if (XINT (lines) <= 0)
+ {
+ it.vpos = 0;
+ /* Do this even if LINES is 0, so that we move back to the
+ beginning of the current line as we ought. */
+ if (XINT (lines) == 0 || IT_CHARPOS (it) > 0)
+ move_it_by_lines (&it, XINT (lines), 0);
+ }
+ else
+ {
+ if (IT_CHARPOS (it) > it_start)
+ {
+ /* IT may move too far if truncate-lines is on and PT
+ lies beyond the right margin. In that case,
+ backtrack unless the starting point is on an image,
+ stretch glyph, composition, or Lisp string. */
+ if (!it_overshoot_expected
+ /* Also, backtrack if the Lisp string contains no
+ newline, but there is a newline right after it.
+ In this case, IT overshoots if there is an
+ after-string just before the newline. */
+ || (it_overshoot_expected < 0
+ && it.method == GET_FROM_BUFFER
+ && it.c == '\n'))
+ move_it_by_lines (&it, -1, 0);
+ it.vpos = 0;
+ move_it_by_lines (&it, XINT (lines), 0);
+ }
+ else
+ {
+ /* Otherwise, we are at the first row occupied by PT,
+ which might span multiple screen lines (e.g., if it's
+ on a multi-line display string). We want to start
+ from the last line that it occupies. */
+ if (it_start < ZV)
+ {
+ while (IT_CHARPOS (it) <= it_start)
+ {
+ it.vpos = 0;
+ move_it_by_lines (&it, 1, 0);
+ }
+ if (XINT (lines) > 1)
+ move_it_by_lines (&it, XINT (lines) - 1, 0);
+ }
+ else
+ {
+ it.vpos = 0;
+ move_it_by_lines (&it, XINT (lines), 0);
+ }
+ }
+ }
+
+ /* Move to the goal column, if one was specified. */
+ if (!NILP (lcols))
+ {
+ /* If the window was originally hscrolled, move forward by
+ the hscrolled amount first. */
+ if (first_x > 0)
+ {
+ move_it_in_display_line (&it, ZV, first_x, MOVE_TO_X);
+ it.current_x = 0;
+ }
+ move_it_in_display_line
+ (&it, ZV,
+ (int)(cols * FRAME_COLUMN_WIDTH (XFRAME (w->frame)) + 0.5),
+ MOVE_TO_X);
+ }