diff options
Diffstat (limited to 'lisp/erc/erc-backend.el')
-rw-r--r-- | lisp/erc/erc-backend.el | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el index 3e2a9bc4e56..210830a2b49 100644 --- a/lisp/erc/erc-backend.el +++ b/lisp/erc/erc-backend.el @@ -466,14 +466,18 @@ If this is set to nil, never try to reconnect." The length is specified in `erc-split-line-length'. Currently this is called by `erc-send-input'." - (if (< (length longline) - erc-split-line-length) - (list longline) + (let ((charset (car (erc-coding-system-for-target nil)))) (with-temp-buffer (insert longline) + ;; The line lengths are in octets, not characters (because these + ;; are server protocol limits), so we have to first make the + ;; text into bytes, then fold the bytes on "word" boundaries, + ;; and then make the bytes into text again. + (encode-coding-region (point-min) (point-max) charset) (let ((fill-column erc-split-line-length)) (fill-region (point-min) (point-max) nil t)) + (decode-coding-region (point-min) (point-max) charset) (split-string (buffer-string) "\n")))) (defun erc-forward-word () @@ -644,22 +648,24 @@ Make sure you are in an ERC buffer when running this." (erc-log-irc-protocol line nil) (erc-parse-server-response process line))))))) -(defsubst erc-server-reconnect-p (event) +(define-inline 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) - ;; 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 - (if (string-match "^failed with code 111" event) 'nonblocking t)))) + (inline-letevals (event) + (inline-quote + (or erc-server-reconnecting + (and erc-server-auto-reconnect + (not erc-server-banned) + ;; 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 + (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." @@ -838,10 +844,9 @@ Additionally, detect whether the IRC process has hung." erc-server-last-received-time)) (with-current-buffer buf (if (and erc-server-send-ping-timeout - (> - (erc-time-diff (erc-current-time) - erc-server-last-received-time) - erc-server-send-ping-timeout)) + (time-less-p + erc-server-send-ping-timeout + (time-since erc-server-last-received-time))) (progn ;; if the process is hung, kill it (setq erc-server-timed-out t) @@ -859,16 +864,15 @@ Additionally, detect whether the IRC process has hung." See `erc-server-flood-margin' for an explanation of the flood protection algorithm." (with-current-buffer buffer - (let ((now (erc-current-time))) + (let ((now (current-time))) (when erc-server-flood-timer (erc-cancel-timer erc-server-flood-timer) (setq erc-server-flood-timer nil)) - (when (< erc-server-flood-last-message - now) - (setq erc-server-flood-last-message now)) + (when (time-less-p erc-server-flood-last-message now) + (setq erc-server-flood-last-message (erc-emacs-time-to-erc-time now))) (while (and erc-server-flood-queue - (< erc-server-flood-last-message - (+ now erc-server-flood-margin))) + (time-less-p erc-server-flood-last-message + (time-add now erc-server-flood-margin))) (let ((msg (caar erc-server-flood-queue)) (encoding (cdar erc-server-flood-queue))) (setq erc-server-flood-queue (cdr erc-server-flood-queue) @@ -1064,8 +1068,8 @@ Hands off to helper functions via `erc-call-hooks'." erc-server-prevent-duplicates) (let ((m (erc-response.unparsed parsed-response))) ;; duplicate suppression - (if (< (or (gethash m erc-server-duplicates) 0) - (- (erc-current-time) erc-server-duplicate-timeout)) + (if (time-less-p (or (gethash m erc-server-duplicates) 0) + (time-since erc-server-duplicate-timeout)) (erc-call-hooks process parsed-response)) (puthash m (erc-current-time) erc-server-duplicates)) ;; Hand off to the relevant handler. @@ -1281,7 +1285,7 @@ add things to `%s' instead." (pcase-let ((`(,nick ,login ,host) (erc-parse-user (erc-response.sender parsed)))) ;; strip the stupid combined JOIN facility (IRC 2.9) - (if (string-match "^\\(.*\\)?\^g.*$" chnl) + (if (string-match "^\\(.*\\)\^g.*$" chnl) (setq chnl (match-string 1 chnl))) (save-excursion (let* ((str (cond @@ -1441,7 +1445,7 @@ add things to `%s' instead." "Handle pong messages." nil (let ((time (string-to-number (erc-response.contents parsed)))) (when (> time 0) - (setq erc-server-lag (erc-time-diff time (erc-current-time))) + (setq erc-server-lag (erc-time-diff time nil)) (when erc-verbose-server-ping (erc-display-message parsed 'notice proc 'PONG @@ -1724,7 +1728,7 @@ See `erc-display-server-message'." nil (cdr (erc-response.command-args parsed)))) (setq time (when on-since (format-time-string erc-server-timestamp-format - (erc-string-to-emacs-time on-since)))) + (string-to-number on-since)))) (erc-update-user-nick nick nick nil nil nil (and time (format "on since %s" time))) (if time @@ -1796,7 +1800,7 @@ See `erc-display-server-message'." nil (define-erc-response-handler (329) "Channel creation date." nil (let ((channel (cadr (erc-response.command-args parsed))) - (time (erc-string-to-emacs-time + (time (string-to-number (nth 2 (erc-response.command-args parsed))))) (erc-display-message parsed 'notice (erc-get-buffer channel proc) @@ -1838,7 +1842,7 @@ See `erc-display-server-message'." nil (pcase-let ((`(,channel ,nick ,time) (cdr (erc-response.command-args parsed)))) (setq time (format-time-string erc-server-timestamp-format - (erc-string-to-emacs-time time))) + (string-to-number time))) (erc-update-channel-topic channel (format "\C-o (%s, %s)" nick time) 'append) |