X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Friece-identity.el;h=b1a2f340d299db7ab9d16e5f2015c4518c52cc5d;hb=bf3cea82e421d7bc2b717780c4d30805899847c0;hp=adada4caa19025c00a96a2a77b24c6d927e753a2;hpb=2244c15ef11848cbc76e818e37a52c22fe359076;p=riece diff --git a/lisp/riece-identity.el b/lisp/riece-identity.el index adada4c..b1a2f34 100644 --- a/lisp/riece-identity.el +++ b/lisp/riece-identity.el @@ -19,14 +19,20 @@ ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. ;;; Code: (require 'riece-globals) (require 'riece-coding) +(defcustom riece-channel-coding-system-alist nil + "An alist mapping from channels to coding-systems." + :type '(repeat (cons (string :tag "Channel") + (symbol :tag "Coding system"))) + :group 'riece-coding) + (defvar riece-abbrev-identity-string-function nil) (defvar riece-expand-identity-string-function nil) @@ -184,6 +190,40 @@ The rest of arguments are the same as `completing-read'." ;;; (error "Invalid channel name!")) identity)) +(defun riece-coding-system-for-identity (identity) + (let ((alist riece-channel-coding-system-alist) + matcher) + (catch 'found + (while alist + (setq matcher (riece-parse-identity (car (car alist)))) + (if (and (equal (riece-identity-server matcher) + (riece-identity-server identity)) + (equal (riece-identity-prefix matcher) + (riece-identity-prefix identity))) + (throw 'found (cdr (car alist)))) + (setq alist (cdr alist)))))) + +(defun riece-decoded-string-for-identity (decoded identity) + "Return the string decoded for IDENTITY." + (let ((coding-system (riece-coding-system-for-identity identity))) + (if (and coding-system + (not (eq (riece-decoded-coding-system decoded) + (if (consp coding-system) + (car coding-system) + coding-system)))) + (riece-decode-coding-string-1 (riece-decoded-encoded-string decoded) + coding-system) + decoded))) + +(defun riece-encode-coding-string-for-identity (string identity) + (let ((coding-system (riece-coding-system-for-identity identity))) + (if coding-system + (encode-coding-string string + (if (consp coding-system) + (cdr coding-system) + coding-system)) + (riece-encode-coding-string string)))) + (provide 'riece-identity) ;;; riece-identity.el ends here