From: It's me F. ;) <m_...@16...> - 2004-12-06 00:02:21
|
Damien Elmes <erc...@re...> writes: > Hi folks, > > I jumped on a network the other day which doesn't use any English, and > their server messages (such as MOTD and LIST messages) are sent using > a 7bit character encoding (iso-2022-jp). You can test it if you want > want by going to irc.2ch.net. > > Unfortunately it seems like ERC can't cope with foreign characters in > the server messages yet - at least not on my setup. I hacked up a > quick patch to fix the problem for me, and thought someone might be > interested. It's probably not suitable for inclusion in ERC yet, but I > wanted to know if anyone has thought of a better way to support > foreign characters in this context. Note that I changed the TOPIC > handler since I thought a more generalised solution would be better - > which means that after the patch is applied /topic messages won't be > customisable on a per-channel basis, until > erc-decode-server-message-string is improved. > > Any thoughts? > > Damien > > --- erc-backend.el 10 Nov 2004 17:01:42 +0900 1.15 > +++ erc-backend.el 05 Dec 2004 18:39:31 +0900 > @@ -110,6 +110,19 @@ > (command-args '() :type list) > (contents "" :type string)) > > +(defvar erc-delayed-decoding-responses '("PRIVMSG" "NOTICE") > + "A list of responses which handle character decoding by themselves") > + > +(defun erc-decode-server-message-string (str msg) > + "Decode a server message if a separate handler won't do it later. > +This is useful for /lists, /topics etc on international networks. > +It could modify target based on the network or other information in > +the future." > + (let ((target nil)) ; NYI > + (if (member (erc-response.command msg) erc-delayed-decoding-responses) > + str > + (erc-decode-string-from-target str target)))) > + > (defun erc-parse-server-response (proc string) > "Parse and act upon a complete line from an IRC server. > PROC is the process (connection) from which STRING was received. > @@ -135,15 +148,19 @@ > > (while (and posn > (not (eq (aref string posn) ?:))) > - (push (let* ((bposn posn) > - (eposn (string-match " " string bposn))) > - (setq posn (and eposn > - (string-match "[^ ]" string eposn))) > - (substring string bposn eposn)) > - (erc-response.command-args msg))) > + (push > + (erc-decode-server-message-string > + (let* ((bposn posn) > + (eposn (string-match " " string bposn))) > + (setq posn (and eposn > + (string-match "[^ ]" string eposn))) > + (substring string bposn eposn)) msg) > + (erc-response.command-args msg))) > (when posn > - (let ((str (substring string (1+ posn)))) > - (push str (erc-response.command-args msg)))) > + (let ((str (substring string (1+ posn)))) > + (push > + (erc-decode-server-message-string str msg) > + (erc-response.command-args msg)))) > > (setf (erc-response.contents msg) > (first (erc-response.command-args msg))) > @@ -665,8 +682,7 @@ > (define-erc-response-handler (TOPIC) > nil nil > (let* ((ch (first (erc-response.command-args parsed))) > - (topic (erc-trim-string (erc-decode-string-from-target > - (erc-response.contents parsed) ch))) > + (topic (erc-trim-string (erc-response.contents parsed))) > (time (format-time-string "%T %m/%d/%y" (current-time)))) > (multiple-value-bind (nick login host) > (erc-parse-user (erc-response.sender parsed)) hi, I also write a patch for this. and It is per-channel basic. Here is it: Index: erc-backend.el =================================================================== RCS file: E:\FKtPp\cvsroot/emacs/erc/erc-backend.el,v retrieving revision 1.1.1.3 retrieving revision 1.3 diff -u -r1.1.1.3 -r1.3 --- erc-backend.el 21 Oct 2004 14:25:08 -0000 1.1.1.3 +++ erc-backend.el 21 Oct 2004 14:36:39 -0000 1.3 @@ -151,8 +151,45 @@ (setf (erc-response.command-args msg) (nreverse (erc-response.command-args msg))) + (erc-decode-parsed-server-response msg) + (erc-handle-parsed-server-response proc msg))))) +(defun erc-decode-parsed-server-response (parsed-response) + "Decode a pre-parsed PARSED-RESPONSE before it can be handled. + +Decode `erc-response' acroding the car of it's `command-args' or if +that is not a channel, use the `erc-default-coding-system' to +decoding." + (let* ((args (erc-response.command-args parsed-response)) + (first-arg (car args)) + (matchp (string-match "^[#&].*" first-arg)) + (decode-target (if matchp + (erc-decode-string-from-target first-arg nil) + nil)) + (decoded-args ())) + (setf (erc-response.unparsed parsed-response) + (erc-decode-string-from-target + (erc-response.unparsed parsed-response) + decode-target)) + (setf (erc-response.sender parsed-response) + (erc-decode-string-from-target + (erc-response.sender parsed-response) + decode-target)) + (setf (erc-response.command parsed-response) + (erc-decode-string-from-target + (erc-response.command parsed-response) + decode-target)) + (dolist (arg args nil) + (add-to-list 'decoded-args + (erc-decode-string-from-target arg decode-target) + t)) + (setf (erc-response.command-args parsed-response) decoded-args) + (setf (erc-response.contents parsed-response) + (erc-decode-string-from-target + (erc-response.contents parsed-response) + decode-target)))) + ;; (defun erc-parse-server-response (process response) ;; "Parse a server PROCESS's IRC RESPONSE." ;; ;; FIXME: this function doesn't do the same as our original @@ -602,8 +639,9 @@ (privp (erc-current-nick-p tgt)) s buffer fnick - (msg (erc-decode-string-from-target msg - (if privp sender-spec tgt)))) + ;; (msg (erc-decode-string-from-target msg +;; (if privp sender-spec tgt))) + ) (setf (erc-response.contents parsed) msg) (setq buffer (erc-get-buffer (if privp nick tgt) proc)) (when buffer @@ -665,8 +703,9 @@ (define-erc-response-handler (TOPIC) nil nil (let* ((ch (first (erc-response.command-args parsed))) - (topic (erc-trim-string (erc-decode-string-from-target - (erc-response.contents parsed) ch))) + (topic (erc-trim-string ;; (erc-decode-string-from-target + (erc-response.contents parsed) ;; ch) + )) (time (format-time-string "%T %m/%d/%y" (current-time)))) (multiple-value-bind (nick login host) (erc-parse-user (erc-response.sender parsed)) |