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: Sun, 11 Sep 2016 16:58:08 -0400 Message-ID: <87d1ka17dr.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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1473627514 8060 195.159.176.226 (11 Sep 2016 20:58:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 11 Sep 2016 20:58:34 +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 Sep 11 22:58:29 2016 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 1bjBpQ-0000HW-ID for geb-bug-gnu-emacs@m.gmane.org; Sun, 11 Sep 2016 22:58:16 +0200 Original-Received: from localhost ([::1]:39049 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjBpO-0008DB-Na for geb-bug-gnu-emacs@m.gmane.org; Sun, 11 Sep 2016 16:58:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjBpI-0008D6-R6 for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2016 16:58:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjBpC-0007u8-QR for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2016 16:58:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjBpC-0007tq-Kz for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2016 16:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bjBpC-0002Ay-9w for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2016 16:58:02 -0400 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, 11 Sep 2016 20:58: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.14736274778352 (code B ref 5718); Sun, 11 Sep 2016 20:58:02 +0000 Original-Received: (at 5718) by debbugs.gnu.org; 11 Sep 2016 20:57:57 +0000 Original-Received: from localhost ([127.0.0.1]:56811 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bjBp6-0002Ae-TT for submit@debbugs.gnu.org; Sun, 11 Sep 2016 16:57:57 -0400 Original-Received: from mail-oi0-f51.google.com ([209.85.218.51]:33768) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bjBp4-0002AP-67 for 5718@debbugs.gnu.org; Sun, 11 Sep 2016 16:57:54 -0400 Original-Received: by mail-oi0-f51.google.com with SMTP id y2so269225578oie.0 for <5718@debbugs.gnu.org>; Sun, 11 Sep 2016 13:57:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=BTypXMY/hhKelU3k1ShGbVOaLcMjqXbCf2RCePlQ1xU=; b=g8/Oxs3y/kiPTT9/LCyX6zkSclMxhXclLmHF4NCtD/e7HjjuDNdBOfvzKWTPeGZr4z ezrJcVl5dfNtAG/IQF69rhTrMxQEvAymo/01tdsgutA+IzBxwilI4iirgdTL8frcy+re H/0nEX8lPaI4SyddJLyslsi+T+MVZnBFroI790szx/ffPXbbcVhOcoidnAgQFsxSwuof Xp9GX+J0oJV1DOL0D18iOueYOi01VulKHVsWYjdhMAi6OVZ2vJGtM7etHCmkiowZQojw lXicaUImgZTv6KlnncY84FGHITfWs55wrWm5GJMRilmMLZ6W4qoDVm0Oe57AiSfaO9FW iqKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:references:date :in-reply-to:message-id:user-agent:mime-version; bh=BTypXMY/hhKelU3k1ShGbVOaLcMjqXbCf2RCePlQ1xU=; b=Ut93Nx9dm9fMi38X8C8YQNR6MrKUwnv+pt6I60FAcgxjrSqfHoDzgdlEALfaKoi683 4c9jaZFIl7Utwjh8EMMfehr5MUVgcufWubGLQ5se35KKmHfNf6OwqLmPoTzPTFVoB+KC xx1cDq/YZVxM6kW3NiGpt4QMV7Tm6oNSvdmjKGrVUTFvEW8/U4uoWXeXBFkfC42uGwgd tiNwpRvoYBlB1ah+b/B1Gw2jcXaGqD9bP6WwgFCP0W34dLtzQNZrIVtTWmtDFBKuPXyG X8e7qAxRo9KbYY2Iav7JCXA8VxRPEOEvs1NCp1bV0nohy6MN+PsEzsPu0x+SfV/jyl/n hqLw== X-Gm-Message-State: AE9vXwN3/A2udXdkcKMwCDYGvOpb4VY/wFeROgGq3dajZH3BWdzkDtSvu2Erp+20xMDXPg== X-Received: by 10.157.38.167 with SMTP id l36mr19681855otb.59.1473627468375; Sun, 11 Sep 2016 13:57:48 -0700 (PDT) Original-Received: from zony ([45.2.7.130]) by smtp.googlemail.com with ESMTPSA id z125sm13713621itc.0.2016.09.11.13.57.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Sep 2016 13:57:47 -0700 (PDT) In-Reply-To: <83inv4cc0s.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 14 Aug 2016 05:36:19 +0300") 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:123196 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: npostavs@users.sourceforge.net >> Cc: 5718@debbugs.gnu.org, ahyatt@gmail.com, gavenkoa@gmail.com >> Date: Sat, 13 Aug 2016 18:01:43 -0400 >> >> >> this_scroll_margin = max (0, scroll_margin); >> >> this_scroll_margin >> >> = min (this_scroll_margin, window_total_lines / 4); >> > >> > Which reveals a subtle bug: the actual scroll margin should be 1 for 7 >> > lines, 2 for 11, etc. The problem is that the value of >> > window_total_lines includes the mode line, which it shouldn't. Maybe >> > this should be fixed. I have a patch set for fixing this and allowing the user to change the maximum margin from 0.25. The latter doesn't quite work perfectly, for some reason when setting the maximum margin to 0.5 and scroll-margin to 100, `scroll-down-command' doesn't keep point centered in the window, even though other commands (e.g. `scroll-up-command') do. The patches come with tests demonstrating this (the tests only work in interactive mode). --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=v1-0001-Refactor-uses-of-scroll_margin-to-a-function.patch.gz Content-Transfer-Encoding: base64 Content-Description: compressed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apVhnnHDlIjBWUMEkxKc/e8AwuuaivP84Jdl50cSla1tLPbuNqKytb3tKtVa+A9i yxutlYXTn0idzYDufLDXgTCeU6L5WblJJw20VQ2l7lkLdfk5XeJDO0mPrTqoYb6C2/JjVtBa/IGj unKUmof4dpzS6IILgf7PTuf67KN/LXc57YOApyGWczSUJeF9daHmVOyDgiD+LkDOLX2vpenMWMqL UqhjTmBGFFVSBenk9fHb35BRbLC8WrtWt6z/AVq7qodhKwAA --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v1-0002-Don-t-count-mode-line-for-scroll-margin-limit.patch Content-Description: patch >From 0f3a50fa311e6ec1ccb1a0d03d521cc2ef9b309a Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 28 Aug 2016 17:23:04 -0400 Subject: [PATCH v1 2/3] Don't count mode line for scroll-margin limit * src/window.c (window_scroll_margin): Subtract mode line height from upper limit applied to scroll margin (Bug #5718). * test/src/window-tests.el: New tests for scroll-margin behavior. --- src/window.c | 3 +- test/src/window-tests.el | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 test/src/window-tests.el diff --git a/src/window.c b/src/window.c index 2046fe7..dbda435 100644 --- a/src/window.c +++ b/src/window.c @@ -4800,7 +4800,8 @@ window_scroll_margin (struct window *window, enum margin_unit unit) { int frame_line_height = default_line_pixel_height (window); int window_total_lines - = window->total_lines * WINDOW_FRAME_LINE_HEIGHT (window) + = (window->total_lines * WINDOW_FRAME_LINE_HEIGHT (window) + - WINDOW_MODE_LINE_HEIGHT (window)) / frame_line_height; int margin = min (scroll_margin, window_total_lines / 4); if (unit == MARGIN_IN_PIXELS) diff --git a/test/src/window-tests.el b/test/src/window-tests.el new file mode 100644 index 0000000..88ded18 --- /dev/null +++ b/test/src/window-tests.el @@ -0,0 +1,86 @@ +;;; window-tests.el -- tests for window.c -*- lexical-binding: t -*- + +;; Copyright (C) 2016 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 . + +;;; Code: + +(require 'ert) + +(defun window-test-scrolling (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) + (mode-lines (/ (window-mode-line-height) (line-pixel-height))) + (wstart (window-start))) + ;; Stopping before `scroll-margin' so we shouldn't have + ;; scrolled. + (let ((current-prefix-arg (- (window-height) + mode-lines (window-start) 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 window-with-test-buffer-window (&rest body) + (let ((bufvar (make-symbol "buf"))) + `(let ((,bufvar (get-buffer-create "*test*"))) + (with-selected-window (display-buffer ,bufvar) + (with-current-buffer ,bufvar + ,@body))))) + +(ert-deftest window-test-scroll-margin-0 () + (skip-unless (not noninteractive)) + (window-with-test-buffer-window + (window-test-scrolling 0))) + +(ert-deftest window-test-scroll-margin-negative () + "A negative `scroll-margin' should be the same as 0." + (skip-unless (not noninteractive)) + (window-with-test-buffer-window + (window-test-scrolling -10 0))) + +(ert-deftest window-test-scroll-margin-max () + (skip-unless (not noninteractive)) + (window-with-test-buffer-window + (let* ((mode-lines (/ (window-mode-line-height) (line-pixel-height))) + (max-margin (/ (- (window-height) mode-lines) 4))) + (window-test-scrolling max-margin)))) + +(ert-deftest window-test-scroll-margin-over-max () + "A `scroll-margin' more than max should be the same as max." + (skip-unless (not noninteractive)) + (window-with-test-buffer-window + ;; Check that mode line is not counted for determining max margin. + (set-window-text-height nil 7) + (let* ((mode-lines (/ (window-mode-line-height) (line-pixel-height))) + (max-margin (/ (- (window-height) mode-lines) 4))) + (window-test-scrolling (+ max-margin 1) max-margin) + (window-test-scrolling (+ max-margin 2) max-margin)))) -- 2.9.3 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v1-0003-BROKEN-Make-limit-on-scroll-margin-variable.patch Content-Description: patch >From 0697341a9cdc1f9962a7b984e2a8ffe5150831f5 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 11 Sep 2016 11:09:57 -0400 Subject: [PATCH v1 3/3] [BROKEN] Make limit on scroll-margin variable [BROKEN]: The `scroll-down-command' doesn't stay in the middle of the window. * src/xdisp.c (maximum-scroll-margin): New variable. * src/window.c (window_scroll_pixel_based): Use it instead of hardcoding division by 4 (Bug #5718). * test/src/window-tests.el (window-test-scroll-margin-whole-window): Test it. --- src/window.c | 13 ++++++++++++- src/xdisp.c | 5 +++++ test/src/window-tests.el | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/window.c b/src/window.c index dbda435..20a7f3a 100644 --- a/src/window.c +++ b/src/window.c @@ -4803,7 +4803,18 @@ window_scroll_margin (struct window *window, enum margin_unit unit) = (window->total_lines * WINDOW_FRAME_LINE_HEIGHT (window) - WINDOW_MODE_LINE_HEIGHT (window)) / frame_line_height; - int margin = min (scroll_margin, window_total_lines / 4); + + int margin, max_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); + } + max_margin = (int) (window_total_lines * ratio); + margin = max (0, scroll_margin); + margin = min (scroll_margin, max_margin); if (unit == MARGIN_IN_PIXELS) return margin * frame_line_height; else diff --git a/src/xdisp.c b/src/xdisp.c index 3602025..b22242a 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -31451,6 +31451,11 @@ Recenter the window whenever point gets within this many lines 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. */); + 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). */); diff --git a/test/src/window-tests.el b/test/src/window-tests.el index 88ded18..c6152c8 100644 --- a/test/src/window-tests.el +++ b/test/src/window-tests.el @@ -50,6 +50,7 @@ window-test-scrolling (should (= 1 (window-start))))) (defmacro window-with-test-buffer-window (&rest body) + (declare (debug t)) (let ((bufvar (make-symbol "buf"))) `(let ((,bufvar (get-buffer-create "*test*"))) (with-selected-window (display-buffer ,bufvar) @@ -84,3 +85,32 @@ window-with-test-buffer-window (max-margin (/ (- (window-height) mode-lines) 4))) (window-test-scrolling (+ max-margin 1) max-margin) (window-test-scrolling (+ max-margin 2) max-margin)))) + +(defun window-test--point-in-middle-of-window-p () + (= (count-lines (window-start) (window-point)) + (- (count-lines (window-point) (window-end)) 1 + (if (pos-visible-in-window-p (window-end)) 0 1)))) + +(ert-deftest window-test-scroll-margin-whole-window () + "Test `maximum-scroll-margin' at 0.5. +With a high `scroll-margin', this should keep cursor in the +middle of the window." + (skip-unless (not noninteractive)) + (let ((maximum-scroll-margin 0.5) + (scroll-margin 100)) + (window-with-test-buffer-window + (set-window-text-height nil 7) + (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 (window-test--point-in-middle-of-window-p)) + (call-interactively 'scroll-up-command) + (sit-for 0) + (should (window-test--point-in-middle-of-window-p)) + (call-interactively 'scroll-down-command) + (sit-for 0) + (should (window-test--point-in-middle-of-window-p))))) -- 2.9.3 --=-=-= Content-Type: text/plain >> >> >> /* Height in pixels, and in lines, of the mode line. >> May be zero if W doesn't have a mode line. */ >> #define WINDOW_MODE_LINE_HEIGHT(W) \ >> >> How is the height "in pixels, and in lines"? Doesn't it have to be one >> or the other? > > It's in pixels. The comment should be fixed. Fixed pushed as ea0f750e, "Fix comments on window height macros" --=-=-=--