mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-12 09:00:40 -08:00
* etc/ERC-NEWS: Add entry for option `erc-scrolltobottom-all', and mention explicit hook-depth intervals reserved by ERC. * lisp/erc/erc-backend.el (erc--hide-prompt): Change hook depth on `pre-command-hook' from 91 to 80. * lisp/erc/erc-goodies.el (erc-input-line-position): Mention secondary role when new option `erc-scroll-to-bottom-relaxed' is non-nil. (erc-scrolltobottom-all): New option that decides whether module `scrolltobottom' affects all windows or just the selected one, as it always has. (erc-scrolltobottom-relaxed): New option to leave the prompt stationary instead of forcing it to the bottom of the window. (erc-scrolltobottom-mode, erc-scrolltobottom-enable, erc-scrolltobottom-disable): Use `erc--scrolltobottom-setup' instead of `erc-add-scroll-to-bottom' for adding and removing local hooks and instead of ranging over buffers when removing them. Also add and remove new hook members when `erc-scrolltobottom-all' is non-nil. (erc--scrolltobottom-relaxed-commands, erc--scrolltobottom-window-info, erc--scrolltobottom-post-force-commands, erc--scrolltobottom-relaxed-skip-commands): New internal variables. (erc--scrolltobottom-on-pre-command erc--scrolltobottom-on-post-command): New functions resembling `erc-possibly-scroll-to-bottom' that try to avoid scrolling repeatedly for no reason. (erc--scrolltobottom-on-pre-command-relaxed, erc--scrolltobottom-on-post-command-relaxed): New commands to help implement `erc-scroll-to-bottom-relaxed'. (erc--scrolltobottom-at-prompt-minibuffer-active): New function to scroll to bottom on window configuration changes when using the minibuffer. (erc--scrolltobottom-all): New function to scroll all windows displaying the current buffer. (erc-add-scroll-to-bottom): Deprecate this function because it is now unused in the default client and trivial to implement otherwise. (erc--scrolltobottom-setup): New generic function to perform teardown as well as setup depending on the state of the module's mode variable. Also add an implementation specifically for `erc-scrolltobottom-all' that locally modifies different sets of hooks depending on `erc-scrolltobottom-relaxed'. (erc--scrolltobottom-on-pre-insert): New generic function that remembers the last `window-start' and maybe the current screen line before inserting a message, in order to restore it afterward. (erc--scrolltobottom-confirm): New function, a replacement for `erc-scroll-to-bottom' that returns non-nil when it's actually recentered the window. For now, used only when `erc-scrolltobottom-all' is enabled. (erc-move-to-prompt-setup): Add `erc-move-to-prompt' to `pre-command-hook' at a depth of 70 in the current buffer. (erc-keep-place-mode, erc-keep-place-enable): Change hook depth from 0 to 85. (erc--keep-place-indicator-setup): Add overlay arrow `after-string' in non-graphical settings in case users have time stamps or other content occupying the left margin. (erc-keep-place-indicator-mode, erc-keep-place-indicator-enable): Change hook depth from 90 to 85 locally so as not to conflict with a value of t, for append. (erc--keep-place-indicator-on-global-module): Change hook depth from 90 to 85 locally. * test/lisp/erc/erc-scenarios-scrolltobottom-relaxed.el: New file. * test/lisp/erc/erc-scenarios-scrolltobottom.el: New file. * test/lisp/erc/resources/erc-scenarios-common.el (erc-scenarios-common--term-size, erc-scenarios-common--run-in-term, erc-scenarios-common-interactive-debug-term-p, erc-scenarios-common-with-noninteractive-in-term): New test macro and supporting helper function and variables to facilitate running scenario-based tests in an inferior Emacs, in term-mode. (erc-scenarios-common--at-win-end-p, erc-scenarios-common--above-win-end-p, erc-scenarios-common--prompt-past-win-end-p, erc-scenarios-common--recenter-top-bottom-around, erc-scenarios-common--recenter-top-bottom, erc-scenarios-scrolltobottom--normal): New test fixture and assertion helper functions. * test/lisp/erc/resources/scrolltobottom/help.eld: New file. (Bug#64855)
140 lines
5.9 KiB
EmacsLisp
140 lines
5.9 KiB
EmacsLisp
;;; erc-scenarios-scrolltobottom-relaxed.el --- erc-scrolltobottom-relaxed -*- lexical-binding: t -*-
|
|
|
|
;; Copyright (C) 2023 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 <https://www.gnu.org/licenses/>.
|
|
|
|
;; TODO assert behavior of prompt input spanning multiple lines, with
|
|
;; and without line endings.
|
|
|
|
;;; Code:
|
|
|
|
(require 'ert-x)
|
|
(eval-and-compile
|
|
(let ((load-path (cons (ert-resource-directory) load-path)))
|
|
(require 'erc-scenarios-common)))
|
|
|
|
(require 'erc-goodies)
|
|
|
|
(ert-deftest erc-scenarios-scrolltobottom--relaxed ()
|
|
:tags '(:expensive-test)
|
|
(when (version< emacs-version "29") (ert-skip "Times out"))
|
|
|
|
(should-not erc-scrolltobottom-all)
|
|
|
|
(erc-scenarios-common-with-noninteractive-in-term
|
|
((erc-scenarios-common-dialog "scrolltobottom")
|
|
(dumb-server (erc-d-run "localhost" t 'help))
|
|
(port (process-contact dumb-server :service))
|
|
(erc-modules `(scrolltobottom fill-wrap ,@erc-modules))
|
|
(erc-scrolltobottom-all t)
|
|
(erc-scrolltobottom-relaxed t)
|
|
(erc-server-flood-penalty 0.1)
|
|
(expect (erc-d-t-make-expecter))
|
|
lower upper)
|
|
|
|
(ert-info ("Connect")
|
|
(with-current-buffer (erc :server "127.0.0.1"
|
|
:port port
|
|
:full-name "tester"
|
|
:nick "tester")
|
|
(funcall expect 10 "debug mode")))
|
|
|
|
(with-current-buffer "foonet"
|
|
(should (looking-at " and"))
|
|
(set-window-buffer nil (current-buffer))
|
|
(delete-other-windows)
|
|
(split-window-below 15)
|
|
(recenter 0)
|
|
|
|
(ert-info ("Moving into prompt does not trigger scroll")
|
|
(with-selected-window (next-window)
|
|
(should-not (erc-scenarios-common--at-win-end-p))
|
|
(recenter 0)
|
|
(goto-char (1- erc-insert-marker))
|
|
(execute-kbd-macro "\C-n")
|
|
(should-not (erc-scenarios-common--at-win-end-p))
|
|
(should (= (point) (point-max)))
|
|
(setq lower (count-screen-lines (window-start) (window-point)))))
|
|
|
|
(ert-info ("Module `move-to-prompt' still works")
|
|
;; Prompt is somewhere in the middle of the window.
|
|
(should (erc-scenarios-common--above-win-end-p))
|
|
(should-not (= (point-max) (point)))
|
|
;; Hitting a self-insert key triggers `move-to-prompt' but not
|
|
;; a scroll (to bottom).
|
|
(execute-kbd-macro "hi")
|
|
;; Prompt and input appear on same line.
|
|
(should (= (point-max) (point)))
|
|
(setq upper (count-screen-lines (window-start) (window-point)))
|
|
(should-not (= upper (window-body-height))))
|
|
|
|
(ert-info ("Command `recenter-top-bottom' allowed at prompt")
|
|
;; Hitting C-l recenters the window.
|
|
(should (= upper (count-screen-lines (window-start) (window-point))))
|
|
(let ((lines (list upper)))
|
|
(erc-scenarios-common--recenter-top-bottom)
|
|
(push (count-screen-lines (window-start) (window-point)) lines)
|
|
(erc-scenarios-common--recenter-top-bottom)
|
|
(push (count-screen-lines (window-start) (window-point)) lines)
|
|
(erc-scenarios-common--recenter-top-bottom)
|
|
(push (count-screen-lines (window-start) (window-point)) lines)
|
|
(setq lines (delete-dups lines))
|
|
(should (= (length lines) 4))))
|
|
|
|
(ert-info ("Command `beginning-of-buffer' allowed at prompt")
|
|
;; Hitting C-< goes to beginning of buffer.
|
|
(execute-kbd-macro "\M-<")
|
|
(should (= 1 (point)))
|
|
(redisplay)
|
|
(should (zerop (count-screen-lines (window-start) (window-point))))
|
|
(should (erc-scenarios-common--prompt-past-win-end-p)))
|
|
|
|
(ert-info ("New message doesn't trigger scroll when away from prompt")
|
|
;; Arriving insertions don't trigger a scroll when away from the
|
|
;; prompt. New output not seen.
|
|
(erc-cmd-MSG "NickServ help register")
|
|
(save-excursion (erc-d-t-search-for 10 "End of NickServ"))
|
|
(should (= 1 (point)))
|
|
(should (zerop (count-screen-lines (window-start) (window-point))))
|
|
(should (erc-scenarios-common--prompt-past-win-end-p)))
|
|
|
|
(ert-info ("New insertion keeps prompt stationary in other window")
|
|
(let ((w (next-window)))
|
|
;; We're at prompt and completely stationary.
|
|
(should (>= (window-point w) erc-input-marker))
|
|
(erc-d-t-wait-for 10
|
|
(= lower (count-screen-lines (window-start w) (window-point w))))
|
|
(erc-d-t-ensure-for 0.5
|
|
(= lower (count-screen-lines (window-start w)
|
|
(window-point w))))))
|
|
|
|
(should (= 2 (length (window-list))))
|
|
(ert-info ("New message does not trigger a scroll when at prompt")
|
|
;; Recenter so prompt is above rather than at window's end.
|
|
(funcall expect 10 "End of NickServ HELP")
|
|
(recenter 0)
|
|
(set-window-point nil (point-max))
|
|
(setq upper (count-screen-lines (window-start) (window-point)))
|
|
;; Prompt is somewhere in the middle of the window.
|
|
(erc-d-t-wait-for 10 (erc-scenarios-common--above-win-end-p))
|
|
(erc-scenarios-common-say "/msg NickServ help identify")
|
|
;; New arriving messages don't move prompt.
|
|
(erc-d-t-ensure-for 1
|
|
(= upper (count-screen-lines (window-start) (window-point))))
|
|
(funcall expect 10 "IDENTIFY lets you login")))))
|
|
|
|
;;; erc-scenarios-scrolltobottom-relaxed.el ends here
|