1 ;;; characters.el --- set syntax and category for multibyte characters
3 ;; Copyright (C) 1997, 2000-2018 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 ;; National Institute of Advanced Industrial Science and Technology (AIST)
7 ;; Registration Number H14PRO021
9 ;; National Institute of Advanced Industrial Science and Technology (AIST)
10 ;; Registration Number H13PRO009
12 ;; Keywords: multibyte character, character set, syntax, category
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
33 ;;; Predefined categories.
35 ;; For each character set.
37 (define-category ?a
"ASCII
38 ASCII graphic characters 32-126 (ISO646 IRV:1983[4/0])")
39 (define-category ?l
"Latin")
40 (define-category ?t
"Thai")
41 (define-category ?g
"Greek")
42 (define-category ?b
"Arabic")
43 (define-category ?w
"Hebrew")
44 (define-category ?y
"Cyrillic")
45 (define-category ?k
"Katakana
47 (define-category ?r
"Roman
49 (define-category ?c
"Chinese")
50 (define-category ?j
"Japanese")
51 (define-category ?h
"Korean")
52 (define-category ?e
"Ethiopic
54 (define-category ?v
"Viet
56 (define-category ?i
"Indian")
57 (define-category ?o
"Lao")
58 (define-category ?q
"Tibetan")
60 ;; For each group (row) of 2-byte character sets.
62 (define-category ?A
"2-byte alnum
63 Alpha-numeric characters of 2-byte character sets")
64 (define-category ?C
"2-byte han
65 Chinese (Han) characters of 2-byte character sets")
66 (define-category ?G
"2-byte Greek
67 Greek characters of 2-byte character sets")
68 (define-category ?H
"2-byte Hiragana
69 Japanese Hiragana characters of 2-byte character sets")
70 (define-category ?K
"2-byte Katakana
71 Japanese Katakana characters of 2-byte character sets")
72 (define-category ?N
"2-byte Korean
73 Korean Hangul characters of 2-byte character sets")
74 (define-category ?Y
"2-byte Cyrillic
75 Cyrillic characters of 2-byte character sets")
76 (define-category ?I
"Indian Glyphs")
78 ;; For phonetic classifications.
80 (define-category ?
0 "consonant")
81 (define-category ?
1 "base vowel
82 Base (independent) vowel")
83 (define-category ?
2 "upper diacritic
84 Upper diacritical mark (including upper vowel)")
85 (define-category ?
3 "lower diacritic
86 Lower diacritical mark (including lower vowel)")
87 (define-category ?
4 "combining tone
89 (define-category ?
5 "symbol")
90 (define-category ?
6 "digit")
91 (define-category ?
7 "vowel diacritic
92 Vowel-modifying diacritical mark")
93 (define-category ?
8 "vowel-signs")
94 (define-category ?
9 "semivowel lower")
97 (define-category ?|
"line breakable
98 While filling, we can break a line at this character.")
100 ;; For indentation calculation.
103 This character counts as a space for indentation purposes.")
105 ;; Keep the following for `kinsoku' processing. See comments in
107 (define-category ?
> "Not at bol
108 A character which can't be placed at beginning of line.")
109 (define-category ?
< "Not at eol
110 A character which can't be placed at end of line.")
112 ;; Base and Combining
113 (define-category ?.
"Base
114 Base characters (Unicode General Category L,N,P,S,Zs)")
115 (define-category ?^
"Combining
116 Combining diacritic or mark (Unicode General Category M)")
119 (define-category ?R
"Right-to-left (strong)
120 Characters with \"strong\" right-to-left directionality, i.e.
121 with R, AL, RLE, or RLO Unicode bidi character type.")
123 (define-category ?L
"Left-to-right (strong)
124 Characters with \"strong\" left-to-right directionality, i.e.
125 with L, LRE, or LRO Unicode bidi character type.")
128 ;;; Setting syntax and category.
132 ;; All ASCII characters have the category `a' (ASCII) and `l' (Latin).
133 (modify-category-entry '(32 .
127) ?a
)
134 (modify-category-entry '(32 .
127) ?l
)
136 ;; Deal with the CJK charsets first. Since the syntax of blocks is
137 ;; defined per charset, and the charsets may contain e.g. Latin
138 ;; characters, we end up with the wrong syntax definitions if we're
141 ;; Chinese characters (Unicode)
142 (modify-category-entry '(#x2E80 .
#x312F
) ?|
)
143 (modify-category-entry '(#x3190 .
#x33FF
) ?|
)
144 (modify-category-entry '(#x3400 .
#x4DB5
) ?C
)
145 (modify-category-entry '(#x4E00 .
#x9FD5
) ?C
)
146 (modify-category-entry '(#x3400 .
#x9FD5
) ?c
)
147 (modify-category-entry '(#x3400 .
#x9FD5
) ?|
)
148 (modify-category-entry '(#xF900 .
#xFAFF
) ?C
)
149 (modify-category-entry '(#xF900 .
#xFAFF
) ?c
)
150 (modify-category-entry '(#xF900 .
#xFAFF
) ?|
)
151 (modify-category-entry '(#x1B170 .
#x1B2FF
) ?c
)
152 (modify-category-entry '(#x20000 .
#x2FFFF
) ?|
)
153 (modify-category-entry '(#x20000 .
#x2FFFF
) ?C
)
154 (modify-category-entry '(#x20000 .
#x2FFFF
) ?c
)
157 ;; Chinese character set (GB2312)
159 (map-charset-chars #'modify-syntax-entry
'chinese-gb2312
"_" #x2121
#x217E
)
160 (map-charset-chars #'modify-syntax-entry
'chinese-gb2312
"_" #x2221
#x227E
)
161 (map-charset-chars #'modify-syntax-entry
'chinese-gb2312
"_" #x2921
#x297E
)
163 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?c
)
164 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?A
#x2330
#x2339
)
165 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?A
#x2341
#x235A
)
166 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?A
#x2361
#x237A
)
167 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?H
#x2421
#x247E
)
168 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?K
#x2521
#x257E
)
169 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?G
#x2621
#x267E
)
170 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?Y
#x2721
#x277E
)
171 (map-charset-chars #'modify-category-entry
'chinese-gb2312 ?C
#x3021
#x7E7E
)
173 ;; Chinese character set (BIG5)
175 (map-charset-chars #'modify-category-entry
'big5 ?c
)
176 (map-charset-chars #'modify-category-entry
'big5 ?C
#xA259
#xA261
)
177 (map-charset-chars #'modify-category-entry
'big5 ?C
#xA440
#xC67E
)
178 (map-charset-chars #'modify-category-entry
'big5 ?C
#xC940
#xF9DC
)
180 ;; Chinese character set (CNS11643)
182 (dolist (c '(chinese-cns11643-1 chinese-cns11643-2 chinese-cns11643-3
183 chinese-cns11643-4 chinese-cns11643-5 chinese-cns11643-6
185 (map-charset-chars #'modify-category-entry c ?c
)
186 (if (eq c
'chinese-cns11643-1
)
187 (map-charset-chars #'modify-category-entry c ?C
#x4421
#x7E7E
)
188 (map-charset-chars #'modify-category-entry c ?C
)))
190 ;; Japanese character set (JISX0201, JISX0208, JISX0212, JISX0213)
192 (map-charset-chars #'modify-category-entry
'katakana-jisx0201 ?k
)
194 (map-charset-chars #'modify-category-entry
'latin-jisx0201 ?r
)
196 (dolist (l '(katakana-jisx0201 japanese-jisx0208 japanese-jisx0212
197 japanese-jisx0213-1 japanese-jisx0213-2
198 japanese-jisx0213.2004-
1
200 (map-charset-chars #'modify-category-entry l ?j
))
202 ;; Fullwidth characters
203 (modify-category-entry '(#xff01 .
#xff60
) ?\|
)
205 ;; Unicode equivalents of JISX0201-kana
206 (let ((range '(#xff61 .
#xff9f
)))
207 (modify-category-entry range ?k
)
208 (modify-category-entry range ?j
)
209 (modify-category-entry range ?\|
))
212 (modify-category-entry '(#x3099 .
#x309C
) ?K
)
213 (modify-category-entry '(#x30A0 .
#x30FF
) ?K
)
214 (modify-category-entry '(#x31F0 .
#x31FF
) ?K
)
215 (modify-category-entry '(#x30A0 .
#x30FA
) ?\|
)
216 (modify-category-entry #x30FF ?\|
)
219 (modify-category-entry '(#x3040 .
#x309F
) ?H
)
220 (modify-category-entry '(#x3040 .
#x3096
) ?\|
)
221 (modify-category-entry #x309F ?\|
)
222 (modify-category-entry #x30A0 ?H
)
223 (modify-category-entry #x30FC ?H
)
225 (modify-category-entry '(#x1B000 .
#x1B1FF
) ?j
)
229 (map-charset-chars #'modify-syntax-entry
'japanese-jisx0208
"_" #x2121
#x227E
)
230 (map-charset-chars #'modify-syntax-entry
'japanese-jisx0208
"_" #x2821
#x287E
)
231 (let ((chars '(?ー ?゛ ?゜ ?ヽ ?ヾ ?ゝ ?ゞ ?〃 ?仝 ?々 ?〆 ?〇
)))
233 (modify-syntax-entry elt
"w")))
235 (map-charset-chars #'modify-category-entry
'japanese-jisx0208 ?A
#x2321
#x237E
)
236 (map-charset-chars #'modify-category-entry
'japanese-jisx0208 ?H
#x2421
#x247E
)
237 (map-charset-chars #'modify-category-entry
'japanese-jisx0208 ?K
#x2521
#x257E
)
238 (map-charset-chars #'modify-category-entry
'japanese-jisx0208 ?G
#x2621
#x267E
)
239 (map-charset-chars #'modify-category-entry
'japanese-jisx0208 ?Y
#x2721
#x277E
)
240 (map-charset-chars #'modify-category-entry
'japanese-jisx0208 ?C
#x3021
#x7E7E
)
241 (let ((chars '(?仝 ?々 ?〆 ?〇
)))
243 (modify-category-entry (car chars
) ?C
)
244 (setq chars
(cdr chars
))))
248 (map-charset-chars #'modify-syntax-entry
'japanese-jisx0212
"_" #x2121
#x237E
)
252 (let ((chars '(?。 ?、 ?・
)))
254 (modify-syntax-entry (car chars
) ".")
255 (setq chars
(cdr chars
))))
257 (modify-syntax-entry ?\「
"(」")
258 (modify-syntax-entry ?\」
"(「")
260 ;; Korean character set (KSC5601)
262 (map-charset-chars #'modify-category-entry
'korean-ksc5601 ?h
)
264 (map-charset-chars #'modify-syntax-entry
'korean-ksc5601
"_" #x2121
#x227E
)
265 (map-charset-chars #'modify-syntax-entry
'korean-ksc5601
"_" #x2621
#x277E
)
266 (map-charset-chars #'modify-syntax-entry
'korean-ksc5601
"_" #x2830
#x287E
)
267 (map-charset-chars #'modify-syntax-entry
'korean-ksc5601
"_" #x2930
#x297E
)
268 (map-charset-chars #'modify-category-entry
'korean-ksc5601 ?A
#x2330
#x2339
)
269 (map-charset-chars #'modify-category-entry
'korean-ksc5601 ?A
#x2341
#x235A
)
270 (map-charset-chars #'modify-category-entry
'korean-ksc5601 ?A
#x2361
#x237A
)
271 (map-charset-chars #'modify-category-entry
'korean-ksc5601 ?G
#x2521
#x257E
)
272 (map-charset-chars #'modify-category-entry
'korean-ksc5601 ?H
#x2A21
#x2A7E
)
273 (map-charset-chars #'modify-category-entry
'korean-ksc5601 ?K
#x2B21
#x2B7E
)
274 (map-charset-chars #'modify-category-entry
'korean-ksc5601 ?Y
#x2C21
#x2C7E
)
276 ;; These are in more than one charset.
277 (let ((parens (concat "〈〉《》「」『』【】〔〕〖〗〘〙〚〛"
281 (dotimes (i (/ (length parens
) 2))
282 (setq open
(aref parens
(* i
2))
283 close
(aref parens
(1+ (* i
2))))
284 (modify-syntax-entry open
(format "(%c" close
))
285 (modify-syntax-entry close
(format ")%c" open
))))
287 ;; Arabic character set
289 (let ((charsets '(arabic-iso8859-6
294 (map-charset-chars #'modify-category-entry
(car charsets
) ?b
)
295 (setq charsets
(cdr charsets
))))
296 (modify-category-entry '(#x600 .
#x6ff
) ?b
)
297 (modify-category-entry '(#x8a0 .
#x8ff
) ?b
)
298 (modify-category-entry '(#xfb50 .
#xfdff
) ?b
)
299 (modify-category-entry '(#xfe70 .
#xfefe
) ?b
)
301 ;; Cyrillic character set (ISO-8859-5)
303 (modify-syntax-entry ?№
".")
305 ;; Ethiopic character set
307 (modify-category-entry '(#x1200 .
#x1399
) ?e
)
308 (modify-category-entry '(#x2d80 .
#x2dde
) ?e
)
309 (let ((chars '(?፡ ?። ?፣ ?፤ ?፥ ?፦ ?፧ ?፨
)))
311 (modify-syntax-entry (car chars
) ".")
312 (setq chars
(cdr chars
))))
313 (map-charset-chars #'modify-category-entry
'ethiopic ?e
)
315 ;; Hebrew character set (ISO-8859-8)
317 (modify-syntax-entry #x5be
".") ; MAQAF
318 (modify-syntax-entry #x5c0
".") ; PASEQ
319 (modify-syntax-entry #x5c3
".") ; SOF PASUQ
320 (modify-syntax-entry #x5f3
".") ; GERESH
321 (modify-syntax-entry #x5f4
".") ; GERSHAYIM
323 ;; Indian character set (IS 13194 and other Emacs original Indian charsets)
325 (modify-category-entry '(#x901 .
#x970
) ?i
)
326 (map-charset-chars #'modify-category-entry
'indian-is13194 ?i
)
327 (map-charset-chars #'modify-category-entry
'indian-2-column ?i
)
331 (modify-category-entry '(#xe80 .
#xeff
) ?o
)
332 (map-charset-chars #'modify-category-entry
'lao ?o
)
334 (let ((deflist '(("ກ-ຮ" "w" ?
0) ; consonant
335 ("ະາຳຽເ-ໄ" "w" ?
1) ; vowel base
336 ("ັິ-ືົໍ" "w" ?
2) ; vowel upper
337 ("ຸູ" "w" ?
3) ; vowel lower
338 ("່-໋" "w" ?
4) ; tone mark
339 ("ຼຽ" "w" ?
9) ; semivowel lower
340 ("໐-໙" "w" ?
6) ; digit
341 ("ຯໆ" "_" ?
5) ; symbol
343 elm chars len syntax category to ch i
)
345 (setq elm
(car deflist
))
346 (setq chars
(car elm
)
352 (if (= (aref chars i
) ?-
)
355 (setq ch
(aref chars i
)
358 (unless (string-equal syntax
"w")
359 (modify-syntax-entry ch syntax
))
360 (modify-category-entry ch category
)
363 (setq deflist
(cdr deflist
))))
365 ;; Thai character set (TIS620)
367 (modify-category-entry '(#xe00 .
#xe7f
) ?t
)
368 (map-charset-chars #'modify-category-entry
'thai-tis620 ?t
)
370 (let ((deflist '(;; chars syntax category
371 ("ก-รลว-ฮ" "w" ?
0) ; consonant
372 ("ฤฦะาำเ-ๅ" "w" ?
1) ; vowel base
373 ("ัิ-ื็๎" "w" ?
2) ; vowel upper
374 ("ุ-ฺ" "w" ?
3) ; vowel lower
375 ("่-ํ" "w" ?
4) ; tone mark
376 ("๐-๙" "w" ?
6) ; digit
377 ("ฯๆ฿๏๚๛" "_" ?
5) ; symbol
379 elm chars len syntax category to ch i
)
381 (setq elm
(car deflist
))
382 (setq chars
(car elm
)
388 (if (= (aref chars i
) ?-
)
391 (setq ch
(aref chars i
)
394 (unless (string-equal syntax
"w")
395 (modify-syntax-entry ch syntax
))
396 (modify-category-entry ch category
)
399 (setq deflist
(cdr deflist
))))
401 ;; Tibetan character set
403 (modify-category-entry '(#xf00 .
#xfff
) ?q
)
404 (map-charset-chars #'modify-category-entry
'tibetan ?q
)
405 (map-charset-chars #'modify-category-entry
'tibetan-1-column ?q
)
407 (let ((deflist '(;; chars syntax category
408 ("ཀ-ཀྵཪ" "w" ?
0) ; consonant
410 ("ིེཻོཽྀ" "w" ?
2) ; upper vowel
411 ("ཾྂྃ྆྇ྈྉྊྋ" "w" ?
2) ; upper modifier
412 ("྄ཱུ༙༵༷" "w" ?
3) ; lower vowel/modifier
413 ("" "w" ?
3) ; invisible vowel a
414 ("༠-༩༪-༳" "w" ?
6) ; digit
415 ("་།-༒༔ཿ" "." ?|
) ; line-break char
417 ("༈་།-༒༔ཿ༽༴" "." ?
>) ; prohibition
419 ("ༀ-༊༼࿁࿂྅" "." ?
<) ; prohibition
420 ("༓༕-༘༚-༟༶༸-༻༾༿྾྿-࿏" "." ?q
) ; others
422 elm chars len syntax category to ch i
)
424 (setq elm
(car deflist
))
425 (setq chars
(car elm
)
431 (if (= (aref chars i
) ?-
)
434 (setq ch
(aref chars i
)
437 (unless (string-equal syntax
"w")
438 (modify-syntax-entry ch syntax
))
439 (modify-category-entry ch category
)
442 (setq deflist
(cdr deflist
))))
444 ;; Vietnamese character set
446 ;; To make a word with Latin characters
447 (map-charset-chars #'modify-category-entry
'vietnamese-viscii-lower ?l
)
448 (map-charset-chars #'modify-category-entry
'vietnamese-viscii-lower ?v
)
450 (map-charset-chars #'modify-category-entry
'vietnamese-viscii-upper ?l
)
451 (map-charset-chars #'modify-category-entry
'vietnamese-viscii-upper ?v
)
453 (let ((tbl (standard-case-table))
456 (let* ((char (decode-char 'vietnamese-viscii-upper i
))
457 (charl (decode-char 'vietnamese-viscii-lower i
))
458 (uc (encode-char char
'ucs
))
459 (lc (encode-char charl
'ucs
)))
460 (set-case-syntax-pair char
(decode-char 'vietnamese-viscii-lower i
)
462 (if uc
(modify-category-entry uc ?v
))
463 (if lc
(modify-category-entry lc ?v
)))
467 (let ((deflist '(;; chars syntax category
468 ((?ꪀ. ?ꪯ
) "w" ?
0) ; consonant
469 ("ꪱꪵꪶ" "w" ?
1) ; vowel base
470 ((?ꪹ . ?ꪽ
) "w" ?
1) ; vowel base
471 ("ꪰꪲꪳꪷꪸꪾ" "w" ?
2) ; vowel upper
472 ("ꪴ" "w" ?
3) ; vowel lower
473 ("ꫀꫂ" "w" ?
1) ; non-combining tone-mark
474 ("꪿꫁" "w" ?
4) ; combining tone-mark
475 ((?ꫛ . ?꫟
) "_" ?
5) ; symbol
477 (dolist (elm deflist
)
478 (let ((chars (car elm
))
480 (category (nth 2 elm
)))
483 (modify-syntax-entry chars syntax
)
484 (modify-category-entry chars category
))
486 (modify-syntax-entry x syntax
)
487 (modify-category-entry x category
))
492 ;; If bootstrapping without generated uni-*.el files, table not defined.
493 (let ((table (unicode-property-table-internal 'bidi-class
)))
495 (map-char-table (lambda (key val
)
497 ((memq val
'(R AL RLO RLE
))
498 (modify-category-entry key ?R
))
499 ((memq val
'(L LRE LRO
))
500 (modify-category-entry key ?L
))))
503 ;; Load uni-mirrored.el and uni-brackets.el if available, so that they
504 ;; get dumped into Emacs. This allows starting Emacs with
505 ;; force-load-messages in ~/.emacs, and avoid infinite recursion in
506 ;; bidi_initialize, which needs to load uni-mirrored.el and
507 ;; uni-brackets.el in order to display the "Loading" messages.
508 (unicode-property-table-internal 'mirroring
)
509 (unicode-property-table-internal 'bracket-type
)
513 (modify-category-entry '(#x80 .
#x024F
) ?l
)
515 (let ((tbl (standard-case-table)) c
)
519 ;; Fixme: Some of the non-word syntaxes here perhaps should be
520 ;; reviewed. (Note that the following all implicitly have word
521 ;; syntax: ¢£¤¥¨ª¯²³´¶¸¹º.) There should be a well-defined way of
522 ;; relating Unicode categories to Emacs syntax codes.
524 ;; NBSP isn't semantically interchangeable with other whitespace chars,
525 ;; so it's more like punctuation.
526 (set-case-syntax ?
"." tbl
)
527 (set-case-syntax ?¡
"." tbl
)
528 (set-case-syntax ?¦
"_" tbl
)
529 (set-case-syntax ?§
"." tbl
)
530 (set-case-syntax ?©
"_" tbl
)
532 ;; (set-case-syntax-delims ?« ?» tbl)
534 ;; (set-case-syntax-delims ?» ?« tbl)
535 ;; So let's stay neutral and let users set these up if/when they want to.
536 (set-case-syntax ?«
"." tbl
)
537 (set-case-syntax ?»
"." tbl
)
538 (set-case-syntax ?¬
"_" tbl
)
539 (set-case-syntax ?
"_" tbl
)
540 (set-case-syntax ?®
"_" tbl
)
541 (set-case-syntax ?°
"_" tbl
)
542 (set-case-syntax ?±
"_" tbl
)
543 (set-case-syntax ?µ
"_" tbl
)
544 (set-case-syntax ?·
"_" tbl
)
545 (set-case-syntax ?¼
"_" tbl
)
546 (set-case-syntax ?½
"_" tbl
)
547 (set-case-syntax ?¾
"_" tbl
)
548 (set-case-syntax ?¿
"." tbl
)
549 (set-case-syntax ?×
"_" tbl
)
550 (set-case-syntax ?ß
"w" tbl
)
551 (set-case-syntax ?÷
"_" tbl
)
554 ;; Latin Extended-A, Latin Extended-B
557 (modify-category-entry c ?l
)
560 ;; Latin Extended Additional
561 (modify-category-entry '(#x1e00 .
#x1ef9
) ?l
)
566 (modify-category-entry c ?l
)
572 (modify-category-entry c ?l
)
578 (modify-category-entry c ?l
)
582 (modify-category-entry '(#x0370 .
#x03ff
) ?g
)
588 (modify-category-entry '(#x1f00 .
#x1fff
) ?g
)
591 (modify-category-entry '(#x0400 .
#x04FF
) ?y
)
592 (modify-category-entry '(#xA640 .
#xA69F
) ?y
)
597 ;; Cyrillic Extended-C
598 (modify-category-entry '(#x1C80 .
#x1C8F
) ?y
)
600 ;; general punctuation
603 (set-case-syntax c
" " tbl
)
606 (set-case-syntax c
"." tbl
)
608 ;; Fixme: These aren't all right:
611 (set-case-syntax c
"_" tbl
)
613 ;; Punctuation syntax for quotation marks (like `)
615 (set-case-syntax c
"." tbl
)
617 ;; Fixme: These aren't all right:
619 (set-case-syntax c
"_" tbl
)
622 (set-case-syntax c
"." tbl
)
625 ;; Fixme: The following blocks might be better as symbol rather than
630 (set-case-syntax c
"." tbl
)
632 ;; Mathematical Operators
634 (set-case-syntax c
"." tbl
)
636 ;; Miscellaneous Technical
638 (set-case-syntax c
"." tbl
)
642 (set-case-syntax c
"_" tbl
)
648 (modify-category-entry c ?l
)
649 (modify-category-entry (+ c
26) ?l
)
653 ;; There's no Coptic category. However, Coptic letters that are
654 ;; part of the Greek block above get the Greek category, and those
655 ;; in this block are derived from Greek letters, so let's be
656 ;; consistent about their category.
657 (modify-category-entry '(#x2C80 .
#x2CFF
) ?g
)
662 (modify-category-entry c ?l
)
663 (modify-category-entry (+ c
#x20
) ?l
)
666 ;; Combining diacritics
667 (modify-category-entry '(#x300 .
#x362
) ?^
)
669 (modify-category-entry '(#x20d0 .
#x20ff
) ?^
)
671 (let ((gc (unicode-property-table-internal 'general-category
))
672 (syn-table (standard-syntax-table)))
673 ;; In early bootstrapping Unicode tables are not available so we need to
674 ;; skip this step in those cases.
676 ;; Set all Letter, uppercase; Letter, lowercase and Letter,
677 ;; titlecase syntax to word.
680 (when (memq cat
'(Lu Ll Lt
))
681 (modify-syntax-entry ch
"w " syn-table
)))
683 ;; Ⅰ through Ⅻ had word syntax in the past so set it here as well.
684 ;; The general category of those characters is Number, Letter.
685 (modify-syntax-entry '(#x2160 .
#x216b
) "w " syn-table
)
687 ;; ⓐ through ⓩ are symbols, other according to Unicode but Emacs set
688 ;; their syntax to word in the past so keep backwards compatibility.
689 (modify-syntax-entry '(#x24D0 .
#x24E9
) "w " syn-table
)
691 ;; Set downcase and upcase from Unicode properties
693 ;; In some languages, such as Turkish, U+0049 LATIN CAPITAL LETTER I and
694 ;; U+0131 LATIN SMALL LETTER DOTLESS I make a case pair, and so do U+0130
695 ;; LATIN CAPITAL LETTER I WITH DOT ABOVE and U+0069 LATIN SMALL LETTER I.
697 ;; We used to set up half of those correspondence unconditionally, but
698 ;; that makes searches slow. So now we don't set up either half of these
699 ;; correspondences by default.
701 ;; (set-downcase-syntax ?İ ?i tbl)
702 ;; (set-upcase-syntax ?I ?ı tbl)
704 (let ((map-unicode-property
705 (lambda (property func
)
708 ;; ASCII characters skipped due to reasons outlined above. As
709 ;; of Unicode 9.0, this exception affects the following:
715 (let ((end (if (consp ch
) (cdr ch
) ch
)))
716 (setq ch
(max 128 (if (consp ch
) (car ch
) ch
)))
718 (funcall func ch cased
)
719 (setq ch
(1+ ch
))))))
720 (unicode-property-table-internal property
))))
722 (up (case-table-get-table tbl
'up
)))
724 ;; This works on an assumption that if toUpper(x) != x then toLower(x)
725 ;; == x (and the opposite for toLower/toUpper). This doesn’t hold for
726 ;; title case characters but those incorrect mappings will be
727 ;; overwritten later.
728 (funcall map-unicode-property
'uppercase
729 (lambda (lc uc
) (aset down lc lc
) (aset up uc uc
)))
730 (funcall map-unicode-property
'lowercase
731 (lambda (uc lc
) (aset down lc lc
) (aset up uc uc
)))
733 ;; Now deal with the actual mapping. This will correctly assign casing
734 ;; for title-case characters.
735 (funcall map-unicode-property
'uppercase
736 (lambda (lc uc
) (aset up lc uc
) (aset up uc uc
)))
737 (funcall map-unicode-property
'lowercase
738 (lambda (uc lc
) (aset down uc lc
) (aset down lc lc
))))))
740 ;; Clear out the extra slots so that they will be recomputed from the main
741 ;; (downcase) table and upcase table. Since we’re side-stepping the usual
742 ;; set-case-syntax-* functions, we need to do it explicitly.
743 (set-char-table-extra-slot tbl
1 nil
)
744 (set-char-table-extra-slot tbl
2 nil
)
746 ;; Fixme: syntax for symbols &c
750 '("⁅⁆" ; U+2045 U+2046
804 (modify-syntax-entry (aref elt
0) (string ?\
( (aref elt
1)))
805 (modify-syntax-entry (aref elt
1) (string ?\
) (aref elt
0)))))
808 ;; For each character set, put the information of the most proper
809 ;; coding system to encode it by `preferred-coding-system' property.
811 ;; Fixme: should this be junked?
812 (let ((l '((latin-iso8859-1 . iso-latin-1
)
813 (latin-iso8859-2 . iso-latin-2
)
814 (latin-iso8859-3 . iso-latin-3
)
815 (latin-iso8859-4 . iso-latin-4
)
816 (thai-tis620 . thai-tis620
)
817 (greek-iso8859-7 . greek-iso-8bit
)
818 (arabic-iso8859-6 . iso-2022-7bit
)
819 (hebrew-iso8859-8 . hebrew-iso-8bit
)
820 (katakana-jisx0201 . japanese-shift-jis
)
821 (latin-jisx0201 . japanese-shift-jis
)
822 (cyrillic-iso8859-5 . cyrillic-iso-8bit
)
823 (latin-iso8859-9 . iso-latin-5
)
824 (japanese-jisx0208-1978 . iso-2022-jp
)
825 (chinese-gb2312 . chinese-iso-8bit
)
826 (chinese-gbk . chinese-gbk
)
827 (gb18030-2-byte . chinese-gb18030
)
828 (gb18030-4-byte-bmp . chinese-gb18030
)
829 (gb18030-4-byte-smp . chinese-gb18030
)
830 (gb18030-4-byte-ext-1 . chinese-gb18030
)
831 (gb18030-4-byte-ext-2 . chinese-gb18030
)
832 (japanese-jisx0208 . iso-2022-jp
)
833 (korean-ksc5601 . iso-2022-kr
)
834 (japanese-jisx0212 . iso-2022-jp
)
835 (chinese-big5-1 . chinese-big5
)
836 (chinese-big5-2 . chinese-big5
)
837 (chinese-sisheng . iso-2022-7bit
)
838 (ipa . iso-2022-7bit
)
839 (vietnamese-viscii-lower . vietnamese-viscii
)
840 (vietnamese-viscii-upper . vietnamese-viscii
)
841 (arabic-digit . iso-2022-7bit
)
842 (arabic-1-column . iso-2022-7bit
)
844 (arabic-2-column . iso-2022-7bit
)
845 (indian-is13194 . devanagari
)
846 (indian-glyph . devanagari
)
847 (tibetan-1-column . tibetan
)
848 (ethiopic . iso-2022-7bit
)
849 (chinese-cns11643-1 . iso-2022-cn
)
850 (chinese-cns11643-2 . iso-2022-cn
)
851 (chinese-cns11643-3 . iso-2022-cn
)
852 (chinese-cns11643-4 . iso-2022-cn
)
853 (chinese-cns11643-5 . iso-2022-cn
)
854 (chinese-cns11643-6 . iso-2022-cn
)
855 (chinese-cns11643-7 . iso-2022-cn
)
856 (indian-2-column . devanagari
)
858 (latin-iso8859-14 . iso-latin-8
)
859 (latin-iso8859-15 . iso-latin-9
))))
861 (put-charset-property (car (car l
)) 'preferred-coding-system
(cdr (car l
)))
865 ;; Setup auto-fill-chars for charsets that should invoke auto-filling.
866 ;; SPACE and NEWLINE are already set.
868 (set-char-table-range auto-fill-chars
'(#x3041 .
#x30FF
) t
)
869 (set-char-table-range auto-fill-chars
'(#x3400 .
#x4DB5
) t
)
870 (set-char-table-range auto-fill-chars
'(#x4e00 .
#x9fbb
) t
)
871 (set-char-table-range auto-fill-chars
'(#xF900 .
#xFAFF
) t
)
872 (set-char-table-range auto-fill-chars
'(#xFF00 .
#xFF9F
) t
)
873 (set-char-table-range auto-fill-chars
'(#x20000 .
#x2FFFF
) t
)
876 ;;; Setting char-width-table. The default is 1.
878 ;; 0: non-spacing, enclosing combining, formatting, Hangul Jamo medial
879 ;; and final characters.
880 (let ((l '((#x0300 .
#x036F
)
1150 (#xE0001 .
#xE01EF
))))
1152 (set-char-table-range char-width-table elt
0)))
1154 ;; 2: East Asian Wide and Full-width characters.
1155 (let ((l '((#x1100 .
#x115F
)
1244 (#x30000 .
#x3FFFF
))))
1246 (set-char-table-range char-width-table elt
2)))
1248 ;; Other double width
1249 ;;(map-charset-chars
1250 ;; (lambda (range ignore) (set-char-table-range char-width-table range 2))
1252 ;; (map-charset-chars
1253 ;; (lambda (range ignore) (set-char-table-range char-width-table range 2))
1256 (lambda (range _ignore
) (set-char-table-range char-width-table range
2))
1259 (lambda (range _ignore
) (set-char-table-range char-width-table range
2))
1262 ;; Internal use only.
1263 ;; Alist of locale symbol vs charsets. In a language environment
1264 ;; corresponding to the locale, width of characters in the charsets is
1265 ;; set to 2. Each element has the form:
1266 ;; (LOCALE TABLE (CHARSET (FROM-CODE . TO-CODE) ...) ...)
1267 ;; LOCALE: locale symbol
1268 ;; TABLE: char-table used for char-width-table, initially nil.
1269 ;; CHARSET: character set
1270 ;; FROM-CODE, TO-CODE: range of code-points in CHARSET
1272 (defvar cjk-char-width-table-list
1273 '((ja_JP nil
(japanese-jisx0208 (#x2121 .
#x287E
))
1274 (cp932-2-byte (#x8140 .
#x879F
)))
1275 (zh_CN nil
(chinese-gb2312 (#x2121 .
#x297E
)))
1276 (zh_HK nil
(big5-hkscs (#xA140 .
#xA3FE
) (#xC6A0 .
#xC8FE
)))
1277 (zh_TW nil
(big5 (#xA140 .
#xA3FE
))
1278 (chinese-cns11643-1 (#x2121 .
#x427E
)))
1279 (ko_KR nil
(korean-ksc5601 (#x2121 .
#x2C7E
)))))
1281 ;; Internal use only.
1282 ;; Setup char-width-table appropriate for a language environment
1283 ;; corresponding to LOCALE-NAME (symbol).
1285 (defun use-cjk-char-width-table (locale-name)
1286 (while (char-table-parent char-width-table
)
1287 (setq char-width-table
(char-table-parent char-width-table
)))
1288 (let ((slot (assq locale-name cjk-char-width-table-list
)))
1289 (or slot
(error "Unknown locale for CJK language environment: %s"
1291 (unless (nth 1 slot
)
1292 (let ((table (make-char-table nil
)))
1293 (dolist (charset-info (nthcdr 2 slot
))
1294 (let ((charset (car charset-info
)))
1295 (dolist (code-range (cdr charset-info
))
1296 (map-charset-chars #'(lambda (range _arg
)
1297 (set-char-table-range table range
2))
1299 (car code-range
) (cdr code-range
)))))
1300 (optimize-char-table table
)
1301 (set-char-table-parent table char-width-table
)
1302 (setcar (cdr slot
) table
)))
1303 (setq char-width-table
(nth 1 slot
))))
1305 (defun use-default-char-width-table ()
1307 Setup char-width-table appropriate for non-CJK language environment."
1308 (while (char-table-parent char-width-table
)
1309 (setq char-width-table
(char-table-parent char-width-table
))))
1311 (optimize-char-table (standard-case-table))
1312 (optimize-char-table (standard-syntax-table))
1315 ;; Setting char-script-table.
1317 ;; While dumping, we can't use require, and international is not
1319 (load "international/charscript")
1320 (require 'charscript
))
1323 #'(lambda (range _ignore
)
1324 (set-char-table-range char-script-table range
'tibetan
))
1328 ;;; Setting unicode-category-table.
1330 (when (setq unicode-category-table
1331 (unicode-property-table-internal 'general-category
))
1332 (map-char-table #'(lambda (key val
)
1334 (cond ((or (and (/= (aref (symbol-name val
) 0) ?M
)
1335 (/= (aref (symbol-name val
) 0) ?C
))
1337 (modify-category-entry key ?.
))
1339 (modify-category-entry key ?^
)))))
1340 unicode-category-table
))
1342 (optimize-char-table (standard-category-table))
1345 ;; Display of glyphless characters.
1347 (defvar char-acronym-table
1348 (make-char-table 'char-acronym-table nil
)
1349 "Char table of acronyms for non-graphic characters.")
1351 (let ((c0-acronyms '("NUL" "SOH" "STX" "ETX" "EOT" "ENQ" "ACK" "BEL"
1352 "BS" nil nil
"VT" "FF" "CR" "SO" "SI"
1353 "DLE" "DC1" "DC2" "DC3" "DC4" "NAK" "SYN" "ETB"
1354 "CAN" "EM" "SUB" "ESC" "FC" "GS" "RS" "US")))
1356 (aset char-acronym-table i
(car c0-acronyms
))
1357 (setq c0-acronyms
(cdr c0-acronyms
))))
1359 (let ((c1-acronyms '("PAD" "HOP" "BPH" "NBH" "IND" "NEL" "SSA" "ESA"
1360 "HTS" "HTJ" "VTS" "PLD" "PLU" "R1" "SS2" "SS1"
1361 "DCS" "PU1" "PU2" "STS" "CCH" "MW" "SPA" "EPA"
1362 "SOS" "SGCI" "SC1" "CSI" "ST" "OSC" "PM" "APC")))
1364 (aset char-acronym-table
(+ #x0080 i
) (car c1-acronyms
))
1365 (setq c1-acronyms
(cdr c1-acronyms
))))
1367 (aset char-acronym-table
#x17B4
"KIVAQ") ; KHMER VOWEL INHERENT AQ
1368 (aset char-acronym-table
#x17B5
"KIVAA") ; KHMER VOWEL INHERENT AA
1369 (aset char-acronym-table
#x200B
"ZWSP") ; ZERO WIDTH SPACE
1370 (aset char-acronym-table
#x200C
"ZWNJ") ; ZERO WIDTH NON-JOINER
1371 (aset char-acronym-table
#x200D
"ZWJ") ; ZERO WIDTH JOINER
1372 (aset char-acronym-table
#x200E
"LRM") ; LEFT-TO-RIGHT MARK
1373 (aset char-acronym-table
#x200F
"RLM") ; RIGHT-TO-LEFT MARK
1374 (aset char-acronym-table
#x202A
"LRE") ; LEFT-TO-RIGHT EMBEDDING
1375 (aset char-acronym-table
#x202B
"RLE") ; RIGHT-TO-LEFT EMBEDDING
1376 (aset char-acronym-table
#x202C
"PDF") ; POP DIRECTIONAL FORMATTING
1377 (aset char-acronym-table
#x202D
"LRO") ; LEFT-TO-RIGHT OVERRIDE
1378 (aset char-acronym-table
#x202E
"RLO") ; RIGHT-TO-LEFT OVERRIDE
1379 (aset char-acronym-table
#x2060
"WJ") ; WORD JOINER
1380 (aset char-acronym-table
#x206A
"ISS") ; INHIBIT SYMMETRIC SWAPPING
1381 (aset char-acronym-table
#x206B
"ASS") ; ACTIVATE SYMMETRIC SWAPPING
1382 (aset char-acronym-table
#x206C
"IAFS") ; INHIBIT ARABIC FORM SHAPING
1383 (aset char-acronym-table
#x206D
"AAFS") ; ACTIVATE ARABIC FORM SHAPING
1384 (aset char-acronym-table
#x206E
"NADS") ; NATIONAL DIGIT SHAPES
1385 (aset char-acronym-table
#x206F
"NODS") ; NOMINAL DIGIT SHAPES
1386 (aset char-acronym-table
#xFEFF
"ZWNBSP") ; ZERO WIDTH NO-BREAK SPACE
1387 (aset char-acronym-table
#xFFF9
"IAA") ; INTERLINEAR ANNOTATION ANCHOR
1388 (aset char-acronym-table
#xFFFA
"IAS") ; INTERLINEAR ANNOTATION SEPARATOR
1389 (aset char-acronym-table
#xFFFB
"IAT") ; INTERLINEAR ANNOTATION TERMINATOR
1390 (aset char-acronym-table
#x1D173
"BEGBM") ; MUSICAL SYMBOL BEGIN BEAM
1391 (aset char-acronym-table
#x1D174
"ENDBM") ; MUSICAL SYMBOL END BEAM
1392 (aset char-acronym-table
#x1D175
"BEGTIE") ; MUSICAL SYMBOL BEGIN TIE
1393 (aset char-acronym-table
#x1D176
"END") ; MUSICAL SYMBOL END TIE
1394 (aset char-acronym-table
#x1D177
"BEGSLR") ; MUSICAL SYMBOL BEGIN SLUR
1395 (aset char-acronym-table
#x1D178
"ENDSLR") ; MUSICAL SYMBOL END SLUR
1396 (aset char-acronym-table
#x1D179
"BEGPHR") ; MUSICAL SYMBOL BEGIN PHRASE
1397 (aset char-acronym-table
#x1D17A
"ENDPHR") ; MUSICAL SYMBOL END PHRASE
1398 (aset char-acronym-table
#xE0001
"|->TAG") ; LANGUAGE TAG
1399 (aset char-acronym-table
#xE0020
"SP TAG") ; TAG SPACE
1401 (aset char-acronym-table
(+ #xE0021 i
) (format " %c TAG" (+ 33 i
))))
1402 (aset char-acronym-table
#xE007F
"->|TAG") ; CANCEL TAG
1404 (defun update-glyphless-char-display (&optional variable value
)
1405 "Make the setting of `glyphless-char-display-control' take effect.
1406 This function updates the char-table `glyphless-char-display'."
1408 (set-default variable value
))
1410 (let ((target (car elt
))
1412 (or (memq method
'(zero-width thin-space empty-box acronym hex-code
))
1413 (error "Invalid glyphless character display method: %s" method
))
1414 (cond ((eq target
'c0-control
)
1415 (glyphless-set-char-table-range glyphless-char-display
1417 ;; Users will not expect their newlines and TABs be
1418 ;; displayed as anything but themselves, so exempt those
1419 ;; two characters from c0-control.
1420 (set-char-table-range glyphless-char-display
#x9 nil
)
1421 (set-char-table-range glyphless-char-display
#xa nil
))
1422 ((eq target
'c1-control
)
1423 (glyphless-set-char-table-range glyphless-char-display
1425 ((eq target
'format-control
)
1426 (when unicode-category-table
1428 #'(lambda (char category
)
1429 (if (eq category
'Cf
)
1430 (let ((this-method method
)
1433 (setq from
(car char
) to
(cdr char
))
1434 (setq from char to char
))
1436 (when (/= from
#xAD
)
1437 (if (eq method
'acronym
)
1439 (aref char-acronym-table from
)))
1440 (set-char-table-range glyphless-char-display
1442 (setq from
(1+ from
))))))
1443 unicode-category-table
)))
1444 ((eq target
'no-font
)
1445 (set-char-table-extra-slot glyphless-char-display
0 method
))
1447 (error "Invalid glyphless character group: %s" target
))))))
1449 (defun glyphless-set-char-table-range (chartable from to method
)
1450 (if (eq method
'acronym
)
1453 (set-char-table-range chartable i
(aref char-acronym-table i
))
1455 (set-char-table-range chartable
(cons from to
) method
)))
1457 ;;; Control of displaying glyphless characters.
1458 (defcustom glyphless-char-display-control
1459 '((format-control . thin-space
)
1460 (no-font . hex-code
))
1461 "List of directives to control display of glyphless characters.
1463 Each element has the form (GROUP . METHOD), where GROUP is a
1464 symbol specifying the character group, and METHOD is a symbol
1465 specifying the method of displaying characters belonging to that
1468 GROUP must be one of these symbols:
1469 `c0-control': U+0000..U+001F, but excluding newline and TAB.
1470 `c1-control': U+0080..U+009F.
1471 `format-control': Characters of Unicode General Category `Cf',
1472 such as U+200C (ZWNJ), U+200E (LRM), but
1473 excluding characters that have graphic images,
1474 such as U+00AD (SHY).
1475 `no-font': characters for which no suitable font is found.
1476 For character terminals, characters that cannot
1477 be encoded by `terminal-coding-system'.
1479 METHOD must be one of these symbols:
1480 `zero-width': don't display.
1481 `thin-space': display a thin (1-pixel width) space. On character
1482 terminals, display as 1-character space.
1483 `empty-box': display an empty box.
1484 `acronym': display an acronym of the character in a box. The
1485 acronym is taken from `char-acronym-table', which see.
1486 `hex-code': display the hexadecimal character code in a box.
1488 Do not set its value directly from Lisp; the value takes effect
1489 only via a custom `:set'
1490 function (`update-glyphless-char-display'), which updates
1491 `glyphless-char-display'."
1493 :type
'(alist :key-type
(symbol :tag
"Character Group")
1494 :value-type
(symbol :tag
"Display Method"))
1495 :options
'((c0-control
1496 (choice (const :tag
"Don't display" zero-width
)
1497 (const :tag
"Display as thin space" thin-space
)
1498 (const :tag
"Display as empty box" empty-box
)
1499 (const :tag
"Display acronym" acronym
)
1500 (const :tag
"Display hex code in a box" hex-code
)))
1502 (choice (const :tag
"Don't display" zero-width
)
1503 (const :tag
"Display as thin space" thin-space
)
1504 (const :tag
"Display as empty box" empty-box
)
1505 (const :tag
"Display acronym" acronym
)
1506 (const :tag
"Display hex code in a box" hex-code
)))
1508 (choice (const :tag
"Don't display" zero-width
)
1509 (const :tag
"Display as thin space" thin-space
)
1510 (const :tag
"Display as empty box" empty-box
)
1511 (const :tag
"Display acronym" acronym
)
1512 (const :tag
"Display hex code in a box" hex-code
)))
1514 (choice (const :tag
"Don't display" zero-width
)
1515 (const :tag
"Display as thin space" thin-space
)
1516 (const :tag
"Display as empty box" empty-box
)
1517 (const :tag
"Display acronym" acronym
)
1518 (const :tag
"Display hex code in a box" hex-code
))))
1519 :set
'update-glyphless-char-display
1523 ;;; Setting word boundary.
1525 (setq word-combining-categories
1531 (setq word-separating-categories
; (2-byte character sets)
1532 '((?H . ?K
) ; Hiragana - Katakana
1539 ;;; characters.el ends here