From 9a230327870370ca2d3861c6a891d83e3e8ed0d0 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 11 Jun 2021 03:55:07 -0700 Subject: [PATCH 1/2] Deprecate instead of redefine erc-server-reconnecting * lisp/erc/erc-backend.el (erc-server-reconnecting, erc--server-reconnecting): obsolete and replace the former with new internal variant, which carries a simplified meaning. (erc-server-reconnect-p, erc--server-reconnect-p): Obsolete and replace the former with an internal function, and change behavior to disregard `erc-server-reconnecting' when rendering verdict. (erc-process-sentinel-2): ensure local var `erc--server-reconnecting' is t when timers are scheduled or firing, and nil otherwise, including after retries exhausted. This agrees with the straightforward way `erc-server-reconnecting' has always been used by `erc-cmd-RECONNECT'. (erc-server-connect): set `erc--server-reconnecting'. * lisp/erc/erc.el (erc-cmd-RECONNECT): use `erc--server-reconnecting' instead of `erc-server-reconnecting'. --- lisp/erc/erc-backend.el | 26 +++++++++++++++++++++----- lisp/erc/erc.el | 8 ++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 6e5a768b70..69f63dfbc4 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -197,7 +197,13 @@ erc-server-quitting "Non-nil if the user requests a quit.") (defvar-local erc-server-reconnecting nil - "Non-nil if reconnecting or scheduled to.") + "Non-nil if the user requests an explicit reconnect, and the +current IRC process is still alive.") +(make-obsolete-variable 'erc-server-reconnecting + "see `erc--server-reconnecting'" "29.1") + +(defvar-local erc--server-reconnecting nil + "Non-nil when reconnecting.") (defvar-local erc-server-timed-out nil "Non-nil if the IRC server failed to respond to a ping.") @@ -532,7 +538,8 @@ erc-server-connect (with-current-buffer buffer (setq erc-server-process process) (setq erc-server-quitting nil) - (setq erc-server-reconnecting nil) + (setq erc-server-reconnecting nil + erc--server-reconnecting nil) (setq erc-server-timed-out nil) (setq erc-server-banned nil) (setq erc-server-error-occurred nil) @@ -616,7 +623,7 @@ erc-server-filter-function (erc-parse-server-response process line))))))) (defun erc--server-reconnect-p (event) - "Return non-nil if ERC should attempt to reconnect automatically. + "Return non-nil when ERC should attempt to reconnect. EVENT is the message received from the closed connection process." (and erc-server-auto-reconnect (not erc-server-banned) @@ -631,6 +638,14 @@ erc--server-reconnect-p ;; open-network-stream-nowait error for connection refused (if (string-match "^failed with code 111" event) 'nonblocking t))) +(defun erc-server-reconnect-p (event) + "Return non-nil if ERC should attempt to reconnect automatically. +EVENT is the message received from the closed connection process." + (declare (obsolete "see `erc--server-reconnect-p'" "29.1")) + (or (with-suppressed-warnings ((obsolete erc-server-reconnecting)) + erc-server-reconnecting) + (erc--server-reconnect-p event))) + (defun erc-process-sentinel-2 (event buffer) "Called when `erc-process-sentinel-1' has detected an unexpected disconnect." (if (not (buffer-live-p buffer)) @@ -642,7 +657,7 @@ erc-process-sentinel-2 (if (not reconnect-p) ;; terminate, do not reconnect (progn - (setq erc-server-reconnecting nil) + (setq erc--server-reconnecting nil) (erc-display-message nil 'error (current-buffer) 'terminated ?e event) ;; Update mode line indicators @@ -651,7 +666,8 @@ erc-process-sentinel-2 ;; reconnect (condition-case nil (progn - (setq erc-server-reconnecting t + (setq erc-server-reconnecting nil + erc--server-reconnecting t erc-server-reconnect-count (1+ erc-server-reconnect-count)) (setq delay erc-server-reconnect-timeout) (run-at-time delay nil diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 0da837012c..9fa1736535 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -3752,13 +3752,17 @@ erc-cmd-RECONNECT (setq buffer (current-buffer))) (with-current-buffer buffer (setq erc-server-quitting nil) - (setq erc-server-reconnecting t) + (with-suppressed-warnings ((obsolete erc-server-reconnecting)) + (setq erc-server-reconnecting t)) + (setq erc--server-reconnecting t) (setq erc-server-reconnect-count 0) (setq process (get-buffer-process (erc-server-buffer))) (if process (delete-process process) (erc-server-reconnect)) - (setq erc-server-reconnecting nil))) + (with-suppressed-warnings ((obsolete erc-server-reconnecting)) + (setq erc-server-reconnecting nil)) + (setq erc--server-reconnecting nil))) t) (put 'erc-cmd-RECONNECT 'process-not-needed t) -- 2.31.1