From 68cdc4bd7a780641a45b53b8fb71431e2da1a058 Mon Sep 17 00:00:00 2001 From: l3thal Date: Fri, 13 Nov 2015 16:34:32 -0500 Subject: Reconnect asynchronously. --- lisp/erc/erc-backend.el | 49 +++++++++++++++++++++++++------------------------ lisp/erc/erc.el | 6 +++++- 2 files changed, 30 insertions(+), 25 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index ec45dcfcf24..755443f8a94 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -376,7 +376,7 @@ alist." :type '(repeat (cons (string :tag "Target") coding-system))) -(defcustom erc-server-connect-function 'open-network-stream +(defcustom erc-server-connect-function 'erc-open-network-stream "Function used to initiate a connection. It should take same arguments as `open-network-stream' does." :group 'erc-server @@ -505,6 +505,10 @@ The current buffer is given by BUFFER." (memq (process-status erc-server-process) '(run open))))) ;;;; Connecting to a server +(defun erc-open-network-stream (name buffer host service) + "As `open-network-stream', but does non-blocking IO" + (make-network-process :name name :buffer buffer + :host host :service service :nowait t)) (defun erc-server-connect (server port buffer) "Perform the connection and login using the specified SERVER and PORT. @@ -565,10 +569,15 @@ Make sure you are in an ERC buffer when running this." (setq erc-server-last-sent-time 0) (setq erc-server-lines-sent 0) (let ((erc-server-connect-function (or erc-session-connector - 'open-network-stream))) + 'erc-open-network-stream))) (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 (event 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) @@ -615,17 +624,16 @@ EVENT is the message received from the closed connection process." (or erc-server-timed-out (not (string-match "^deleted" event))) ;; open-network-stream-nowait error for connection refused - (not (string-match "^failed with code 111" event))))) + (if (string-match "^failed with code 111" event) 'nonblocking t)))) (defun erc-process-sentinel-2 (event buffer) "Called when `erc-process-sentinel-1' has detected an unexpected disconnect." (if (not (buffer-live-p buffer)) (erc-update-mode-line) (with-current-buffer buffer - (let ((reconnect-p (erc-server-reconnect-p event))) - (erc-display-message nil 'error (current-buffer) - (if reconnect-p 'disconnected - 'disconnected-noreconnect)) + (let ((reconnect-p (erc-server-reconnect-p event)) message delay) + (setq message (if reconnect-p 'disconnected 'disconnected-noreconnect)) + (erc-display-message nil 'error (current-buffer) message) (if (not reconnect-p) ;; terminate, do not reconnect (progn @@ -637,23 +645,16 @@ EVENT is the message received from the closed connection process." ;; reconnect (condition-case err (progn - (setq erc-server-reconnecting nil) - (erc-server-reconnect) - (setq erc-server-reconnect-count 0)) - (error (when (buffer-live-p buffer) - (set-buffer buffer) - (if (integerp erc-server-reconnect-attempts) - (setq erc-server-reconnect-count - (1+ erc-server-reconnect-count)) - (message "%s ... %s" - "Reconnecting until we succeed" - "kill the ERC server buffer to stop")) - (if (numberp erc-server-reconnect-timeout) - (run-at-time erc-server-reconnect-timeout nil - #'erc-process-sentinel-2 - event buffer) - (error (concat "`erc-server-reconnect-timeout'" - " must be a number"))))))))))) + (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 event 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 event buffer)))))))) (defun erc-process-sentinel-1 (event buffer) "Called when `erc-process-sentinel' has decided that we're disconnecting. diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 8e26db1d9d3..d82089f5b05 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1963,7 +1963,9 @@ Returns the buffer for the given server or channel." (erc-update-modules) (set-buffer buffer) (setq old-point (point)) - (erc-mode) + (let ((old-recon-count erc-server-reconnect-count)) + (erc-mode) + (setq erc-server-reconnect-count old-recon-count)) (setq erc-server-announced-name server-announced-name) (setq erc-server-connected connected-p) ;; connection parameters @@ -2203,6 +2205,7 @@ Arguments are the same as for `erc'." The process will be given the name NAME, its target buffer will be BUFFER. HOST and PORT specify the connection target." (open-network-stream name buffer host port + :nowait t :type 'tls)) ;;; Displaying error messages @@ -4483,6 +4486,7 @@ 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) (erc-update-mode-line) (erc-set-initial-user-mode nick buffer) (erc-server-setup-periodical-ping buffer) -- cgit v1.2.1 From ac16149ba470ae8a625d42a61adbb6e84254c675 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 17 Nov 2015 15:28:50 -0800 Subject: =?UTF-8?q?Fix=20docstring=20quoting=20problems=20with=20=E2=80=98?= =?UTF-8?q?=20'=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem reported by Artur Malabarba in: http://lists.gnu.org/archive/html/emacs-devel/2015-11/msg01513.html Most of these fixes are to documentation; many involve fixing longstanding quoting glitches that are independent of the recent substitute-command-keys changes. The changes to code are: * lisp/cedet/mode-local.el (mode-local-augment-function-help) (describe-mode-local-overload): Substitute docstrings before displaying them. * lisp/emacs-lisp/cl-macs.el (cl--transform-lambda): Quote the generated docstring for later substitution. --- lisp/erc/erc-backend.el | 2 +- lisp/erc/erc-button.el | 6 +++--- lisp/erc/erc-match.el | 2 +- lisp/erc/erc-ring.el | 3 +-- lisp/erc/erc-track.el | 6 +++--- lisp/erc/erc.el | 10 +++++----- 6 files changed, 14 insertions(+), 15 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 755443f8a94..b52c8f5454f 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -370,7 +370,7 @@ This overrides `erc-server-coding-system' depending on the current target as returned by `erc-default-target'. Example: If you know that the channel #linux-ru uses the coding-system -`cyrillic-koi8', then add '(\"#linux-ru\" . cyrillic-koi8) to the +`cyrillic-koi8', then add (\"#linux-ru\" . cyrillic-koi8) to the alist." :group 'erc-server :type '(repeat (cons (string :tag "Target") diff --git a/lisp/erc/erc-button.el b/lisp/erc/erc-button.el index 0e4c70944bb..d6f4b12ebbf 100644 --- a/lisp/erc/erc-button.el +++ b/lisp/erc/erc-button.el @@ -165,11 +165,11 @@ REGEXP is the string matching text around the button or a symbol entries in lists or alists are considered to be nicks or other complete words. Therefore they are enclosed in \\< and \\> while searching. REGEXP can also be the quoted symbol - 'nicknames, which matches the nickname of any user on the + \\='nicknames, which matches the nickname of any user on the current server. BUTTON is the number of the regexp grouping actually matching the - button, This is ignored if REGEXP is 'nicknames. + button, This is ignored if REGEXP is \\='nicknames. FORM is a lisp expression which must eval to true for the button to be added, @@ -180,7 +180,7 @@ CALLBACK is the function to call when the user push this button. PAR is a number of a regexp grouping whose text will be passed to CALLBACK. There can be several PAR arguments. If REGEXP is - 'nicknames, these are ignored, and CALLBACK will be called with + \\='nicknames, these are ignored, and CALLBACK will be called with the nickname matched as the argument." :group 'erc-button :version "24.1" ; remove finger (bug#4443) diff --git a/lisp/erc/erc-match.el b/lisp/erc/erc-match.el index 0622b18ca7f..ec3266fa1bd 100644 --- a/lisp/erc/erc-match.el +++ b/lisp/erc/erc-match.el @@ -191,7 +191,7 @@ use for the logged message." "Flag specifying when matched message logging should happen. When nil, don't log any matched messages. When t, log messages. -When 'away, log messages only when away." +When `away', log messages only when away." :group 'erc-match :type '(choice (const nil) (const away) diff --git a/lisp/erc/erc-ring.el b/lisp/erc/erc-ring.el index de988cc8275..77528eae88c 100644 --- a/lisp/erc/erc-ring.el +++ b/lisp/erc/erc-ring.el @@ -58,7 +58,7 @@ be recalled using M-p and M-n." (defvar erc-input-ring-index nil "Position in the input ring for erc. -If nil, the input line is blank and the user is conceptually 'after' +If nil, the input line is blank and the user is conceptually after the most recently added item in the ring. If an integer, the input line is non-blank and displays the item from the ring indexed by this variable.") @@ -148,4 +148,3 @@ containing a password." ;; Local Variables: ;; indent-tabs-mode: nil ;; End: - diff --git a/lisp/erc/erc-track.el b/lisp/erc/erc-track.el index 2ebc1f22c09..5af1663378f 100644 --- a/lisp/erc/erc-track.el +++ b/lisp/erc/erc-track.el @@ -101,7 +101,7 @@ disconnected from `erc-modified-channels-alist'." (defcustom erc-track-exclude-types '("NICK" "333" "353") "List of message types to be ignored. -This list could look like '(\"JOIN\" \"PART\"). +This list could look like (\"JOIN\" \"PART\"). By default, exclude changes of nicknames (NICK), display of who set the channel topic (333), and listing of users on the current @@ -210,7 +210,7 @@ If you would like to ignore changes in certain channels where there are no faces corresponding to your `erc-track-faces-priority-list', set this variable. You can set a list of channel name strings, so those will be ignored while all other channels will be tracked as normal. -Other options are 'all, to apply this to all channels or nil, to disable +Other options are `all', to apply this to all channels or nil, to disable this feature. Note: If you have a lot of faces listed in `erc-track-faces-priority-list', @@ -326,7 +326,7 @@ when there are no more active channels." leastactive - find buffer with least unseen messages mostactive - find buffer with most unseen messages. -If set to 'importance, the importance is determined by position +If set to `importance', the importance is determined by position in `erc-track-faces-priority-list', where first is most important." :group 'erc-track diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index d82089f5b05..ab90df8fd3c 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -629,7 +629,7 @@ See also: `erc-get-channel-user-list'." (defvar erc-channel-modes nil "List of strings representing channel modes. -E.g. '(\"i\" \"m\" \"s\" \"b Quake!*@*\") +E.g. (\"i\" \"m\" \"s\" \"b Quake!*@*\") \(not sure the ban list will be here, but why not)") (make-variable-buffer-local 'erc-channel-modes) @@ -3249,7 +3249,7 @@ LINE has the format \"USER ACTION\"." (put 'erc-cmd-ME 'do-not-parse-args t) (defun erc-cmd-ME\'S (line) - "Do a /ME command, but add the string \" 's\" to the beginning." + "Do a /ME command, but add the string \" \\='s\" to the beginning." (erc-cmd-ME (concat " 's" line))) (put 'erc-cmd-ME\'S 'do-not-parse-args t) @@ -5025,7 +5025,7 @@ See also `erc-remove-current-channel-member'." (defun erc-update-channel-topic (channel topic &optional modify) "Find a buffer for CHANNEL and set the TOPIC for it. -If optional MODIFY is 'append or 'prepend, then append or prepend the +If optional MODIFY is `append' or `prepend', then append or prepend the TOPIC string to the current topic." (erc-with-buffer (channel) (cond ((eq modify 'append) @@ -5188,7 +5188,7 @@ person who changed the modes." (t (setq erc-channel-user-limit nil)))))) (defun erc-update-channel-key (channel onoff key) - "Update CHANNEL's key to KEY if ONOFF is 'on or to nil if it's 'off." + "Update CHANNEL's key to KEY if ONOFF is `on' or to nil if it's `off'." (erc-with-buffer (channel) (cond ((eq onoff 'on) (setq erc-channel-key key)) @@ -6730,7 +6730,7 @@ This function should be on `erc-kill-channel-hook'." (text-property-not-all (point-min) (point-max) 'erc-parsed nil)) (defun erc-restore-text-properties () - "Restore the property 'erc-parsed for the region." + "Restore the property `erc-parsed' for the region." (let ((parsed-posn (erc-find-parsed-property))) (put-text-property (point-min) (point-max) -- cgit v1.2.1 From bb4303c536a2ac5fe683a711ef8072074f77670e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 18 Nov 2015 09:17:20 -0800 Subject: Quote symbols in docstrings using `' Be more systematic about quoting symbols `like-this' rather than `like-this or 'like-this' in docstrings. This follows up Artur Malabarba's email in: http://lists.gnu.org/archive/html/emacs-devel/2015-11/msg01647.html --- lisp/erc/erc.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index ab90df8fd3c..a66338dff02 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2419,9 +2419,9 @@ If STRING is nil, the function does nothing." "Display STRING in the ERC BUFFER. All screen output must be done through this function. If BUFFER is nil or omitted, the default ERC buffer for the `erc-session-server' is used. -The BUFFER can be an actual buffer, a list of buffers, 'all or 'active. -If BUFFER = 'all, the string is displayed in all the ERC buffers for the -current session. 'active means the current active buffer +The BUFFER can be an actual buffer, a list of buffers, `all' or `active'. +If BUFFER = `all', the string is displayed in all the ERC buffers for the +current session. `active' means the current active buffer \(`erc-active-buffer'). If the buffer can't be resolved, the current buffer is used. `erc-display-line-1' is used to display STRING. -- cgit v1.2.1 From 6ae0aa6a504c6023dfe234b507c95f146d668436 Mon Sep 17 00:00:00 2001 From: Fran Litterio Date: Sun, 27 Dec 2015 08:56:45 +0100 Subject: Run erc-kill-channel-hook always on exit * lisp/erc/erc.el (erc-kill-buffer-function): Run erc-kill-channel-hook when erc-kill-queries-on-quit is set (bug#21187). --- lisp/erc/erc.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index a66338dff02..70e37348b6a 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -6702,7 +6702,7 @@ or `erc-kill-buffer-hook' if any other buffer." (cond ((eq (erc-server-buffer) (current-buffer)) (run-hooks 'erc-kill-server-hook)) - ((erc-channel-p (erc-default-target)) + ((erc-channel-p (or (erc-default-target) (buffer-name))) (run-hooks 'erc-kill-channel-hook)) (t (run-hooks 'erc-kill-buffer-hook))))) -- cgit v1.2.1 From f9d87dd8791d4e77929f21e4f73d92ef966722cc Mon Sep 17 00:00:00 2001 From: Krzysztof Jurewicz Date: Sun, 27 Dec 2015 09:04:02 +0100 Subject: Fix auth source lookups from erc with port numbers * lisp/erc/erc.el (erc-open): `auth-source' wants strings, not port numbers (bug#20541). Copyright-paperwork-exempt: yes --- lisp/erc/erc.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 70e37348b6a..04e99c7b884 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2025,7 +2025,8 @@ Returns the buffer for the given server or channel." (auth-source-search :host server :max 1 :user nick - :port port + ;; secrets.el wouldn’t accept a number + :port (if (numberp port) (number-to-string port) port) :require '(:secret))) :secret))) (if (functionp secret) -- cgit v1.2.1 From 504982765cc563d96a0b773f4cf183ceacaf5861 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 27 Dec 2015 20:25:57 +0100 Subject: Don't join erc channels doubly * erc-join.el (erc-autojoin-channels): Don't join channels more than once (if you have several nicks) (bug#20695). --- lisp/erc/erc-join.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-join.el b/lisp/erc/erc-join.el index 4c99898bc41..c1ce14ab016 100644 --- a/lisp/erc/erc-join.el +++ b/lisp/erc/erc-join.el @@ -156,7 +156,13 @@ This function is run from `erc-nickserv-identified-hook'." (dolist (l erc-autojoin-channels-alist) (when (string-match (car l) server) (dolist (chan (cdr l)) - (erc-server-join-channel server chan))))) + (let ((buffer (erc-get-buffer chan))) + ;; Only auto-join the channels that we aren't already in + ;; using a different nick. + (when (or (not buffer) + (not (with-current-buffer buffer + (erc-server-process-alive)))) + (erc-server-join-channel server chan))))))) ;; Return nil to avoid stomping on any other hook funcs. nil) @@ -170,7 +176,7 @@ This function is run from `erc-nickserv-identified-hook'." (password (if (functionp secret) (funcall secret) secret))) - (erc-server-send (concat "join " channel + (erc-server-send (concat "JOIN " channel (if password (concat " " password) ""))))) -- cgit v1.2.1 From 5caa4dea5a3432e2b9c5f85b63265c05954c3d53 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 27 Dec 2015 21:08:01 +0100 Subject: Don't insert erc logs at the end * erc-log.el (erc-log-setup-logging): Insert the previous log at the start of the buffer, not at the end (bug#20496). --- lisp/erc/erc-log.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-log.el b/lisp/erc/erc-log.el index f022284450a..4ac13aab070 100644 --- a/lisp/erc/erc-log.el +++ b/lisp/erc/erc-log.el @@ -270,9 +270,12 @@ The current buffer is given by BUFFER." (setq buffer-file-name nil) (erc-set-write-file-functions '(erc-save-buffer-in-logs)) (when erc-log-insert-log-on-open - (ignore-errors (insert-file-contents (erc-current-logfile)) - (move-marker erc-last-saved-position - (1- (point-max)))))))) + (ignore-errors + (save-excursion + (goto-char (point-min)) + (insert-file-contents (erc-current-logfile))) + (move-marker erc-last-saved-position + (1- (point-max)))))))) (defun erc-log-disable-logging (buffer) "Disable logging in BUFFER." -- cgit v1.2.1 From 2cd894dc348b4872d7beb10275387c30027c8f26 Mon Sep 17 00:00:00 2001 From: Dima Kogan Date: Sun, 27 Dec 2015 21:19:13 +0100 Subject: Ensure that we don't have several timers in erc * lisp/erc/erc-backend.el (erc-server-setup-periodical-ping): Checks for existing timers in the alist before adding new ones. If a timer already exists, it is cancelled and overwritten. (bug#19292). --- lisp/erc/erc-backend.el | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index b52c8f5454f..daaa1b0428a 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -493,9 +493,19 @@ The current buffer is given by BUFFER." 4 erc-server-send-ping-interval #'erc-server-send-ping buffer)) - (setq erc-server-ping-timer-alist (cons (cons buffer - erc-server-ping-handler) - erc-server-ping-timer-alist))))) + + ;; I check the timer alist for an existing timer. If one exists, + ;; I get rid of it + (let ((timer-tuple (assq buffer erc-server-ping-timer-alist))) + (if timer-tuple + ;; this buffer already has a timer. Cancel it and set the new one + (progn + (erc-cancel-timer (cdr timer-tuple)) + (setf (cdr (assq buffer erc-server-ping-timer-alist)) erc-server-ping-handler)) + + ;; no existing timer for this buffer. Add new one + (add-to-list 'erc-server-ping-timer-alist + (cons buffer erc-server-ping-handler))))))) (defun erc-server-process-alive (&optional buffer) "Return non-nil when BUFFER has an `erc-server-process' open or running." -- cgit v1.2.1 From 507e98a54d1aa37823c64993d6b59257a82fe8f4 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Sun, 27 Dec 2015 21:33:01 +0100 Subject: Proxy error in erc with multiple clients * lisp/erc/erc.el (erc-channel-receive-names): Fix errors generated when multiple IRC clients talk to a single IRC proxy (bug#19034). --- lisp/erc/erc.el | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lisp/erc') diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index cd8c8a817e1..126cac68a7b 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -4826,6 +4826,11 @@ channel." (_ (error "Unknown prefix char `%S'" ch) voice)) 'on))) (when updatep + ;; If we didn't issue the NAMES request (consider two clients + ;; talking to an IRC proxy), `erc-channel-begin-receiving-names' + ;; will not have been called, so we have to do it here. + (unless erc-channel-new-member-names + (erc-channel-begin-receiving-names)) (puthash (erc-downcase name) t erc-channel-new-member-names) (erc-update-current-channel-member -- cgit v1.2.1 From af25edebbcb33e788a0f4f9619787417aa0834b8 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Sun, 27 Dec 2015 21:33:01 +0100 Subject: Proxy error in erc with multiple clients * lisp/erc/erc.el (erc-channel-receive-names): Fix errors generated when multiple IRC clients talk to a single IRC proxy (bug#19034). Backport: (cherry picked from commit 507e98a54d1aa37823c64993d6b59257a82fe8f4) --- lisp/erc/erc.el | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lisp/erc') diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 04e99c7b884..2b22bd55ccc 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -4826,6 +4826,11 @@ channel." (_ (error "Unknown prefix char `%S'" ch) voice)) 'on))) (when updatep + ;; If we didn't issue the NAMES request (consider two clients + ;; talking to an IRC proxy), `erc-channel-begin-receiving-names' + ;; will not have been called, so we have to do it here. + (unless erc-channel-new-member-names + (erc-channel-begin-receiving-names)) (puthash (erc-downcase name) t erc-channel-new-member-names) (erc-update-current-channel-member -- cgit v1.2.1 From ff5f37e56a1df53dbc15c8590d904ac37a82a335 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 27 Dec 2015 22:18:32 +0100 Subject: Don't bug out in erc after waking from sleep * erc-backend.el (erc-server-send-ping): If the server has closed connection, this may already have been detected and `erc-server-last-received-time' has been set to nil (bug#13608). --- lisp/erc/erc-backend.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index daaa1b0428a..df957d1ce42 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -805,7 +805,9 @@ protection algorithm." (defun erc-server-send-ping (buf) "Send a ping to the IRC server buffer in BUF. Additionally, detect whether the IRC process has hung." - (if (buffer-live-p buf) + (if (and (buffer-live-p buf) + (with-current-buffer buf + erc-server-last-received-time)) (with-current-buffer buf (if (and erc-server-send-ping-timeout (> -- cgit v1.2.1 From a36c88806dcfc993e6af83b0d0f44b077293bc30 Mon Sep 17 00:00:00 2001 From: Deniz Dogan Date: Sun, 27 Dec 2015 22:36:55 +0100 Subject: Clear erc user list upon disconnection * lisp/erc/erc-backend.el (erc-process-sentinel): Clear channel user lists upon disconnection. This prevents invalid channel user lists when reconnecting (bug#10947). --- lisp/erc/erc-backend.el | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index df957d1ce42..06a23e80fdd 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -703,6 +703,9 @@ Conditionally try to reconnect and take appropriate action." (setq erc-server-ping-handler nil))) (run-hook-with-args 'erc-disconnected-hook (erc-current-nick) (system-name) "") + (dolist (buf (erc-buffer-filter (lambda () (boundp 'erc-channel-users)) cproc)) + (with-current-buffer buf + (setq erc-channel-users (make-hash-table :test 'equal)))) ;; Remove the prompt (goto-char (or (marker-position erc-input-marker) (point-max))) (forward-line 0) -- cgit v1.2.1 From 92e1878a04a7940413c426d641334dd8f090f741 Mon Sep 17 00:00:00 2001 From: Vivek Dasmohapatra Date: Sun, 27 Dec 2015 23:12:30 +0100 Subject: Make erc connect asynchronously * lisp/erc/erc-backend.el (erc-server-reconnect): Use it to reconnect asynchronously. * lisp/erc/erc-backend.el (erc-open-network-stream): New function (bug#5650). --- lisp/erc/erc-backend.el | 84 +++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 41 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index ec45dcfcf24..a0b3537afee 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -376,7 +376,7 @@ alist." :type '(repeat (cons (string :tag "Target") coding-system))) -(defcustom erc-server-connect-function 'open-network-stream +(defcustom erc-server-connect-function 'erc-open-network-stream "Function used to initiate a connection. It should take same arguments as `open-network-stream' does." :group 'erc-server @@ -505,51 +505,53 @@ The current buffer is given by BUFFER." (memq (process-status erc-server-process) '(run open))))) ;;;; Connecting to a server +(defun erc-open-network-stream (name buffer host service) + "As `open-network-stream', but does non-blocking IO" + (make-network-process :name name :buffer buffer + :host host :service service :nowait t)) (defun erc-server-connect (server port buffer) "Perform the connection and login using the specified SERVER and PORT. We will store server variables in the buffer given by BUFFER." - (let ((msg (erc-format-message 'connect ?S server ?p port))) + (let ((msg (erc-format-message 'connect ?S server ?p port)) process) (message "%s" msg) - (let ((process (funcall erc-server-connect-function - (format "erc-%s-%s" server port) - nil server port))) - (unless (processp process) - (error "Connection attempt failed")) + (setq process (funcall erc-server-connect-function + (format "erc-%s-%s" server port) nil server port)) + (unless (processp process) + (error "Connection attempt failed")) + ;; Misc server variables + (with-current-buffer buffer + (setq erc-server-process process) + (setq erc-server-quitting nil) + (setq erc-server-reconnecting nil) + (setq erc-server-timed-out nil) + (setq erc-server-banned nil) + (setq erc-server-error-occurred nil) + (let ((time (erc-current-time))) + (setq erc-server-last-sent-time time) + (setq erc-server-last-ping-time time) + (setq erc-server-last-received-time time)) + (setq erc-server-lines-sent 0) + ;; last peers (sender and receiver) + (setq erc-server-last-peers '(nil . nil))) + ;; we do our own encoding and decoding + (when (fboundp 'set-process-coding-system) + (set-process-coding-system process 'raw-text)) + ;; process handlers + (set-process-sentinel process 'erc-process-sentinel) + (set-process-filter process 'erc-server-filter-function) + (set-process-buffer process buffer) + (erc-log "\n\n\n********************************************\n") + (message "%s" (erc-format-message + 'login ?n + (with-current-buffer buffer (erc-current-nick)))) + ;; wait with script loading until we receive a confirmation (first + ;; MOTD line) + (if (eq (process-status process) 'connect) + ;; waiting for a non-blocking connect - keep the user informed + (erc-display-message nil nil buffer "Opening connection..\n") (message "%s...done" msg) - ;; Misc server variables - (with-current-buffer buffer - (setq erc-server-process process) - (setq erc-server-quitting nil) - (setq erc-server-reconnecting nil) - (setq erc-server-timed-out nil) - (setq erc-server-banned nil) - (setq erc-server-error-occurred nil) - (let ((time (erc-current-time))) - (setq erc-server-last-sent-time time) - (setq erc-server-last-ping-time time) - (setq erc-server-last-received-time time)) - (setq erc-server-lines-sent 0) - ;; last peers (sender and receiver) - (setq erc-server-last-peers '(nil . nil))) - ;; we do our own encoding and decoding - (when (fboundp 'set-process-coding-system) - (set-process-coding-system process 'raw-text)) - ;; process handlers - (set-process-sentinel process 'erc-process-sentinel) - (set-process-filter process 'erc-server-filter-function) - (set-process-buffer process buffer))) - (erc-log "\n\n\n********************************************\n") - (message "%s" (erc-format-message - 'login ?n - (with-current-buffer buffer (erc-current-nick)))) - ;; wait with script loading until we receive a confirmation (first - ;; MOTD line) - (if (eq erc-server-connect-function 'open-network-stream-nowait) - ;; it's a bit unclear otherwise that it's attempting to establish a - ;; connection - (erc-display-message nil nil buffer "Opening connection..\n") - (erc-login))) + (erc-login)) )) (defun erc-server-reconnect () "Reestablish the current IRC connection. @@ -565,7 +567,7 @@ Make sure you are in an ERC buffer when running this." (setq erc-server-last-sent-time 0) (setq erc-server-lines-sent 0) (let ((erc-server-connect-function (or erc-session-connector - 'open-network-stream))) + 'erc-open-network-stream))) (erc-open erc-session-server erc-session-port erc-server-current-nick erc-session-user-full-name t erc-session-password))))) -- cgit v1.2.1 From d50b89dda9478b5e7e20e9b23bf48bd07ee6210a Mon Sep 17 00:00:00 2001 From: Thomas Riccardi Date: Sun, 27 Dec 2015 23:14:13 +0100 Subject: Further erc asynch fixes * lisp/erc/erc-backend.el (erc-process-sentinel-2): Make erc-server-connect to return even if the connection is not ready. Then erc-open and erc-server-reconnect do the same. (bug#5650). Copyright-paperwork-exempt: yes --- lisp/erc/erc-backend.el | 8 +++----- lisp/erc/erc.el | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index a0b3537afee..fbac849a1d8 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -640,13 +640,11 @@ EVENT is the message received from the closed connection process." (condition-case err (progn (setq erc-server-reconnecting nil) - (erc-server-reconnect) - (setq erc-server-reconnect-count 0)) + (setq erc-server-reconnect-count (1+ erc-server-reconnect-count)) + (erc-server-reconnect)) (error (when (buffer-live-p buffer) (set-buffer buffer) - (if (integerp erc-server-reconnect-attempts) - (setq erc-server-reconnect-count - (1+ erc-server-reconnect-count)) + (unless (integerp erc-server-reconnect-attempts) (message "%s ... %s" "Reconnecting until we succeed" "kill the ERC server buffer to stop")) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 126cac68a7b..cd8e427f72b 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -4488,6 +4488,7 @@ 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) (erc-update-mode-line) (erc-set-initial-user-mode nick buffer) (erc-server-setup-periodical-ping buffer) -- cgit v1.2.1 From 1fe73447864345c03fb28005122137419286853b Mon Sep 17 00:00:00 2001 From: Vivek Dasmohapatra Date: Sun, 27 Dec 2015 23:28:52 +0100 Subject: Disconnection fixes for erc * lisp/erc/erc-backend.el (erc-server-reconnect-p): Don't reconnect if the user has disconnected explicitly (bug#4589). --- lisp/erc/erc-backend.el | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index fbac849a1d8..cab0fb9d537 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -604,20 +604,22 @@ Make sure you are in an ERC buffer when running this." (defsubst 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." - (or erc-server-reconnecting - (and erc-server-auto-reconnect - (not erc-server-banned) - (not erc-server-error-occurred) - ;; make sure we don't infinitely try to reconnect, unless the - ;; user wants that - (or (eq erc-server-reconnect-attempts t) - (and (integerp erc-server-reconnect-attempts) - (< erc-server-reconnect-count - erc-server-reconnect-attempts))) - (or erc-server-timed-out - (not (string-match "^deleted" event))) - ;; open-network-stream-nowait error for connection refused - (not (string-match "^failed with code 111" event))))) + (and (not erc-server-quitting) ;; user issued an explicit quit, give up now + (or erc-server-reconnecting ;; user issued explicit reconnect + ;; otherwise go through the full spectrum of checks: + (and erc-server-auto-reconnect + (not erc-server-banned) + (not erc-server-error-occurred) + ;; make sure we don't infinitely try to reconnect, unless the + ;; user wants that + (or (eq erc-server-reconnect-attempts t) + (and (integerp erc-server-reconnect-attempts) + (< erc-server-reconnect-count + erc-server-reconnect-attempts))) + (or erc-server-timed-out + (not (string-match "^deleted" event))) + ;; open-network-stream-nowait error for connection refused + (not (string-match "^failed with code 111" event)))))) (defun erc-process-sentinel-2 (event buffer) "Called when `erc-process-sentinel-1' has detected an unexpected disconnect." -- cgit v1.2.1 From d686802510c3902f6be4a4c4e82b1134d9dfb8a0 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 28 Dec 2015 20:52:41 +0100 Subject: Reconnect erc even on server errors * lisp/erc/erc-backend.el (erc-server-reconnect-p): Try to reconnect even if a server error has occurred (bug#18527). --- lisp/erc/erc-backend.el | 1 - 1 file changed, 1 deletion(-) (limited to 'lisp/erc') diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index cab0fb9d537..1ef2fac1627 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -609,7 +609,6 @@ EVENT is the message received from the closed connection process." ;; otherwise go through the full spectrum of checks: (and erc-server-auto-reconnect (not erc-server-banned) - (not erc-server-error-occurred) ;; make sure we don't infinitely try to reconnect, unless the ;; user wants that (or (eq erc-server-reconnect-attempts t) -- cgit v1.2.1