Mercurial > emacs
diff lisp/erc/erc-backend.el @ 111410:15a32889e96c
Decode utf-8 strings in mixed environments by default.
Done via the new `erc-coding-system-precedence' variable.
author | Lars Magne Ingebrigtsen <larsi@gnus.org> |
---|---|
date | Fri, 05 Nov 2010 15:17:46 +0100 |
parents | bf6806de6892 |
children | 417b1e4d63cd |
line wrap: on
line diff
--- a/lisp/erc/erc-backend.el Fri Nov 05 13:11:12 2010 +0100 +++ b/lisp/erc/erc-backend.el Fri Nov 05 15:17:46 2010 +0100 @@ -324,6 +324,13 @@ :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 + :type '(repeat coding-system)) + (defcustom erc-server-coding-system (if (and (fboundp 'coding-system-p) (coding-system-p 'undecided) (coding-system-p 'utf-8)) @@ -334,7 +341,9 @@ 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. @@ -705,6 +714,14 @@ (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