;;; erc-backend.el --- Backend network communication for ERC
-;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
;; Filename: erc-backend.el
;; Author: Lawrence Mitchell <wence@gmx.li>
;;; TODO:
-;; o Generalise the display-line code so that we can use it to
+;; o Generalize the display-line code so that we can use it to
;; display the stuff we send, as well as the stuff we receive.
;; Then, move all display-related code into another backend-like
;; file, erc-display.el, say.
:type 'integer
:group 'erc-server)
+(defcustom erc-coding-system-precedence '(utf-8 undecided)
+ "List of coding systems to be preferred when receiving a string from the server.
+This will only be consulted if the coding system in
+`erc-server-coding-system' is `undecided'."
+ :group 'erc-server
+ :version "24.1"
+ :type '(repeat coding-system))
+
(defcustom erc-server-coding-system (if (and (fboundp 'coding-system-p)
(coding-system-p 'undecided)
(coding-system-p 'utf-8))
If a cons, the encoding system for outgoing text is in the car
and the decoding system for incoming text is in the cdr. The most
-interesting use for this is to put `undecided' in the cdr.
+interesting use for this is to put `undecided' in the cdr. This
+means that `erc-coding-system-precedence' will be consulted, and the
+first match there will be used.
If a function, it is called with the argument `target' and should
return a coding system or a cons as described above.
(defun erc-process-sentinel (cproc event)
"Sentinel function for ERC process."
- (with-current-buffer (process-buffer cproc)
- (erc-log (format
- "SENTINEL: proc: %S status: %S event: %S (quitting: %S)"
- cproc (process-status cproc) event erc-server-quitting))
- (if (string-match "^open" event)
- ;; newly opened connection (no wait)
- (erc-login)
- ;; assume event is 'failed
- (let ((buf (process-buffer cproc)))
- (erc-with-all-buffers-of-server cproc nil
- (setq erc-server-connected nil))
- (when erc-server-ping-handler
- (progn (erc-cancel-timer erc-server-ping-handler)
- (setq erc-server-ping-handler nil)))
- (run-hook-with-args 'erc-disconnected-hook
- (erc-current-nick) (system-name) "")
- ;; Remove the prompt
- (goto-char (or (marker-position erc-input-marker) (point-max)))
- (forward-line 0)
- (erc-remove-text-properties-region (point) (point-max))
- (delete-region (point) (point-max))
- ;; Decide what to do with the buffer
- ;; Restart if disconnected
- (erc-process-sentinel-1 event buf)))))
+ (let ((buf (process-buffer cproc)))
+ (when (buffer-live-p buf)
+ (with-current-buffer buf
+ (erc-log (format
+ "SENTINEL: proc: %S status: %S event: %S (quitting: %S)"
+ cproc (process-status cproc) event erc-server-quitting))
+ (if (string-match "^open" event)
+ ;; newly opened connection (no wait)
+ (erc-login)
+ ;; assume event is 'failed
+ (erc-with-all-buffers-of-server cproc nil
+ (setq erc-server-connected nil))
+ (when erc-server-ping-handler
+ (progn (erc-cancel-timer erc-server-ping-handler)
+ (setq erc-server-ping-handler nil)))
+ (run-hook-with-args 'erc-disconnected-hook
+ (erc-current-nick) (system-name) "")
+ ;; Remove the prompt
+ (goto-char (or (marker-position erc-input-marker) (point-max)))
+ (forward-line 0)
+ (erc-remove-text-properties-region (point) (point-max))
+ (delete-region (point) (point-max))
+ ;; Decide what to do with the buffer
+ ;; Restart if disconnected
+ (erc-process-sentinel-1 event buf))))))
;;;; Sending messages
(let ((coding (erc-coding-system-for-target target)))
(when (consp coding)
(setq coding (cdr coding)))
+ (when (eq coding 'undecided)
+ (let ((codings (detect-coding-string str))
+ (precedence erc-coding-system-precedence))
+ (while (and precedence
+ (not (memq (car precedence) codings)))
+ (pop precedence))
+ (when precedence
+ (setq coding (car precedence)))))
(erc-decode-coding-string str coding)))
;; proposed name, not used by anything yet
(if (member (erc-response.command parsed-response)
erc-server-prevent-duplicates)
(let ((m (erc-response.unparsed parsed-response)))
- ;; duplicate supression
+ ;; duplicate suppression
(if (< (or (gethash m erc-server-duplicates) 0)
(- (erc-current-time) erc-server-duplicate-timeout))
(erc-call-hooks process parsed-response))
(setq buffer (erc-open erc-session-server erc-session-port
nick erc-session-user-full-name
nil nil
- erc-default-recipients chnl
+ (list chnl) chnl
erc-server-process))
(when buffer
(set-buffer buffer)
(when (string= cmd "PRIVMSG")
(erc-auto-query proc parsed))))))
-;; FIXME: need clean way of specifiying extra hooks in
+;; FIXME: need clean way of specifying extra hooks in
;; define-erc-response-handler.
(add-hook 'erc-server-PRIVMSG-functions 'erc-auto-query)
(erc-display-message parsed '(error notice) 'active 's482
?c channel ?m message)))
+(define-erc-response-handler (671)
+ "Secure connection response in WHOIS." nil
+ (let ((nick (second (erc-response.command-args parsed)))
+ (securemsg (erc-response.contents parsed)))
+ (erc-display-message parsed 'notice 'active 's671
+ ?n nick ?a securemsg)))
+
(define-erc-response-handler (431 445 446 451 462 463 464 481 483 484 485
491 501 502)
;; 431 - No nickname given
;; Local Variables:
;; indent-tabs-mode: nil
;; End:
-
-;; arch-tag: a64e6bb7-a780-4efd-8f98-083b18c7c84a