summaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authorNoam Postavsky <npostavs@gmail.com>2016-08-28 16:38:04 -0400
committerNoam Postavsky <npostavs@gmail.com>2017-02-02 21:19:52 -0500
commitd17e92da064cabf376597f5de2a8d5a6484bfea6 (patch)
treeb608581cb4e883357a753c12e4526cac53066427 /src/window.c
parent53c16c75a57aa486dfc1f46ef5aa538264e6ad47 (diff)
downloademacs-d17e92da064cabf376597f5de2a8d5a6484bfea6.tar.gz
Refactor uses of scroll_margin to a function
Its effective range needs to be clamped between 0 and (window height / 4), so it's better to have this constraint in a single place. * src/window.c (window_scroll_margin): New function. (window_scroll_pixel_based, window_scroll_line_based): (Frecenter, Fmove_to_window_line): * src/xdisp.c (try_scrolling, try_cursor_movement): (redisplay_window, try_window, try_window_id): Use it.
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/src/window.c b/src/window.c
index bc3f488f37f..1c83d989aa8 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4790,6 +4790,29 @@ window_scroll (Lisp_Object window, EMACS_INT n, bool whole, bool noerror)
XWINDOW (window)->window_end_valid = false;
}
+/* Compute scroll margin for WINDOW.
+ We scroll when point is within this distance from the top or bottom
+ of the window. The result is measured in lines or in pixels
+ depending on the second parameter. */
+int
+window_scroll_margin (struct window *window, enum margin_unit unit)
+{
+ if (scroll_margin > 0)
+ {
+ int frame_line_height = default_line_pixel_height (window);
+ int window_total_lines
+ = window->total_lines * WINDOW_FRAME_LINE_HEIGHT (window)
+ / frame_line_height;
+ int margin = min (scroll_margin, window_total_lines / 4);
+ if (unit == MARGIN_IN_PIXELS)
+ return margin * frame_line_height;
+ else
+ return margin;
+ }
+ else
+ return 0;
+}
+
/* Implementation of window_scroll that works based on pixel line
heights. See the comment of window_scroll for parameter
@@ -4806,7 +4829,6 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, bool noerror)
bool vscrolled = false;
int x, y, rtop, rbot, rowh, vpos;
void *itdata = NULL;
- int window_total_lines;
int frame_line_height = default_line_pixel_height (w);
bool adjust_old_pointm = !NILP (Fequal (Fwindow_point (window),
Fwindow_old_point (window)));
@@ -5062,12 +5084,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, bool noerror)
/* Move PT out of scroll margins.
This code wants current_y to be zero at the window start position
even if there is a header line. */
- window_total_lines
- = w->total_lines * WINDOW_FRAME_LINE_HEIGHT (w) / frame_line_height;
- this_scroll_margin = max (0, scroll_margin);
- this_scroll_margin
- = min (this_scroll_margin, window_total_lines / 4);
- this_scroll_margin *= frame_line_height;
+ this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS);
if (n > 0)
{
@@ -5290,9 +5307,7 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, bool noerror)
if (pos < ZV)
{
- /* Don't use a scroll margin that is negative or too large. */
- int this_scroll_margin =
- max (0, min (scroll_margin, w->total_lines / 4));
+ int this_scroll_margin = window_scroll_margin (w, MARGIN_IN_LINES);
set_marker_restricted_both (w->start, w->contents, pos, pos_byte);
w->start_at_line_beg = !NILP (bolp);
@@ -5722,8 +5737,7 @@ and redisplay normally--don't erase and redraw the frame. */)
/* Do this after making BUF current
in case scroll_margin is buffer-local. */
- this_scroll_margin
- = max (0, min (scroll_margin, w->total_lines / 4));
+ this_scroll_margin = window_scroll_margin (w, MARGIN_IN_LINES);
/* Don't use redisplay code for initial frames, as the necessary
data structures might not be set up yet then. */
@@ -5962,10 +5976,6 @@ from the top of the window. */)
lines = displayed_window_lines (w);
-#if false
- this_scroll_margin = max (0, min (scroll_margin, lines / 4));
-#endif
-
if (NILP (arg))
XSETFASTINT (arg, lines / 2);
else
@@ -5981,6 +5991,8 @@ from the top of the window. */)
it is probably better not to install it. However, it is here
inside #if false so as not to lose it. -- rms. */
+ this_scroll_margin = window_scroll_margin (w, MARGIN_IN_LINES);
+
/* Don't let it get into the margin at either top or bottom. */
iarg = max (iarg, this_scroll_margin);
iarg = min (iarg, lines - this_scroll_margin - 1);