aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
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)
4790 XWINDOW (window)->window_end_valid = false; 4790 XWINDOW (window)->window_end_valid = false;
4791} 4791}
4792 4792
4793/* Compute scroll margin for WINDOW.
4794 We scroll when point is within this distance from the top or bottom
4795 of the window. The result is measured in lines or in pixels
4796 depending on the second parameter. */
4797int
4798window_scroll_margin (struct window *window, enum margin_unit unit)
4799{
4800 if (scroll_margin > 0)
4801 {
4802 int frame_line_height = default_line_pixel_height (window);
4803 int window_total_lines
4804 = window->total_lines * WINDOW_FRAME_LINE_HEIGHT (window)
4805 / frame_line_height;
4806 int margin = min (scroll_margin, window_total_lines / 4);
4807 if (unit == MARGIN_IN_PIXELS)
4808 return margin * frame_line_height;
4809 else
4810 return margin;
4811 }
4812 else
4813 return 0;
4814}
4815
4793 4816
4794/* Implementation of window_scroll that works based on pixel line 4817/* Implementation of window_scroll that works based on pixel line
4795 heights. See the comment of window_scroll for parameter 4818 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)
4806 bool vscrolled = false; 4829 bool vscrolled = false;
4807 int x, y, rtop, rbot, rowh, vpos; 4830 int x, y, rtop, rbot, rowh, vpos;
4808 void *itdata = NULL; 4831 void *itdata = NULL;
4809 int window_total_lines;
4810 int frame_line_height = default_line_pixel_height (w); 4832 int frame_line_height = default_line_pixel_height (w);
4811 bool adjust_old_pointm = !NILP (Fequal (Fwindow_point (window), 4833 bool adjust_old_pointm = !NILP (Fequal (Fwindow_point (window),
4812 Fwindow_old_point (window))); 4834 Fwindow_old_point (window)));
@@ -5062,12 +5084,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, bool noerror)
5062 /* Move PT out of scroll margins. 5084 /* Move PT out of scroll margins.
5063 This code wants current_y to be zero at the window start position 5085 This code wants current_y to be zero at the window start position
5064 even if there is a header line. */ 5086 even if there is a header line. */
5065 window_total_lines 5087 this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS);
5066 = w->total_lines * WINDOW_FRAME_LINE_HEIGHT (w) / frame_line_height;
5067 this_scroll_margin = max (0, scroll_margin);
5068 this_scroll_margin
5069 = min (this_scroll_margin, window_total_lines / 4);
5070 this_scroll_margin *= frame_line_height;
5071 5088
5072 if (n > 0) 5089 if (n > 0)
5073 { 5090 {
@@ -5290,9 +5307,7 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, bool noerror)
5290 5307
5291 if (pos < ZV) 5308 if (pos < ZV)
5292 { 5309 {
5293 /* Don't use a scroll margin that is negative or too large. */ 5310 int this_scroll_margin = window_scroll_margin (w, MARGIN_IN_LINES);
5294 int this_scroll_margin =
5295 max (0, min (scroll_margin, w->total_lines / 4));
5296 5311
5297 set_marker_restricted_both (w->start, w->contents, pos, pos_byte); 5312 set_marker_restricted_both (w->start, w->contents, pos, pos_byte);
5298 w->start_at_line_beg = !NILP (bolp); 5313 w->start_at_line_beg = !NILP (bolp);
@@ -5722,8 +5737,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5722 5737
5723 /* Do this after making BUF current 5738 /* Do this after making BUF current
5724 in case scroll_margin is buffer-local. */ 5739 in case scroll_margin is buffer-local. */
5725 this_scroll_margin 5740 this_scroll_margin = window_scroll_margin (w, MARGIN_IN_LINES);
5726 = max (0, min (scroll_margin, w->total_lines / 4));
5727 5741
5728 /* Don't use redisplay code for initial frames, as the necessary 5742 /* Don't use redisplay code for initial frames, as the necessary
5729 data structures might not be set up yet then. */ 5743 data structures might not be set up yet then. */
@@ -5962,10 +5976,6 @@ from the top of the window. */)
5962 5976
5963 lines = displayed_window_lines (w); 5977 lines = displayed_window_lines (w);
5964 5978
5965#if false
5966 this_scroll_margin = max (0, min (scroll_margin, lines / 4));
5967#endif
5968
5969 if (NILP (arg)) 5979 if (NILP (arg))
5970 XSETFASTINT (arg, lines / 2); 5980 XSETFASTINT (arg, lines / 2);
5971 else 5981 else
@@ -5981,6 +5991,8 @@ from the top of the window. */)
5981 it is probably better not to install it. However, it is here 5991 it is probably better not to install it. However, it is here
5982 inside #if false so as not to lose it. -- rms. */ 5992 inside #if false so as not to lose it. -- rms. */
5983 5993
5994 this_scroll_margin = window_scroll_margin (w, MARGIN_IN_LINES);
5995
5984 /* Don't let it get into the margin at either top or bottom. */ 5996 /* Don't let it get into the margin at either top or bottom. */
5985 iarg = max (iarg, this_scroll_margin); 5997 iarg = max (iarg, this_scroll_margin);
5986 iarg = min (iarg, lines - this_scroll_margin - 1); 5998 iarg = min (iarg, lines - this_scroll_margin - 1);