diff options
| author | Kenichi Handa | 1997-06-18 12:55:11 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1997-06-18 12:55:11 +0000 |
| commit | be1d31dcea2631d5204286849f67e449c5758302 (patch) | |
| tree | bb6c1447a7ea4e9b65e23a35f0597d7bdf095788 | |
| parent | 6e9722b0623c953d36ab97725525de58ffcee1fb (diff) | |
| download | emacs-be1d31dcea2631d5204286849f67e449c5758302.tar.gz emacs-be1d31dcea2631d5204286849f67e449c5758302.zip | |
(coding-system-parent): New function.
(coding-system-lessp): New function.
(coding-system-list): Sort coding systems by coding-system-lessp.
An element of returned list is always coing system, never be a
cons.
(modify-coding-system-alist): Renamed from
set-coding-system-alist.
(prefer-coding-system): New function.
(compose-chars-component): But fix for handling a composite
character of no compositon rule.
| -rw-r--r-- | lisp/international/mule-util.el | 238 |
1 files changed, 155 insertions, 83 deletions
diff --git a/lisp/international/mule-util.el b/lisp/international/mule-util.el index 97404446c69..25f2c6db6ba 100644 --- a/lisp/international/mule-util.el +++ b/lisp/international/mule-util.el | |||
| @@ -196,51 +196,10 @@ Optional 3rd argument NIL-FOR-TOO-LONG non-nil means return nil | |||
| 196 | (if nil-for-too-long nil i) | 196 | (if nil-for-too-long nil i) |
| 197 | alist))) | 197 | alist))) |
| 198 | 198 | ||
| 199 | |||
| 199 | ;; Coding system related functions. | 200 | ;; Coding system related functions. |
| 200 | 201 | ||
| 201 | ;;;###autoload | 202 | ;;;###autoload |
| 202 | (defun coding-system-list (&optional base-only) | ||
| 203 | "Return a list of all existing coding systems. | ||
| 204 | If optional arg BASE-ONLY is non-nil, each element of the list | ||
| 205 | is a base coding system or a list of coding systems. | ||
| 206 | In the latter case, the first element is a base coding system, | ||
| 207 | and the remainings are aliases of it." | ||
| 208 | (let (l) | ||
| 209 | (mapatoms (lambda (x) (if (get x 'coding-system) (setq l (cons x l))))) | ||
| 210 | (if (not base-only) | ||
| 211 | l | ||
| 212 | (let* ((codings (sort l (function | ||
| 213 | (lambda (x y) | ||
| 214 | (<= (coding-system-mnemonic x) | ||
| 215 | (coding-system-mnemonic y)))))) | ||
| 216 | (tail (cons nil codings)) | ||
| 217 | (aliases nil) ; ((BASE ALIAS ...) ...) | ||
| 218 | base coding) | ||
| 219 | ;; At first, remove subsidiary coding systems (eol variants) and | ||
| 220 | ;; move alias coding systems to ALIASES. | ||
| 221 | (while (cdr tail) | ||
| 222 | (setq coding (car (cdr tail))) | ||
| 223 | (if (get coding 'eol-variant) | ||
| 224 | (setcdr tail (cdr (cdr tail))) | ||
| 225 | (setq base (coding-system-base coding)) | ||
| 226 | (if (and (not (eq coding base)) | ||
| 227 | (coding-system-equal coding base)) | ||
| 228 | (let ((slot (memq base aliases))) | ||
| 229 | (setcdr tail (cdr (cdr tail))) | ||
| 230 | (if slot | ||
| 231 | (setcdr slot (cons coding (cdr slot))) | ||
| 232 | (setq aliases (cons (list base coding) aliases)))) | ||
| 233 | (setq tail (cdr tail))))) | ||
| 234 | ;; Then, replace a coding system who has aliases with a list. | ||
| 235 | (setq tail codings) | ||
| 236 | (while tail | ||
| 237 | (let ((alias (assq (car tail) aliases))) | ||
| 238 | (if alias | ||
| 239 | (setcar tail alias))) | ||
| 240 | (setq tail (cdr tail))) | ||
| 241 | codings)))) | ||
| 242 | |||
| 243 | ;;;###autoload | ||
| 244 | (defun coding-system-base (coding-system) | 203 | (defun coding-system-base (coding-system) |
| 245 | "Return a base of CODING-SYSTEM. | 204 | "Return a base of CODING-SYSTEM. |
| 246 | The base is a coding system of which coding-system property is a | 205 | The base is a coding system of which coding-system property is a |
| @@ -251,6 +210,136 @@ coding-spec (see the function `make-coding-system')." | |||
| 251 | (coding-system-base coding-spec)))) | 210 | (coding-system-base coding-spec)))) |
| 252 | 211 | ||
| 253 | ;;;###autoload | 212 | ;;;###autoload |
| 213 | (defun coding-system-eol-type-mnemonic (coding-system) | ||
| 214 | "Return mnemonic letter of eol-type of CODING-SYSTEM." | ||
| 215 | (let ((eol-type (coding-system-eol-type coding-system))) | ||
| 216 | (cond ((vectorp eol-type) eol-mnemonic-undecided) | ||
| 217 | ((eq eol-type 0) eol-mnemonic-unix) | ||
| 218 | ((eq eol-type 1) eol-mnemonic-unix) | ||
| 219 | ((eq eol-type 2) eol-mnemonic-unix) | ||
| 220 | (t ?-)))) | ||
| 221 | |||
| 222 | ;;;###autoload | ||
| 223 | (defun coding-system-post-read-conversion (coding-system) | ||
| 224 | "Return post-read-conversion property of CODING-SYSTEM." | ||
| 225 | (and coding-system | ||
| 226 | (symbolp coding-system) | ||
| 227 | (or (get coding-system 'post-read-conversion) | ||
| 228 | (coding-system-post-read-conversion | ||
| 229 | (get coding-system 'coding-system))))) | ||
| 230 | |||
| 231 | ;;;###autoload | ||
| 232 | (defun coding-system-pre-write-conversion (coding-system) | ||
| 233 | "Return pre-write-conversion property of CODING-SYSTEM." | ||
| 234 | (and coding-system | ||
| 235 | (symbolp coding-system) | ||
| 236 | (or (get coding-system 'pre-write-conversion) | ||
| 237 | (coding-system-pre-write-conversion | ||
| 238 | (get coding-system 'coding-system))))) | ||
| 239 | |||
| 240 | ;;;###autoload | ||
| 241 | (defun coding-system-unification-table (coding-system) | ||
| 242 | "Return unification-table property of CODING-SYSTEM." | ||
| 243 | (and coding-system | ||
| 244 | (symbolp coding-system) | ||
| 245 | (or (get coding-system 'unification-table) | ||
| 246 | (coding-system-unification-table | ||
| 247 | (get coding-system 'coding-system))))) | ||
| 248 | |||
| 249 | ;;;###autoload | ||
| 250 | (defun coding-system-parent (coding-system) | ||
| 251 | "Return parent of CODING-SYSTEM." | ||
| 252 | (let ((parent (get coding-system 'parent-coding-system))) | ||
| 253 | (and parent | ||
| 254 | (or (coding-system-parent parent) | ||
| 255 | parent)))) | ||
| 256 | |||
| 257 | (defun coding-system-lessp (x y) | ||
| 258 | (cond ((eq x 'no-conversion) t) | ||
| 259 | ((eq y 'no-conversion) nil) | ||
| 260 | ((eq x 'emacs-mule) t) | ||
| 261 | ((eq y 'emacs-mule) nil) | ||
| 262 | ((eq x 'undecided) t) | ||
| 263 | ((eq y 'undecided) nil) | ||
| 264 | (t (let ((c1 (coding-system-mnemonic x)) | ||
| 265 | (c2 (coding-system-mnemonic y))) | ||
| 266 | (or (< (downcase c1) (downcase c2)) | ||
| 267 | (and (not (> (downcase c1) (downcase c2))) | ||
| 268 | (< c1 c2))))))) | ||
| 269 | |||
| 270 | ;;;###autoload | ||
| 271 | (defun coding-system-list (&optional base-only) | ||
| 272 | "Return a list of all existing coding systems. | ||
| 273 | If optional arg BASE-ONLY is non-nil, only base coding systems are listed." | ||
| 274 | (let (l) | ||
| 275 | (mapatoms (lambda (x) (if (get x 'coding-system) (setq l (cons x l))))) | ||
| 276 | (let* ((codings (sort l 'coding-system-lessp)) | ||
| 277 | (tail (cons nil codings)) | ||
| 278 | coding) | ||
| 279 | ;; At first, remove subsidiary coding systems (eol variants) and | ||
| 280 | ;; alias coding systems (if necessary). | ||
| 281 | (while (cdr tail) | ||
| 282 | (setq coding (car (cdr tail))) | ||
| 283 | (if (or (get coding 'eol-variant) | ||
| 284 | (and base-only (coding-system-parent coding))) | ||
| 285 | (setcdr tail (cdr (cdr tail))) | ||
| 286 | (setq tail (cdr tail)))) | ||
| 287 | codings))) | ||
| 288 | |||
| 289 | ;;;###autoload | ||
| 290 | (defun modify-coding-system-alist (target-type regexp coding-system) | ||
| 291 | "Modify one of look up tables for finding a coding system on I/O operation. | ||
| 292 | There are three of such tables, file-coding-system-alist, | ||
| 293 | process-coding-system-alist, and network-coding-system-alist. | ||
| 294 | |||
| 295 | TARGET-TYPE specifies which of them to modify. | ||
| 296 | If it is `file', it affects file-coding-system-alist (which see). | ||
| 297 | If it is `process', it affects process-coding-system-alist (which see). | ||
| 298 | If it is `network', it affects network-codign-system-alist (which see). | ||
| 299 | |||
| 300 | REGEXP is a regular expression matching a target of I/O operation. | ||
| 301 | The target is a file name if TARGET-TYPE is `file', a program name if | ||
| 302 | TARGET-TYPE is `process', or a network service name or a port number | ||
| 303 | to connect to if TARGET-TYPE is `network'. | ||
| 304 | |||
| 305 | CODING-SYSTEM is a coding system to perform code conversion on the I/O | ||
| 306 | operation, or a cons of coding systems for decoding and encoding | ||
| 307 | respectively, or a function symbol which returns the cons." | ||
| 308 | (or (memq target-type '(file process network)) | ||
| 309 | (error "Invalid target type: %s" target-type)) | ||
| 310 | (or (stringp regexp) | ||
| 311 | (and (eq target-type 'network) (integerp regexp)) | ||
| 312 | (error "Invalid regular expression: %s" regexp)) | ||
| 313 | (if (symbolp coding-system) | ||
| 314 | (if (not (fboundp coding-system)) | ||
| 315 | (progn | ||
| 316 | (check-coding-system coding-system) | ||
| 317 | (setq coding-system (cons coding-system coding-system)))) | ||
| 318 | (check-coding-system (car coding-system)) | ||
| 319 | (check-coding-system (cdr coding-system))) | ||
| 320 | (cond ((eq target-type 'file) | ||
| 321 | (let ((slot (assoc regexp file-coding-system-alist))) | ||
| 322 | (if slot | ||
| 323 | (setcdr slot coding-system) | ||
| 324 | (setq file-coding-system-alist | ||
| 325 | (cons (cons regexp coding-system) | ||
| 326 | file-coding-system-alist))))) | ||
| 327 | ((eq target-type 'process) | ||
| 328 | (let ((slot (assoc regexp process-coding-system-alist))) | ||
| 329 | (if slot | ||
| 330 | (setcdr slot coding-system) | ||
| 331 | (setq process-coding-system-alist | ||
| 332 | (cons (cons regexp coding-system) | ||
| 333 | process-coding-system-alist))))) | ||
| 334 | (t | ||
| 335 | (let ((slot (assoc regexp network-coding-system-alist))) | ||
| 336 | (if slot | ||
| 337 | (setcdr slot coding-system) | ||
| 338 | (setq network-coding-system-alist | ||
| 339 | (cons (cons regexp coding-system) | ||
| 340 | network-coding-system-alist))))))) | ||
| 341 | |||
| 342 | ;;;###autoload | ||
| 254 | (defun coding-system-plist (coding-system) | 343 | (defun coding-system-plist (coding-system) |
| 255 | "Return property list of CODING-SYSTEM." | 344 | "Return property list of CODING-SYSTEM." |
| 256 | (let ((found nil) | 345 | (let ((found nil) |
| @@ -283,48 +372,33 @@ coding-spec (see the function `make-coding-system')." | |||
| 283 | 372 | ||
| 284 | ;;;###autoload | 373 | ;;;###autoload |
| 285 | (defun coding-system-equal (coding-system-1 coding-system-2) | 374 | (defun coding-system-equal (coding-system-1 coding-system-2) |
| 286 | "Return t if and only of CODING-SYSTEM-1 and CODING-SYSTEM-2 are identical. | 375 | "Return t if and only if CODING-SYSTEM-1 and CODING-SYSTEM-2 are identical. |
| 287 | Two coding systems are identical if two symbols are equal | 376 | Two coding systems are identical if two symbols are equal |
| 288 | or one is an alias of the other." | 377 | or one is an alias of the other." |
| 289 | (equal (coding-system-plist coding-system-1) | 378 | (or (eq coding-system-1 coding-system-2) |
| 290 | (coding-system-plist coding-system-2))) | 379 | (equal (coding-system-plist coding-system-1) |
| 380 | (coding-system-plist coding-system-2)))) | ||
| 291 | 381 | ||
| 292 | ;;;###autoload | 382 | ;;;###autoload |
| 293 | (defun coding-system-eol-type-mnemonic (coding-system) | 383 | (defun prefer-coding-system (coding-system) |
| 294 | "Return mnemonic letter of eol-type of CODING-SYSTEM." | 384 | (interactive "zPrefered coding system: ") |
| 295 | (let ((eol-type (coding-system-eol-type coding-system))) | 385 | (if (not (and coding-system (coding-system-p coding-system))) |
| 296 | (cond ((vectorp eol-type) eol-mnemonic-undecided) | 386 | (error "Invalid coding system `%s'" coding-system)) |
| 297 | ((eq eol-type 0) eol-mnemonic-unix) | 387 | (let ((coding-category (coding-system-category coding-system)) |
| 298 | ((eq eol-type 1) eol-mnemonic-unix) | 388 | (parent (coding-system-parent coding-system))) |
| 299 | ((eq eol-type 2) eol-mnemonic-unix) | 389 | (if (not coding-category) |
| 300 | (t ?-)))) | 390 | ;; CODING-SYSTEM is no-conversion or undecided. |
| 301 | 391 | (error "Can't prefer the coding system `%s'" coding-system)) | |
| 302 | ;;;###autoload | 392 | (set coding-category (or parent coding-system)) |
| 303 | (defun coding-system-post-read-conversion (coding-system) | 393 | (if (not (eq coding-category (car coding-category-list))) |
| 304 | "Return post-read-conversion property of CODING-SYSTEM." | 394 | ;; We must change the order. |
| 305 | (and coding-system | 395 | (setq coding-category-list |
| 306 | (symbolp coding-system) | 396 | (cons coding-category |
| 307 | (or (get coding-system 'post-read-conversion) | 397 | (delq coding-category coding-category-list)))) |
| 308 | (coding-system-post-read-conversion | 398 | (if (and parent (interactive-p)) |
| 309 | (get coding-system 'coding-system))))) | 399 | (message "Highest priority is set to %s (parent of %s)" |
| 310 | 400 | parent coding-system)) | |
| 311 | ;;;###autoload | 401 | )) |
| 312 | (defun coding-system-pre-write-conversion (coding-system) | ||
| 313 | "Return pre-write-conversion property of CODING-SYSTEM." | ||
| 314 | (and coding-system | ||
| 315 | (symbolp coding-system) | ||
| 316 | (or (get coding-system 'pre-write-conversion) | ||
| 317 | (coding-system-pre-write-conversion | ||
| 318 | (get coding-system 'coding-system))))) | ||
| 319 | |||
| 320 | ;;;###autoload | ||
| 321 | (defun coding-system-unification-table (coding-system) | ||
| 322 | "Return unification-table property of CODING-SYSTEM." | ||
| 323 | (and coding-system | ||
| 324 | (symbolp coding-system) | ||
| 325 | (or (get coding-system 'unification-table) | ||
| 326 | (coding-system-unification-table | ||
| 327 | (get coding-system 'coding-system))))) | ||
| 328 | 402 | ||
| 329 | 403 | ||
| 330 | ;;; Composite charcater manipulations. | 404 | ;;; Composite charcater manipulations. |
| @@ -410,9 +484,7 @@ overall glyph is updated as follows: | |||
| 410 | (format "\240%c" (+ ch 128)) | 484 | (format "\240%c" (+ ch 128)) |
| 411 | (let ((str (char-to-string ch))) | 485 | (let ((str (char-to-string ch))) |
| 412 | (if (cmpcharp ch) | 486 | (if (cmpcharp ch) |
| 413 | (if (/= (aref str 1) ?\xFF) | 487 | (substring str (if (= (aref str 1) ?\xFF) 2 1)) |
| 414 | (error "Char %c can't be composed" ch) | ||
| 415 | (substring str 2)) | ||
| 416 | (aset str 0 (+ (aref str 0) ?\x20)) | 488 | (aset str 0 (+ (aref str 0) ?\x20)) |
| 417 | str)))) | 489 | str)))) |
| 418 | 490 | ||