diff options
| author | Noam Postavsky | 2016-08-28 16:38:04 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2017-02-02 21:19:52 -0500 |
| commit | d17e92da064cabf376597f5de2a8d5a6484bfea6 (patch) | |
| tree | b608581cb4e883357a753c12e4526cac53066427 /src | |
| parent | 53c16c75a57aa486dfc1f46ef5aa538264e6ad47 (diff) | |
| download | emacs-d17e92da064cabf376597f5de2a8d5a6484bfea6.tar.gz emacs-d17e92da064cabf376597f5de2a8d5a6484bfea6.zip | |
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')
| -rw-r--r-- | src/window.c | 44 | ||||
| -rw-r--r-- | src/window.h | 2 | ||||
| -rw-r--r-- | src/xdisp.c | 67 |
3 files changed, 39 insertions, 74 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. */ | ||
| 4797 | int | ||
| 4798 | window_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); |
diff --git a/src/window.h b/src/window.h index 061cf244943..acb8a5cabfa 100644 --- a/src/window.h +++ b/src/window.h | |||
| @@ -1120,6 +1120,8 @@ extern bool compare_window_configurations (Lisp_Object, Lisp_Object, bool); | |||
| 1120 | extern void mark_window_cursors_off (struct window *); | 1120 | extern void mark_window_cursors_off (struct window *); |
| 1121 | extern int window_internal_height (struct window *); | 1121 | extern int window_internal_height (struct window *); |
| 1122 | extern int window_body_width (struct window *w, bool); | 1122 | extern int window_body_width (struct window *w, bool); |
| 1123 | enum margin_unit { MARGIN_IN_LINES, MARGIN_IN_PIXELS }; | ||
| 1124 | extern int window_scroll_margin (struct window *, enum margin_unit); | ||
| 1123 | extern void temp_output_buffer_show (Lisp_Object); | 1125 | extern void temp_output_buffer_show (Lisp_Object); |
| 1124 | extern void replace_buffer_in_windows (Lisp_Object); | 1126 | extern void replace_buffer_in_windows (Lisp_Object); |
| 1125 | extern void replace_buffer_in_windows_safely (Lisp_Object); | 1127 | extern void replace_buffer_in_windows_safely (Lisp_Object); |
diff --git a/src/xdisp.c b/src/xdisp.c index 33661c882cd..8a450b7a8a4 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -15316,7 +15316,6 @@ try_scrolling (Lisp_Object window, bool just_this_one_p, | |||
| 15316 | bool temp_scroll_step, bool last_line_misfit) | 15316 | bool temp_scroll_step, bool last_line_misfit) |
| 15317 | { | 15317 | { |
| 15318 | struct window *w = XWINDOW (window); | 15318 | struct window *w = XWINDOW (window); |
| 15319 | struct frame *f = XFRAME (w->frame); | ||
| 15320 | struct text_pos pos, startp; | 15319 | struct text_pos pos, startp; |
| 15321 | struct it it; | 15320 | struct it it; |
| 15322 | int this_scroll_margin, scroll_max, rc, height; | 15321 | int this_scroll_margin, scroll_max, rc, height; |
| @@ -15327,8 +15326,6 @@ try_scrolling (Lisp_Object window, bool just_this_one_p, | |||
| 15327 | /* We will never try scrolling more than this number of lines. */ | 15326 | /* We will never try scrolling more than this number of lines. */ |
| 15328 | int scroll_limit = SCROLL_LIMIT; | 15327 | int scroll_limit = SCROLL_LIMIT; |
| 15329 | int frame_line_height = default_line_pixel_height (w); | 15328 | int frame_line_height = default_line_pixel_height (w); |
| 15330 | int window_total_lines | ||
| 15331 | = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; | ||
| 15332 | 15329 | ||
| 15333 | #ifdef GLYPH_DEBUG | 15330 | #ifdef GLYPH_DEBUG |
| 15334 | debug_method_add (w, "try_scrolling"); | 15331 | debug_method_add (w, "try_scrolling"); |
| @@ -15336,13 +15333,7 @@ try_scrolling (Lisp_Object window, bool just_this_one_p, | |||
| 15336 | 15333 | ||
| 15337 | SET_TEXT_POS_FROM_MARKER (startp, w->start); | 15334 | SET_TEXT_POS_FROM_MARKER (startp, w->start); |
| 15338 | 15335 | ||
| 15339 | /* Compute scroll margin height in pixels. We scroll when point is | 15336 | this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS); |
| 15340 | within this distance from the top or bottom of the window. */ | ||
| 15341 | if (scroll_margin > 0) | ||
| 15342 | this_scroll_margin = min (scroll_margin, window_total_lines / 4) | ||
| 15343 | * frame_line_height; | ||
| 15344 | else | ||
| 15345 | this_scroll_margin = 0; | ||
| 15346 | 15337 | ||
| 15347 | /* Force arg_scroll_conservatively to have a reasonable value, to | 15338 | /* Force arg_scroll_conservatively to have a reasonable value, to |
| 15348 | avoid scrolling too far away with slow move_it_* functions. Note | 15339 | avoid scrolling too far away with slow move_it_* functions. Note |
| @@ -15816,23 +15807,12 @@ try_cursor_movement (Lisp_Object window, struct text_pos startp, | |||
| 15816 | { | 15807 | { |
| 15817 | int this_scroll_margin, top_scroll_margin; | 15808 | int this_scroll_margin, top_scroll_margin; |
| 15818 | struct glyph_row *row = NULL; | 15809 | struct glyph_row *row = NULL; |
| 15819 | int frame_line_height = default_line_pixel_height (w); | ||
| 15820 | int window_total_lines | ||
| 15821 | = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; | ||
| 15822 | 15810 | ||
| 15823 | #ifdef GLYPH_DEBUG | 15811 | #ifdef GLYPH_DEBUG |
| 15824 | debug_method_add (w, "cursor movement"); | 15812 | debug_method_add (w, "cursor movement"); |
| 15825 | #endif | 15813 | #endif |
| 15826 | 15814 | ||
| 15827 | /* Scroll if point within this distance from the top or bottom | 15815 | this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS); |
| 15828 | of the window. This is a pixel value. */ | ||
| 15829 | if (scroll_margin > 0) | ||
| 15830 | { | ||
| 15831 | this_scroll_margin = min (scroll_margin, window_total_lines / 4); | ||
| 15832 | this_scroll_margin *= frame_line_height; | ||
| 15833 | } | ||
| 15834 | else | ||
| 15835 | this_scroll_margin = 0; | ||
| 15836 | 15816 | ||
| 15837 | top_scroll_margin = this_scroll_margin; | 15817 | top_scroll_margin = this_scroll_margin; |
| 15838 | if (WINDOW_WANTS_HEADER_LINE_P (w)) | 15818 | if (WINDOW_WANTS_HEADER_LINE_P (w)) |
| @@ -16280,7 +16260,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) | |||
| 16280 | int centering_position = -1; | 16260 | int centering_position = -1; |
| 16281 | bool last_line_misfit = false; | 16261 | bool last_line_misfit = false; |
| 16282 | ptrdiff_t beg_unchanged, end_unchanged; | 16262 | ptrdiff_t beg_unchanged, end_unchanged; |
| 16283 | int frame_line_height; | 16263 | int frame_line_height, margin; |
| 16284 | bool use_desired_matrix; | 16264 | bool use_desired_matrix; |
| 16285 | void *itdata = NULL; | 16265 | void *itdata = NULL; |
| 16286 | 16266 | ||
| @@ -16310,6 +16290,8 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) | |||
| 16310 | restart: | 16290 | restart: |
| 16311 | reconsider_clip_changes (w); | 16291 | reconsider_clip_changes (w); |
| 16312 | frame_line_height = default_line_pixel_height (w); | 16292 | frame_line_height = default_line_pixel_height (w); |
| 16293 | margin = window_scroll_margin (w, MARGIN_IN_LINES); | ||
| 16294 | |||
| 16313 | 16295 | ||
| 16314 | /* Has the mode line to be updated? */ | 16296 | /* Has the mode line to be updated? */ |
| 16315 | update_mode_line = (w->update_mode_line | 16297 | update_mode_line = (w->update_mode_line |
| @@ -16614,10 +16596,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) | |||
| 16614 | /* Some people insist on not letting point enter the scroll | 16596 | /* Some people insist on not letting point enter the scroll |
| 16615 | margin, even though this part handles windows that didn't | 16597 | margin, even though this part handles windows that didn't |
| 16616 | scroll at all. */ | 16598 | scroll at all. */ |
| 16617 | int window_total_lines | 16599 | int pixel_margin = margin * frame_line_height; |
| 16618 | = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; | ||
| 16619 | int margin = min (scroll_margin, window_total_lines / 4); | ||
| 16620 | int pixel_margin = margin * frame_line_height; | ||
| 16621 | bool header_line = WINDOW_WANTS_HEADER_LINE_P (w); | 16600 | bool header_line = WINDOW_WANTS_HEADER_LINE_P (w); |
| 16622 | 16601 | ||
| 16623 | /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop | 16602 | /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop |
| @@ -16901,12 +16880,6 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) | |||
| 16901 | it.current_y = it.last_visible_y; | 16880 | it.current_y = it.last_visible_y; |
| 16902 | if (centering_position < 0) | 16881 | if (centering_position < 0) |
| 16903 | { | 16882 | { |
| 16904 | int window_total_lines | ||
| 16905 | = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; | ||
| 16906 | int margin | ||
| 16907 | = scroll_margin > 0 | ||
| 16908 | ? min (scroll_margin, window_total_lines / 4) | ||
| 16909 | : 0; | ||
| 16910 | ptrdiff_t margin_pos = CHARPOS (startp); | 16883 | ptrdiff_t margin_pos = CHARPOS (startp); |
| 16911 | Lisp_Object aggressive; | 16884 | Lisp_Object aggressive; |
| 16912 | bool scrolling_up; | 16885 | bool scrolling_up; |
| @@ -17150,10 +17123,6 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) | |||
| 17150 | { | 17123 | { |
| 17151 | int window_total_lines | 17124 | int window_total_lines |
| 17152 | = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; | 17125 | = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; |
| 17153 | int margin = | ||
| 17154 | scroll_margin > 0 | ||
| 17155 | ? min (scroll_margin, window_total_lines / 4) | ||
| 17156 | : 0; | ||
| 17157 | bool move_down = w->cursor.vpos >= window_total_lines / 2; | 17126 | bool move_down = w->cursor.vpos >= window_total_lines / 2; |
| 17158 | 17127 | ||
| 17159 | move_it_by_lines (&it, move_down ? margin + 1 : -(margin + 1)); | 17128 | move_it_by_lines (&it, move_down ? margin + 1 : -(margin + 1)); |
| @@ -17359,7 +17328,6 @@ try_window (Lisp_Object window, struct text_pos pos, int flags) | |||
| 17359 | struct it it; | 17328 | struct it it; |
| 17360 | struct glyph_row *last_text_row = NULL; | 17329 | struct glyph_row *last_text_row = NULL; |
| 17361 | struct frame *f = XFRAME (w->frame); | 17330 | struct frame *f = XFRAME (w->frame); |
| 17362 | int frame_line_height = default_line_pixel_height (w); | ||
| 17363 | 17331 | ||
| 17364 | /* Make POS the new window start. */ | 17332 | /* Make POS the new window start. */ |
| 17365 | set_marker_both (w->start, Qnil, CHARPOS (pos), BYTEPOS (pos)); | 17333 | set_marker_both (w->start, Qnil, CHARPOS (pos), BYTEPOS (pos)); |
| @@ -17385,17 +17353,7 @@ try_window (Lisp_Object window, struct text_pos pos, int flags) | |||
| 17385 | if ((flags & TRY_WINDOW_CHECK_MARGINS) | 17353 | if ((flags & TRY_WINDOW_CHECK_MARGINS) |
| 17386 | && !MINI_WINDOW_P (w)) | 17354 | && !MINI_WINDOW_P (w)) |
| 17387 | { | 17355 | { |
| 17388 | int this_scroll_margin; | 17356 | int this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS); |
| 17389 | int window_total_lines | ||
| 17390 | = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (f) / frame_line_height; | ||
| 17391 | |||
| 17392 | if (scroll_margin > 0) | ||
| 17393 | { | ||
| 17394 | this_scroll_margin = min (scroll_margin, window_total_lines / 4); | ||
| 17395 | this_scroll_margin *= frame_line_height; | ||
| 17396 | } | ||
| 17397 | else | ||
| 17398 | this_scroll_margin = 0; | ||
| 17399 | 17357 | ||
| 17400 | if ((w->cursor.y >= 0 /* not vscrolled */ | 17358 | if ((w->cursor.y >= 0 /* not vscrolled */ |
| 17401 | && w->cursor.y < this_scroll_margin | 17359 | && w->cursor.y < this_scroll_margin |
| @@ -18679,15 +18637,8 @@ try_window_id (struct window *w) | |||
| 18679 | 18637 | ||
| 18680 | /* Don't let the cursor end in the scroll margins. */ | 18638 | /* Don't let the cursor end in the scroll margins. */ |
| 18681 | { | 18639 | { |
| 18682 | int this_scroll_margin, cursor_height; | 18640 | int this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS); |
| 18683 | int frame_line_height = default_line_pixel_height (w); | 18641 | int cursor_height = MATRIX_ROW (w->desired_matrix, w->cursor.vpos)->height; |
| 18684 | int window_total_lines | ||
| 18685 | = WINDOW_TOTAL_LINES (w) * FRAME_LINE_HEIGHT (it.f) / frame_line_height; | ||
| 18686 | |||
| 18687 | this_scroll_margin = | ||
| 18688 | max (0, min (scroll_margin, window_total_lines / 4)); | ||
| 18689 | this_scroll_margin *= frame_line_height; | ||
| 18690 | cursor_height = MATRIX_ROW (w->desired_matrix, w->cursor.vpos)->height; | ||
| 18691 | 18642 | ||
| 18692 | if ((w->cursor.y < this_scroll_margin | 18643 | if ((w->cursor.y < this_scroll_margin |
| 18693 | && CHARPOS (start) > BEGV) | 18644 | && CHARPOS (start) > BEGV) |