unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Victor Orlikowski <vjo@duke.edu>
To: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: [PATCH] Allow ERC to re-connect in the background properly
Date: Sun, 3 Feb 2019 17:43:30 +0000	[thread overview]
Message-ID: <FFC88752-F968-4633-BD36-C6B5019ADED1.notmuch@neverland> (raw)

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



             reply	other threads:[~2019-02-03 17:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-03 17:43 Victor Orlikowski [this message]
2019-02-08  7:57 ` [PATCH] Allow ERC to re-connect in the background properly Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=FFC88752-F968-4633-BD36-C6B5019ADED1.notmuch@neverland \
    --to=vjo@duke.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).