From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: npostavs@users.sourceforge.net Newsgroups: gmane.emacs.bugs Subject: bug#5718: scroll-margin in buffer with small line count. Date: Sat, 28 Jan 2017 19:57:21 -0500 Message-ID: <87inoysmxa.fsf@users.sourceforge.net> References: <4B9D1C61.70903@gmail.com> <87mvkjy0l5.fsf@users.sourceforge.net> <83fuqbfhpb.fsf@gnu.org> <87a8ggwcoo.fsf@users.sourceforge.net> <83inv4cc0s.fsf@gnu.org> <87d1ka17dr.fsf@users.sourceforge.net> <834m5l9g1d.fsf@gnu.org> <874m5j19wi.fsf@users.sourceforge.net> <83zina75pa.fsf@gnu.org> <87pok555q4.fsf@users.sourceforge.net> <831swfcmhz.fsf@gnu.org> <871sw6z32n.fsf@users.sourceforge.net> <83o9zaax8x.fsf@gnu.org> <87k29wxam1.fsf@users.sourceforge.net> <83a8ar9bl6.fsf@gnu.org> <87pojguu7m.fsf@users.sourceforge.net> <83d1fg5iku.fsf@gnu.org> <87inp7ui27.fsf@users.sourceforge.net> <83shob3rjr.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1485651455 20389 195.159.176.226 (29 Jan 2017 00:57:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 29 Jan 2017 00:57:35 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: ahyatt@gmail.com, 5718@debbugs.gnu.org, gavenkoa@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jan 29 01:57:29 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXdnr-0003HE-9m for geb-bug-gnu-emacs@m.gmane.org; Sun, 29 Jan 2017 01:57:11 +0100 Original-Received: from localhost ([::1]:53693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXdnw-0003QI-My for geb-bug-gnu-emacs@m.gmane.org; Sat, 28 Jan 2017 19:57:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXdno-0003Of-22 for bug-gnu-emacs@gnu.org; Sat, 28 Jan 2017 19:57:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXdnj-0003Zu-2Y for bug-gnu-emacs@gnu.org; Sat, 28 Jan 2017 19:57:08 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51380) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cXdni-0003Zn-VV for bug-gnu-emacs@gnu.org; Sat, 28 Jan 2017 19:57:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cXdni-00054p-An for bug-gnu-emacs@gnu.org; Sat, 28 Jan 2017 19:57:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: npostavs@users.sourceforge.net Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 Jan 2017 00:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5718 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 5718-submit@debbugs.gnu.org id=B5718.148565138319471 (code B ref 5718); Sun, 29 Jan 2017 00:57:02 +0000 Original-Received: (at 5718) by debbugs.gnu.org; 29 Jan 2017 00:56:23 +0000 Original-Received: from localhost ([127.0.0.1]:49579 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXdn4-00053x-Qw for submit@debbugs.gnu.org; Sat, 28 Jan 2017 19:56:23 -0500 Original-Received: from mail-io0-f177.google.com ([209.85.223.177]:34810) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXdn1-00053Z-5W; Sat, 28 Jan 2017 19:56:19 -0500 Original-Received: by mail-io0-f177.google.com with SMTP id l66so86136085ioi.1; Sat, 28 Jan 2017 16:56:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=cK0iK/GIgw9rGNxc4xkfEey0b7FVOwtKtgGsDCJYFnU=; b=B90JCnpFHToVnzCDdZnN//I1JiH5cESdXXRaBTKJhNvCUDOBqvkKo7vuQNiuy2M7T5 yKD30i4ZtpGdJ4rCezWyUyB1Q/P1qzyNr34B+v32wbxmF47+Q+CDhZMFAckq4wRAL+UW b2pMh+v8rzF+uT+n3aQL8S+v0Rx7yVCDmveWhdkEB9dsOgs/bggmRrovvD0iAixE1Esu 0jzG/HsOvTZEvrgjTDppR6TEuMTgs8N3M1eBYmpiFxMGnhqI/uGEeyIX9NqkhMBcimCL ZMiD7Bhh8UMUQ/XUnX9lg8GIrXFQ8myMS3MYUhebfx+yNTVzNCVVXdla8zZ4z0zrfyZs XQew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=cK0iK/GIgw9rGNxc4xkfEey0b7FVOwtKtgGsDCJYFnU=; b=pqMUbNK0VEbXBaf3qGbh+PLrm0XzaBAhUhw8TYEClAWV0X5NgFDgigWwC1YTNdjSuF hZWd9j+0vD07UKtYexmj47cg6CrmYjkHt08+VieXmKbR09q/KT4CrboffVjdqficoQhI zzDNvRRwI02nvvs1tFGpp/VFKYCMH9g9bjEs8Gi7Qvuj7YL8ZQAjUeONUO8Y42ZxO4t6 qCzj1plbDDJGhHHlE2Z0xmGK0i26PY+N5eAo4pu0P94DOtMvKyQWve7ZvNobTVwl9a7/ Gjcc1EZujizGMqJ1U2RuYtfDKYQ+zfhb8Ws96x9cO3qaEXjiRCQMP0gmiQ74Vyscd8CU 53cg== X-Gm-Message-State: AIkVDXIepOZKr/Sg0cUdF8S6D1FexxNBOZB4w86wWJz+HR5L7T7Se4g2nqkSs+2DSP8ENQ== X-Received: by 10.107.59.129 with SMTP id i123mr15565409ioa.232.1485651373521; Sat, 28 Jan 2017 16:56:13 -0800 (PST) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id m79sm5910993ioo.0.2017.01.28.16.56.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 28 Jan 2017 16:56:12 -0800 (PST) In-Reply-To: <83shob3rjr.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 22 Jan 2017 19:58:32 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:128741 Archived-At: --=-=-= Content-Type: text/plain tags 5718 patch quit Eli Zaretskii writes: >> >> I came up with this modified version of partial_line_height, which does >> actually work. > > It looks good to me, thanks. Okay, I think this is ready now, I'm posting the final patchset for reference. It's basically the same as the previous stuff, but I've made maximum-scroll-margin customizable, and renamed window-tests.el to test/manual/scroll-tests.el (since it only works in an interactive session). I'll push to master in a couple of days. --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=v4-0001-Refactor-uses-of-scroll_margin-to-a-function.patch.gz Content-Transfer-Encoding: base64 Content-Description: patch H4sICMk3jVgAA3Y0LTAwMDEtUmVmYWN0b3ItdXNlcy1vZi1zY3JvbGxfbWFyZ2luLXRvLWEtZnVu Y3Rpb24ucGF0Y2gA3VptU9tIEv6MfkVvtirBYBn53YbALiEmUAuEA2eTvasr7dga29rIGq8kA75c /vt1z4ts2TIJL7sfjkqBLc20Rt1PP/N0T44jMYZ6b+C1206r5dVZrd0c1HqtuldlrFnus3qD11pO vcfqvQacixCu+QTKTXCcXfkPKo5Tto7RzC5cCDaGSxEn7Cb+PIPX4UR9/nk4Zn5Q6ovxgfWWJXwX rqdhESotOJwO0UC5AeXGbrW169TAdmqOY11Pe3/wfrIL/7o87B6dwE0Nyjv1f8MVH7B+IiKYxjwG MYC4H4kgcMcsGvohJAIYDKZhP/FFaFmnSQx8MEBD/g2HiIVDDiHnXkwDexz6ARtPuIcfk1vOQ3CA hR5s3vqhJ25hxP3hKIEdq1YoQizAT17FNDThEc0fMbSZjPwY+iKMk4j5YQK4BgaxHw4DDpOA9XnJ srYgjvo7ymipb8y7mZUX0Hn8Nl16yVoaNfHveOD2WMy9ImRvBX7I1Z3CrrV5HPE+D3GJRTgeixvu JsLV42kgDlHLufP8eEKrSaKZtoSrLgJ97U+jWEQuTR+jLTIbcRofsJk2pgaufnZ9XAV8iDl6q2TZ tm1lX/6/UKvB9pofO/uTmTrCqVDBqVZm+Xi10YQ1Br7rx4IqDPwA0dQfEUDQv9U2xjHmEUUi3tzG 6Ddr4PGAqwt2wbI8fzAA2x76CbCdzBv2Ml8t/MvvoFlmrUqvXirVq9Uqawyg7DiNWo0ctDTfwtdY tvHzz2DXmu1KsQHb8m+lDXgtAwPYPEOPuO9l2oAJTOf88OjaPb3oAqZbT4gAbkci4PpzKHgUiahg AYA/HmOIMTfdP6f4UvswYEHM9yz4aoG1vbMFR2I8mSZcJxzohBtgKn48vXj7/mPJ2kYzH9MBty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Yn7LwF6as5oO8QND1hwaD5qiAmHyTkhxHh+oAT8m+Ep3gwsF+vqWKyTsj53sz05F+6dOO mpr8ybzHNpTxufbm/Ks5Sy03q/W21BvNaqU17wncF6XcZoXc3gM2jAu5/YpVES/TUdpYlPPwnT2T dVLjO46qzeEu+8yBYK+OJG4zh7Npd2LhdGr5SOofoR8U58mDXigU4c1v3U76de7jVr1YVk6uL1T3 T3Qysdem/AovoXv1m6sz4Oikc/SLqwTEdcFk68uX8MP56cWpGaVF5yrN5anYv4kF/0+qjKecj65W GjLMc26YETE4G4hgElHz/x1CeN1QcV4c/Drv5FCistVotovlOqKy1ag2lW7O/P/A1eZ4YencL1Cn cqCrVSwHwA8XRFz6fyVMOmmgrWsC6D5DZld8SmV/X/fvoVsGKohv4Db/mB20jL3nkDYfpeYlvh+n NDrjQqD/s9W9Ov3kXsnOtH2QLa2KS3tOwT7IaMlnAXJq6bmWpjNjJS9yoY45gRmRlTgFpJM3nXe/ IqPYYFVK7VLVsv4H7XLOXGAtAAA= --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=v4-0002-Don-t-count-mode-line-for-scroll-margin-limit.patch Content-Description: patch >From 775da8da80acd65033624c57057015628a8f2bba Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 28 Aug 2016 17:23:04 -0400 Subject: [PATCH v4 2/5] Don't count mode line for scroll-margin limit * src/window.c (window_scroll_margin): Use window_box_height to avoid counting header line, scrollbars for scroll-margin limit (Bug #5718). --- src/window.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/window.c b/src/window.c index 5333a6f..e499dfb 100644 --- a/src/window.c +++ b/src/window.c @@ -4802,10 +4802,8 @@ 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); + int window_lines = window_box_height (window) / frame_line_height; + int margin = min (scroll_margin, window_lines / 4); if (unit == MARGIN_IN_PIXELS) return margin * frame_line_height; else -- 2.9.3 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=v4-0003-Make-limit-on-scroll-margin-variable.patch Content-Description: patch >From ae56bb9600019e2c2a6a5f8c22c36bd08a737d1c Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 11 Sep 2016 11:09:57 -0400 Subject: [PATCH v4 3/5] 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. * src/window.c (window_scroll_pixel_based): Use it instead of hardcoding division by 4 (Bug #5718). --- etc/NEWS | 4 ++++ lisp/cus-start.el | 1 + src/window.c | 19 ++++++++++++++----- src/xdisp.c | 8 ++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index b89e8e4..07b8051 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -307,6 +307,10 @@ local part of a remote file name. Thus, if you have a directory named "/~" on the remote host "foo", you can prevent it from being substituted by a home directory by writing it as "/foo:/:/~/file". +** The new variable 'maximum-scroll-margin' allows having effective +settings of 'scroll-margin' up to half the window size, instead of +always restricting the margin to a quarter of the window. + * Editing Changes in Emacs 26.1 diff --git a/lisp/cus-start.el b/lisp/cus-start.el index a790419..51c43c7 100644 --- a/lisp/cus-start.el +++ b/lisp/cus-start.el @@ -511,6 +511,7 @@ minibuffer-prompt-properties--setter (scroll-step windows integer) (scroll-conservatively windows integer) (scroll-margin windows integer) + (maximum-scroll-margin windows float "26.1") (hscroll-margin windows integer "22.1") (hscroll-step windows number "22.1") (truncate-partial-width-windows diff --git a/src/window.c b/src/window.c index e499dfb..7d86d9d 100644 --- a/src/window.c +++ b/src/window.c @@ -4803,11 +4803,20 @@ window_scroll_margin (struct window *window, enum margin_unit unit) { int frame_line_height = default_line_pixel_height (window); int window_lines = window_box_height (window) / frame_line_height; - int margin = min (scroll_margin, window_lines / 4); - if (unit == MARGIN_IN_PIXELS) - return margin * frame_line_height; - else - return margin; + + double ratio = 0.25; + if (FLOATP (Vmaximum_scroll_margin)) + { + ratio = XFLOAT_DATA (Vmaximum_scroll_margin); + ratio = max (0.0, ratio); + ratio = min (ratio, 0.5); + } + int max_margin = min ((window_lines - 1)/2, + (int) (window_lines * ratio)); + int margin = clip_to_bounds (0, scroll_margin, max_margin); + return (unit == MARGIN_IN_PIXELS) + ? margin * frame_line_height + : margin; } else return 0; diff --git a/src/xdisp.c b/src/xdisp.c index 8a450b7..134ef6c 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -31520,6 +31520,14 @@ syms_of_xdisp (void) of the top or bottom of the window. */); scroll_margin = 0; + DEFVAR_LISP ("maximum-scroll-margin", Vmaximum_scroll_margin, + doc: /* Maximum effective value of `scroll-margin'. +Given as a fraction of the current window's lines. The value should +be a floating point number between 0.0 and 0.5. The effective maximum +is limited to (/ (1- window-lines) 2). Non-float values for this +variable are ignored and the default 0.25 is used instead. */); + Vmaximum_scroll_margin = make_float (0.25); + DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch, doc: /* Pixels per inch value for non-window system displays. Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */); -- 2.9.3 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=v4-0004-Fix-scrolling-with-partial-lines.patch Content-Description: patch >From 239fe08b7667e397913842fe4a7fc5784dd5ea27 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 21 Jan 2017 13:24:47 -0500 Subject: [PATCH v4 4/5] Fix scrolling with partial lines * src/xdisp.c (partial_line_height): New function. (try_scrolling): * src/window.c (window_scroll_pixel_based): Use it for calculating the pixel scroll margin correctly in a window with partial lines. --- src/dispextern.h | 1 + src/window.c | 2 +- src/xdisp.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/dispextern.h b/src/dispextern.h index 51222e6..eb71a82 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3263,6 +3263,7 @@ void move_it_past_eol (struct it *); void move_it_in_display_line (struct it *it, ptrdiff_t to_charpos, int to_x, enum move_operation_enum op); +int partial_line_height (struct it *it_origin); bool in_display_vector_p (struct it *); int frame_mode_line_height (struct frame *); extern bool redisplaying_p; diff --git a/src/window.c b/src/window.c index 7d86d9d..9feeede 100644 --- a/src/window.c +++ b/src/window.c @@ -5149,7 +5149,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, bool noerror) in the scroll margin at the bottom. */ move_it_to (&it, PT, -1, (it.last_visible_y - WINDOW_HEADER_LINE_HEIGHT (w) - - this_scroll_margin - 1), + - partial_line_height (&it) - this_scroll_margin - 1), -1, MOVE_TO_POS | MOVE_TO_Y); diff --git a/src/xdisp.c b/src/xdisp.c index 134ef6c..0e329df 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -9859,6 +9859,32 @@ move_it_by_lines (struct it *it, ptrdiff_t dvpos) } } +int +partial_line_height (struct it *it_origin) +{ + int partial_height; + void *it_data = NULL; + struct it it; + SAVE_IT (it, *it_origin, it_data); + move_it_to (&it, ZV, -1, it.last_visible_y, -1, + MOVE_TO_POS | MOVE_TO_Y); + if (it.what == IT_EOB) + { + int vis_height = it.last_visible_y - it.current_y; + int height = it.ascent + it.descent; + partial_height = (vis_height < height) ? vis_height : 0; + } + else + { + int last_line_y = it.current_y; + move_it_by_lines (&it, 1); + partial_height = (it.current_y > it.last_visible_y) + ? it.last_visible_y - last_line_y : 0; + } + RESTORE_IT (&it, &it, it_data); + return partial_height; +} + /* Return true if IT points into the middle of a display vector. */ bool @@ -15368,7 +15394,8 @@ try_scrolling (Lisp_Object window, bool just_this_one_p, /* Compute the pixel ypos of the scroll margin, then move IT to either that ypos or PT, whichever comes first. */ start_display (&it, w, startp); - scroll_margin_y = it.last_visible_y - this_scroll_margin + scroll_margin_y = it.last_visible_y - partial_line_height (&it) + - this_scroll_margin - frame_line_height * extra_scroll_margin_lines; move_it_to (&it, PT, -1, scroll_margin_y - 1, -1, (MOVE_TO_POS | MOVE_TO_Y)); -- 2.9.3 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=v4-0005-Add-tests-for-scrolling.patch Content-Description: patch >From 198d9ec8bbcc93ba676b09627b08ace1cd611a74 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sat, 28 Jan 2017 16:54:33 -0500 Subject: [PATCH v4 5/5] Add tests for scrolling * test/manual/scroll-tests.el: New tests for scroll-margin behavior. --- test/manual/scroll-tests.el | 130 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 test/manual/scroll-tests.el diff --git a/test/manual/scroll-tests.el b/test/manual/scroll-tests.el new file mode 100644 index 0000000..1167efd --- /dev/null +++ b/test/manual/scroll-tests.el @@ -0,0 +1,130 @@ +;;; scroll-tests.el -- tests for scrolling -*- lexical-binding: t -*- + +;; Copyright (C) 2017 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; These are mostly automated ert tests, but they don't work in batch +;; mode which is why they are under test/manual. + +;;; Code: + +(require 'ert) +(eval-when-compile (require 'cl-lib)) + +(defun scroll-tests-up-and-down (margin &optional effective-margin) + (unless effective-margin + (setq effective-margin margin)) + (erase-buffer) + (insert (mapconcat #'number-to-string + (number-sequence 1 200) "\n")) + (goto-char 1) + (sit-for 0) + (let ((scroll-margin margin) + (wstart (window-start))) + ;; Stopping before `scroll-margin' so we shouldn't have + ;; scrolled. + (let ((current-prefix-arg (- (window-text-height) 1 effective-margin))) + (call-interactively 'next-line)) + (sit-for 0) + (should (= wstart (window-start))) + ;; Passing `scroll-margin' should trigger scrolling. + (call-interactively 'next-line) + (sit-for 0) + (should (/= wstart (window-start))) + ;; Scroll back to top. + (let ((current-prefix-arg (window-start))) + (call-interactively 'scroll-down-command)) + (sit-for 0) + (should (= 1 (window-start))))) + +(defmacro scroll-tests-with-buffer-window (&rest body) + (declare (debug t)) + `(with-temp-buffer + (with-selected-window (display-buffer (current-buffer)) + ,@body))) + +(ert-deftest scroll-tests-scroll-margin-0 () + (skip-unless (not noninteractive)) + (scroll-tests-with-buffer-window + (scroll-tests-up-and-down 0))) + +(ert-deftest scroll-tests-scroll-margin-negative () + "A negative `scroll-margin' should be the same as 0." + (skip-unless (not noninteractive)) + (scroll-tests-with-buffer-window + (scroll-tests-up-and-down -10 0))) + +(ert-deftest scroll-tests-scroll-margin-max () + (skip-unless (not noninteractive)) + (scroll-tests-with-buffer-window + (let ((max-margin (/ (window-text-height) 4))) + (scroll-tests-up-and-down max-margin)))) + +(ert-deftest scroll-tests-scroll-margin-over-max () + "A `scroll-margin' more than max should be the same as max." + (skip-unless (not noninteractive)) + (scroll-tests-with-buffer-window + (set-window-text-height nil 7) + (let ((max-margin (/ (window-text-height) 4))) + (scroll-tests-up-and-down (+ max-margin 1) max-margin) + (scroll-tests-up-and-down (+ max-margin 2) max-margin)))) + +(defun scroll-tests--point-in-middle-of-window-p () + (= (count-lines (window-start) (window-point)) + (/ (1- (window-text-height)) 2))) + +(cl-defun scroll-tests--scroll-margin-whole-window (&key with-line-spacing) + "Test `maximum-scroll-margin' at 0.5. +With a high `scroll-margin', this should keep cursor in the +middle of the window." + (let ((maximum-scroll-margin 0.5) + (scroll-margin 100)) + (scroll-tests-with-buffer-window + (setq-local line-spacing with-line-spacing) + ;; Choose an odd number, so there is one line in the middle. + (set-window-text-height nil 7) + ;; `set-window-text-height' doesn't count `line-spacing'. + (when with-line-spacing + (window-resize nil (* line-spacing 7) nil nil 'pixels)) + (erase-buffer) + (insert (mapconcat #'number-to-string + (number-sequence 1 200) "\n")) + (goto-char 1) + (sit-for 0) + (call-interactively 'scroll-up-command) + (sit-for 0) + (should (scroll-tests--point-in-middle-of-window-p)) + (call-interactively 'scroll-up-command) + (sit-for 0) + (should (scroll-tests--point-in-middle-of-window-p)) + (call-interactively 'scroll-down-command) + (sit-for 0) + (should (scroll-tests--point-in-middle-of-window-p))))) + +(ert-deftest scroll-tests-scroll-margin-whole-window () + (skip-unless (not noninteractive)) + (scroll-tests--scroll-margin-whole-window)) + +(ert-deftest scroll-tests-scroll-margin-whole-window-line-spacing () + ;; `line-spacing' has no effect on tty displays. + (skip-unless (display-graphic-p)) + (scroll-tests--scroll-margin-whole-window :with-line-spacing 3)) + + +;;; scroll-tests.el ends here -- 2.9.3 --=-=-=--