aboutsummaryrefslogtreecommitdiffstats
path: root/src/indent.c
diff options
context:
space:
mode:
authorEli Zaretskii2015-02-09 18:24:46 +0200
committerEli Zaretskii2015-02-09 18:24:46 +0200
commit403cb178c75a80603dbd8ed23e342d2109645401 (patch)
tree815315bef8212ed239805f13089612ebcef78a82 /src/indent.c
parentaf560cd6f15e7cc7e42bff5b3c802b9d1d1640b5 (diff)
downloademacs-403cb178c75a80603dbd8ed23e342d2109645401.tar.gz
emacs-403cb178c75a80603dbd8ed23e342d2109645401.zip
Speed up vertical-motion when screen coordinates are known
src/indent.c (Fvertical_motion): Accept an additional argument CUR-COL and use it as the starting screen coordinate. src/window.c (window_scroll_line_based, Fmove_to_window_line): All callers of vertical-motion changed. doc/lispref/positions.texi (Screen Lines): Update the documentation of vertical-motion to document the new additional argument.
Diffstat (limited to 'src/indent.c')
-rw-r--r--src/indent.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/indent.c b/src/indent.c
index 8660400e1ce..f0aea002fd2 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -1928,7 +1928,7 @@ vmotion (register ptrdiff_t from, register ptrdiff_t from_byte,
1928 -1, hscroll, 0, w); 1928 -1, hscroll, 0, w);
1929} 1929}
1930 1930
1931DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 2, 0, 1931DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 3, 0,
1932 doc: /* Move point to start of the screen line LINES lines down. 1932 doc: /* Move point to start of the screen line LINES lines down.
1933If LINES is negative, this means moving up. 1933If LINES is negative, this means moving up.
1934 1934
@@ -1951,12 +1951,18 @@ is). If the line is scrolled horizontally, COLS is interpreted
1951visually, i.e., as addition to the columns of text beyond the left 1951visually, i.e., as addition to the columns of text beyond the left
1952edge of the window. 1952edge of the window.
1953 1953
1954The optional third argument CUR-COL specifies the horizontal
1955window-relative coordinate of point, in units of frame's canonical
1956character width, where the function is invoked. If this argument is
1957omitted or nil, the function will determine the point coordinate by
1958going back to the beginning of the line.
1959
1954`vertical-motion' always uses the current buffer, 1960`vertical-motion' always uses the current buffer,
1955regardless of which buffer is displayed in WINDOW. 1961regardless of which buffer is displayed in WINDOW.
1956This is consistent with other cursor motion functions 1962This is consistent with other cursor motion functions
1957and makes it possible to use `vertical-motion' in any buffer, 1963and makes it possible to use `vertical-motion' in any buffer,
1958whether or not it is currently displayed in some window. */) 1964whether or not it is currently displayed in some window. */)
1959 (Lisp_Object lines, Lisp_Object window) 1965 (Lisp_Object lines, Lisp_Object window, Lisp_Object cur_col)
1960{ 1966{
1961 struct it it; 1967 struct it it;
1962 struct text_pos pt; 1968 struct text_pos pt;
@@ -2006,6 +2012,22 @@ whether or not it is currently displayed in some window. */)
2006 bool disp_string_at_start_p = 0; 2012 bool disp_string_at_start_p = 0;
2007 ptrdiff_t nlines = XINT (lines); 2013 ptrdiff_t nlines = XINT (lines);
2008 int vpos_init = 0; 2014 int vpos_init = 0;
2015 double start_col;
2016 int start_x;
2017 bool start_x_given = false;
2018 int to_x = -1;
2019
2020 if (!NILP (cur_col))
2021 {
2022 CHECK_NUMBER_OR_FLOAT (cur_col);
2023 start_col =
2024 INTEGERP (cur_col)
2025 ? (double) XINT (cur_col)
2026 : XFLOAT_DATA (cur_col);
2027 start_x =
2028 (int)(start_col * FRAME_COLUMN_WIDTH (XFRAME (w->frame)) + 0.5);
2029 start_x_given = true;
2030 }
2009 2031
2010 itdata = bidi_shelve_cache (); 2032 itdata = bidi_shelve_cache ();
2011 SET_TEXT_POS (pt, PT, PT_BYTE); 2033 SET_TEXT_POS (pt, PT, PT_BYTE);
@@ -2042,11 +2064,19 @@ whether or not it is currently displayed in some window. */)
2042 it_overshoot_count = 2064 it_overshoot_count =
2043 !(it.method == GET_FROM_IMAGE || it.method == GET_FROM_STRETCH); 2065 !(it.method == GET_FROM_IMAGE || it.method == GET_FROM_STRETCH);
2044 2066
2045 /* Scan from the start of the line containing PT. If we don't 2067 if (start_x_given)
2046 do this, we start moving with IT->current_x == 0, while PT is 2068 {
2047 really at some x > 0. */ 2069 it.hpos = (int) start_col;
2048 reseat_at_previous_visible_line_start (&it); 2070 it.current_x = start_x;
2049 it.current_x = it.hpos = 0; 2071 }
2072 else
2073 {
2074 /* Scan from the start of the line containing PT. If we don't
2075 do this, we start moving with IT->current_x == 0, while PT is
2076 really at some x > 0. */
2077 reseat_at_previous_visible_line_start (&it);
2078 it.current_x = it.hpos = 0;
2079 }
2050 if (IT_CHARPOS (it) != PT) 2080 if (IT_CHARPOS (it) != PT)
2051 /* We used to temporarily disable selective display here; the 2081 /* We used to temporarily disable selective display here; the
2052 comment said this is "so we don't move too far" (2005-01-19 2082 comment said this is "so we don't move too far" (2005-01-19
@@ -2108,12 +2138,15 @@ whether or not it is currently displayed in some window. */)
2108 return the correct value to the caller. */ 2138 return the correct value to the caller. */
2109 vpos_init = -1; 2139 vpos_init = -1;
2110 } 2140 }
2141 if (!NILP (lcols))
2142 to_x = (int)(cols * FRAME_COLUMN_WIDTH (XFRAME (w->frame)) + 0.5);
2111 if (nlines <= 0) 2143 if (nlines <= 0)
2112 { 2144 {
2113 it.vpos = vpos_init; 2145 it.vpos = vpos_init;
2114 /* Do this even if LINES is 0, so that we move back to the 2146 /* Do this even if LINES is 0, so that we move back to the
2115 beginning of the current line as we ought. */ 2147 beginning of the current line as we ought. */
2116 if (nlines == 0 || IT_CHARPOS (it) > 0) 2148 if ((nlines < 0 && IT_CHARPOS (it) > 0)
2149 || (nlines == 0 && !(start_x_given && start_x <= to_x)))
2117 move_it_by_lines (&it, max (PTRDIFF_MIN, nlines)); 2150 move_it_by_lines (&it, max (PTRDIFF_MIN, nlines));
2118 } 2151 }
2119 else if (overshoot_handled) 2152 else if (overshoot_handled)
@@ -2153,11 +2186,7 @@ whether or not it is currently displayed in some window. */)
2153 was originally hscrolled, the goal column is interpreted as 2186 was originally hscrolled, the goal column is interpreted as
2154 an addition to the hscroll amount. */ 2187 an addition to the hscroll amount. */
2155 if (!NILP (lcols)) 2188 if (!NILP (lcols))
2156 { 2189 move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X);
2157 int to_x = (int)(cols * FRAME_COLUMN_WIDTH (XFRAME (w->frame)) + 0.5);
2158
2159 move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X);
2160 }
2161 2190
2162 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); 2191 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
2163 bidi_unshelve_cache (itdata, 0); 2192 bidi_unshelve_cache (itdata, 0);