annotate lisp/textmodes/po.el @ 47985:9f3ecf5e3d65

(risky-local-variable-p): New function. (compile-command): Use `stringp' for `safe-local-variable' prop. (hack-one-local-variable): Use `risky-local-variable-p'.
author Richard M. Stallman <rms@gnu.org>
date Wed, 23 Oct 2002 17:38:44 +0000
parents 6082da91c94d
children 10d4bf044393
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43926
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
1 ;;; po.el --- basic support of PO translation files -*- coding: latin-1; -*-
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
2
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
4
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
5 ;; Authors: François Pinard <pinard@iro.umontreal.ca>,
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
6 ;; Greg McGary <gkm@magilla.cichlid.com>,
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
7 ;; Bruno Haible <bruno@clisp.org>.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
8 ;; Keywords: i18n, files
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
9
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
11
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
15 ;; any later version.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
16
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
21
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
26
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
28
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
29 ;; This package makes sure visiting PO files decodes them correctly,
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
30 ;; according to the Charset= header in the PO file. For more support
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
31 ;; for editing PO files, see po-mode.el.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
32
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
33 ;;; Code:
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
34
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
35 (defconst po-content-type-charset-alist
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
36 '(; Note: Emacs 21 doesn't support all encodings, thus the missing entries.
43958
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
37 ("ASCII" . undecided)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
38 ("ANSI_X3.4-1968" . undecided)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
39 ("US-ASCII" . undecided)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
40 ("ISO-8859-1" . iso-8859-1)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
41 ("ISO_8859-1" . iso-8859-1)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
42 ("ISO-8859-2" . iso-8859-2)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
43 ("ISO_8859-2" . iso-8859-2)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
44 ("ISO-8859-3" . iso-8859-3)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
45 ("ISO_8859-3" . iso-8859-3)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
46 ("ISO-8859-4" . iso-8859-4)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
47 ("ISO_8859-4" . iso-8859-4)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
48 ("ISO-8859-5" . iso-8859-5)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
49 ("ISO_8859-5" . iso-8859-5)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
50 ;("ISO-8859-6" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
51 ;("ISO_8859-6" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
52 ("ISO-8859-7" . iso-8859-7)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
53 ("ISO_8859-7" . iso-8859-7)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
54 ("ISO-8859-8" . iso-8859-8)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
55 ("ISO_8859-8" . iso-8859-8)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
56 ("ISO-8859-9" . iso-8859-9)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
57 ("ISO_8859-9" . iso-8859-9)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
58 ;("ISO-8859-13" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
59 ;("ISO_8859-13" . ??)
47655
6082da91c94d Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 43958
diff changeset
60 ;("ISO-8859-14" . ??)
6082da91c94d Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 43958
diff changeset
61 ;("ISO_8859-14" . ??)
43958
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
62 ("ISO-8859-15" . iso-8859-15) ; requires Emacs 21
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
63 ("ISO_8859-15" . iso-8859-15) ; requires Emacs 21
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
64 ("KOI8-R" . koi8-r)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
65 ;("KOI8-U" . ??)
47655
6082da91c94d Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 43958
diff changeset
66 ;("KOI8-T" . ??)
43958
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
67 ("CP437" . cp437) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
68 ("CP775" . cp775) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
69 ("CP850" . cp850) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
70 ("CP852" . cp852) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
71 ("CP855" . cp855) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
72 ;("CP856" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
73 ("CP857" . cp857) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
74 ("CP861" . cp861) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
75 ("CP862" . cp862) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
76 ("CP864" . cp864) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
77 ("CP865" . cp865) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
78 ("CP866" . cp866) ; requires Emacs 21
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
79 ("CP869" . cp869) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
80 ;("CP874" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
81 ;("CP922" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
82 ;("CP932" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
83 ;("CP943" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
84 ;("CP949" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
85 ;("CP950" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
86 ;("CP1046" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
87 ;("CP1124" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
88 ;("CP1129" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
89 ("CP1250" . cp1250) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
90 ("CP1251" . cp1251) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
91 ("CP1252" . iso-8859-1) ; approximation
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
92 ("CP1253" . cp1253) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
93 ("CP1254" . iso-8859-9) ; approximation
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
94 ("CP1255" . iso-8859-8) ; approximation
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
95 ;("CP1256" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
96 ("CP1257" . cp1257) ; requires Emacs 20
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
97 ("GB2312" . cn-gb-2312) ; also named 'gb2312' in XEmacs 21 or Emacs 21
43926
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
98 ; also named 'euc-cn' in Emacs 20 or Emacs 21
43958
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
99 ("EUC-JP" . euc-jp)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
100 ("EUC-KR" . euc-kr)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
101 ;("EUC-TW" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
102 ("BIG5" . big5)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
103 ;("BIG5-HKSCS" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
104 ;("GBK" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
105 ;("GB18030" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
106 ("SHIFT_JIS" . shift_jis)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
107 ;("JOHAB" . ??)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
108 ("TIS-620" . tis-620) ; requires Emacs 20 or Emacs 21
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
109 ("VISCII" . viscii) ; requires Emacs 20 or Emacs 21
47655
6082da91c94d Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 43958
diff changeset
110 ;("GEORGIAN-PS" . ??)
43958
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
111 ("UTF-8" . utf-8) ; requires Mule-UCS in Emacs 20, or Emacs 21
43926
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
112 )
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
113 "How to convert a GNU libc/libiconv canonical charset name as seen in
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
114 Content-Type into a Mule coding system.")
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
115
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
116 (defun po-find-charset (filename)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
117 "Return PO file charset value."
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
118 (interactive)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
119 (let ((charset-regexp
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
120 "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"")
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
121 (short-read nil))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
122 ;; Try the first 4096 bytes. In case we cannot find the charset value
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
123 ;; within the first 4096 bytes (the PO file might start with a long
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
124 ;; comment) try the next 4096 bytes repeatedly until we'll know for sure
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
125 ;; we've checked the empty header entry entirely.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
126 (while (not (or short-read (re-search-forward "^msgid" nil t)))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
127 (save-excursion
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
128 (goto-char (point-max))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
129 (let ((pair (insert-file-contents-literally filename nil
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
130 (1- (point))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
131 (1- (+ (point) 4096)))))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
132 (setq short-read (< (nth 1 pair) 4096)))))
43952
bd36495e6ade (po-find-charset): Search for Charset= header even if we've read less than
Eli Zaretskii <eliz@gnu.org>
parents: 43937
diff changeset
133 (cond ((re-search-forward charset-regexp nil t) (match-string 1))
bd36495e6ade (po-find-charset): Search for Charset= header even if we've read less than
Eli Zaretskii <eliz@gnu.org>
parents: 43937
diff changeset
134 (short-read nil)
43926
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
135 ;; We've found the first msgid; maybe, only a part of the msgstr
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
136 ;; value was loaded. Load the next 1024 bytes; if charset still
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
137 ;; isn't available, give up.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
138 (t (save-excursion
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
139 (goto-char (point-max))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
140 (insert-file-contents-literally filename nil
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
141 (1- (point))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
142 (1- (+ (point) 1024))))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
143 (if (re-search-forward charset-regexp nil t)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
144 (match-string 1))))))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
145
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
146 (defun po-find-file-coding-system-guts (operation filename)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
147 "\
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
148 Return a Mule (DECODING . ENCODING) pair, according to PO file charset.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
149 Called through file-coding-system-alist, before the file is visited for real."
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
150 (and (eq operation 'insert-file-contents)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
151 (file-exists-p filename)
43937
e572fbd0d2c8 (po-find-file-coding-system-guts): Use
Eli Zaretskii <eliz@gnu.org>
parents: 43926
diff changeset
152 (with-temp-buffer
43926
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
153 (let* ((coding-system-for-read 'no-conversion)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
154 (charset (or (po-find-charset filename) "ascii"))
43958
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
155 (charset-upper (upcase charset))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
156 (charset-lower (downcase charset))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
157 (candidate
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
158 (cdr (assoc charset-upper po-content-type-charset-alist)))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
159 (try (or candidate (intern-soft charset-lower))))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
160 (list (cond ((and try (coding-system-p try))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
161 try)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
162 ((and try
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
163 (string-match "\\`cp[1-9][0-9][0-9]?\\'"
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
164 (symbol-name try))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
165 (assoc (substring (symbol-name try) 2)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
166 (cp-supported-codepages)))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
167 (codepage-setup (substring (symbol-name try) 2))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
168 try)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
169 ((and (string-match "\\`cp[1-9][0-9][0-9]?\\'"
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
170 charset-lower)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
171 (assoc (substring charset-lower 2)
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
172 (cp-supported-codepages)))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
173 (codepage-setup (substring charset-lower 2))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
174 (intern charset-lower))
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
175 (t
2479ec7d435b (po-content-type-charset-alist): Convert the
Eli Zaretskii <eliz@gnu.org>
parents: 43954
diff changeset
176 'no-conversion)))))))
43926
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
177
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
178 ;;;###autoload
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
179 (defun po-find-file-coding-system (arg-list)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
180 "\
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
181 Return a Mule (DECODING . ENCODING) pair, according to PO file charset.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
182 Called through file-coding-system-alist, before the file is visited for real."
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
183 (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list))))
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
184 ;; This is for XEmacs.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
185 ;(defun po-find-file-coding-system (operation filename)
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
186 ; "\
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
187 ;Return a Mule (DECODING . ENCODING) pair, according to PO file charset.
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
188 ;Called through file-coding-system-alist, before the file is visited for real."
11fdbf69b362 New file.
Eli Zaretskii <eliz@gnu.org>
parents:
diff changeset
189 ; (po-find-file-coding-system-guts operation filename))