summaryrefslogtreecommitdiff
path: root/lisp/erc
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen <larsi@gnus.org>2010-11-05 15:17:46 +0100
committerLars Magne Ingebrigtsen <larsi@gnus.org>2010-11-05 15:17:46 +0100
commit5c0c0f77b0b3af28653a6a8e798f69d132425c0e (patch)
tree6c484c9782fc9a92497fc9674fb2b6f4bf56adb1 /lisp/erc
parente06918d22b68821e7c1aa8148622232f106fbfc5 (diff)
downloademacs-5c0c0f77b0b3af28653a6a8e798f69d132425c0e.tar.gz
Decode utf-8 strings in mixed environments by default.
Done via the new `erc-coding-system-precedence' variable.
Diffstat (limited to 'lisp/erc')
-rw-r--r--lisp/erc/ChangeLog5
-rw-r--r--lisp/erc/erc-backend.el19
2 files changed, 23 insertions, 1 deletions
diff --git a/lisp/erc/ChangeLog b/lisp/erc/ChangeLog
index 49f039c51b9..1f27dbdb7f7 100644
--- a/lisp/erc/ChangeLog
+++ b/lisp/erc/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-05 Lars Magne Ingebrigtsen <larsi@gnus.org>
+
+ * erc-backend.el (erc-coding-system-precedence): New variable.
+ (erc-decode-string-from-target): Use it.
+
2010-10-24 Julien Danjou <julien@danjou.info>
* erc-backend.el (erc-server-JOIN): Set the correct target list on join.
diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 46e9d6c8c2c..3bc56989f4f 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -324,6 +324,13 @@ Good luck."
: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 @@ This is either a coding system, a cons, a function, or nil.
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 @@ This is indicated by `erc-encoding-coding-alist', defaulting to the value of
(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