aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Wahl2019-07-04 22:32:44 +0200
committerEli Zaretskii2019-07-14 09:23:20 +0300
commit352530ee0a52153a7936864275dce7f89e070a15 (patch)
treead132f6c5f219c2fbddeae0b148efc9f487822ca
parent474bd9d4a0f57c55d8c7ab435885804062992d0f (diff)
downloademacs-352530ee0a52153a7936864275dce7f89e070a15.tar.gz
emacs-352530ee0a52153a7936864275dce7f89e070a15.zip
New function for scroll-lock-mode 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. (Bug#36494) * test/lisp/scroll-lock-tests.el: A few tests for scroll-lock-next-line-always-scroll. * etc/NEWS: Announce the new command.
-rw-r--r--etc/NEWS7
-rw-r--r--lisp/scroll-lock.el11
-rw-r--r--test/lisp/scroll-lock-tests.el68
3 files changed, 86 insertions, 0 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 46800214011..5ae60262d2a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1684,6 +1684,13 @@ This runs after changing the dictionary and could be used to
1684automatically spellcheck a buffer when changing language without 1684automatically spellcheck a buffer when changing language without
1685needing to advice 'ispell-change-dictionary'. 1685needing to advice 'ispell-change-dictionary'.
1686 1686
1687** scroll-lock
1688
1689---
1690*** New command 'scroll-lock-next-line-always-scroll'.
1691This command is bound to 'S-down' and scrolls the buffer up in
1692particular when the end of the buffer is visible in the window.
1693
1687 1694
1688* New Modes and Packages in Emacs 27.1 1695* New Modes and Packages in Emacs 27.1
1689 1696
diff --git a/lisp/scroll-lock.el b/lisp/scroll-lock.el
index 8281edb1720..3a74c11b7a1 100644
--- a/lisp/scroll-lock.el
+++ b/lisp/scroll-lock.el
@@ -36,6 +36,7 @@
36 (define-key map [remap previous-line] 'scroll-lock-previous-line) 36 (define-key map [remap previous-line] 'scroll-lock-previous-line)
37 (define-key map [remap forward-paragraph] 'scroll-lock-forward-paragraph) 37 (define-key map [remap forward-paragraph] 'scroll-lock-forward-paragraph)
38 (define-key map [remap backward-paragraph] 'scroll-lock-backward-paragraph) 38 (define-key map [remap backward-paragraph] 'scroll-lock-backward-paragraph)
39 (define-key map [S-down] 'scroll-lock-next-line-always-scroll)
39 map) 40 map)
40 "Keymap for Scroll Lock mode.") 41 "Keymap for Scroll Lock mode.")
41 42
@@ -81,6 +82,16 @@ boundaries during scrolling."
81 (move-to-column column) 82 (move-to-column column)
82 (forward-char (min column (- (line-end-position) (point)))))) 83 (forward-char (min column (- (line-end-position) (point))))))
83 84
85(defun scroll-lock-next-line-always-scroll (&optional arg)
86 "Scroll up ARG lines keeping point fixed."
87 (interactive "p")
88 (or arg (setq arg 1))
89 (scroll-lock-update-goal-column)
90 (condition-case nil
91 (scroll-up arg)
92 (end-of-buffer (goto-char (point-max)) (recenter 1)))
93 (scroll-lock-move-to-column scroll-lock-temporary-goal-column))
94
84(defun scroll-lock-next-line (&optional arg) 95(defun scroll-lock-next-line (&optional arg)
85 "Scroll up ARG lines keeping point fixed." 96 "Scroll up ARG lines keeping point fixed."
86 (interactive "p") 97 (interactive "p")
diff --git a/test/lisp/scroll-lock-tests.el b/test/lisp/scroll-lock-tests.el
new file mode 100644
index 00000000000..f1ffeed2654
--- /dev/null
+++ b/test/lisp/scroll-lock-tests.el
@@ -0,0 +1,68 @@
1;;; scroll-lock-tests.el --- Test suite for scroll-lock -*- lexical-binding: t -*-
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23(require 'scroll-lock)
24
25
26(defun point-in-window-line-p (n)
27 "Return if point is in window line N.
28Meaning of N as in `move-to-window-line'.
29Precondition: the line N must be available in the window."
30 (save-excursion
31 (let ((point (progn (beginning-of-line) (point))))
32 (let ((moved-to-line (move-to-window-line n)))
33 (cl-assert (= n moved-to-line) t "precondition violation"))
34 (= point (progn (beginning-of-line) (point))))))
35
36
37(ert-deftest scroll-lock-next-line-always-scroll-1 ()
38 "Point stays in top line."
39 (with-temp-buffer
40 (insert "\n\n\n")
41 (goto-char (point-min))
42 (switch-to-buffer (current-buffer))
43 (scroll-lock-next-line-always-scroll)
44 (should (point-in-window-line-p 0))))
45
46(ert-deftest scroll-lock-next-line-always-scroll-2 ()
47 "Point stays in second line."
48 (with-temp-buffer
49 (scroll-lock-mode)
50 (insert "\n\n\n")
51 (goto-char (1+ (point-min)))
52 (switch-to-buffer (current-buffer))
53 (scroll-lock-next-line-always-scroll)
54 (should (point-in-window-line-p 1))))
55
56(ert-deftest scroll-lock-next-line-always-scroll-3 ()
57 "Point stays in second line when scrolling beyond the number of buffer lines."
58 (with-temp-buffer
59 (scroll-lock-mode)
60 (insert (make-string 1000 ?\n))
61 (goto-char (1+ (point-min)))
62 (switch-to-buffer (current-buffer))
63 (scroll-lock-next-line-always-scroll 1234)
64 (should (point-in-window-line-p 1))))
65
66(provide 'scroll-lock-tests)
67
68;;; scroll-lock-tests.el ends here