(gnus-set-summary-default-charset): Add comment.
[elisp/gnus.git-] / lisp / gnus-i18n.el
1 ;;; gnus-i18n.el --- Internationalization for Gnus
2
3 ;; Copyright (C) 1996,1997 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Created: 1997/11/27
7 ;; Keywords: internationalization, news, mail
8
9 ;; This file is not part of GNU Emacs yet.
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (require 'gnus-sum)
29 (require 'gnus-util)
30
31 ;;; @ newsgroup default charset
32 ;;;
33
34 (defvar gnus-newsgroup-default-charset-alist
35   '(("^\\(fj\\|tnn\\|japan\\)\\."       . iso-2022-jp-2)
36     ("^han\\."                          . euc-kr)
37     ("^relcom\\."                       . koi8-r)
38     ("^alt\\.chinese\\.text\\.big5"     . cn-big5)
39     ("^hk\\(star\\)?\\."                . cn-big5)
40     ("^tw\\."                           . cn-big5)
41     ("^alt\\.chinese"                   . hz-gb-2312)
42     )
43   "Alist of newsgroup patterns vs. corresponding default MIME charset.
44 Each element looks like (REGEXP . SYMBOL).  REGEXP is pattern for
45 newsgroup name.  SYMBOL is MIME charset or coding-system.")
46
47 (defun gnus-set-newsgroup-default-charset (newsgroup charset)
48   "Set CHARSET for the NEWSGROUP as default MIME charset."
49   (let* ((ng-regexp (concat "^" (regexp-quote newsgroup) "\\($\\|\\.\\)"))
50          (pair (assoc ng-regexp gnus-newsgroup-default-charset-alist)))
51     (if pair
52         (setcdr pair charset)
53       (setq gnus-newsgroup-default-charset-alist
54             (cons (cons ng-regexp charset)
55                   gnus-newsgroup-default-charset-alist)))))
56
57
58 ;;; @ localization
59 ;;;
60
61 (defun gnus-set-summary-default-charset ()
62   "Set up `default-mime-charset' of summary buffer.
63 It is specified by variable `gnus-newsgroup-default-charset-alist'
64 \(cf. function `gnus-set-newsgroup-default-charset')."
65   ;; We are in `nntp-server-buffer' now.
66   (if (buffer-live-p gnus-summary-buffer)
67       (let* ((qgroup (save-excursion
68                        (set-buffer gnus-summary-buffer)
69                        gnus-newsgroup-name))
70              (rgroup (gnus-group-real-name qgroup))
71              alist pair charset)
72         (setq charset (catch 'found
73                         ;; First, use "qualified" newsgroup name.
74                         (setq alist gnus-newsgroup-default-charset-alist)
75                         (while (setq pair (car alist))
76                           (if (string-match (car pair) qgroup)
77                               (throw 'found (cdr pair)))
78                           (setq alist (cdr alist)))
79                         ;; Next, try "real" newsgroup name.
80                         (setq alist gnus-newsgroup-default-charset-alist)
81                         (while (setq pair (car alist))
82                           (if (string-match (car pair) rgroup)
83                               (throw 'found (cdr pair)))
84                           (setq alist (cdr alist)))))
85         (if charset
86             (progn
87               (save-excursion
88                 ;; Set `default-mime-charset' in summary buffer.
89                 (set-buffer gnus-summary-buffer)
90                 (make-local-variable 'default-mime-charset)
91                 (setq default-mime-charset charset))
92               ;; Also set `default-mime-charset' in current buffer.
93               (make-local-variable 'default-mime-charset)
94               (setq default-mime-charset charset))
95           ;; Reset `default-mime-charset' in current buffer.
96           (kill-local-variable 'default-mime-charset)))))
97
98 (defun gnus-get-summary-default-charset ()
99   "Get the value of `default-mime-charset' from summary buffer."
100   (and (buffer-live-p gnus-summary-buffer)
101        (save-excursion
102          (set-buffer gnus-summary-buffer)
103          default-mime-charset)))
104
105
106 ;;; @ end
107 ;;;
108
109 (provide 'gnus-i18n)
110
111 ;;; gnus-i18n.el ends here