Add alias erc-buffer-do for erc-buffer-filter

* lisp/erc/erc-goodies.el (erc-scrolltobottom-enable,
erc-scrolltobottom-mode): Prefer `erc-buffer-do' to
`erc-buffer-filter'.
(erc-move-to-prompt-mode, erc-move-to-prompt-enable): Prefer
`erc-buffer-do' to `erc-buffer-filter'.
* lisp/erc/erc-imenu.el (erc-imenu-mode, erc-imenu-enable): Prefer
`erc-buffer-do' to `erc-buffer-filter'.
* lisp/erc/erc-match.el (erc-match-enable, erc-match-mode): Prefer
`erc-buffer-do' to `erc-buffer-filter'.
* lisp/erc/erc-stamp.el (erc-stamp-mode, erc-stamp-enable): Prefer
`erc-buffer-do' to `erc-buffer-filter'.
* lisp/erc/erc.el (erc-buffer-filter): Improve doc string.
(erc-buffer-do): Add alias for new code to prefer when calling
`erc-buffer-filter' for effect.  Do this because continually having to
refer back to the doc strings and implementations of the latter as
well as `erc-buffer-p', `erc-buffer-list', and co. is unproductive.
(erc-buffer-list): Use `always' as fallback predicate.
This commit is contained in:
F. Jason Park 2023-06-01 22:07:03 -07:00
parent 0f76bed492
commit bd969326e9
5 changed files with 17 additions and 12 deletions

View file

@ -53,8 +53,7 @@ argument to `recenter'."
"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)
(unless erc--updating-modules-p
(erc-buffer-filter #'erc-add-scroll-to-bottom)))
(unless erc--updating-modules-p (erc-buffer-do #'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))
@ -119,8 +118,7 @@ Put this function on `erc-insert-post-hook' and/or `erc-send-post-hook'."
(define-erc-module move-to-prompt nil
"This mode causes the point to be moved to the prompt when typing text."
((add-hook 'erc-mode-hook #'erc-move-to-prompt-setup)
(unless erc--updating-modules-p
(erc-buffer-filter #'erc-move-to-prompt-setup)))
(unless erc--updating-modules-p (erc-buffer-do #'erc-move-to-prompt-setup)))
((remove-hook 'erc-mode-hook #'erc-move-to-prompt-setup)
(dolist (buffer (erc-buffer-list))
(with-current-buffer buffer

View file

@ -139,7 +139,7 @@ Don't rely on this function, read it first!"
(define-erc-module imenu nil
"Simple Imenu integration for ERC."
((add-hook 'erc-mode-hook #'erc-imenu-setup)
(unless erc--updating-modules-p (erc-buffer-filter #'erc-imenu-setup)))
(unless erc--updating-modules-p (erc-buffer-do #'erc-imenu-setup)))
((remove-hook 'erc-mode-hook #'erc-imenu-setup)
(erc-with-all-buffers-of-server nil nil
(when erc-imenu--create-index-function

View file

@ -55,7 +55,7 @@ highlighted."
((add-hook 'erc-insert-modify-hook #'erc-match-message 'append)
(add-hook 'erc-mode-hook #'erc-match--modify-invisibility-spec)
(unless erc--updating-modules-p
(erc-buffer-filter #'erc-match--modify-invisibility-spec))
(erc-buffer-do #'erc-match--modify-invisibility-spec))
(erc--modify-local-map t "C-c C-k" #'erc-go-to-log-matches-buffer))
((remove-hook 'erc-insert-modify-hook #'erc-match-message)
(remove-hook 'erc-mode-hook #'erc-match--modify-invisibility-spec)

View file

@ -168,7 +168,7 @@ from entering them and instead jump over them."
(add-hook 'erc-mode-hook #'erc-stamp--recover-on-reconnect)
(add-hook 'erc--pre-clear-functions #'erc-stamp--reset-on-clear)
(unless erc--updating-modules-p
(erc-buffer-filter #'erc-munge-invisibility-spec)))
(erc-buffer-do #'erc-munge-invisibility-spec)))
((remove-hook 'erc-mode-hook #'erc-munge-invisibility-spec)
(remove-hook 'erc-insert-modify-hook #'erc-add-timestamp)
(remove-hook 'erc-send-modify-hook #'erc-add-timestamp)

View file

@ -1830,8 +1830,9 @@ If PROC is not supplied, all processes are searched."
(defun erc-buffer-filter (predicate &optional proc)
"Return a list of `erc-mode' buffers matching certain criteria.
PREDICATE is a function executed with each buffer, if it returns t, that buffer
is considered a valid match.
Call PREDICATE without arguments in all ERC buffers or only those
belonging to a non-nil PROC. Expect it to return non-nil in
buffers that should be included in the returned list.
PROC is either an `erc-server-process', identifying a certain
server connection, or nil which means all open connections."
@ -1843,15 +1844,21 @@ server connection, or nil which means all open connections."
(erc--buffer-p buf predicate proc)))
(buffer-list)))))
(defalias 'erc-buffer-do 'erc-buffer-filter
"Call FUNCTION in all ERC buffers or only those for PROC.
Expect users to prefer this alias to `erc-buffer-filter' in cases
where the latter would only be called for effect and its return
value thrown away.
\(fn FUNCTION &optional PROC)")
(defun erc-buffer-list (&optional predicate proc)
"Return a list of ERC buffers.
PREDICATE is a function which executes with every buffer satisfying
the predicate. If PREDICATE is passed as nil, return a list of all ERC
buffers. If PROC is given, the buffers local variable `erc-server-process'
needs to match PROC."
(unless predicate
(setq predicate (lambda () t)))
(erc-buffer-filter predicate proc))
(erc-buffer-filter (or predicate #'always) proc))
(define-obsolete-function-alias 'erc-iswitchb #'erc-switch-to-buffer "25.1")
(defun erc--switch-to-buffer (&optional arg)