From: Lars Ingebrigtsen Date: Wed, 23 Oct 2019 09:55:13 +0000 (+0200) Subject: Ensure that the prompt is kept on the final line X-Git-Tag: emacs-27.0.90~905 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b7037662e1111d55218fb2345f9ebb9ed3ebef13;p=emacs.git Ensure that the prompt is kept on the final line * lisp/erc/erc-goodies.el (erc-possibly-scroll-to-bottom): New function. (scrolltobottom): Add to erc-insert-done-hook. * lisp/erc/erc.el (erc-insert-done-hook): New hook (bug#11697). (erc-display-line-1): Use it. --- diff --git a/etc/NEWS b/etc/NEWS index 43411b7d4f1..01fdf39ab04 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1233,6 +1233,13 @@ fail. ** erc +--- +*** New hook 'erc-insert-done-hook'. +This hook is called after strings have been inserted into the buffer, +and is free to alter point and window configurations, as it's not +called from inside a 'save-excursion', as opposed to +'erc-insert-post-hook'. + --- *** 'erc-button-google-url' has been renamed to 'erc-button-search-url' and its value has been changed to Duck Duck Go. diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index 5e7946810be..b08970d2585 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el @@ -55,14 +55,21 @@ argument to `recenter'." (define-erc-module scrolltobottom nil "This mode causes the prompt to stay at the end of the window." ((add-hook 'erc-mode-hook 'erc-add-scroll-to-bottom) + (add-hook 'erc-insert-done-hook 'erc-possibly-scroll-to-bottom) (dolist (buffer (erc-buffer-list)) (with-current-buffer buffer (erc-add-scroll-to-bottom)))) ((remove-hook 'erc-mode-hook 'erc-add-scroll-to-bottom) + (remove-hook 'erc-insert-done-hook 'erc-possibly-scroll-to-bottom) (dolist (buffer (erc-buffer-list)) (with-current-buffer buffer (remove-hook 'post-command-hook 'erc-scroll-to-bottom t))))) +(defun erc-possibly-scroll-to-bottom () + "Like `erc-add-scroll-to-bottom', but only if window is selected." + (when (eq (selected-window) (get-buffer-window)) + (erc-scroll-to-bottom))) + (defun erc-add-scroll-to-bottom () "A hook function for `erc-mode-hook' to recenter output at bottom of window. diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 86f103ef231..1c5ecf99c6b 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1097,6 +1097,14 @@ At this point, all modifications from prior hook functions are done." erc-make-read-only erc-save-buffer-in-logs)) +(defcustom erc-insert-done-hook nil + "This hook is called after inserting strings into the buffer. +This hook is not called from inside `save-excursion' and should +preserve point if needed." + :group 'erc-hooks + :version "27.1" + :type 'hook) + (defcustom erc-send-modify-hook nil "Sending hook for functions that will change the text's appearance. This hook is called just after `erc-send-pre-hook' when the values @@ -2419,6 +2427,7 @@ If STRING is nil, the function does nothing." (when erc-remove-parsed-property (remove-text-properties (point-min) (point-max) '(erc-parsed nil)))))))) + (run-hooks 'erc-insert-done-hook) (erc-update-undo-list (- (or (marker-position erc-insert-marker) (point-max)) insert-position))))))