* Riece: Version 0.0.2 released.
[riece] / lisp / riece-coding.el
1 ;;; riece-coding.el --- converting string with coding system
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece, coding-system, MULE
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (require 'riece-globals)
28
29 (defgroup riece-coding nil
30   "Coding system"
31   :tag "Coding"
32   :prefix "riece-"
33   :group 'riece)
34   
35 (defcustom riece-default-coding-system
36   (if (and (or (featurep 'mule)
37                (featurep 'file-coding)))
38       (cons 'ctext 'iso-2022-jp-2))
39   "Coding system for process I/O.
40 The value is a coding system, or a cons cell (DECODING . ENCODING)
41 specifying the coding systems for decoding and encoding respectively."
42   :type '(choice (symbol :tag "Coding system")
43                  (cons (symbol :tag "Input coding system")
44                        (symbol :tag "Output coding system"))
45                  (const nil :tag "No conversion"))
46   :group 'riece-coding)
47
48 (defun riece-encode-coding-string (string)
49   (if (and (local-variable-p 'riece-coding-system (current-buffer))
50            riece-coding-system)         ;should be nil on non-Mule environment
51       (if (consp riece-coding-system)
52           (encode-coding-string string (cdr riece-coding-system))
53         (encode-coding-string string riece-coding-system))
54     string))
55
56 (defun riece-decode-coding-string (string)
57   (if (and (local-variable-p 'riece-coding-system (current-buffer))
58            riece-coding-system)         ;should be nil on non-Mule environment
59       (if (consp riece-coding-system)
60           (decode-coding-string string (car riece-coding-system))
61         (decode-coding-string string riece-coding-system))
62     string))
63
64 (provide 'riece-coding)
65
66 ;;; riece-coding.el ends here