comparison lisp/international/mule.el @ 18195:9650375d0a68

Delete declaration for buffer-file-coding-system. It is done in buffer.c now. In the comment, change coding-system to coding system. The name coding-vector is changed to coding-spec. (coding-vector-type, coding-vector-mnemonic, coding-vector-docstring, coding-vector-flags): Deleted. (coding-system-spec-ref): New function. (coding-system-type, coding-system-mnemonic, coding-system-flags): Use coding-system-spec-ref. (coding-system-doc-string): Renamed from coding-system-docstring. (coding-system-eol-type): Renamed from coding-system-eoltype. (coding-system-eol-type-mnemonic): Moved to mule-util.el. (coding-system-post-read-conversion): Likewise. (coding-system-pre-write-conversion): Likewise. (default-process-coding-system): Deleted. Now declared in buffer.c. (make-subsidiary-coding-system): New function. (make-coding-system): Check arguments more strictly. Do not make -unix, -dos, -mac variants for TYPE 4. (define-coding-system-alias): Call make-subsidiary-coding-system. (set-buffer-file-coding-system): Adjusted for the function name changes. (find-new-buffer-file-coding-system): Likewise. (default-process-coding-system): Deleted. Now defined in coding.c.
author Kenichi Handa <handa@m17n.org>
date Tue, 10 Jun 1997 00:56:15 +0000
parents 4882d58acf01
children 3d036a21fc93
comparison
equal deleted inserted replaced
18194:c291aa915b85 18195:9650375d0a68
209 See also the documentation of make-char." 209 See also the documentation of make-char."
210 (let ((l (split-char char))) 210 (let ((l (split-char char)))
211 (and (or (= (nth 1 l) 0) (eq (nth 2 l) 0)) 211 (and (or (= (nth 1 l) 0) (eq (nth 2 l) 0))
212 (not (eq (car l) 'composition))))) 212 (not (eq (car l) 'composition)))))
213 213
214 ;; Coding-system staffs 214 ;; Coding system staffs
215 215
216 ;; Coding-system object is a symbol that has the property 216 ;; Coding system is a symbol that has the property `coding-system'.
217 ;; `coding-system' and `eol-type'.
218 ;; 217 ;;
219 ;; The value of the property `coding-system' is a coding-vector of the 218 ;; The value of the property `coding-system' is a vector of the
220 ;; format: [TYPE MNEMONIC DOCSTRING NOT-USED-NOW FLAGS]. 219 ;; following format:
221 ;; See comments in src/coding.c for more detail. The property value 220 ;; [TYPE MNEMONIC DOC-STRING NOT-USED-NOW FLAGS]
222 ;; may be another coding-system, in which case, the coding-vector 221 ;; We call this vector as coding-spec. See comments in src/coding.c
223 ;; should be taken from that coding-system. 222 ;; for more detail. The property value may be another coding system,
224 ;; 223 ;; in which case, the coding-spec should be taken from that
225 ;; The value of the property `eol-type' is integer 0..2 or a vector of 224 ;; coding-system. The 4th element NOT-USED-NOW is kept just for
226 ;; length 3. The integer value 0, 1, and 2 indicate the format of 225 ;; backward compatibility with old version of Mule.
226
227 (defconst coding-spec-type-idx 0)
228 (defconst coding-spec-mnemonic-idx 1)
229 (defconst coding-spec-doc-string-idx 2)
230 (defconst coding-spec-flags-idx 4)
231
232 ;; Coding system may have proerpty `eol-type'. The value of the
233 ;; property `eol-type' is integer 0..2 or a vector of three coding
234 ;; systems. The integer value 0, 1, and 2 indicate the format of
227 ;; end-of-line LF, CRLF, and CR respectively. The vector value 235 ;; end-of-line LF, CRLF, and CR respectively. The vector value
228 ;; indicates that the format of end-of-line should be detected 236 ;; indicates that the format of end-of-line should be detected
229 ;; automatically. Nth element of the vector is the subsidiary 237 ;; automatically. Nth element of the vector is the subsidiary coding
230 ;; coding-system whose `eol-type' property is integer value. 238 ;; system whose `eol-type' property is N.
231 ;; 239 ;;
232 ;; Coding-system may also have properties `post-read-conversion' and 240 ;; Coding system may also have properties `post-read-conversion' and
233 ;; `pre-write-conversion and the values are functions. 241 ;; `pre-write-conversion. Values of these properties are functions.
234 ;; 242 ;;
235 ;; The function in `post-read-conversion' is called after some text is 243 ;; The function in `post-read-conversion' is called after some text is
236 ;; inserted and decoded along the coding-system and before any 244 ;; inserted and decoded along the coding system and before any
237 ;; functions in `after-insert-functions' are called. The arguments to 245 ;; functions in `after-insert-functions' are called. The arguments to
238 ;; this function is the same as those of a function in 246 ;; this function is the same as those of a function in
239 ;; `after-insert-functions', i.e. LENGTH of a text while putting point 247 ;; `after-insert-functions', i.e. LENGTH of a text while putting point
240 ;; at the head of the text to be decoded 248 ;; at the head of the text to be decoded
241 ;; 249 ;;
242 ;; The function in `pre-write-conversion' is called after all 250 ;; The function in `pre-write-conversion' is called after all
243 ;; functions in `write-region-annotate-functions' and 251 ;; functions in `write-region-annotate-functions' and
244 ;; `buffer-file-format' are called, and before the text is encoded by 252 ;; `buffer-file-format' are called, and before the text is encoded by
245 ;; the coding-system. The arguments to this function is the same as 253 ;; the coding system. The arguments to this function is the same as
246 ;; those of a function in `write-region-annotate-functions', i.e. FROM 254 ;; those of a function in `write-region-annotate-functions', i.e. FROM
247 ;; and TO specifying region of a text. 255 ;; and TO specifying region of a text.
248 256
249 (defsubst coding-vector-type (vec) (aref vec 0)) 257 ;; Return Nth element of coding-spec of CODING-SYSTEM.
250 (defsubst coding-vector-mnemonic (vec) (aref vec 1)) 258 (defun coding-system-spec-ref (coding-system n)
251 (defsubst coding-vector-docstring (vec) (aref vec 2)) 259 (check-coding-system coding-system)
252 (defsubst coding-vector-flags (vec) (aref vec 4)) 260 (let ((vec (coding-system-spec coding-system)))
253 261 (and vec (aref vec n))))
254 ;; Return type of CODING-SYSTEM. 262
255 (defun coding-system-type (coding-system) 263 (defun coding-system-type (coding-system)
256 (check-coding-system coding-system) 264 "Return TYPE element in coding-spec of CODING-SYSTEM."
257 (let ((vec (coding-system-vector coding-system))) 265 (coding-system-spec-ref coding-system coding-spec-type-idx))
258 (if vec (coding-vector-type vec)))) 266
259
260 ;; Return mnemonic character of CODING-SYSTEM.
261 (defun coding-system-mnemonic (coding-system) 267 (defun coding-system-mnemonic (coding-system)
262 (check-coding-system coding-system) 268 "Return MNEMONIC element in coding-spec of CODING-SYSTEM."
263 (let ((vec (coding-system-vector coding-system))) 269 (or (coding-system-spec-ref coding-system coding-spec-mnemonic-idx)
264 (if vec (coding-vector-mnemonic vec) 270 ?-))
265 ?-))) 271
266 272 (defun coding-system-doc-string (coding-system)
267 ;; Return docstring of CODING-SYSTEM. 273 "Return DOC-STRING element in coding-spec of CODING-SYSTEM."
268 (defun coding-system-docstring (coding-system) 274 (coding-system-spec-ref coding-system coding-spec-doc-string-idx))
269 (check-coding-system coding-system) 275
270 (let ((vec (coding-system-vector coding-system)))
271 (if vec (coding-vector-docstring vec))))
272
273 ;; Return flags of CODING-SYSTEM.
274 (defun coding-system-flags (coding-system) 276 (defun coding-system-flags (coding-system)
275 (check-coding-system coding-system) 277 "Return FLAGS element in coding-spec of CODING-SYSTEM."
276 (let ((vec (coding-system-vector coding-system))) 278 (coding-system-spec-ref coding-system coding-spec-flags-idx))
277 (if vec (coding-vector-flags vec)))) 279
278 280 (defun coding-system-eol-type (coding-system)
279 ;; Return eol-type of CODING-SYSTEM. 281 "Return eol-type property of CODING-SYSTEM."
280 (defun coding-system-eoltype (coding-system)
281 (check-coding-system coding-system) 282 (check-coding-system coding-system)
282 (and coding-system 283 (and coding-system
283 (or (get coding-system 'eol-type) 284 (or (get coding-system 'eol-type)
284 (coding-system-eoltype (get coding-system 'coding-system))))) 285 (coding-system-eol-type (get coding-system 'coding-system)))))
285 286
286 ;; Return mnemonic character of eol-type of CODING-SYSTEM. 287 ;; Make subsidiear coding systems of CODING-SYSTEM whose base is BASE.
287 (defun coding-system-eoltype-mnemonic (coding-system) 288 (defun make-subsidiary-coding-system (coding-system base)
288 (let ((eol-type (coding-system-eoltype coding-system))) 289 (let ((subsidiaries (vector (intern (format "%s-unix" coding-system))
289 (cond ((vectorp eol-type) eol-mnemonic-undecided) 290 (intern (format "%s-dos" coding-system))
290 ((eq eol-type 0) eol-mnemonic-unix) 291 (intern (format "%s-mac" coding-system))))
291 ((eq eol-type 1) eol-mnemonic-unix) 292 (i 0))
292 ((eq eol-type 2) eol-mnemonic-unix) 293 (while (< i 3)
293 (t ?-)))) 294 (put (aref subsidiaries i) 'coding-system base)
294 295 (put (aref subsidiaries i) 'eol-type i)
295 ;; Return function for post-read-conversion of CODING-SYSTEM. 296 (put (aref subsidiaries i) 'eol-variant t)
296 (defun coding-system-post-read-conversion (coding-system) 297 (setq i (1+ i)))
297 (and coding-system 298 subsidiaries))
298 (symbolp coding-system) 299
299 (or (get coding-system 'post-read-conversion) 300 (defun make-coding-system (coding-system type mnemonic doc-string
300 (coding-system-post-read-conversion 301 &optional flags)
301 (get coding-system 'coding-system)))))
302
303 ;; Return function for pre-write-conversion of CODING-SYSTEM.
304 (defun coding-system-pre-write-conversion (coding-system)
305 (and coding-system
306 (symbolp coding-system)
307 (or (get coding-system 'pre-write-conversion)
308 (coding-system-pre-write-conversion
309 (get coding-system 'coding-system)))))
310
311 (defun make-coding-system (coding-system type mnemonic docstring
312 &optional flags)
313 "Define a new CODING-SYSTEM (symbol). 302 "Define a new CODING-SYSTEM (symbol).
314 Remaining arguments are TYPE, MNEMONIC, DOCSTRING, and FLAGS (optional). 303 Remaining arguments are TYPE, MNEMONIC, DOC-STRING, and FLAGS (optional) which
304 construct a coding-spec of CODING-SYSTEM in the following format:
305 [TYPE MNEMONIC DOC-STRING nil FLAGS]
315 TYPE is an integer value indicating the type of coding-system as follows: 306 TYPE is an integer value indicating the type of coding-system as follows:
316 0: Emacs internal format, 307 0: Emacs internal format,
317 1: Shift-JIS (or MS-Kanji) used mainly on Japanese PC, 308 1: Shift-JIS (or MS-Kanji) used mainly on Japanese PC,
318 2: ISO-2022 including many variants, 309 2: ISO-2022 including many variants,
319 3: Big5 used mainly on Chinese PC, 310 3: Big5 used mainly on Chinese PC,
320 4: private, CCL programs provide encoding/decoding algorithm. 311 4: private, CCL programs provide encoding/decoding algorithm.
321 MNEMONIC is a character to be displayed on mode line for the coding-system. 312 MNEMONIC is a character to be displayed on mode line for the coding-system.
322 DOCSTRING is a documentation string for the coding-system. 313 DOC-STRING is a documentation string for the coding-system.
323 FLAGS specifies more precise information of each TYPE. 314 FLAGS specifies more precise information of each TYPE.
324 If TYPE is 2 (ISO-2022), FLAGS should be a list of: 315 If TYPE is 2 (ISO-2022), FLAGS should be a list of:
325 CHARSET0, CHARSET1, CHARSET2, CHARSET3, SHORT-FORM, 316 CHARSET0, CHARSET1, CHARSET2, CHARSET3, SHORT-FORM,
326 ASCII-EOL, ASCII-CNTL, SEVEN, LOCKING-SHIFT, SINGLE-SHIFT, 317 ASCII-EOL, ASCII-CNTL, SEVEN, LOCKING-SHIFT, SINGLE-SHIFT,
327 USE-ROMAN, USE-OLDJIS, NO-ISO6429, INIT-BOL, DESIGNATION-BOL. 318 USE-ROMAN, USE-OLDJIS, NO-ISO6429, INIT-BOL, DESIGNATION-BOL.
346 at beginning of line on output. 337 at beginning of line on output.
347 If TYPE is 4 (private), FLAGS should be a cons of CCL programs, 338 If TYPE is 4 (private), FLAGS should be a cons of CCL programs,
348 for encoding and decoding. See the documentation of CCL for more detail." 339 for encoding and decoding. See the documentation of CCL for more detail."
349 340
350 ;; At first, set a value of `coding-system' property. 341 ;; At first, set a value of `coding-system' property.
351 (let ((coding-vector (make-vector 5 nil))) 342 (let ((coding-spec (make-vector 5 nil)))
352 (aset coding-vector 0 type) 343 (if (or (not (integerp type)) (< type 0) (> type 4))
353 (aset coding-vector 1 344 (error "TYPE argument must be 0..4"))
354 ;; MNEMONIC must be a printable character. 345 (if (or (not (integerp mnemonic)) (<= mnemonic ? ) (> mnemonic 127))
355 (if (and (> mnemonic ? ) (< mnemonic 127)) mnemonic ? )) 346 (error "MNEMONIC arguemnt must be a printable character."))
356 (aset coding-vector 2 (if (stringp docstring) docstring "")) 347 (aset coding-spec 0 type)
357 (aset coding-vector 3 nil) ; obsolete element 348 (aset coding-spec 1 mnemonic)
349 (aset coding-spec 2 (if (stringp doc-string) doc-string ""))
350 (aset coding-spec 3 nil) ; obsolete element
358 (cond ((eq type 2) ; ISO2022 351 (cond ((eq type 2) ; ISO2022
359 (let ((i 0) 352 (let ((i 0)
360 (vec (make-vector 32 nil))) 353 (vec (make-vector 32 nil)))
361 (while (< i 4) 354 (while (< i 4)
362 (let ((charset (car flags))) 355 (let ((charset (car flags)))
374 (aset vec i charset)) 367 (aset vec i charset))
375 (setq flags (cdr flags) i (1+ i))) 368 (setq flags (cdr flags) i (1+ i)))
376 (while (and (< i 32) flags) 369 (while (and (< i 32) flags)
377 (aset vec i (car flags)) 370 (aset vec i (car flags))
378 (setq flags (cdr flags) i (1+ i))) 371 (setq flags (cdr flags) i (1+ i)))
379 (aset coding-vector 4 vec))) 372 (aset coding-spec 4 vec)))
380 ((eq type 4) ; private 373 ((eq type 4) ; private
381 (if (and (consp flags) 374 (if (and (consp flags)
382 (vectorp (car flags)) 375 (vectorp (car flags))
383 (vectorp (cdr flags))) 376 (vectorp (cdr flags)))
384 (aset coding-vector 4 flags) 377 (aset coding-spec 4 flags)
385 (error "Invalid FLAGS argument for TYPE 4 (CCL)"))) 378 (error "Invalid FLAGS argument for TYPE 4 (CCL)")))
386 (t (aset coding-vector 4 flags))) 379 (t (aset coding-spec 4 flags)))
387 (put coding-system 'coding-system coding-vector)) 380 (put coding-system 'coding-system coding-spec))
388 381
389 ;; Next, set a value of `eol-type' property. The value is a vector 382 ;; Next, set a value of `eol-type' property. The value is a vector
390 ;; of subsidiary coding-systems, each corresponds to a coding-system 383 ;; of subsidiary coding systems, each corresponds to a coding-system
391 ;; for the detected end-of-line format. 384 ;; for the detected end-of-line format.
392 (let ((codings (vector (intern (format "%s-unix" coding-system)) 385 (put coding-system 'eol-type
393 (intern (format "%s-dos" coding-system)) 386 (if (<= type 3)
394 (intern (format "%s-mac" coding-system)))) 387 (make-subsidiary-coding-system coding-system coding-system)
395 (i 0)) 388 0)))
396 (while (< i 3) 389
397 (put (aref codings i) 'coding-system coding-system) 390 (defun define-coding-system-alias (coding-system alias)
398 (put (aref codings i) 'eol-type i) 391 "Define ALIAS as an alias coding system of CODING-SYSTEM."
399 (setq i (1+ i))) 392 (check-coding-system coding-system)
400 (put coding-system 'eol-type codings)) 393 (put alias 'coding-system coding-system)
401 ) 394 (if (vectorp (coding-system-eol-type coding-system))
402 395 (make-subsidiary-coding-system alias coding-system)))
403 (defun define-coding-system-alias (symbol new-symbol)
404 "Define NEW-SYMBOL as the same coding system as SYMBOL."
405 (check-coding-system symbol)
406 (put new-symbol 'coding-system symbol)
407 (let ((eol-type (coding-system-eoltype symbol)))
408 (if (vectorp eol-type)
409 (let* ((name (symbol-name new-symbol))
410 (new-eol-type (vector (intern (concat name "-unix"))
411 (intern (concat name "-dos"))
412 (intern (concat name "-mac")))))
413 (define-coding-system-alias (aref eol-type 0) (aref new-eol-type 0))
414 (define-coding-system-alias (aref eol-type 1) (aref new-eol-type 1))
415 (define-coding-system-alias (aref eol-type 2) (aref new-eol-type 2))
416 (setq eol-type new-eol-type)))
417 (put new-symbol 'eol-type eol-type)))
418
419 (defvar buffer-file-coding-system nil
420 "Coding-system of the file which the current-buffer is visiting.")
421 (make-variable-buffer-local 'buffer-file-coding-system)
422 ;; This value should not be reset by changing major mode.
423 (put 'buffer-file-coding-system 'permanent-local t)
424 396
425 (defun set-buffer-file-coding-system (coding-system &optional force) 397 (defun set-buffer-file-coding-system (coding-system &optional force)
426 "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM. 398 "Set buffer-file-coding-system of the current buffer to CODING-SYSTEM.
427 If eol-type of the current buffer-file-coding-system is an integer value N, and 399 If eol-type of the current buffer-file-coding-system is an integer value N, and
428 eol-type of CODING-SYSTEM is a vector, the Nth element of the vector is used 400 eol-type of CODING-SYSTEM is a vector, the Nth element of the vector is used
430 Optional prefix argument FORCE non-nil means CODING-SYSTEM is set 402 Optional prefix argument FORCE non-nil means CODING-SYSTEM is set
431 regardless of eol-type of the current buffer-file-coding-system." 403 regardless of eol-type of the current buffer-file-coding-system."
432 (interactive "zBuffer-file-coding-system: \nP") 404 (interactive "zBuffer-file-coding-system: \nP")
433 (check-coding-system coding-system) 405 (check-coding-system coding-system)
434 (if (null force) 406 (if (null force)
435 (let ((x (coding-system-eoltype buffer-file-coding-system)) 407 (let ((x (coding-system-eol-type buffer-file-coding-system))
436 (y (coding-system-eoltype coding-system))) 408 (y (coding-system-eol-type coding-system)))
437 (if (and (numberp x) (>= x 0) (<= x 2) (vectorp y)) 409 (if (and (numberp x) (>= x 0) (<= x 2) (vectorp y))
438 (setq coding-system (aref y x))))) 410 (setq coding-system (aref y x)))))
439 (setq buffer-file-coding-system coding-system) 411 (setq buffer-file-coding-system coding-system)
440 (set-buffer-modified-p t) 412 (set-buffer-modified-p t)
441 (force-mode-line-update)) 413 (force-mode-line-update))
468 (error "no process") 440 (error "no process")
469 (check-coding-system decoding) 441 (check-coding-system decoding)
470 (check-coding-system encoding) 442 (check-coding-system encoding)
471 (set-process-coding-system proc decoding encoding))) 443 (set-process-coding-system proc decoding encoding)))
472 (force-mode-line-update)) 444 (force-mode-line-update))
473
474 (defvar default-process-coding-system (cons nil nil)
475 "Cons of default values used to read from and write to process.")
476 445
477 (defun set-coding-priority (arg) 446 (defun set-coding-priority (arg)
478 "Set priority of coding-category according to LIST. 447 "Set priority of coding-category according to LIST.
479 LIST is a list of coding-categories ordered by priority." 448 LIST is a list of coding-categories ordered by priority."
480 (let (l) 449 (let (l)
510 479
511 (setq after-insert-file-functions 480 (setq after-insert-file-functions
512 (cons 'after-insert-file-set-buffer-file-coding-system 481 (cons 'after-insert-file-set-buffer-file-coding-system
513 after-insert-file-functions)) 482 after-insert-file-functions))
514 483
515 ;; The coding-vector and eol-type of coding-system returned is decided 484 ;; The coding-spec and eol-type of coding-system returned is decided
516 ;; independently in the following order. 485 ;; independently in the following order.
517 ;; 1. That of buffer-file-coding-system locally bound. 486 ;; 1. That of buffer-file-coding-system locally bound.
518 ;; 2. That of CODING. 487 ;; 2. That of CODING.
519 488
520 (defun find-new-buffer-file-coding-system (coding) 489 (defun find-new-buffer-file-coding-system (coding)
532 ;; Get information of the current local value of 501 ;; Get information of the current local value of
533 ;; `buffer-file-coding-system' in LOCAL-EOL and LOCAL-CODING. 502 ;; `buffer-file-coding-system' in LOCAL-EOL and LOCAL-CODING.
534 (if (local-variable-p 'buffer-file-coding-system) 503 (if (local-variable-p 'buffer-file-coding-system)
535 ;; Something already set locally. 504 ;; Something already set locally.
536 (progn 505 (progn
537 (setq local-eol (coding-system-eoltype buffer-file-coding-system)) 506 (setq local-eol (coding-system-eol-type buffer-file-coding-system))
538 (if (null (numberp local-eol)) 507 (if (null (numberp local-eol))
539 ;; But eol-type is not yet set. 508 ;; But eol-type is not yet set.
540 (setq local-eol nil)) 509 (setq local-eol nil))
541 (if (null (eq (coding-system-type buffer-file-coding-system) t)) 510 (if (null (eq (coding-system-type buffer-file-coding-system) t))
542 ;; This is not `undecided'. 511 ;; This is not `undecided'.
549 (if (and local-eol local-coding) 518 (if (and local-eol local-coding)
550 ;; The current buffer has already set full coding-system, we 519 ;; The current buffer has already set full coding-system, we
551 ;; had better not change it. 520 ;; had better not change it.
552 nil 521 nil
553 522
554 (setq found-eol (coding-system-eoltype coding)) 523 (setq found-eol (coding-system-eol-type coding))
555 (if (null (numberp found-eol)) 524 (if (null (numberp found-eol))
556 ;; But eol-type is not found. 525 ;; But eol-type is not found.
557 (setq found-eol nil)) 526 (setq found-eol nil))
558 (if (eq (coding-system-type coding) t) 527 (if (eq (coding-system-type coding) t)
559 ;; This is `undecided', which means nothing found except 528 ;; This is `undecided', which means nothing found except
562 531
563 ;; The local setting takes precedence over the found one. 532 ;; The local setting takes precedence over the found one.
564 (setq new-coding (or local-coding coding)) 533 (setq new-coding (or local-coding coding))
565 (setq new-eol (or local-eol found-eol)) 534 (setq new-eol (or local-eol found-eol))
566 (if (and (numberp new-eol) 535 (if (and (numberp new-eol)
567 (vectorp (coding-system-eoltype new-coding))) 536 (vectorp (coding-system-eol-type new-coding)))
568 (setq new-coding 537 (setq new-coding
569 (aref (coding-system-eoltype new-coding) new-eol))) 538 (aref (coding-system-eol-type new-coding) new-eol)))
570 new-coding)))) 539 new-coding))))
571 540
572 (defun make-unification-table (&rest args) 541 (defun make-unification-table (&rest args)
573 "Make a unification table (char table) from arguments. 542 "Make a unification table (char table) from arguments.
574 Each argument is a list of the form (FROM . TO), 543 Each argument is a list of the form (FROM . TO),