-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnonascii.texi
1878 lines (1692 loc) · 96.2 KB
/
nonascii.texi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@c -*-texinfo-*-
@c This is part of the GNU Emacs Lisp Reference Manual.
@c Copyright (C) 1998 Free Software Foundation, Inc.
@c See the file elisp.texi for copying conditions.
@setfilename ../info/characters
@node Non-ASCII Characters, Searching and Matching, Text, Top
@c @chapter Non-ASCII Characters
@chapter 非ASCII文字
@c @cindex multibyte characters
@c @cindex non-ASCII characters
@cindex マルチバイト文字
@cindex 非ASCII文字
@c This chapter covers the special issues relating to non-@sc{ASCII}
@c characters and how they are stored in strings and buffers.
本章では、非@sc{ASCII}に関連する特別なことがらと
それらが文字列やバッファにどのように保存されるかについて述べます。
@menu
* Text Representations::
* Converting Representations::
* Selecting a Representation::
* Character Codes::
* Character Sets::
* Chars and Bytes::
* Splitting Characters::
* Scanning Charsets::
* Translation of Characters::
* Coding Systems::
* Input Methods::
@end menu
@node Text Representations
@c @section Text Representations
@section テキスト表現
@c @cindex text representations
@cindex テキスト表現
@c Emacs has two @dfn{text representations}---two ways to represent text
@c in a string or buffer. These are called @dfn{unibyte} and
@c @dfn{multibyte}. Each string, and each buffer, uses one of these two
@c representations. For most purposes, you can ignore the issue of
@c representations, because Emacs converts text between them as
@c appropriate. Occasionally in Lisp programming you will need to pay
@c attention to the difference.
Emacsには2つの@dfn{テキスト表現}、つまり、
文字列やバッファでテキストを表す方法が2つあります。
これらは、@dfn{ユニバイト}(unibyte)と
@dfn{マルチバイト}(multibyte)と呼ばれます。
各文字列や各バッファでは、これらの2つの表現の一方を使います。
ほとんどの目的には、Emacsがこれらのあいだで適切に変換するので、
読者はこれらの表現に関しては無視できます。
Lispプログラムでは、これらの違いに注意する必要がしばしばあります。
@c @cindex unibyte text
@cindex ユニバイトテキスト
@c In unibyte representation, each character occupies one byte and
@c therefore the possible character codes range from 0 to 255. Codes 0
@c through 127 are @sc{ASCII} characters; the codes from 128 through 255
@c are used for one non-@sc{ASCII} character set (you can choose which
@c character set by setting the variable @code{nonascii-insert-offset}).
ユニバイト表現では、各文字は1バイトを占め、
そのため、可能な文字コードの範囲は0から255です。
コード0から127は@sc{ASCII}文字です。
コード128から255は非@sc{ASCII}文字集合の1つ
(変数@code{nonascii-insert-offset}に設定して文字集合を選べる)
に使われます。
@c @cindex leading code
@c @cindex multibyte text
@c @cindex trailing codes
@cindex リーディングコード
@cindex マルチバイトテキスト
@cindex トレイリングコード
@c In multibyte representation, a character may occupy more than one
@c byte, and as a result, the full range of Emacs character codes can be
@c stored. The first byte of a multibyte character is always in the range
@c 128 through 159 (octal 0200 through 0237). These values are called
@c @dfn{leading codes}. The second and subsequent bytes of a multibyte
@c character are always in the range 160 through 255 (octal 0240 through
@c 0377); these values are @dfn{trailing codes}.
マルチバイト表現では、1文字は1バイト以上を占め、
そのため、Emacsの文字コードの範囲全体を格納できるのです。
マルチバイト文字の最初のバイトはつねに128から159(8進数で0200から0237)の
範囲にあります。
これらの値を@dfn{リーディングコード}(leading code)と呼びます。
マルチバイト文字の2バイト以降はつねに160から255(8進数で0240から0377)の
範囲にあります。
これらの値を@dfn{トレイリングコード}(trailing code)と呼びます。
@c In a buffer, the buffer-local value of the variable
@c @code{enable-multibyte-characters} specifies the representation used.
@c The representation for a string is determined based on the string
@c contents when the string is constructed.
バッファでは、変数@code{enable-multibyte-characters}の
バッファローカルな値が使用する表現を指定します。
文字列の表現は、文字列を作成するときの文字列の内容に基づいて決定されます。
@defvar enable-multibyte-characters
@tindex enable-multibyte-characters
@c This variable specifies the current buffer's text representation.
@c If it is non-@code{nil}, the buffer contains multibyte text; otherwise,
@c it contains unibyte text.
この変数は、バッファのテキスト表現を指定する。
これが@code{nil}以外であると、バッファはマルチバイトテキストを保持する。
さもなければユニバイトテキストを保持する。
@c You cannot set this variable directly; instead, use the function
@c @code{set-buffer-multibyte} to change a buffer's representation.
この変数に直接設定することはできない。
そのかわりに、バッファの表現を変更するには、
関数@code{set-buffer-multibyte}を使う。
@end defvar
@defvar default-enable-multibyte-characters
@tindex default-enable-multibyte-characters
@c This variable's value is entirely equivalent to @code{(default-value
@c 'enable-multibyte-characters)}, and setting this variable changes that
@c default value. Setting the local binding of
@c @code{enable-multibyte-characters} in a specific buffer is not allowed,
@c but changing the default value is supported, and it is a reasonable
@c thing to do, because it has no effect on existing buffers.
この変数の値は、
@code{(default-value 'enable-multibyte-characters)}に完全に等価であり、
この変数に設定するとデフォルト値を変更する。
バッファの@code{enable-multibyte-characters}のローカルな束縛に設定することは
許されていないが、デフォルト値を変更することは可能であり、
そうしても既存のバッファには影響しないので理にかなっている。
@c The @samp{--unibyte} command line option does its job by setting the
@c default value to @code{nil} early in startup.
コマンド行オプション@samp{--unibyte}は、
起動時の早い段階でデフォルト値に@code{nil}を設定することで役目を果たす。
@end defvar
@defun multibyte-string-p string
@tindex multibyte-string-p
@c Return @code{t} if @var{string} contains multibyte characters.
文字列@var{string}にマルチバイト文字が含まれると@code{t}を返す。
@end defun
@node Converting Representations
@c @section Converting Text Representations
@section テキスト表現の変換
@c Emacs can convert unibyte text to multibyte; it can also convert
@c multibyte text to unibyte, though this conversion loses information. In
@c general these conversions happen when inserting text into a buffer, or
@c when putting text from several strings together in one string. You can
@c also explicitly convert a string's contents to either representation.
Emacsはユニバイトテキストをマルチバイトに変換できます。
マルチバイトテキストをユニバイトにも変換できますが、
この変換では情報が欠落します。
バッファにテキストを挿入するとき、あるいは、
複数の文字列から1つの文字列にテキストを収めるときに、
一般にこれらの変換が行われます。
文字列の内容をどちらかの表現に明示的にも変換できます。
@c Emacs chooses the representation for a string based on the text that
@c it is constructed from. The general rule is to convert unibyte text to
@c multibyte text when combining it with other multibyte text, because the
@c multibyte representation is more general and can hold whatever
@c characters the unibyte text has.
Emacsは、文字列を作成するときにはその内容に基づいて
文字列の表現を選びます。
一般則は、ユニバイトテキストを他のマルチバイトテキストに組み入れるときには
ユニバイトテキストをマルチバイトテキストに変換します。
マルチバイト表現のほうが汎用であり、
ユニバイトテキストのどんな文字でも保持できるからです。
@c When inserting text into a buffer, Emacs converts the text to the
@c buffer's representation, as specified by
@c @code{enable-multibyte-characters} in that buffer. In particular, when
@c you insert multibyte text into a unibyte buffer, Emacs converts the text
@c to unibyte, even though this conversion cannot in general preserve all
@c the characters that might be in the multibyte text. The other natural
@c alternative, to convert the buffer contents to multibyte, is not
@c acceptable because the buffer's representation is a choice made by the
@c user that cannot be overridden automatically.
バッファにテキストを挿入するときには、Emacsは、
当該バッファの@code{enable-multibyte-characters}の指定に従った
バッファの表現にテキストを変換します。
特に、ユニバイトバッファにマルチバイトテキストを挿入するときには、
マルチバイトテキスト内のすべての文字を一般には保存できなくても、
Emacsはテキストをユニバイトに変換します。
自然な代替案はバッファ内容をマルチバイトに変換することですが、
これは受け入れられません。
バッファの表現はユーザーが選択したものであり自動的には無視できないからです。
@c Converting unibyte text to multibyte text leaves @sc{ASCII} characters
@c unchanged, and likewise 128 through 159. It converts the non-@sc{ASCII}
@c codes 160 through 255 by adding the value @code{nonascii-insert-offset}
@c to each character code. By setting this variable, you specify which
@c character set the unibyte characters correspond to (@pxref{Character
@c Sets}). For example, if @code{nonascii-insert-offset} is 2048, which is
@c @code{(- (make-char 'latin-iso8859-1) 128)}, then the unibyte
@c non-@sc{ASCII} characters correspond to Latin 1. If it is 2688, which
@c is @code{(- (make-char 'greek-iso8859-7) 128)}, then they correspond to
@c Greek letters.
ユニバイトテキストをマルチバイトテキストに変換しても
@sc{ASCII}文字は無変更であり、128から159も同様です。
160から255の非@sc{ASCII}については、
各文字に@code{nonascii-insert-offset}の値を加算することで変換します。
この変数に設定すると、ユニバイト文字がどの文字集合に対応するかを指定できます
(@pxref{Character Sets})。
たとえば、@code{nonascii-insert-offset}が
@code{(- (make-char 'latin-iso8859-1) 128)}の2048であると、
非@sc{ASCII}のユニバイトはLatin 1に対応します。
@code{(- (make-char 'greek-iso8859-7) 128)}の2688であると、
ギリシャ文字に対応します。
@c Converting multibyte text to unibyte is simpler: it performs
@c logical-and of each character code with 255. If
@c @code{nonascii-insert-offset} has a reasonable value, corresponding to
@c the beginning of some character set, this conversion is the inverse of
@c the other: converting unibyte text to multibyte and back to unibyte
@c reproduces the original unibyte text.
マルチバイトテキストをユニバイトに変換するのは簡単で、
各文字コードと255の論理積をとります。
@code{nonascii-insert-offset}に
文字集合の始まりに対応する合理的な値が設定されていれば、
この変換は逆変換になります。
つまり、ユニバイトテキストをマルチバイトに変換し、
それをユニバイトに戻すともとのユニバイトテキストになります。
@defvar nonascii-insert-offset
@tindex nonascii-insert-offset
@c This variable specifies the amount to add to a non-@sc{ASCII} character
@c when converting unibyte text to multibyte. It also applies when
@c @code{self-insert-command} inserts a character in the unibyte
@c non-@sc{ASCII} range, 128 through 255. However, the function
@c @code{insert-char} does not perform this conversion.
この変数は、ユニバイトテキストをマルチバイトに変換するときに
非@sc{ASCII}文字に加算する値を指定する。
これは、128から255のユニバイトの非@sc{ASCII}の範囲の文字を挿入する
@code{self-insert-command}にも適用される。
しかし、関数@code{insert-char}はこの変換を行わない。
@c The right value to use to select character set @var{cs} is @code{(-
@c (make-char @var{cs}) 128)}. If the value of
@c @code{nonascii-insert-offset} is zero, then conversion actually uses the
@c value for the Latin 1 character set, rather than zero.
文字集合@var{cs}を選択する正しい値は、
@code{(- (make-char @var{cs}) 128)}である。
@code{nonascii-insert-offset}の値が0であると、
実際の変換には0ではなくLatin 1文字集合に対する値を使う。
@end defvar
@defvar nonascii-translation-table
@tindex nonascii-translation-table
@c This variable provides a more general alternative to
@c @code{nonascii-insert-offset}. You can use it to specify independently
@c how to translate each code in the range of 128 through 255 into a
@c multibyte character. The value should be a vector, or @code{nil}.
@c If this is non-@code{nil}, it overrides @code{nonascii-insert-offset}.
この変数は、@code{nonascii-insert-offset}のより一般的な代替を提供する。
128から255の範囲の各コードをマルチバイト文字に変換する方法を
独立して指定するために使える。
その値はベクトルか@code{nil}であること。
これが@code{nil}以外であると、@code{nonascii-insert-offset}に優先する。
@end defvar
@defun string-make-unibyte string
@tindex string-make-unibyte
@c This function converts the text of @var{string} to unibyte
@c representation, if it isn't already, and returns the result. If
@c @var{string} is a unibyte string, it is returned unchanged.
この関数は、@var{string}のテキストがすでにユニバイトでなければ
ユニバイト表現に変換してから結果を返す。
@var{string}がユニバイトであれば無変更で返す。
@end defun
@defun string-make-multibyte string
@tindex string-make-multibyte
@c This function converts the text of @var{string} to multibyte
@c representation, if it isn't already, and returns the result. If
@c @var{string} is a multibyte string, it is returned unchanged.
この関数は、@var{string}のテキストがすでにマルチバイトでなければ
マルチバイト表現に変換してから結果を返す。
@var{string}がマルチバイトであれば無変更で返す。
@end defun
@node Selecting a Representation
@c @section Selecting a Representation
@section 表現の選択
@c Sometimes it is useful to examine an existing buffer or string as
@c multibyte when it was unibyte, or vice versa.
既存のバッファや文字列がユニバイトであるときに
マルチバイトとして調べたり、その逆のように調べるのが
有用なこともあります
@defun set-buffer-multibyte multibyte
@tindex set-buffer-multibyte
@c Set the representation type of the current buffer. If @var{multibyte}
@c is non-@code{nil}, the buffer becomes multibyte. If @var{multibyte}
@c is @code{nil}, the buffer becomes unibyte.
カレントバッファの表現方法を設定する。
@var{multibyte}が@code{nil}以外であると、バッファはマルチバイトになる。
@var{multibyte}が@code{nil}であると、バッファはユニバイトになる。
@c This function leaves the buffer contents unchanged when viewed as a
@c sequence of bytes. As a consequence, it can change the contents viewed
@c as characters; a sequence of two bytes which is treated as one character
@c in multibyte representation will count as two characters in unibyte
@c representation.
この関数は、バイト列としてみたバッファ内容を変更しない。
その結果、文字として見たときの内容を変更できる。
マルチバイト表現では1文字とみなされる2バイトの列は、
ユニバイト表現では2文字になる。
@c This function sets @code{enable-multibyte-characters} to record which
@c representation is in use. It also adjusts various data in the buffer
@c (including overlays, text properties and markers) so that they cover the
@c same text as they did before.
この関数は、@code{enable-multibyte-characters}に
どちらの表現を使用しているかを記録する。
さらに(オーバレイ、テキスト属性、マーカなどの)バッファ内のさまざまな
データを調整して、それ以前と同様に同じテキストに及ぶようにする。
@end defun
@defun string-as-unibyte string
@tindex string-as-unibyte
@c This function returns a string with the same bytes as @var{string} but
@c treating each byte as a character. This means that the value may have
@c more characters than @var{string} has.
この関数は、各バイトを1文字とみなして
@var{string}と同じバイトの文字列を返す。
つまり、値には@var{string}より多くの文字が含まれることがある。
@c If @var{string} is unibyte already, then the value is @var{string}
@c itself.
@var{string}がすでにユニバイトであると、
値は@var{string}そのものである。
@end defun
@defun string-as-multibyte string
@tindex string-as-multibyte
@c This function returns a string with the same bytes as @var{string} but
@c treating each multibyte sequence as one character. This means that the
@c value may have fewer characters than @var{string} has.
この関数は、マルチバイトの各列を1文字とみなして
@var{string}と同じバイトの文字列を返す。
つまり、値には@var{string}より少ない文字が含まれることがある。
@c If @var{string} is multibyte already, then the value is @var{string}
@c itself.
@var{string}がすでにマルチバイトであると、
値は@var{string}そのものである。
@end defun
@node Character Codes
@c @section Character Codes
@section 文字コード
@c @cindex character codes
@cindex 文字コード
@c The unibyte and multibyte text representations use different character
@c codes. The valid character codes for unibyte representation range from
@c 0 to 255---the values that can fit in one byte. The valid character
@c codes for multibyte representation range from 0 to 524287, but not all
@c values in that range are valid. In particular, the values 128 through
@c 255 are not legitimate in multibyte text (though they can occur in ``raw
@c bytes''; @pxref{Explicit Encoding}). Only the @sc{ASCII} codes 0
@c through 127 are fully legitimate in both representations.
ユニバイトとマルチバイトのテキスト表現では、
異なる文字コードを使っています。
ユニバイト表現において正しい文字コードは0から255の範囲であり、
これらの値は1バイトに収まります。
マルチバイト表現において正しい文字コードは0から524287の範囲ですが、
この範囲のすべての値が正しいとは限りません。
特に、値128から255は
(『生のバイト』にはありうる。@pxref{Explicit Encoding})、
マルチバイトテキストでは正しくありません。
0から127の@sc{ASCII}コードのみが、どちらの表現でも完全に正しいのです。
@defun char-valid-p charcode
@c This returns @code{t} if @var{charcode} is valid for either one of the two
@c text representations.
この関数は、@var{charcode}が2つのテキスト表現のどちらか一方で
正しければ@code{t}を返す。
@example
(char-valid-p 65)
@result{} t
(char-valid-p 256)
@result{} nil
(char-valid-p 2248)
@result{} t
@end example
@end defun
@node Character Sets
@c @section Character Sets
@section 文字集合
@c @cindex character sets
@cindex 文字集合
@c Emacs classifies characters into various @dfn{character sets}, each of
@c which has a name which is a symbol. Each character belongs to one and
@c only one character set.
Emacsは文字をさまざまな@dfn{文字集合}(character set)に分類します。
文字集合にはシンボルである名前があります。
各文字はたった1つの文字集合に属します。
@c In general, there is one character set for each distinct script. For
@c example, @code{latin-iso8859-1} is one character set,
@c @code{greek-iso8859-7} is another, and @code{ascii} is another. An
@c Emacs character set can hold at most 9025 characters; therefore, in some
@c cases, characters that would logically be grouped together are split
@c into several character sets. For example, one set of Chinese
@c characters, generally known as Big 5, is divided into two Emacs
@c character sets, @code{chinese-big5-1} and @code{chinese-big5-2}.
一般に、異なる文字体系ごとに1つの文字集合があります。
たとえば、@code{latin-iso8859-1}は1つの文字集合であり、
@code{greek-iso8859-7}は別の文字集合であり、
@code{ascii}も別の文字集合です。
Emacsの1つの文字集合には最大9025個の文字を保持できます。
したがって、論理的には1つの文字集合にまとめられる文字群を、
複数の文字集合に分割する場合もあります。
たとえば、Big 5として一般には知られている中国文字の1つの集合は、
Emacsの2つの文字集合、@code{chinese-big5-1}と@code{chinese-big5-2}に
分割されます。
@defun charsetp object
@tindex charsetp
@c Return @code{t} if @var{object} is a character set name symbol,
@c @code{nil} otherwise.
@var{object}が文字集合の名前のシンボルであれば@code{t}を返す。
さもなければ@code{nil}を返す。
@end defun
@defun charset-list
@tindex charset-list
@c This function returns a list of all defined character set names.
この関数は、定義されているすべての文字集合の名前のリストを返す。
@end defun
@defun char-charset character
@tindex char-charset
@c This function returns the name of the character
@c set that @var{character} belongs to.
この関数は文字@var{character}が属する文字集合の名前を返す。
@end defun
@node Chars and Bytes
@c @section Characters and Bytes
@section 文字とバイト
@c @cindex bytes and characters
@cindex バイトと文字
@c @cindex introduction sequence
@c @cindex dimension (of character set)
@cindex 導入列
@cindex 次元(文字集合)
@c In multibyte representation, each character occupies one or more
@c bytes. Each character set has an @dfn{introduction sequence}, which is
@c normally one or two bytes long. (Exception: the @sc{ASCII} character
@c set has a zero-length introduction sequence.) The introduction sequence
@c is the beginning of the byte sequence for any character in the character
@c set. The rest of the character's bytes distinguish it from the other
@c characters in the same character set. Depending on the character set,
@c there are either one or two distinguishing bytes; the number of such
@c bytes is called the @dfn{dimension} of the character set.
マルチバイト表現では、各文字は1バイトかそれ以上のバイトを占めます。
各文字集合には、通常は1バイト長か2バイト長の
@dfn{導入列}(introduction sequence)があります
(例外:@sc{ASCII}の導入列は0バイト長である)。
導入列は、文字集合の任意の文字のバイト列の始まりです。
文字のバイト列の残りの部分は、同じ文字集合内で他の文字とその文字を区別します。
文字集合に依存して、区別するためのバイトは1バイトか2バイトです。
そのようなバイト数を文字集合の@dfn{次元}(dimension)と呼びます。
@defun charset-dimension charset
@tindex charset-dimension
@c This function returns the dimension of @var{charset};
@c at present, the dimension is always 1 or 2.
この関数は、文字集合@var{charset}の次元を返す。
現在、次元はつねに1か2である。
@end defun
@c This is the simplest way to determine the byte length of a character
@c set's introduction sequence:
文字集合の導入列のバイト長を判定するもっとも簡単な方法はつぎのとおりです。
@example
(- (char-bytes (make-char @var{charset}))
(charset-dimension @var{charset}))
@end example
@node Splitting Characters
@c @section Splitting Characters
@section 文字の分割
@c The functions in this section convert between characters and the byte
@c values used to represent them. For most purposes, there is no need to
@c be concerned with the sequence of bytes used to represent a character,
@c because Emacs translates automatically when necessary.
本節の関数は、文字とそれを表現するために用いられるバイト値のあいだの
変換を行います。
ほとんどの目的に関しては、Emacsが必要に応じて自動的に行うため、
文字を表現するためのバイト列を扱う必要はありません。
@defun char-bytes character
@tindex char-bytes
@c This function returns the number of bytes used to represent the
@c character @var{character}. This depends only on the character set that
@c @var{character} belongs to; it equals the dimension of that character
@c set (@pxref{Character Sets}), plus the length of its introduction
@c sequence.
この関数は、文字@var{character}を表現するために必要なバイト数を返す。
これは、文字@var{character}が属する文字集合だけに依存し、
その文字集合(@pxref{Character Sets})の次元とその導入列の和に等しい。
@example
(char-bytes 2248)
@result{} 2
(char-bytes 65)
@result{} 1
(char-bytes 192)
@result{} 1
@end example
@c The reason this function can give correct results for both multibyte and
@c unibyte representations is that the non-@sc{ASCII} character codes used
@c in those two representations do not overlap.
マルチバイト表現とユニバイト表現のどちらに対しても
この関数で正しい結果を得られるのは、
2つの表現で用いられる非@sc{ASCII}文字コードに重なりがないからである。
@end defun
@defun split-char character
@tindex split-char
@c Return a list containing the name of the character set of
@c @var{character}, followed by one or two byte values (integers) which
@c identify @var{character} within that character set. The number of byte
@c values is the character set's dimension.
文字@var{character}の文字集合の名前に続けて、
その文字集合で@var{character}を識別する1バイトか2バイトの値(整数)から
成るリストを返す。
バイト値の個数はその文字集合の次元である。
@example
(split-char 2248)
@result{} (latin-iso8859-1 72)
(split-char 65)
@result{} (ascii 65)
@end example
@c Unibyte non-@sc{ASCII} characters are considered as part of
@c the @code{ascii} character set:
ユニバイトの非@sc{ASCII}文字は、
文字集合@code{ascii}の一部とみなす。
@example
(split-char 192)
@result{} (ascii 192)
@end example
@end defun
@defun make-char charset &rest byte-values
@tindex make-char
@c This function returns the character in character set @var{charset}
@c identified by @var{byte-values}. This is roughly the inverse of
@c @code{split-char}. Normally, you should specify either one or two
@c @var{byte-values}, according to the dimension of @var{charset}. For
@c example,
この関数は、文字集合@var{charset}において
@var{byte-values}で識別される文字を返す。
これは、@code{split-char}のほぼ逆関数にあたる。
通常、文字集合@var{charset}の次元に応じて、
1つか2つの@var{byte-values}を指定する。
たとえばつぎのとおり。
@example
(make-char 'latin-iso8859-1 72)
@result{} 2248
@end example
@end defun
@c @cindex generic characters
@cindex 汎用文字
@c If you call @code{make-char} with no @var{byte-values}, the result is
@c a @dfn{generic character} which stands for @var{charset}. A generic
@c character is an integer, but it is @emph{not} valid for insertion in the
@c buffer as a character. It can be used in @code{char-table-range} to
@c refer to the whole character set (@pxref{Char-Tables}).
@c @code{char-valid-p} returns @code{nil} for generic characters.
@c For example:
@var{byte-values}を指定せずに@code{make-char}を呼び出すと、
その結果は文字集合@var{charset}を代表する
@dfn{汎用文字}(generic character)である。
汎用文字は整数であるが、文字としてバッファに挿入するには
正しく@emph{ない}ものである。
1つの文字集合全体を表すために@code{char-table-range}で使える
(@pxref{Char-Tables})。
@code{char-valid-p}は汎用文字に対しては@code{nil}を返す。
たとえばつぎのとおり。
@example
(make-char 'latin-iso8859-1)
@result{} 2176
(char-valid-p 2176)
@result{} nil
(split-char 2176)
@result{} (latin-iso8859-1 0)
@end example
@node Scanning Charsets
@c @section Scanning for Character Sets
@section 文字集合の走査
@c Sometimes it is useful to find out which character sets appear in a
@c part of a buffer or a string. One use for this is in determining which
@c coding systems (@pxref{Coding Systems}) are capable of representing all
@c of the text in question.
バッファや文字列の一部分にどの文字集合が現れるかを
調べられると有用なことがあります。
その1つの用途は、当該テキストすべてを表現する能力がある
コーディングシステム(@pxref{Coding Systems})を探すことです。
@defun find-charset-region beg end &optional translation
@tindex find-charset-region
@c This function returns a list of the character sets that appear in the
@c current buffer between positions @var{beg} and @var{end}.
この関数は、カレントバッファの@var{beg}と@var{end}のあいだに
現れる文字集合のリストを返す。
@c The optional argument @var{translation} specifies a translation table to
@c be used in scanning the text (@pxref{Translation of Characters}). If it
@c is non-@code{nil}, then each character in the region is translated
@c through this table, and the value returned describes the translated
@c characters instead of the characters actually in the buffer.
省略可能な引数@var{translation}は、
テキストを走査するときに使用する変換表を指定する
(@pxref{Translation of Characters})。
これが@code{nil}以外であると、領域内の各文字をこの表を介して変換し、
戻り値は、バッファ内の実際の文字のかわりに変換した文字に関する情報を与える。
@end defun
@defun find-charset-string string &optional translation
@tindex find-charset-string
@c This function returns a list of the character sets
@c that appear in the string @var{string}.
この関数は、文字列@var{string}に現れる文字集合のリストを返す。
@c The optional argument @var{translation} specifies a
@c translation table; see @code{find-charset-region}, above.
省略可能な引数@var{translation}は変換表を指定する。
上記の@code{find-charset-region}を参照。
@end defun
@node Translation of Characters
@c @section Translation of Characters
@section 文字の変換
@c @cindex character translation tables
@c @cindex translation tables
@cindex 文字変換表
@cindex 変換表
@c A @dfn{translation table} specifies a mapping of characters
@c into characters. These tables are used in encoding and decoding, and
@c for other purposes. Some coding systems specify their own particular
@c translation tables; there are also default translation tables which
@c apply to all other coding systems.
@dfn{変換表}(translation table)は、文字群を文字群へ対応付けます。
これらの表は、符号化と復号化、他の目的に使われます。
独自の変換表を指定するコーディングシステムもあります。
他のすべてのコーディングシステムに適用される
デフォルトの変換表もあります。
@defun make-translation-table translations
@c This function returns a translation table based on the arguments
@c @var{translations}. Each argument---each element of
@c @var{translations}---should be a list of the form @code{(@var{from}
@c . @var{to})}; this says to translate the character @var{from} into
@c @var{to}.
この関数は、引数@var{translations}に基づいた変換表を返す。
引数@var{translations}の各要素は、
@code{(@var{from} . @var{to})}の形であり、
文字@var{from}を@var{to}へ変換することを意味する。
@c You can also map one whole character set into another character set with
@c the same dimension. To do this, you specify a generic character (which
@c designates a character set) for @var{from} (@pxref{Splitting Characters}).
@c In this case, @var{to} should also be a generic character, for another
@c character set of the same dimension. Then the translation table
@c translates each character of @var{from}'s character set into the
@c corresponding character of @var{to}'s character set.
1つの文字集合全体を同じ次元の別の文字集合へ対応付けることも可能である。
それには、@var{from}に(文字集合を表す)汎用文字を指定する
(@pxref{Splitting Characters})。
この場合、@var{to}も、同じ次元の別の文字集合の汎用文字であること。
こうすると、この変換表は、@var{from}の文字集合の各文字を
@var{to}の文字集合の対応する文字へ変換する。
@end defun
@c In decoding, the translation table's translations are applied to the
@c characters that result from ordinary decoding. If a coding system has
@c property @code{character-translation-table-for-decode}, that specifies
@c the translation table to use. Otherwise, if
@c @code{standard-character-translation-table-for-decode} is
@c non-@code{nil}, decoding uses that table.
復号化では、もとの復号化結果の文字に変換表による変換を適用します。
コーディングシステムに属性@code{character-translation-table-for-decode}が
あれば、これは使用する変換表を指定します。
さもなければ、@code{standard-character-translation-table-for-decode}が
@code{nil}以外であれば、復号化ではその表を使います。
@c In encoding, the translation table's translations are applied to the
@c characters in the buffer, and the result of translation is actually
@c encoded. If a coding system has property
@c @code{character-translation-table-for-encode}, that specifies the
@c translation table to use. Otherwise the variable
@c @code{standard-character-translation-table-for-encode} specifies the
@c translation table.
符号化では、バッファ内の文字に変換表による変換を適用し、
変換結果を実際に符号化します。
コーディングシステムに属性@code{character-translation-table-for-encode}が
あれば、これは使用する変換表を指定します。
さもなければ、変数@code{standard-character-translation-table-for-encode}が
使用する変換表を指定します。
@defvar standard-character-translation-table-for-decode
@c This is the default translation table for decoding, for
@c coding systems that don't specify any other translation table.
これは、変換表を指定しないコーディングシステムに対する
復号化時のデフォルトの変換表である。
@end defvar
@defvar standard-character-translation-table-for-encode
@c This is the default translation table for encoding, for
@c coding systems that don't specify any other translation table.
これは、変換表を指定しないコーディングシステムに対する
符号化時のデフォルトの変換表である。
@end defvar
@node Coding Systems
@c @section Coding Systems
@section コーディングシステム
@c @cindex coding system
@cindex コーディングシステム
@c When Emacs reads or writes a file, and when Emacs sends text to a
@c subprocess or receives text from a subprocess, it normally performs
@c character code conversion and end-of-line conversion as specified
@c by a particular @dfn{coding system}.
Emacsがファイルを読み書きしたり、
Emacsがサブプロセスへテキストを送ったり
サブプロセスからテキストを受け取るときには、
@dfn{コーディングシステム}(coding system)で指定される
文字コード変換と行末変換を行います。
@menu
* Coding System Basics::
* Encoding and I/O::
* Lisp and Coding Systems::
* User-Chosen Coding Systems::
* Default Coding Systems::
* Specifying Coding Systems::
* Explicit Encoding::
* Terminal I/O Encoding::
* MS-DOS File Types::
@end menu
@node Coding System Basics
@c @subsection Basic Concepts of Coding Systems
@subsection コーディングシステムの基本概念
@c @cindex character code conversion
@cindex 文字コード変換
@c @dfn{Character code conversion} involves conversion between the encoding
@c used inside Emacs and some other encoding. Emacs supports many
@c different encodings, in that it can convert to and from them. For
@c example, it can convert text to or from encodings such as Latin 1, Latin
@c 2, Latin 3, Latin 4, Latin 5, and several variants of ISO 2022. In some
@c cases, Emacs supports several alternative encodings for the same
@c characters; for example, there are three coding systems for the Cyrillic
@c (Russian) alphabet: ISO, Alternativnyj, and KOI8.
@dfn{文字コード変換}(character code conversion)とは、
Emacsの内部で使用する符号と他の符号とのあいだでの変換のことです。
Emacsでは、相互に変換できる多くの異なる符号を扱えます。
たとえば、Emacsは、Latin 1、Latin 2、Latin 3、Latin 4、Latin 5、
ISO 2022のいくつかの変種を相互に変換できます。
同じ文字集合に対する異なる符号を扱うこともできます。
たとえば、キリル(ロシア語)文字に対しては
ISO、Alternativnyj、KOI8の3つのコーディングシステムがあります。
@c Most coding systems specify a particular character code for
@c conversion, but some of them leave this unspecified---to be chosen
@c heuristically based on the data.
ほとんどのコーディングシステムでは変換する文字コードを特定しますが、
指定せずにデータに基づいて発見的手法で選ぶものもあります。
@c @cindex end of line conversion
@cindex 行末変換
@c @dfn{End of line conversion} handles three different conventions used
@c on various systems for representing end of line in files. The Unix
@c convention is to use the linefeed character (also called newline). The
@c DOS convention is to use the two character sequence, carriage-return
@c linefeed, at the end of a line. The Mac convention is to use just
@c carriage-return.
@dfn{行末変換}(end of line conversion)は、
ファイル内の行の終りを表すさまざまなシステムで
使われている3つの異なる慣習を扱います。
UNIXの慣習では、行送り文字(改行文字とも呼ぶ)を使います。
DOSの慣習では、行末には復帰と行送りの2文字の列を使います。
Macの慣習では、復帰のみを使います。
@c @cindex base coding system
@c @cindex variant coding system
@cindex 基底コーディングシステム
@cindex 変種コーディングシステム
@c @dfn{Base coding systems} such as @code{latin-1} leave the end-of-line
@c conversion unspecified, to be chosen based on the data. @dfn{Variant
@c coding systems} such as @code{latin-1-unix}, @code{latin-1-dos} and
@c @code{latin-1-mac} specify the end-of-line conversion explicitly as
@c well. Most base coding systems have three corresponding variants whose
@c names are formed by adding @samp{-unix}, @samp{-dos} and @samp{-mac}.
@code{latin-1}のような@dfn{基底コーディングシステム}(base coding system)
では、行末変換を指定せずにデータに基づいて選びます。
@code{latin-1-unix}、@code{latin-1-dos}、@code{latin-1-mac}のような
@dfn{変種コーディングシステム}(variant coding system)では、
明示的に行末変換も指定します。
ほとんどの基底コーディングシステムには、
@samp{-unix}、@samp{-dos}、@samp{-mac}を付加して作られる名前の
対応する3つの変種があります。
@c The coding system @code{raw-text} is special in that it prevents
@c character code conversion, and causes the buffer visited with that
@c coding system to be a unibyte buffer. It does not specify the
@c end-of-line conversion, allowing that to be determined as usual by the
@c data, and has the usual three variants which specify the end-of-line
@c conversion. @code{no-conversion} is equivalent to @code{raw-text-unix}:
@c it specifies no conversion of either character codes or end-of-line.
コーディングシステム@code{raw-text}は
文字コード変換を行わない特別なもので、
このコーディングシステムで訪問したバッファはユニバイトバッファになります。
行末変換も指定しないので内容に基づいて決定でき、
行末変換を指定する3つの変種もあります。
@code{no-conversion}は@code{raw-text-unix}に等価であり、
文字コードも行末も変換しないことを指定します。
@c The coding system @code{emacs-mule} specifies that the data is
@c represented in the internal Emacs encoding. This is like
@c @code{raw-text} in that no code conversion happens, but different in
@c that the result is multibyte data.
コーディングシステム@code{emacs-mule}は、
Emacs内部での符号でデータを表現することを指定します。
これは、コード変換を行わないという意味では@code{raw-text}に似ていますが、
結果がマルチバイトデータになる点が異なります。
@defun coding-system-get coding-system property
@tindex coding-system-get
@c This function returns the specified property of the coding system
@c @var{coding-system}. Most coding system properties exist for internal
@c purposes, but one that you might find useful is @code{mime-charset}.
@c That property's value is the name used in MIME for the character coding
@c which this coding system can read and write. Examples:
この関数は、コーディングシステム@var{coding-system}の指定した属性を返す。
コーディングシステムのほとんどの属性は内部目的用であるが、
読者が有用と思うものが1つ、@code{mime-charset}がある。
この属性の値は、当該コーディングシステムで読み書きする
文字コード向けのMIMEに使用する名前である。
@example
(coding-system-get 'iso-latin-1 'mime-charset)
@result{} iso-8859-1
(coding-system-get 'iso-2022-cn 'mime-charset)
@result{} iso-2022-cn
(coding-system-get 'cyrillic-koi8 'mime-charset)
@result{} koi8-r
@end example
@c The value of the @code{mime-charset} property is also defined
@c as an alias for the coding system.
属性@code{mime-charset}の値は、
コーディングシステムの別名としても定義されている。
@end defun
@node Encoding and I/O
@c @subsection Encoding and I/O
@subsection 符号化と入出力
@c The principal purpose of coding systems is for use in reading and
@c writing files. The function @code{insert-file-contents} uses
@c a coding system for decoding the file data, and @code{write-region}
@c uses one to encode the buffer contents.
コーディングシステムの主目的は、ファイルの読み書きに使うことです。
関数@code{insert-file-contents}はファイルのデータを復号化するために
コーディングシステムを使い、
@code{write-region}はバッファ内容を符号化するために
コーディングシステムを使います。
@c You can specify the coding system to use either explicitly
@c (@pxref{Specifying Coding Systems}), or implicitly using the defaulting
@c mechanism (@pxref{Default Coding Systems}). But these methods may not
@c completely specify what to do. For example, they may choose a coding
@c system such as @code{undefined} which leaves the character code
@c conversion to be determined from the data. In these cases, the I/O
@c operation finishes the job of choosing a coding system. Very often
@c you will want to find out afterwards which coding system was chosen.
使用するコーディングシステムを明示する(@pxref{Specifying Coding Systems})
こともできるし、
デフォルトの機構(@pxref{Default Coding Systems})を暗に使うこともできます。
しかし、これらの方式ではすべきことを完全に指定しきれないこともあります。
たとえば、@code{undefined}のようなコーディングシステムを選んで、
データに基づいて文字コード変換を行うようにするかもしれません。
そのような場合、コーディングシステムの選択は
入出力操作によって完了します。
しばしば、選択されたコーディングシステムをあとで知りたくなります。
@defvar buffer-file-coding-system
@tindex buffer-file-coding-system
@c This variable records the coding system that was used for visiting the
@c current buffer. It is used for saving the buffer, and for writing part
@c of the buffer with @code{write-region}. When those operations ask the
@c user to specify a different coding system,
@c @code{buffer-file-coding-system} is updated to the coding system
@c specified.
この変数は、カレントバッファで訪問するときに使用した
コーディングシステムを記録する。
これは、バッファを保存したり、
@code{write-region}でバッファの一部を書くときに使われる。
これらの操作において、ユーザーに別のコーディングシステムを指定するように
問い合わせた場合には、@code{buffer-file-coding-system}は
指定された別のコーディングシステムに更新される。
@end defvar
@defvar save-buffer-coding-system
@tindex save-buffer-coding-system
@c This variable specifies the coding system for saving the buffer---but it
@c is not used for @code{write-region}. When saving the buffer asks the
@c user to specify a different coding system, and
@c @code{save-buffer-coding-system} was used, then it is updated to the
@c coding system that was specified.
この変数は、@code{write-region}には使わないが、
バッファを保存するために使うコーディングシステムを指定する。
バッファを保存する際に、ユーザーに別のコーディングシステムを指定するように
問い合わせ、かつ、@code{save-buffer-coding-system}を用いている場合には、
これは指定された別のコーディングシステムに更新される。
@end defvar
@defvar last-coding-system-used
@tindex last-coding-system-used
@c I/O operations for files and subprocesses set this variable to the
@c coding system name that was used. The explicit encoding and decoding
@c functions (@pxref{Explicit Encoding}) set it too.
ファイルやサブプロセスに対する入出力操作では、
使用したコーディングシステム名をこの変数に設定する。
明示的に符号化/復号化する関数(@pxref{Explicit Encoding})も
この変数に設定する。
@c @strong{Warning:} Since receiving subprocess output sets this variable,
@c it can change whenever Emacs waits; therefore, you should use copy the
@c value shortly after the function call which stores the value you are
@c interested in.
@strong{警告:}@code{ }
サブプロセスから出力を受け取るとこの変数が設定されるため、
Emacsが待つたびに変化する可能性がある。
したがって、読者の興味がある値を保存するような関数を呼び出した直後に
その値をコピーして使うこと。
@end defvar
@c The variable @code{selection-coding-system} specifies how to encode
@c selections for the window system. @xref{Window System Selections}.
変数@code{selection-coding-system}は、
ウィンドウシステムのセレクションを符号化する方法を指定します。
@xref{Window System Selections}。
@node Lisp and Coding Systems
@c @subsection Coding Systems in Lisp
@subsection Lispにおけるコーディングシステム
@c Here are Lisp facilities for working with coding systems;
コーディングシステムを扱うLispの機能について述べます。
@defun coding-system-list &optional base-only
@tindex coding-system-list
@c This function returns a list of all coding system names (symbols). If
@c @var{base-only} is non-@code{nil}, the value includes only the
@c base coding systems. Otherwise, it includes variant coding systems as well.
この関数は、すべてのコーディングシステム名(シンボル)のリストを返す。
@var{base-only}が@code{nil}以外であると、
値には基底コーディングシステムのみを含める。
さもなければ、値には変種コーディングシステムも含まれる。
@end defun
@defun coding-system-p object
@tindex coding-system-p
@c This function returns @code{t} if @var{object} is a coding system
@c name.
この関数は、@var{object}がコーディングシステム名であると@code{t}を返す。
@end defun
@defun check-coding-system coding-system
@tindex check-coding-system
@c This function checks the validity of @var{coding-system}.
@c If that is valid, it returns @var{coding-system}.
@c Otherwise it signals an error with condition @code{coding-system-error}.