diff options
| author | Noam Postavsky | 2016-09-11 11:09:57 -0400 |
|---|---|---|
| committer | Noam Postavsky | 2017-02-02 21:20:29 -0500 |
| commit | e27a91cddc1a66c25e09d3929c5625637ec34a49 (patch) | |
| tree | 00096f2a38822f4c63ba228e769fb02c1c966b54 | |
| parent | c92fc7a2156a5939439b7236452d4dfcfc13cc89 (diff) | |
| download | emacs-e27a91cddc1a66c25e09d3929c5625637ec34a49.tar.gz emacs-e27a91cddc1a66c25e09d3929c5625637ec34a49.zip | |
Make limit on scroll-margin variable
* src/xdisp.c (maximum-scroll-margin): New variable.
* lisp/cus-start.el: Make it customizable.
* etc/NEWS: Mention it.
* doc/emacs/display.texi (Auto Scrolling):
* doc/lispref/windows.texi (Textual Scrolling): Document it.
* src/window.c (window_scroll_pixel_based): Use it instead of hardcoding
division by 4 (Bug #5718).
| -rw-r--r-- | doc/emacs/display.texi | 12 | ||||
| -rw-r--r-- | doc/lispref/windows.texi | 15 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/cus-start.el | 1 | ||||
| -rw-r--r-- | src/window.c | 19 | ||||
| -rw-r--r-- | src/xdisp.c | 8 |
6 files changed, 51 insertions, 9 deletions
diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi index c6e990d9082..15c700892bc 100644 --- a/doc/emacs/display.texi +++ b/doc/emacs/display.texi | |||
| @@ -285,13 +285,17 @@ multiple variables, the order of priority is: | |||
| 285 | @code{scroll-up-aggressively} / @code{scroll-down-aggressively}. | 285 | @code{scroll-up-aggressively} / @code{scroll-down-aggressively}. |
| 286 | 286 | ||
| 287 | @vindex scroll-margin | 287 | @vindex scroll-margin |
| 288 | @vindex maximum-scroll-margin | ||
| 288 | The variable @code{scroll-margin} restricts how close point can come | 289 | The variable @code{scroll-margin} restricts how close point can come |
| 289 | to the top or bottom of a window (even if aggressive scrolling | 290 | to the top or bottom of a window (even if aggressive scrolling |
| 290 | specifies a fraction @var{f} that is larger than the window portion | 291 | specifies a fraction @var{f} that is larger than the window portion |
| 291 | between the top and the bottom margins). Its value is a number of screen | 292 | between the top and the bottom margins). Its value is a number of |
| 292 | lines; if point comes within that many lines of the top or bottom of | 293 | screen lines; if point comes within that many lines of the top or |
| 293 | the window, Emacs performs automatic scrolling. By default, | 294 | bottom of the window, Emacs performs automatic scrolling. By default, |
| 294 | @code{scroll-margin} is 0. | 295 | @code{scroll-margin} is 0. The effective margin size is limited to a |
| 296 | quarter of the window height by default, but this limit can be | ||
| 297 | increased up to half (or decreased down to zero) by customizing | ||
| 298 | @code{maximum-scroll-margin}. | ||
| 295 | 299 | ||
| 296 | @node Horizontal Scrolling | 300 | @node Horizontal Scrolling |
| 297 | @section Horizontal Scrolling | 301 | @section Horizontal Scrolling |
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 6f3de0c8a0e..affa28c9202 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi | |||
| @@ -3924,6 +3924,21 @@ redisplay scrolls the text automatically (if possible) to move point | |||
| 3924 | out of the margin, closer to the center of the window. | 3924 | out of the margin, closer to the center of the window. |
| 3925 | @end defopt | 3925 | @end defopt |
| 3926 | 3926 | ||
| 3927 | @defopt maximum-scroll-margin | ||
| 3928 | This variable limits the effective value of @code{scroll-margin} to a | ||
| 3929 | fraction of the current window line height. For example, if the | ||
| 3930 | current window has 20 lines and @code{maximum-scroll-margin} is 0.1, | ||
| 3931 | then the scroll margins will never be larger than 2 lines, no matter | ||
| 3932 | how big @code{scroll-margin} is. | ||
| 3933 | |||
| 3934 | @code{maximum-scroll-margin} itself has a maximum value of 0.5, which | ||
| 3935 | allows setting margins large to keep the cursor at the middle line of | ||
| 3936 | the window (or two middle lines if the window has an even number of | ||
| 3937 | lines). If it's set to a larger value (or any value other than a | ||
| 3938 | float between 0.0 and 0.5) then the default value of 0.25 will be used | ||
| 3939 | instead. | ||
| 3940 | @end defopt | ||
| 3941 | |||
| 3927 | @defopt scroll-conservatively | 3942 | @defopt scroll-conservatively |
| 3928 | This variable controls how scrolling is done automatically when point | 3943 | This variable controls how scrolling is done automatically when point |
| 3929 | moves off the screen (or into the scroll margin). If the value is a | 3944 | moves off the screen (or into the scroll margin). If the value is a |
| @@ -307,6 +307,11 @@ local part of a remote file name. Thus, if you have a directory named | |||
| 307 | "/~" on the remote host "foo", you can prevent it from being | 307 | "/~" on the remote host "foo", you can prevent it from being |
| 308 | substituted by a home directory by writing it as "/foo:/:/~/file". | 308 | substituted by a home directory by writing it as "/foo:/:/~/file". |
| 309 | 309 | ||
| 310 | +++ | ||
| 311 | ** The new variable 'maximum-scroll-margin' allows having effective | ||
| 312 | settings of 'scroll-margin' up to half the window size, instead of | ||
| 313 | always restricting the margin to a quarter of the window. | ||
| 314 | |||
| 310 | 315 | ||
| 311 | * Editing Changes in Emacs 26.1 | 316 | * Editing Changes in Emacs 26.1 |
| 312 | 317 | ||
diff --git a/lisp/cus-start.el b/lisp/cus-start.el index a790419b86f..51c43c7d21a 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el | |||
| @@ -511,6 +511,7 @@ since it could result in memory overflow and make Emacs crash." | |||
| 511 | (scroll-step windows integer) | 511 | (scroll-step windows integer) |
| 512 | (scroll-conservatively windows integer) | 512 | (scroll-conservatively windows integer) |
| 513 | (scroll-margin windows integer) | 513 | (scroll-margin windows integer) |
| 514 | (maximum-scroll-margin windows float "26.1") | ||
| 514 | (hscroll-margin windows integer "22.1") | 515 | (hscroll-margin windows integer "22.1") |
| 515 | (hscroll-step windows number "22.1") | 516 | (hscroll-step windows number "22.1") |
| 516 | (truncate-partial-width-windows | 517 | (truncate-partial-width-windows |
diff --git a/src/window.c b/src/window.c index 235c3c1ade8..ba03780f3df 100644 --- a/src/window.c +++ b/src/window.c | |||
| @@ -4801,11 +4801,20 @@ window_scroll_margin (struct window *window, enum margin_unit unit) | |||
| 4801 | { | 4801 | { |
| 4802 | int frame_line_height = default_line_pixel_height (window); | 4802 | int frame_line_height = default_line_pixel_height (window); |
| 4803 | int window_lines = window_box_height (window) / frame_line_height; | 4803 | int window_lines = window_box_height (window) / frame_line_height; |
| 4804 | int margin = min (scroll_margin, window_lines / 4); | 4804 | |
| 4805 | if (unit == MARGIN_IN_PIXELS) | 4805 | double ratio = 0.25; |
| 4806 | return margin * frame_line_height; | 4806 | if (FLOATP (Vmaximum_scroll_margin)) |
| 4807 | else | 4807 | { |
| 4808 | return margin; | 4808 | ratio = XFLOAT_DATA (Vmaximum_scroll_margin); |
| 4809 | ratio = max (0.0, ratio); | ||
| 4810 | ratio = min (ratio, 0.5); | ||
| 4811 | } | ||
| 4812 | int max_margin = min ((window_lines - 1)/2, | ||
| 4813 | (int) (window_lines * ratio)); | ||
| 4814 | int margin = clip_to_bounds (0, scroll_margin, max_margin); | ||
| 4815 | return (unit == MARGIN_IN_PIXELS) | ||
| 4816 | ? margin * frame_line_height | ||
| 4817 | : margin; | ||
| 4809 | } | 4818 | } |
| 4810 | else | 4819 | else |
| 4811 | return 0; | 4820 | return 0; |
diff --git a/src/xdisp.c b/src/xdisp.c index 8a450b7a8a4..134ef6c6196 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -31520,6 +31520,14 @@ Recenter the window whenever point gets within this many lines | |||
| 31520 | of the top or bottom of the window. */); | 31520 | of the top or bottom of the window. */); |
| 31521 | scroll_margin = 0; | 31521 | scroll_margin = 0; |
| 31522 | 31522 | ||
| 31523 | DEFVAR_LISP ("maximum-scroll-margin", Vmaximum_scroll_margin, | ||
| 31524 | doc: /* Maximum effective value of `scroll-margin'. | ||
| 31525 | Given as a fraction of the current window's lines. The value should | ||
| 31526 | be a floating point number between 0.0 and 0.5. The effective maximum | ||
| 31527 | is limited to (/ (1- window-lines) 2). Non-float values for this | ||
| 31528 | variable are ignored and the default 0.25 is used instead. */); | ||
| 31529 | Vmaximum_scroll_margin = make_float (0.25); | ||
| 31530 | |||
| 31523 | DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch, | 31531 | DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch, |
| 31524 | doc: /* Pixels per inch value for non-window system displays. | 31532 | doc: /* Pixels per inch value for non-window system displays. |
| 31525 | Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */); | 31533 | Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */); |