From: F. Jason Park Date: Fri, 2 Jun 2023 05:07:03 +0000 (-0700) Subject: Add alias erc-buffer-do for erc-buffer-filter X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=bd969326e96584249b6c140d972f7b27ab3274f6;p=emacs.git 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. --- diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index 01eae4b63c5..afc05148506 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el @@ -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 diff --git a/lisp/erc/erc-imenu.el b/lisp/erc/erc-imenu.el index 9864d7c4042..60df4e9ac8e 100644 --- a/lisp/erc/erc-imenu.el +++ b/lisp/erc/erc-imenu.el @@ -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 diff --git a/lisp/erc/erc-match.el b/lisp/erc/erc-match.el index 86883260413..0c58524cd9f 100644 --- a/lisp/erc/erc-match.el +++ b/lisp/erc/erc-match.el @@ -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) diff --git a/lisp/erc/erc-stamp.el b/lisp/erc/erc-stamp.el index 500f6f3c0c9..78a8b1bc100 100644 --- a/lisp/erc/erc-stamp.el +++ b/lisp/erc/erc-stamp.el @@ -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) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 0349dc67dbd..d68d27e76d0 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -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)