summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorSam Steingold <sds@gnu.org>2014-05-09 13:04:46 -0400
committerSam Steingold <sds@gnu.org>2014-05-09 13:04:46 -0400
commitf36f0bca381402745550aed8ccfd8e447efb1dd8 (patch)
treed56e024d6f35509bb2fbaa9ee3f757d5e2da52b0 /lisp
parent8e45f27f7e5bc74eb5ce035dff6ab22fb0f9dd20 (diff)
downloademacs-f36f0bca381402745550aed8ccfd8e447efb1dd8.tar.gz
emacs-f36f0bca381402745550aed8ccfd8e447efb1dd8.tar.bz2
emacs-f36f0bca381402745550aed8ccfd8e447efb1dd8.zip
Optionally auto-reconnect depending on `rcirc-reconnect-delay'.
* net/rcirc.el (rcirc-reconnect-delay): New user option. (rcirc-sentinel): Auto-reconnect to the server if `rcirc-reconnect-delay' is non-0 (but not more often than its value in case the host is off-line).
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/net/rcirc.el18
2 files changed, 25 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 18a4eadbed7..1a9b1991279 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2014-05-08 Sam Steingold <sds@gnu.org>
+
+ * net/rcirc.el (rcirc-reconnect-delay): New user option.
+ (rcirc-sentinel): Auto-reconnect to the server if
+ `rcirc-reconnect-delay' is non-0 (but not more often than its
+ value in case the host is off-line).
+
2014-05-09 Eli Zaretskii <eliz@gnu.org>
* progmodes/grep.el (lgrep): Fix a typo in last commit.
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index 5a75617c485..346c885fda4 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -658,6 +658,15 @@ is non-nil."
"Hook functions called when the process sentinel is called.
Functions are called with PROCESS and SENTINEL arguments.")
+(defcustom rcirc-reconnect-delay 0
+ "*The minimum interval in seconds between reconnect attempts.
+When 0, do not auto-reconnect."
+ :type 'integer
+ :group 'rcirc)
+
+(defvar rcirc-last-connect-time nil
+ "The last time the buffer was connected.")
+
(defun rcirc-sentinel (process sentinel)
"Called when PROCESS receives SENTINEL."
(let ((sentinel (replace-regexp-in-string "\n" "" sentinel)))
@@ -671,6 +680,14 @@ Functions are called with PROCESS and SENTINEL arguments.")
sentinel
(process-status process)) (not rcirc-target))
(rcirc-disconnect-buffer)))
+ (when (and (string= sentinel "deleted")
+ (< 0 rcirc-reconnect-delay))
+ (let ((now (current-time)))
+ (when (or (null rcirc-last-connect-time)
+ (< rcirc-reconnect-delay
+ (float-time (time-subtract now rcirc-last-connect-time))))
+ (setq sds-rcirc-sentinel-last now)
+ (rcirc-cmd-reconnect nil))))
(run-hook-with-args 'rcirc-sentinel-functions process sentinel))))
(defun rcirc-disconnect-buffer (&optional buffer)
@@ -1007,6 +1024,7 @@ This number is independent of the number of lines in the buffer.")
(setq-local fill-paragraph-function 'rcirc-fill-paragraph)
(setq-local rcirc-recent-quit-alist nil)
(setq-local rcirc-current-line 0)
+ (setq-local rcirc-last-connect-time (current-time))
(use-hard-newlines t)
(setq-local rcirc-short-buffer-name nil)