emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c5b78a3379 05/25: Customize displaying of ERC buffers on reconnec


From: F. Jason Park
Subject: master c5b78a3379 05/25: Customize displaying of ERC buffers on reconnect
Date: Thu, 30 Jun 2022 18:29:52 -0400 (EDT)

branch: master
commit c5b78a337900fd2a8d29317df7a27dd4e7006e89
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>

    Customize displaying of ERC buffers on reconnect
    
    * lisp/erc/erc-backend.el (erc--server-last-reconnect-count):
    Add variable to record last reconnect tally.
    
    * lisp/erc/erc.el (erc-reconnect-display): Add new option to specify
    channel-buffer display behavior on reconnect.
    (erc-setup-buffer): Use option `erc-reconnect-display' if warranted.
    (erc-cmd-JOIN): Forget last reconnect count when issuing a manual
    /JOIN command.
    (erc-connection-established): Record reconnect count in internal var
    before resetting.
    (Bug#51753)
---
 lisp/erc/erc-backend.el |  3 +++
 lisp/erc/erc.el         | 26 ++++++++++++++++++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 7aec02e897..13303c71f5 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -200,6 +200,9 @@ active, use the `erc-server-process-alive' function 
instead.")
 (defvar-local erc-server-reconnect-count 0
   "Number of times we have failed to reconnect to the current server.")
 
+(defvar-local erc--server-last-reconnect-count 0
+  "Snapshot of reconnect count when the connection was established.")
+
 (defvar-local erc-server-quitting nil
   "Non-nil if the user requests a quit.")
 
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index f9bff7e0c0..2ee461a663 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -131,6 +131,7 @@
   :group 'erc)
 
 ;; Defined in erc-backend
+(defvar erc--server-last-reconnect-count)
 (defvar erc--server-reconnecting)
 (defvar erc-channel-members-changed-hook)
 (defvar erc-server-367-functions)
@@ -1562,6 +1563,22 @@ The available choices are:
                  (const :tag "Use current buffer" buffer)
                  (const :tag "Use current buffer" t)))
 
+(defcustom erc-reconnect-display nil
+  "How (and whether) to display a channel buffer upon reconnecting.
+
+This only affects automatic reconnections and is ignored when
+issuing a /reconnect command or reinvoking `erc-tls' with the
+same args (assuming success, of course).  See `erc-join-buffer'
+for a description of possible values."
+  :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA
+  :group 'erc-buffers
+  :type '(choice (const :tag "Use value of `erc-join-buffer'" nil)
+                 (const :tag "Split window and select" window)
+                 (const :tag "Split window, don't select" window-noselect)
+                 (const :tag "New frame" frame)
+                 (const :tag "Bury in new buffer" bury)
+                 (const :tag "Use current buffer" buffer)))
+
 (defcustom erc-frame-alist nil
   "Alist of frame parameters for creating erc frames.
 A value of nil means to use `default-frame-alist'."
@@ -1983,7 +2000,10 @@ removed from the list will be disabled."
 
 (defun erc-setup-buffer (buffer)
   "Consults `erc-join-buffer' to find out how to display `BUFFER'."
-  (pcase erc-join-buffer
+  (pcase (if (zerop (erc-with-server-buffer
+                      erc--server-last-reconnect-count))
+             erc-join-buffer
+           (or erc-reconnect-display erc-join-buffer))
     ('window
      (if (active-minibuffer-window)
          (display-buffer buffer)
@@ -3250,6 +3270,7 @@ were most recently invited.  See also `invitation'."
             (switch-to-buffer (if (get-buffer chnl-name)
                                   chnl-name
                                 (concat chnl-name "/" server)))
+          (setq erc--server-last-reconnect-count 0)
          (erc-server-join-channel server chnl key)))))
   t)
 
@@ -4741,7 +4762,8 @@ Set user modes and run `erc-after-connect' hook."
             (nick (car (erc-response.command-args parsed)))
             (buffer (process-buffer proc)))
         (setq erc-server-connected t)
-       (setq erc-server-reconnect-count 0)
+        (setq erc--server-last-reconnect-count erc-server-reconnect-count
+              erc-server-reconnect-count 0)
         (erc-update-mode-line)
         (erc-set-initial-user-mode nick buffer)
         (erc-server-setup-periodical-ping buffer)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]