comparison 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
comparison
equal deleted inserted replaced
111409:b5cc0d963641 111410:15a32889e96c
322 You can limit here the maximum length of the \"Hello!\" part. 322 You can limit here the maximum length of the \"Hello!\" part.
323 Good luck." 323 Good luck."
324 :type 'integer 324 :type 'integer
325 :group 'erc-server) 325 :group 'erc-server)
326 326
327 (defcustom erc-coding-system-precedence '(utf-8 undecided)
328 "List of coding systems to be preferred when receiving a string from the server.
329 This will only be consulted if the coding system in
330 `erc-server-coding-system' is `undecided'."
331 :group 'erc-server
332 :type '(repeat coding-system))
333
327 (defcustom erc-server-coding-system (if (and (fboundp 'coding-system-p) 334 (defcustom erc-server-coding-system (if (and (fboundp 'coding-system-p)
328 (coding-system-p 'undecided) 335 (coding-system-p 'undecided)
329 (coding-system-p 'utf-8)) 336 (coding-system-p 'utf-8))
330 '(utf-8 . undecided) 337 '(utf-8 . undecided)
331 nil) 338 nil)
332 "The default coding system for incoming and outgoing text. 339 "The default coding system for incoming and outgoing text.
333 This is either a coding system, a cons, a function, or nil. 340 This is either a coding system, a cons, a function, or nil.
334 341
335 If a cons, the encoding system for outgoing text is in the car 342 If a cons, the encoding system for outgoing text is in the car
336 and the decoding system for incoming text is in the cdr. The most 343 and the decoding system for incoming text is in the cdr. The most
337 interesting use for this is to put `undecided' in the cdr. 344 interesting use for this is to put `undecided' in the cdr. This
345 means that `erc-coding-system-precedence' will be consulted, and the
346 first match there will be used.
338 347
339 If a function, it is called with the argument `target' and should 348 If a function, it is called with the argument `target' and should
340 return a coding system or a cons as described above. 349 return a coding system or a cons as described above.
341 350
342 If you need to send non-ASCII text to people not using a client that 351 If you need to send non-ASCII text to people not using a client that
703 (unless (stringp str) 712 (unless (stringp str)
704 (setq str "")) 713 (setq str ""))
705 (let ((coding (erc-coding-system-for-target target))) 714 (let ((coding (erc-coding-system-for-target target)))
706 (when (consp coding) 715 (when (consp coding)
707 (setq coding (cdr coding))) 716 (setq coding (cdr coding)))
717 (when (eq coding 'undecided)
718 (let ((codings (detect-coding-string str))
719 (precedence erc-coding-system-precedence))
720 (while (and precedence
721 (not (memq (car precedence) codings)))
722 (pop precedence))
723 (when precedence
724 (setq coding (car precedence)))))
708 (erc-decode-coding-string str coding))) 725 (erc-decode-coding-string str coding)))
709 726
710 ;; proposed name, not used by anything yet 727 ;; proposed name, not used by anything yet
711 (defun erc-send-line (text display-fn) 728 (defun erc-send-line (text display-fn)
712 "Send TEXT to the current server. Wrapping and flood control apply. 729 "Send TEXT to the current server. Wrapping and flood control apply.