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: Mon, 02 Jan 2017 19:48:03 -0500 Message-ID: <87pok555q4.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> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1483404496 25718 195.159.176.226 (3 Jan 2017 00:48:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 3 Jan 2017 00:48:16 +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 Tue Jan 03 01:48:11 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 1cODGr-0005b4-7a for geb-bug-gnu-emacs@m.gmane.org; Tue, 03 Jan 2017 01:48:09 +0100 Original-Received: from localhost ([::1]:59686 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cODGv-0002N8-3y for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Jan 2017 19:48:13 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cODGn-0002L3-Fy for bug-gnu-emacs@gnu.org; Mon, 02 Jan 2017 19:48:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cODGk-0004r0-99 for bug-gnu-emacs@gnu.org; Mon, 02 Jan 2017 19:48:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cODGk-0004qs-48 for bug-gnu-emacs@gnu.org; Mon, 02 Jan 2017 19:48:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cODGj-0000nH-O1 for bug-gnu-emacs@gnu.org; Mon, 02 Jan 2017 19:48:01 -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: Tue, 03 Jan 2017 00:48:01 +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.14834044292986 (code B ref 5718); Tue, 03 Jan 2017 00:48:01 +0000 Original-Received: (at 5718) by debbugs.gnu.org; 3 Jan 2017 00:47:09 +0000 Original-Received: from localhost ([127.0.0.1]:39860 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cODFs-0000m5-RC for submit@debbugs.gnu.org; Mon, 02 Jan 2017 19:47:09 -0500 Original-Received: from mail-io0-f169.google.com ([209.85.223.169]:35625) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cODFq-0000lb-21 for 5718@debbugs.gnu.org; Mon, 02 Jan 2017 19:47:06 -0500 Original-Received: by mail-io0-f169.google.com with SMTP id n85so187108995ioi.2 for <5718@debbugs.gnu.org>; Mon, 02 Jan 2017 16:47:05 -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=75g+1e5lLfBnLL9t/13kvmqEsPd4EwFnYfTROHOMX90=; b=U/CHEsce4JXNEJ5JS35KvoOE2emxEo1XWgZLNvPbe2i8yUkjVHfQv7SJ6kD1OnXePx XMhJdoUVIn3uLG1NLdYwE3itailb0NAgc3CxZYAUNUx5o+58+EKCkf9hvsFkFcsY4v4s y8w9x2vd0xSVw4C5c1nUw14kqhsMKTugozbrxI8cyUET9pc6AOzI6y4KCUUa5RNG3wJQ kMAdX5y+4QNJqMAq7T+SO2jqKGYg28pi4L6GwjFMb2HLC9svjYAGytj0ewuzRM945XYr KIB4Sbpmxrip9TLWq92rzQZTuMzMDeRQRl6ATTa8j9q2W23zWrPzPeu29Wqsydavet46 Fing== 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=75g+1e5lLfBnLL9t/13kvmqEsPd4EwFnYfTROHOMX90=; b=Ved+MnKJpNwT+bkKazBsC6Uv8QdlW4fFH/DarXa1xuis/isoAFtLT7q/Ng3DgcKvER aarDuEBY77svYRThyKU8hpOxcricxiLvm+eKbBsFmU9QTPJ5fK6Y2OthikthyoKHEyh9 RjlSRYJkGfoo0gdxf6mbXnmSiwqlgzGWah1LwhYgwjkDS7uaOk2Rv3ckHKH4wWSkP59+ AN1qxWT935AJ8kIyDtdiE6opl3SMGXZTh2TfIRliCPkNnYK7X7EM/A5dNQC2b9G8KQca 0ifLvEUqt5ZyHIM3rqNBK7iQOvVPLucrblLC6iJmru5DwJgSFIQtPRuSzZ8PL8GhgMic suFA== X-Gm-Message-State: AIkVDXKalYJQFkniWcJdl5967z1F5BuwcOkB1OIN1fFniS00IJaVpHwa6q1kBBAyqdSk0Q== X-Received: by 10.107.1.138 with SMTP id 132mr46376349iob.72.1483404420587; Mon, 02 Jan 2017 16:47:00 -0800 (PST) Original-Received: from zony ([45.2.7.65]) by smtp.googlemail.com with ESMTPSA id p20sm31717331itc.2.2017.01.02.16.46.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Jan 2017 16:46:59 -0800 (PST) In-Reply-To: <83zina75pa.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 14 Sep 2016 20:26:57 +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:127696 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: Tue, 13 Sep 2016 22:40:29 -0400 >> >> Eli Zaretskii writes: >> >> 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. [...] > > ... given the above, I now understand that your interpretation of 0.5 > is "half the window minus one line", which leaves the center line for > point. Is that so? Yes, I hadn't quite thought it through, but that was my intention. I've updated the code to clarify this. --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=v2-0001-Refactor-uses-of-scroll_margin-to-a-function.patch.gz Content-Transfer-Encoding: base64 Content-Description: patch H4sICLfXalgAA3YyLTAwMDEtUmVmYWN0b3ItdXNlcy1vZi1zY3JvbGxfbWFyZ2luLXRvLWEtZnVu Y3Rpb24ucGF0Y2gA3VptU9tIEv6MfkVvtirBYDmS3w2BXZJAoBYIB84me1dX2rE1trWRNV5JBny5 /PfrnhfZsmUSXnY/HJUCW5ppjbqffubpnhzFYgz13mDg1N0OazqNNm87bo21ap16s1prOz231e40 eu12q9OAMxHBFZ+A2wLH2ZH/oOo4rnWEZnbgXLAxXIgkZdfJ5xm8iibq88/DMQvCSl+M9623LOU7 cDWNylBtw8F0iAbcJrjNnVp7x6mD7dQdx7qa9v7g/XQH/nVx0H1zDNdVcF/W/g2XfMD6qYhhmvAE xACSfizC0BuzeBhEkApgMJhG/TQQkWWdpAnwwQANBdccYhYNOUSc+wkN7HHoh2w84T5+TG84j8AB FvmweRNEvriBEQ+GoxReWvVSGRIBQfoioaEpj2n+iKHNdBQk0BdRksYsiFLANTBIgmgYcpiErM8r lrUFSdx/qYxW+sa8l1t5CZ3Hb7KlV6ylUZPglodejyXcL0P+VhhEXN0p7VibRzHv8wiXWIajsbjm Xio8PZ4G4hC1nFs/SCa0mjSeaUu46jLQ1/40TkTs0fQx2iKzMafxIZtpY2rg6mcvwFXAh4SjtyqW bdtW/uX/C/U6bK/5sfM/uakjnApVnGrllo9Xmy1YY+C7fiyowSAIEU39EQEE/VvrYBwTHlMkks1t jH6rDj4PubpglyzLDwYDsO1hkAJ7mXvDXu6rhX/5LTis2evU/Uql1ues4zvgOk6zXicHLc238DWW bfz8M9j1VsctN2Fb/q12AK/lYACbp+gR771MGzCBOTw7eHPlnZx3AdOtJ0QINyMRcv05EjyORVyy ACAYjzHEmJven1N8qT0YsDDhuxZ8tcDafrkFb8R4Mk25TjjQCTfAVPx4cv72/ceKtY1mPmYDbkaY UBMhkyLBBWGmRCpdMHQpi/ocBsQ96QizSEwADfVEmoqxtIOZTTe0CwC6+CXmyTSU1sac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Jn8y77ENLj7X3px/NWepbqvW6Ei90apV2/OewF1RKmxWyO09ZMOkVNivWBXxMh2ljUU5D9/ZM1kn Nb7jqNoc7rLPHAj26kjiJnc4m3UnFk6nlo+k/hEFYXmePOiFUhle/9Y9zL7OfdxulF3l5MZCdf9I JxN7bcqv8By6l795OgPeHB+++cVTAuKqZLL1+XP44ezk/MSM0qJzleaKVOzfxIL/J1XGY85HVysN GeY5N8yIGJwNRDCJqPn/DiG8bqg4Lw5+VXRyKFHZbrY6ZbeBqGw3ay2lm3P/P3C1OV5aOvcL1akc 6GoVywEIogURl/1fCZNOGmjrmgC6z5DbFR9T2d/V/bvvloEK4hu4LT5mBy1j7zikLUapeYnvxymN zrkQ6P9sdS9PPnmXsjNt7+dLq/LSnlOy93Na8kmAnFl6qqXpzFjJi0KoY05gRuQlTgnp5PXhu1+R UWywqpVOpWZZ/wMqp1QPYC0AAA== --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v2-0002-Don-t-count-mode-line-for-scroll-margin-limit.patch Content-Description: patch >From 4293c63254fe9ae38391aed1896436c79ebb8f00 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 28 Aug 2016 17:23:04 -0400 Subject: [PATCH v2 2/3] 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). * test/src/window-tests.el: New tests for scroll-margin behavior. --- src/window.c | 6 ++-- test/src/window-tests.el | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 test/src/window-tests.el diff --git a/src/window.c b/src/window.c index 3cea9d0..b710333 100644 --- a/src/window.c +++ b/src/window.c @@ -4801,10 +4801,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 diff --git a/test/src/window-tests.el b/test/src/window-tests.el new file mode 100644 index 0000000..f5cca73 --- /dev/null +++ b/test/src/window-tests.el @@ -0,0 +1,84 @@ +;;; 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-tests-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) + (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 window-tests-with-buffer-window (&rest body) + (declare (debug t)) + (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-tests-scroll-margin-0 () + (skip-unless (not noninteractive)) + (window-tests-with-buffer-window + (window-tests-scrolling 0))) + +(ert-deftest window-tests-scroll-margin-negative () + "A negative `scroll-margin' should be the same as 0." + (skip-unless (not noninteractive)) + (window-tests-with-buffer-window + (window-tests-scrolling -10 0))) + +(ert-deftest window-tests-scroll-margin-max () + (skip-unless (not noninteractive)) + (window-tests-with-buffer-window + (let ((max-margin (/ (window-text-height) 4))) + (window-tests-scrolling max-margin)))) + +(ert-deftest window-tests-scroll-margin-over-max () + "A `scroll-margin' more than max should be the same as max." + (skip-unless (not noninteractive)) + (window-tests-with-buffer-window + (set-window-text-height nil 7) + (let ((max-margin (/ (window-text-height) 4))) + (window-tests-scrolling (+ max-margin 1) max-margin) + (window-tests-scrolling (+ max-margin 2) max-margin)))) + +;;; window-tests.el ends here -- 2.9.3 --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=v2-0003-Make-limit-on-scroll-margin-variable.patch Content-Description: patch >From 87ad96cc13ca45eb5c78e3773cfb1458001f9d83 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Sun, 11 Sep 2016 11:09:57 -0400 Subject: [PATCH v2 3/3] Make limit on scroll-margin variable TODO: `scroll-down-command' doesn't stay in the middle of the window. * src/xdisp.c (maximum-scroll-margin): New variable. * etc/NEWS: Mention it. * src/window.c (window_scroll_pixel_based): Use it instead of hardcoding division by 4 (Bug #5718). * test/src/window-tests.el (window-tests-scroll-margin-whole-window): (window-tests--point-in-middle-of-window-p): New test and helper function. --- etc/NEWS | 4 ++++ src/window.c | 19 ++++++++++++++----- src/xdisp.c | 8 ++++++++ test/src/window-tests.el | 27 +++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index d91204b..f4fa98a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -298,6 +298,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/src/window.c b/src/window.c index b710333..f664597 100644 --- a/src/window.c +++ b/src/window.c @@ -4802,11 +4802,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 0fd2a7c..55bb34a 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). */); diff --git a/test/src/window-tests.el b/test/src/window-tests.el index f5cca73..1dcebef 100644 --- a/test/src/window-tests.el +++ b/test/src/window-tests.el @@ -81,4 +81,31 @@ window-tests-with-buffer-window (window-tests-scrolling (+ max-margin 1) max-margin) (window-tests-scrolling (+ max-margin 2) max-margin)))) +(defun window-tests--point-in-middle-of-window-p () + (= (count-lines (window-start) (window-point)) + (/ (1- (window-text-height)) 2))) + +(ert-deftest window-tests-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-tests-with-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-tests--point-in-middle-of-window-p)) + (call-interactively 'scroll-up-command) + (sit-for 0) + (should (window-tests--point-in-middle-of-window-p)) + (call-interactively 'scroll-down-command) + (sit-for 0) + (should (window-tests--point-in-middle-of-window-p))))) ;;; window-tests.el ends here -- 2.9.3 --=-=-= Content-Type: text/plain The issues with `scroll-down-command' (and `next-line', below) remain. I find the following change fixes the problem for `scroll-down-command', though I'm not sure whether it's the right thing to do. --- a/src/window.c +++ b/src/window.c @@ -5148,7 +5148,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), + - this_scroll_margin - 1 - frame_line_height), -1, MOVE_TO_POS | MOVE_TO_Y); >>> >>> Also, did you test these changes with scroll-conservatively set to >>> 101? If not, please do, as that setting activates some code parts >>> that no other option does. >> >> I hadn't; trying it out now, it seems to cause `next-line' to also have >> the bad behaviour of `scroll-down-command' where point is one line too >> far down. For `next-line', the initial difference seems to be in `line-move'. When `scroll-conservatively' is non-zero (I found no change at 101, in particular), it calls `vertical-motion` (via `line-move-visual'), otherwise `line-move-partial'. (defun line-move (arg &optional noerror _to-end try-vscroll) ... (unless (and auto-window-vscroll try-vscroll ;; Only vscroll for single line moves (= (abs arg) 1) ;; Under scroll-conservatively, the display engine ;; does this better. (zerop scroll-conservatively) ... (line-move-partial arg noerror)) ... (prog1 (line-move-visual arg noerror) The problem involves partial lines. In a window where (window-screen-lines) returns 7.222, doing M-: (vertical-motion '(0.0 . 1)) does not scroll the window, which lets point end up 1 line away from the center. Doing M-: (vertical-motion '(0.0 . -1)) does scroll the window, keeping the point in the center (as expected). Adjusting the window so that (window-screen-lines) returns 7.0, there is no discrepancy between up and down motion. I guess there is some incorrect boundary condition in try_scrolling, though I haven't worked out where. --=-=-=--