all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Allow ERC to re-connect in the background properly
@ 2019-02-03 17:43 Victor Orlikowski
  2019-02-08  7:57 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Victor Orlikowski @ 2019-02-03 17:43 UTC (permalink / raw)
  To: emacs-devel@gnu.org

In my experience, the existing code for re-connecting to a
disconnected server forces ERC into the foreground.

The following patch changes ERC so that reconnection attempts
proceed in the background, without interrupting the user's workflow.

From 7a64c15406225a14dca6863342da3d90569baf49 Mon Sep 17 00:00:00 2001
From: "Victor J. Orlikowski" <vjo@duke.edu>
Date: Sun, 3 Feb 2019 12:32:12 -0500
Subject: [PATCH] Handle reconnection attempts in the background, rather than
 forcing to the foreground.

---
 lisp/erc/erc-backend.el | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 2fd3d454bf..57f34073be 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -613,11 +613,6 @@ Make sure you are in an ERC buffer when running this."
         (erc-open erc-session-server erc-session-port erc-server-current-nick
                   erc-session-user-full-name t erc-session-password)))))
 
-(defun erc-server-delayed-reconnect (buffer)
-  (if (buffer-live-p buffer)
-    (with-current-buffer buffer
-      (erc-server-reconnect))))
-
 (defun erc-server-filter-function (process string)
   "The process filter for the ERC server."
   (with-current-buffer (process-buffer process)
@@ -667,6 +662,25 @@ EVENT is the message received from the closed connection process."
               ;; open-network-stream-nowait error for connection refused
               (if (string-match "^failed with code 111" ,event) 'nonblocking t))))))
 
+(defun erc-server-background-reconnect (buffer)
+  (let ((process nil))
+    (condition-case err
+        (progn
+          (setq erc-server-reconnecting nil
+                erc-server-reconnect-count (1+ erc-server-reconnect-count))
+          (if (buffer-live-p buffer)
+              (with-current-buffer buffer
+                (setq process (get-buffer-process (erc-server-buffer)))
+                (erc-server-reconnect))))
+      (error (unless (integerp erc-server-reconnect-attempts)
+               (message "%s ... %s"
+                        "Reconnecting until we succeed"
+                        "kill the ERC server buffer to stop"))
+             (run-at-time erc-server-reconnect-timeout nil
+                          #'erc-server-background-reconnect buffer)))
+    (if process
+        (delete-process process))))
+
 (defun erc-process-sentinel-2 (event buffer)
   "Called when `erc-process-sentinel-1' has detected an unexpected disconnect."
   (if (not (buffer-live-p buffer))
@@ -684,18 +698,8 @@ EVENT is the message received from the closed connection process."
               (erc-update-mode-line)
               (set-buffer-modified-p nil))
           ;; reconnect
-          (condition-case nil
-              (progn
-                (setq erc-server-reconnecting   nil
-                      erc-server-reconnect-count (1+ erc-server-reconnect-count))
-                (setq delay erc-server-reconnect-timeout)
-                (run-at-time delay nil
-                             #'erc-server-delayed-reconnect buffer))
-            (error (unless (integerp erc-server-reconnect-attempts)
-                     (message "%s ... %s"
-                              "Reconnecting until we succeed"
-                              "kill the ERC server buffer to stop"))
-                   (erc-server-delayed-reconnect buffer))))))))
+          (run-at-time erc-server-reconnect-timeout nil
+                       #'erc-server-background-reconnect buffer))))))
 
 (defun erc-process-sentinel-1 (event buffer)
   "Called when `erc-process-sentinel' has decided that we're disconnecting.

Best,
Victor
-- 
Victor J. Orlikowski <> vjo@(ee.|cs.)?duke.edu



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Allow ERC to re-connect in the background properly
  2019-02-03 17:43 [PATCH] Allow ERC to re-connect in the background properly Victor Orlikowski
@ 2019-02-08  7:57 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2019-02-08  7:57 UTC (permalink / raw)
  To: Victor Orlikowski; +Cc: emacs-devel

> From: Victor Orlikowski <vjo@duke.edu>
> Date: Sun, 3 Feb 2019 17:43:30 +0000
> 
> In my experience, the existing code for re-connecting to a
> disconnected server forces ERC into the foreground.
> 
> The following patch changes ERC so that reconnection attempts
> proceed in the background, without interrupting the user's workflow.

Thanks.  I don't use ERC and am not familiar with its code.  Would
someone who does please review this patch and comment on it?



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-02-08  7:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-03 17:43 [PATCH] Allow ERC to re-connect in the background properly Victor Orlikowski
2019-02-08  7:57 ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.