From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 7 May 2021 01:52:41 -0700 Subject: [PATCH 20/35] Don't call erc-auto-query twice on PRIVMSG * lisp/erc/erc-backend.el (erc-server-JOIN): Use `erc--open-target' instead of `erc-join'. (erc-server-PRIVMSG): Don't call `erc-auto-query' at all, and instead borrow the portion of its logic that detects when a query buffer should be created instead of a channel buffer. * lisp/erc/erc.el (erc-cmd-QUERY): Update the mode line explicitly after calling `erc-query' in case it's needed after `erc-setup-buffer' runs. Simplify. (erc-query, erc--open-target): Replace uses of `erc-query' with `erc--open-target' and make the former obsolete. Don't call `erc-update-mode-line' because `erc-open' already does that. (erc-auto-query): Make this function obsolete. It was previously only used in erc-backend.el and only sewed confusion. (erc-query-on-unjoined-chan-privmsg): Add note questioning its role. It was previously only used by the now deprecated `erc-auto-query'. --- lisp/erc/erc-backend.el | 26 +++++++------------ lisp/erc/erc.el | 56 +++++++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 2a352874e5..7e174a6fd1 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -1334,16 +1334,7 @@ define-erc-response-handler (let* ((str (cond ;; If I have joined a channel ((erc-current-nick-p nick) - (setq buffer (erc-open erc-session-server erc-session-port - nick erc-session-user-full-name - nil nil - (list chnl) chnl - erc-server-process - nil - erc-session-username - (erc-networks--id-given - erc-networks--id))) - (when buffer + (when (setq buffer (erc--open-target chnl)) (set-buffer buffer) (with-suppressed-warnings ((obsolete erc-add-default-channel)) @@ -1534,6 +1525,13 @@ define-erc-response-handler fnick) (setf (erc-response.contents parsed) msg) (setq buffer (erc-get-buffer (if privp nick tgt) proc)) + ;; Even worth checking for empty target here? (invalid anyway) + (unless (or buffer noticep (string-empty-p tgt) (eq ?$ (aref tgt 0))) + (if (and privp msgp (not (erc-is-message-ctcp-and-not-action-p msg))) + (when erc-auto-query + (let ((erc-join-buffer erc-auto-query)) + (setq buffer (erc--open-target nick)))) + (setq buffer (erc--open-target tgt)))) (when buffer (with-current-buffer buffer (when privp (erc--unhide-prompt)) @@ -1569,13 +1567,7 @@ define-erc-response-handler s parsed buffer nick) (run-hook-with-args-until-success 'erc-echo-notice-hook s parsed buffer nick)) - (erc-display-message parsed nil buffer s))) - (when (string= cmd "PRIVMSG") - (erc-auto-query proc parsed)))))) - -;; FIXME: need clean way of specifying extra hooks in -;; define-erc-response-handler. -(add-hook 'erc-server-PRIVMSG-functions #'erc-auto-query) + (erc-display-message parsed nil buffer s))))))) (define-erc-response-handler (QUIT) "Another user has quit IRC." nil diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 06779c2c60..463c497844 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -3790,13 +3790,14 @@ erc-cmd-QUERY ;; `kill-buffer'? If it makes sense, re-add it. -- SK @ 2021-11-11 (interactive (list (read-string "Start a query with: "))) - (let ((session-buffer (erc-server-buffer)) - (erc-join-buffer erc-query-display)) - (if user - (erc-query user session-buffer) + (unless user ;; currently broken, evil hack to display help anyway ;(erc-delete-query)))) - (signal 'wrong-number-of-arguments "")))) + (signal 'wrong-number-of-arguments "")) + (let ((erc-join-buffer erc-query-display)) + (erc-with-server-buffer + (erc--open-target user)))) + (defalias 'erc-cmd-Q #'erc-cmd-QUERY) (defun erc-quit/part-reason-default () @@ -4472,28 +4473,30 @@ erc-debug-missing-hooks (nconc erc-server-vectors (list parsed)) nil) -(defun erc-query (target server) - "Open a query buffer on TARGET, using SERVER. +(defun erc--open-target (target) + "Open an ERC buffer on TARGET." + (erc-open erc-session-server + erc-session-port + (erc-current-nick) + erc-session-user-full-name + nil + nil + (list target) + target + erc-server-process + nil + erc-session-username + (erc-networks--id-given erc-networks--id))) + +(defun erc-query (target server-buffer) + "Open a query buffer on TARGET using SERVER-BUFFER. To change how this query window is displayed, use `let' to bind `erc-join-buffer' before calling this." - (unless (and server - (buffer-live-p server) - (set-buffer server)) + (declare (obsolete "bind `erc-cmd-query' and call `erc-cmd-QUERY'" "29.1")) + (unless (buffer-live-p server-buffer) (error "Couldn't switch to server buffer")) - (let ((buf (erc-open erc-session-server - erc-session-port - (erc-current-nick) - erc-session-user-full-name - nil - nil - (list target) - target - erc-server-process - erc-session-username))) - (unless buf - (error "Couldn't open query window")) - (erc-update-mode-line) - buf)) + (with-current-buffer server-buffer + (erc--open-target target))) (defcustom erc-auto-query 'window-noselect "If non-nil, create a query buffer each time you receive a private message. @@ -4512,6 +4515,9 @@ erc-auto-query (const :tag "Use current buffer" buffer) (const :tag "Use current buffer" t))) +;; FIXME either retire this or put it to use or more clearly explain +;; what it's supposed to do. It's currently only used by the obsolete +;; function `erc-auto-query'. (defcustom erc-query-on-unjoined-chan-privmsg t "If non-nil create query buffer on receiving any PRIVMSG at all. This includes PRIVMSGs directed to channels. If you are using an IRC @@ -4634,6 +4640,8 @@ erc-auto-query (erc-cmd-QUERY query)) nil)))) +(make-obsolete 'erc-auto-query "try erc-cmd-QUERY instead" "29.1") + (defun erc-is-message-ctcp-p (message) "Check if MESSAGE is a CTCP message or not." (string-match "^\C-a\\([^\C-a]*\\)\C-a?$" message)) -- 2.36.1