From ec00fc5b4c976bf5111a82d7963eac84dbdecff5 Mon Sep 17 00:00:00 2001 From: ueno Date: Sun, 28 Aug 2005 09:10:39 +0000 Subject: [PATCH] * riece-coding.el (riece-coding-system-alist): New user option. (riece-coding-system-for-prefix-server): New function. (riece-encoded-string): New function. (riece-decoded-string): New alias. (riece-decoded-string-for-identity): New function. --- lisp/ChangeLog | 8 ++++++++ lisp/riece-coding.el | 49 ++++++++++++++++++++++++++++++++++++++----------- lisp/riece-handle.el | 35 ++++++++++++++++------------------- 3 files changed, 62 insertions(+), 30 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 91be375..4357f38 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2005-08-28 Daiki Ueno + + * riece-coding.el (riece-coding-system-alist): New user option. + (riece-coding-system-for-prefix-server): New function. + (riece-encoded-string): New function. + (riece-decoded-string): New alias. + (riece-decoded-string-for-identity): New function. + 2005-08-27 Daiki Ueno * riece-addon.el (riece-uninstall-addon): Don't check the add-on diff --git a/lisp/riece-coding.el b/lisp/riece-coding.el index a505f20..e46db0b 100644 --- a/lisp/riece-coding.el +++ b/lisp/riece-coding.el @@ -44,6 +44,12 @@ specifying the coding systems for decoding and encoding respectively." (const nil :tag "No conversion")) :group 'riece-coding) +(defcustom riece-coding-system-alist nil + "An alist mapping from identities to coding-systems." + :type '(repeat (cons (string :tag "Identity") + (symbol :tag "Coding system"))) + :group 'riece-coding) + (defun riece-encode-coding-string (string) (if (and (local-variable-p 'riece-coding-system (current-buffer)) riece-coding-system) ;should be nil on non-Mule environment @@ -61,17 +67,6 @@ specifying the coding systems for decoding and encoding respectively." riece-coding-system)) string)) -(defun riece-retry-decode-coding-string (string coding-system) - (if (eq (get-text-property 0 'riece-coding-decoded-coding-system string) - coding-system) - string - (riece-decode-coding-string-1 - (get-text-property 0 'riece-coding-encoded-string string) - coding-system))) - -(defun riece-decoded-coding-system (string) - (get-text-property 0 'riece-coding-decoded-coding-system string)) - (defun riece-decode-coding-string-1 (string coding-system) (let* ((decoded (decode-coding-string string coding-system)) (length (length decoded))) @@ -81,6 +76,38 @@ specifying the coding systems for decoding and encoding respectively." coding-system decoded) decoded)) +(defun riece-coding-system-for-prefix-server (prefix server) + (let ((alist riece-coding-system-alist) + identity) + (catch 'found + (while alist + (setq identity (riece-parse-identity (car (car alist)))) + (if (and (equal (riece-identity-server identity) + server) + (equal (riece-identity-prefix identity) + prefix)) + (throw 'found (cdr (car alist)))) + (setq alist (cdr alist)))))) + +(defun riece-decoded-coding-system (string) + (get-text-property 0 'riece-coding-decoded-coding-system string)) + +(defun riece-encoded-string (string) + (get-text-property 0 'riece-coding-encoded-string string)) + +(defalias 'riece-decoded-string 'identity) + +(defun riece-decoded-string-for-identity (string identity) + (let ((coding-system (riece-coding-system-for-prefix-server + (riece-identity-prefix identity) + (riece-identity-server identity)))) + (if (and coding-system + (not (eq (riece-decoded-coding-system string) + coding-system))) + (riece-decode-coding-string-1 (riece-encoded-string string) + coding-system) + string))) + (provide 'riece-coding) ;;; riece-coding.el ends here diff --git a/lisp/riece-handle.el b/lisp/riece-handle.el index e516689..dba185c 100644 --- a/lisp/riece-handle.el +++ b/lisp/riece-handle.el @@ -80,25 +80,22 @@ (defun riece-handle-privmsg-message (prefix string) (let* ((user (riece-prefix-nickname prefix)) - (parameters (riece-split-parameters string)) - (targets (split-string (car parameters) ",")) - (coding-system (cdr (assoc (car targets) riece-coding-system-alist))) - (message (nth 1 parameters))) - (if (eq coding-system - (riece-decoded-coding-system string)) - (riece-display-message - (riece-make-message (riece-make-identity user - riece-server-name) - (riece-make-identity (car targets) - riece-server-name) - message - nil - (riece-identity-equal-no-server - user riece-real-nickname))) - (riece-handle-privmsg-message - prefix - (riece-retry-decode-coding-string string - coding-system))))) + (parameters (riece-split-parameters (riece-decoded-string string))) + (targets (split-string (car parameters) ","))) + (setq parameters (riece-split-parameters + (riece-decoded-string-for-identity + string + (riece-make-identity (car targets) riece-server-name))) + message (nth 1 parameters)) + (riece-display-message + (riece-make-message (riece-make-identity user + riece-server-name) + (riece-make-identity (car targets) + riece-server-name) + message + nil + (riece-identity-equal-no-server + user riece-real-nickname))))) (defun riece-handle-notice-message (prefix string) (let* ((user (if prefix -- 1.7.10.4