From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Marco Wahl Newsgroups: gmane.emacs.bugs Subject: bug#36494: 27.0.50; [Proposition] New option to scroll up regardless of eob Date: Sat, 13 Jul 2019 22:10:19 +0200 Organization: Marco Wahl Message-ID: <84o91xvgpg.fsf@gmail.com> References: <84ftnmjc37.fsf@gmail.com> <83d0iqaqvh.fsf@gnu.org> <847e8xkjpp.fsf@gmail.com> <837e8xbw70.fsf@gnu.org> <84zhltzeyk.fsf@gmail.com> <83pnme1j2f.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="115120"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 36494@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jul 13 22:11:09 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hmOMP-000Tn6-2Q for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Jul 2019 22:11:09 +0200 Original-Received: from localhost ([::1]:57862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmOMO-0000H8-3d for geb-bug-gnu-emacs@m.gmane.org; Sat, 13 Jul 2019 16:11:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53720) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hmOML-0000H1-5h for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2019 16:11:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hmOMJ-0004Ch-Hh for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2019 16:11:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34607) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hmOMJ-0004CX-DN for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2019 16:11:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hmOMJ-0005UH-4Z for bug-gnu-emacs@gnu.org; Sat, 13 Jul 2019 16:11:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Marco Wahl Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Jul 2019 20:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 36494 X-GNU-PR-Package: emacs Original-Received: via spool by 36494-submit@debbugs.gnu.org id=B36494.156304863121049 (code B ref 36494); Sat, 13 Jul 2019 20:11:02 +0000 Original-Received: (at 36494) by debbugs.gnu.org; 13 Jul 2019 20:10:31 +0000 Original-Received: from localhost ([127.0.0.1]:43427 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hmOLl-0005TQ-HW for submit@debbugs.gnu.org; Sat, 13 Jul 2019 16:10:31 -0400 Original-Received: from mail-wr1-f46.google.com ([209.85.221.46]:37427) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hmOLj-0005TA-N4 for 36494@debbugs.gnu.org; Sat, 13 Jul 2019 16:10:28 -0400 Original-Received: by mail-wr1-f46.google.com with SMTP id n9so13191128wrr.4 for <36494@debbugs.gnu.org>; Sat, 13 Jul 2019 13:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:organization:references:date:in-reply-to :message-id:user-agent:mime-version; bh=+Bhrqf1a3zCa2e9vsSPJuXps5CfV2hyEaiiysd+hyJ0=; b=k6J/FRuUparrk2LIjUODZ0hjDHYLWYaz56Jm26tZLENAkceWwJGsuP3hWCjVOiA1aK xrAbeqK+SjCKMv4lcAFKVUk65PB4OPJgwNvKlSf+ZGzB/TgiRrabLCg8VTM8hkdoIRlW 17JiKmKkj+1Sc9kKoOVnolT6iKLZ0Smss+h1f4KSHwM8rIAU7k4IWbuQ02q135qnf7PF D8upIuVczcdySjWCqlByvO3nG1Owuc2CJOd5MPr2o4rtC/XzJtBhtyLb0LgcpSPiP0N0 cjQEkE0wCyZ+9s1lqOHH7+0eb3RlFtcunAC6wW+kidjT74IAKygA7G9qZh4MuE0yJlbA BiSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:organization:references:date :in-reply-to:message-id:user-agent:mime-version; bh=+Bhrqf1a3zCa2e9vsSPJuXps5CfV2hyEaiiysd+hyJ0=; b=gfn/fnzspI3biWoInrYxJlasY4toKjME1NBk/eB4SZo63KA4w3jSmh5OV0IOZqUk+w 3z8F37+OYeilRzu7u4V4TlJVYc7ZSZJ/yIKh30gQgkY2uS6atklBcFFDyivpDHp+Hh35 dZP3DSWZnQRSxjrJ69uESDL0HZkH6fZM+38Wmr3ZBfq3vn+42zIgV4X453ZkS7rSi7EP me7tzPY1971mtVlgxoiwMqHKQEiaxBh4IVWnJ7B+PE5gpfWf/AUh6M1t7yfv3PtyHYmZ AlABcw9PbBiKUtKAWX4AqRjGqJ2t0Bdn0FZhdC7H2wqGvB7AmEsQNkN7Y6A1ShSLnP9n kv8A== X-Gm-Message-State: APjAAAWW4A4X19yLdWH7xgXBXg4AHNURt4n+RxVG4tzQLiJ0HJSGlgAo 93h1g0s45R/4/BX0/RU1gx8= X-Google-Smtp-Source: APXvYqwJCdWpmmkgHYOxyF00t7lS/Ddy3GBNMvwVhgEqm9aC8Qy62/AY6Jq4VgHuC6P+one0Wf9qMQ== X-Received: by 2002:adf:8028:: with SMTP id 37mr18615625wrk.106.1563048621990; Sat, 13 Jul 2019 13:10:21 -0700 (PDT) Original-Received: from tm6592 (p200300ECDF02E4CEC8C28A2C900642DF.dip0.t-ipconnect.de. [2003:ec:df02:e4ce:c8c2:8a2c:9006:42df]) by smtp.gmail.com with ESMTPSA id r5sm12327697wmh.35.2019.07.13.13.10.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 13 Jul 2019 13:10:20 -0700 (PDT) In-Reply-To: <83pnme1j2f.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 13 Jul 2019 10:37:28 +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: 209.51.188.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:162937 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Marco Wahl >> Cc: Marco Wahl , 36494@debbugs.gnu.org >> Date: Thu, 04 Jul 2019 23:07:15 +0200 >> >> Ok, sorry for the patch missing. Here is the patch. > > Thanks. > > This seems to work well, but when there's only the single last line > visible in the window, and the cursor is at EOB, S-DOWN scrolls back, > i.e. after pressing it Emacs now shows 2 last lines. I don't think > this is intended, is it? No. Thanks for your review and your finding. The scroll back behavior was due to a counting issue. With the new patch the counting has gone away entirely. > Also, this is a user-visible change, so it needs to be called out in > NEWS. > > Could you please resubmit with these minor nits fixed? Okay. Find a respective proposition in the attachment section, please. Best regards, Marco --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-New-function-for-scroll-lock-to-almost-always-scroll.patch >From e8d3ee812716daa932a62c1ae40e37b3cb326a77 Mon Sep 17 00:00:00 2001 From: Marco Wahl Date: Thu, 4 Jul 2019 22:32:44 +0200 Subject: [PATCH] New function for scroll-lock to almost always scroll * lisp/scroll-lock.el (scroll-lock-next-line-always-scroll): New function. Opposed to scroll-lock-next-line it does not switch to forward-line at eob. S-down is the default key binding for this function. * test/lisp/scroll-lock-tests.el: A few tests for scroll-lock-next-line-always-scroll. * etc/NEWS: Add a respective note. --- etc/NEWS | 7 ++++ lisp/scroll-lock.el | 11 ++++++ test/lisp/scroll-lock-tests.el | 68 ++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 test/lisp/scroll-lock-tests.el diff --git a/etc/NEWS b/etc/NEWS index abbece374a..efa76fe356 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1644,6 +1644,13 @@ This runs after changing the dictionary and could be used to automatically spellcheck a buffer when changing language without needing to advice 'ispell-change-dictionary'. +** scroll-lock + +--- +*** New command 'scroll-lock-next-line-always-scroll'. +This command is bound to 'S-down' and scrolls the buffer up in +particular when the end of the buffer is visible in the window. + * New Modes and Packages in Emacs 27.1 diff --git a/lisp/scroll-lock.el b/lisp/scroll-lock.el index 8281edb172..3a74c11b7a 100644 --- a/lisp/scroll-lock.el +++ b/lisp/scroll-lock.el @@ -36,6 +36,7 @@ scroll-lock-mode-map (define-key map [remap previous-line] 'scroll-lock-previous-line) (define-key map [remap forward-paragraph] 'scroll-lock-forward-paragraph) (define-key map [remap backward-paragraph] 'scroll-lock-backward-paragraph) + (define-key map [S-down] 'scroll-lock-next-line-always-scroll) map) "Keymap for Scroll Lock mode.") @@ -81,6 +82,16 @@ scroll-lock-move-to-column (move-to-column column) (forward-char (min column (- (line-end-position) (point)))))) +(defun scroll-lock-next-line-always-scroll (&optional arg) + "Scroll up ARG lines keeping point fixed." + (interactive "p") + (or arg (setq arg 1)) + (scroll-lock-update-goal-column) + (condition-case nil + (scroll-up arg) + (end-of-buffer (goto-char (point-max)) (recenter 1))) + (scroll-lock-move-to-column scroll-lock-temporary-goal-column)) + (defun scroll-lock-next-line (&optional arg) "Scroll up ARG lines keeping point fixed." (interactive "p") diff --git a/test/lisp/scroll-lock-tests.el b/test/lisp/scroll-lock-tests.el new file mode 100644 index 0000000000..f1ffeed265 --- /dev/null +++ b/test/lisp/scroll-lock-tests.el @@ -0,0 +1,68 @@ +;;; scroll-lock-tests.el --- Test suite for scroll-lock -*- lexical-binding: t -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs 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. + +;; GNU Emacs 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 GNU Emacs. If not, see . + +;;; Code: + +(require 'ert) +(require 'scroll-lock) + + +(defun point-in-window-line-p (n) + "Return if point is in window line N. +Meaning of N as in `move-to-window-line'. +Precondition: the line N must be available in the window." + (save-excursion + (let ((point (progn (beginning-of-line) (point)))) + (let ((moved-to-line (move-to-window-line n))) + (cl-assert (= n moved-to-line) t "precondition violation")) + (= point (progn (beginning-of-line) (point)))))) + + +(ert-deftest scroll-lock-next-line-always-scroll-1 () + "Point stays in top line." + (with-temp-buffer + (insert "\n\n\n") + (goto-char (point-min)) + (switch-to-buffer (current-buffer)) + (scroll-lock-next-line-always-scroll) + (should (point-in-window-line-p 0)))) + +(ert-deftest scroll-lock-next-line-always-scroll-2 () + "Point stays in second line." + (with-temp-buffer + (scroll-lock-mode) + (insert "\n\n\n") + (goto-char (1+ (point-min))) + (switch-to-buffer (current-buffer)) + (scroll-lock-next-line-always-scroll) + (should (point-in-window-line-p 1)))) + +(ert-deftest scroll-lock-next-line-always-scroll-3 () + "Point stays in second line when scrolling beyond the number of buffer lines." + (with-temp-buffer + (scroll-lock-mode) + (insert (make-string 1000 ?\n)) + (goto-char (1+ (point-min))) + (switch-to-buffer (current-buffer)) + (scroll-lock-next-line-always-scroll 1234) + (should (point-in-window-line-p 1)))) + +(provide 'scroll-lock-tests) + +;;; scroll-lock-tests.el ends here -- 2.22.0 --=-=-=--