1997-02-20 07:02:49 +00:00
|
|
|
|
;;; mule.el --- basic commands for mulitilingual environment
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
|
2001-05-17 09:09:14 +00:00
|
|
|
|
;; Copyright (C) 2001 Free Software Foundation, Inc.
|
1997-06-27 02:46:08 +00:00
|
|
|
|
;; Licensed to the Free Software Foundation.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;; Keywords: mule, multilingual, character set, coding system
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
1997-02-23 09:20:52 +00:00
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2001-07-15 19:53:53 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;; Code:
|
|
|
|
|
|
2000-06-16 12:52:34 +00:00
|
|
|
|
(defconst mule-version "5.0 (SAKAKI)" "\
|
1997-02-20 07:02:49 +00:00
|
|
|
|
Version number and name of this version of MULE (multilingual environment).")
|
|
|
|
|
|
1999-12-15 00:40:48 +00:00
|
|
|
|
(defconst mule-version-date "1999.12.7" "\
|
1997-02-20 07:02:49 +00:00
|
|
|
|
Distribution date of this version of MULE (multilingual environment).")
|
|
|
|
|
|
|
|
|
|
(defun load-with-code-conversion (fullname file &optional noerror nomessage)
|
1997-12-04 04:47:41 +00:00
|
|
|
|
"Execute a file of Lisp code named FILE whose absolute name is FULLNAME.
|
|
|
|
|
The file contents are decoded before evaluation if necessary.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
If optional second arg NOERROR is non-nil,
|
|
|
|
|
report no error if FILE doesn't exist.
|
|
|
|
|
Print messages at start and end of loading unless
|
|
|
|
|
optional third arg NOMESSAGE is non-nil.
|
|
|
|
|
Return t if file exists."
|
|
|
|
|
(if (null (file-readable-p fullname))
|
|
|
|
|
(and (null noerror)
|
|
|
|
|
(signal 'file-error (list "Cannot open load file" file)))
|
|
|
|
|
;; Read file with code conversion, and then eval.
|
|
|
|
|
(let* ((buffer
|
|
|
|
|
;; To avoid any autoloading, set default-major-mode to
|
|
|
|
|
;; fundamental-mode.
|
1998-04-20 07:08:17 +00:00
|
|
|
|
;; So that we don't get completely screwed if the
|
|
|
|
|
;; file is encoded in some complicated character set,
|
|
|
|
|
;; read it with real decoding, as a multibyte buffer,
|
|
|
|
|
;; even if this is a --unibyte Emacs session.
|
|
|
|
|
(let ((default-major-mode 'fundamental-mode)
|
|
|
|
|
(default-enable-multibyte-characters t))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; We can't use `generate-new-buffer' because files.el
|
|
|
|
|
;; is not yet loaded.
|
|
|
|
|
(get-buffer-create (generate-new-buffer-name " *load*"))))
|
1997-10-23 14:58:25 +00:00
|
|
|
|
(load-in-progress t)
|
|
|
|
|
(source (save-match-data (string-match "\\.el\\'" fullname))))
|
|
|
|
|
(unless nomessage
|
|
|
|
|
(if source
|
|
|
|
|
(message "Loading %s (source)..." file)
|
|
|
|
|
(message "Loading %s..." file)))
|
|
|
|
|
(when purify-flag
|
|
|
|
|
(setq preloaded-file-list (cons file preloaded-file-list)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(unwind-protect
|
1997-10-23 12:05:45 +00:00
|
|
|
|
(let ((load-file-name fullname)
|
1998-07-06 01:52:48 +00:00
|
|
|
|
(set-auto-coding-for-load t)
|
1997-10-23 12:05:45 +00:00
|
|
|
|
(inhibit-file-name-operation nil))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(set-buffer buffer)
|
|
|
|
|
(insert-file-contents fullname)
|
1998-12-10 13:37:02 +00:00
|
|
|
|
;; If the loaded file was inserted with no-conversion or
|
|
|
|
|
;; raw-text coding system, make the buffer unibyte.
|
|
|
|
|
;; Otherwise, eval-buffer might try to interpret random
|
|
|
|
|
;; binary junk as multibyte characters.
|
|
|
|
|
(if (and enable-multibyte-characters
|
|
|
|
|
(or (eq (coding-system-type last-coding-system-used) 5)
|
|
|
|
|
(eq last-coding-system-used 'no-conversion)))
|
|
|
|
|
(set-buffer-multibyte nil))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; Make `kill-buffer' quiet.
|
|
|
|
|
(set-buffer-modified-p nil))
|
1997-12-04 04:47:41 +00:00
|
|
|
|
;; Have the original buffer current while we eval.
|
1998-04-20 07:08:17 +00:00
|
|
|
|
(eval-buffer buffer nil file
|
|
|
|
|
;; If this Emacs is running with --unibyte,
|
|
|
|
|
;; convert multibyte strings to unibyte
|
|
|
|
|
;; after reading them.
|
1998-04-23 21:57:25 +00:00
|
|
|
|
;; (not default-enable-multibyte-characters)
|
1999-08-07 03:18:48 +00:00
|
|
|
|
nil t
|
1998-04-23 21:57:25 +00:00
|
|
|
|
))
|
1997-07-04 00:17:55 +00:00
|
|
|
|
(let (kill-buffer-hook kill-buffer-query-functions)
|
|
|
|
|
(kill-buffer buffer)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(let ((hook (assoc file after-load-alist)))
|
1997-10-23 14:58:25 +00:00
|
|
|
|
(when hook
|
|
|
|
|
(mapcar (function eval) (cdr hook))))
|
|
|
|
|
(unless (or nomessage noninteractive)
|
|
|
|
|
(if source
|
|
|
|
|
(message "Loading %s (source)...done" file)
|
|
|
|
|
(message "Loading %s...done" file)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
t)))
|
|
|
|
|
|
|
|
|
|
;; API (Application Program Interface) for charsets.
|
|
|
|
|
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(defsubst charset-quoted-standard-p (obj)
|
2001-02-11 17:07:35 +00:00
|
|
|
|
"Return t if OBJ is a quoted symbol, and is the name of a standard charset."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(and (listp obj) (eq (car obj) 'quote)
|
|
|
|
|
(symbolp (car-safe (cdr obj)))
|
|
|
|
|
(let ((vector (get (car-safe (cdr obj)) 'charset)))
|
|
|
|
|
(and (vectorp vector)
|
|
|
|
|
(< (aref vector 0) 160)))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defsubst charsetp (object)
|
1999-12-02 14:34:59 +00:00
|
|
|
|
"T if OBJECT is a charset."
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(and (symbolp object) (vectorp (get object 'charset))))
|
|
|
|
|
|
|
|
|
|
(defsubst charset-info (charset)
|
|
|
|
|
"Return a vector of information of CHARSET.
|
|
|
|
|
The elements of the vector are:
|
|
|
|
|
CHARSET-ID, BYTES, DIMENSION, CHARS, WIDTH, DIRECTION,
|
|
|
|
|
LEADING-CODE-BASE, LEADING-CODE-EXT,
|
|
|
|
|
ISO-FINAL-CHAR, ISO-GRAPHIC-PLANE,
|
|
|
|
|
REVERSE-CHARSET, SHORT-NAME, LONG-NAME, DESCRIPTION,
|
|
|
|
|
PLIST,
|
|
|
|
|
where
|
|
|
|
|
CHARSET-ID (integer) is the identification number of the charset.
|
1999-05-26 08:05:50 +00:00
|
|
|
|
BYTES (integer) is the length of multi-byte form of a character in
|
|
|
|
|
the charset: one of 1, 2, 3, and 4.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
DIMENSION (integer) is the number of bytes to represent a character of
|
|
|
|
|
the charset: 1 or 2.
|
|
|
|
|
CHARS (integer) is the number of characters in a dimension: 94 or 96.
|
|
|
|
|
WIDTH (integer) is the number of columns a character in the charset
|
|
|
|
|
occupies on the screen: one of 0, 1, and 2.
|
|
|
|
|
DIRECTION (integer) is the rendering direction of characters in the
|
1999-05-26 07:14:06 +00:00
|
|
|
|
charset when rendering. If 0, render from left to right, else
|
|
|
|
|
render from right to left.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
LEADING-CODE-BASE (integer) is the base leading-code for the
|
|
|
|
|
charset.
|
|
|
|
|
LEADING-CODE-EXT (integer) is the extended leading-code for the
|
|
|
|
|
charset. All charsets of less than 0xA0 has the value 0.
|
|
|
|
|
ISO-FINAL-CHAR (character) is the final character of the
|
2001-01-31 00:12:02 +00:00
|
|
|
|
corresponding ISO 2022 charset. If the charset is not assigned
|
|
|
|
|
any final character, the value is -1.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked
|
|
|
|
|
while encoding to variants of ISO 2022 coding system, one of the
|
|
|
|
|
following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR).
|
2001-01-31 00:12:02 +00:00
|
|
|
|
If the charset is not assigned any final character, the value is -1.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
REVERSE-CHARSET (integer) is the charset which differs only in
|
|
|
|
|
LEFT-TO-RIGHT value from the charset. If there's no such a
|
|
|
|
|
charset, the value is -1.
|
|
|
|
|
SHORT-NAME (string) is the short name to refer to the charset.
|
|
|
|
|
LONG-NAME (string) is the long name to refer to the charset
|
|
|
|
|
DESCRIPTION (string) is the description string of the charset.
|
|
|
|
|
PLIST (property list) may contain any type of information a user
|
|
|
|
|
want to put and get by functions `put-charset-property' and
|
|
|
|
|
`get-charset-property' respectively."
|
|
|
|
|
(get charset 'charset))
|
|
|
|
|
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
;; It is better not to use backquote in this file,
|
|
|
|
|
;; because that makes a bootstrapping problem
|
|
|
|
|
;; if you need to recompile all the Lisp files using interpreted code.
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(defmacro charset-id (charset)
|
|
|
|
|
"Return charset identification number of CHARSET."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 0)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 0)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-bytes (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return bytes of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 1)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 1)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-dimension (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return dimension of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 2)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 2)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-chars (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return character numbers contained in a dimension of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 3)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 3)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-width (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return width (how many column occupied on a screen) of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 4)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 4)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-direction (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return direction of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 5)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 5)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-iso-final-char (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return final char of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 8)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 8)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-iso-graphic-plane (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return graphic plane of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 9)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 9)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-reverse-charset (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return reverse charset of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 10)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 10)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-short-name (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return short name of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 11)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 11)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-long-name (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return long name of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 12)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 12)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-description (charset)
|
1998-08-31 18:26:27 +00:00
|
|
|
|
"Return description of CHARSET.
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
See the function `charset-info' for more detail."
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(if (charset-quoted-standard-p charset)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aref (charset-info (nth 1 charset)) 13)
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref (list 'charset-info charset) 13)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defmacro charset-plist (charset)
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return list charset property of CHARSET.
|
|
|
|
|
See the function `charset-info' for more detail."
|
* international/mule-cmds.el (global-map):
Do not use backquote, because that makes a bootstrapping
problem if you need to recompile all Lisp files using interpreted code.
* international/mule.el (charset-id, charset-bytes,
charset-dimension, charset-chars, charset-width,
charset-direction, charset-iso-final-char,
charset-iso-graphic-plane, charset-reverse-charset,
charset-short-name, charset-long-name, charset-description,
charset-plist): Likewise.
* international/mule-cmds.el
(set-display-table-and-terminal-coding-system): New function,
containing code migrated out of set-language-environment.
(set-language-environment, set-locale-environment): Use it.
(locale-translation-file-name): Moved here from startup.el.
(locale-language-names, locale-preferred-coding-systems):
New vars.
(locale-name-match, set-locale-environment): New functions.
1999-10-19 07:20:09 +00:00
|
|
|
|
(list 'aref
|
|
|
|
|
(if (charset-quoted-standard-p charset)
|
|
|
|
|
(charset-info (nth 1 charset))
|
|
|
|
|
(list 'charset-info charset))
|
|
|
|
|
14))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defun set-charset-plist (charset plist)
|
1998-09-06 14:31:49 +00:00
|
|
|
|
"Set CHARSET's property list to PLIST, and return PLIST."
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aset (charset-info charset) 14 plist))
|
|
|
|
|
|
2000-12-02 15:30:10 +00:00
|
|
|
|
(defun make-char (charset &optional code1 code2)
|
|
|
|
|
"Return a character of CHARSET whose position codes are CODE1 and CODE2.
|
1997-03-18 23:16:27 +00:00
|
|
|
|
CODE1 and CODE2 are optional, but if you don't supply
|
1999-01-08 04:19:24 +00:00
|
|
|
|
sufficient position codes, return a generic character which stands for
|
|
|
|
|
all characters or group of characters in the character set.
|
2000-12-02 15:30:10 +00:00
|
|
|
|
A generic character can be used to index a char table (e.g. syntax-table).
|
2000-12-21 00:06:23 +00:00
|
|
|
|
|
|
|
|
|
Such character sets as ascii, eight-bit-control, and eight-bit-graphic
|
|
|
|
|
don't have corresponding generic characters. If CHARSET is one of
|
|
|
|
|
them and you don't supply CODE1, return the character of the smallest
|
|
|
|
|
code in CHARSET.
|
|
|
|
|
|
2000-12-02 15:30:10 +00:00
|
|
|
|
If CODE1 or CODE2 are invalid (out of range), this function signals an error."
|
2000-12-02 16:06:04 +00:00
|
|
|
|
(make-char-internal (charset-id charset) code1 code2))
|
1997-10-23 12:05:45 +00:00
|
|
|
|
|
|
|
|
|
(put 'make-char 'byte-compile
|
2001-02-11 17:07:35 +00:00
|
|
|
|
(function
|
1997-10-23 12:05:45 +00:00
|
|
|
|
(lambda (form)
|
|
|
|
|
(let ((charset (nth 1 form)))
|
|
|
|
|
(if (charset-quoted-standard-p charset)
|
|
|
|
|
(byte-compile-normal-call
|
|
|
|
|
(cons 'make-char-internal
|
|
|
|
|
(cons (charset-id (nth 1 charset)) (nthcdr 2 form))))
|
|
|
|
|
(byte-compile-normal-call
|
|
|
|
|
(cons 'make-char-internal
|
|
|
|
|
(cons (list 'charset-id charset) (nthcdr 2 form)))))))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1997-09-25 12:26:38 +00:00
|
|
|
|
(defun charset-list ()
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
"Return list of charsets ever defined.
|
|
|
|
|
|
1997-09-25 12:26:38 +00:00
|
|
|
|
This function is provided for backward compatibility.
|
(charset-bytes, charset-dimension,
charset-chars, charset-width, charset-direction,
charset-iso-final-char, charset-iso-graphic-plane,
charset-reverse-charset, cahrset-short-name, charset-long-name,
charset-description, charset-plit, set-charset-plist): Document
them.
(make-char, charset-list): Doc-string modified.
(find-new-buffer-file-coding-system): Fix bug of handling the
coding system undecided.
1997-07-02 12:59:41 +00:00
|
|
|
|
Now we have the variable `charset-list'."
|
1997-09-25 12:26:38 +00:00
|
|
|
|
charset-list)
|
|
|
|
|
|
1997-05-16 00:58:57 +00:00
|
|
|
|
(defsubst generic-char-p (char)
|
|
|
|
|
"Return t if and only if CHAR is a generic character.
|
2001-02-11 17:07:35 +00:00
|
|
|
|
See also the documentation of `make-char'."
|
1998-04-11 02:18:31 +00:00
|
|
|
|
(and (>= char 0400)
|
|
|
|
|
(let ((l (split-char char)))
|
|
|
|
|
(and (or (= (nth 1 l) 0) (eq (nth 2 l) 0))
|
|
|
|
|
(not (eq (car l) 'composition))))))
|
1997-02-26 13:01:42 +00:00
|
|
|
|
|
2000-10-30 01:32:44 +00:00
|
|
|
|
(defun decode-char (ccs code-point &optional restriction)
|
2000-11-06 12:42:06 +00:00
|
|
|
|
"Return character specified by coded character set CCS and CODE-POINT in it.
|
2000-10-30 01:32:44 +00:00
|
|
|
|
Return nil if such a character is not supported.
|
2000-12-06 18:48:59 +00:00
|
|
|
|
Currently the only supported coded character set is `ucs' (ISO/IEC
|
|
|
|
|
10646: Universal Multi-Octet Coded Character Set).
|
2000-10-30 01:32:44 +00:00
|
|
|
|
|
|
|
|
|
Optional argument RESTRICTION specifies a way to map the pair of CCS
|
2001-05-20 04:19:41 +00:00
|
|
|
|
and CODE-POINT to a character. Currently not supported and just ignored."
|
2000-10-30 01:32:44 +00:00
|
|
|
|
(cond ((eq ccs 'ucs)
|
2001-01-16 06:50:23 +00:00
|
|
|
|
(cond ((< code-point 160)
|
2000-10-30 01:32:44 +00:00
|
|
|
|
code-point)
|
|
|
|
|
((< code-point 256)
|
|
|
|
|
(make-char 'latin-iso8859-1 code-point))
|
|
|
|
|
((< code-point #x2500)
|
|
|
|
|
(setq code-point (- code-point #x0100))
|
2001-02-11 17:07:35 +00:00
|
|
|
|
(make-char 'mule-unicode-0100-24ff
|
2000-10-30 01:32:44 +00:00
|
|
|
|
(+ (/ code-point 96) 32) (+ (% code-point 96) 32)))
|
2001-01-16 06:50:23 +00:00
|
|
|
|
((< code-point #x3400)
|
2000-10-30 01:32:44 +00:00
|
|
|
|
(setq code-point (- code-point #x2500))
|
|
|
|
|
(make-char 'mule-unicode-2500-33ff
|
|
|
|
|
(+ (/ code-point 96) 32) (+ (% code-point 96) 32)))
|
|
|
|
|
((and (>= code-point #xe000) (< code-point #x10000))
|
|
|
|
|
(setq code-point (- code-point #xe000))
|
|
|
|
|
(make-char 'mule-unicode-e000-ffff
|
|
|
|
|
(+ (/ code-point 96) 32) (+ (% code-point 96) 32)))
|
|
|
|
|
))))
|
|
|
|
|
|
|
|
|
|
(defun encode-char (char ccs &optional restriction)
|
2000-11-06 12:42:06 +00:00
|
|
|
|
"Return code-point in coded character set CCS that corresponds to CHAR.
|
2000-10-30 01:32:44 +00:00
|
|
|
|
Return nil if CHAR is not included in CCS.
|
2000-12-06 18:48:59 +00:00
|
|
|
|
Currently the only supported coded character set is `ucs' (ISO/IEC
|
|
|
|
|
10646: Universal Multi-Octet Coded Character Set).
|
2000-11-06 12:42:06 +00:00
|
|
|
|
|
|
|
|
|
CHAR should be in one of these charsets:
|
2000-10-30 01:32:44 +00:00
|
|
|
|
ascii, latin-iso8859-1, mule-unicode-0100-24ff, mule-unicode-2500-33ff,
|
2001-01-16 06:50:23 +00:00
|
|
|
|
mule-unicode-e000-ffff, eight-bit-control
|
2000-10-30 01:32:44 +00:00
|
|
|
|
Otherwise, return nil.
|
|
|
|
|
|
|
|
|
|
Optional argument RESTRICTION specifies a way to map CHAR to a
|
|
|
|
|
code-point in CCS. Currently not supported and just ignored."
|
|
|
|
|
(let* ((split (split-char char))
|
|
|
|
|
(charset (car split)))
|
|
|
|
|
(cond ((eq ccs 'ucs)
|
|
|
|
|
(cond ((eq charset 'ascii)
|
|
|
|
|
char)
|
|
|
|
|
((eq charset 'latin-iso8859-1)
|
|
|
|
|
(+ (nth 1 split) 128))
|
|
|
|
|
((eq charset 'mule-unicode-0100-24ff)
|
|
|
|
|
(+ #x0100 (+ (* (- (nth 1 split) 32) 96)
|
|
|
|
|
(- (nth 2 split) 32))))
|
|
|
|
|
((eq charset 'mule-unicode-2500-33ff)
|
|
|
|
|
(+ #x2500 (+ (* (- (nth 1 split) 32) 96)
|
|
|
|
|
(- (nth 2 split) 32))))
|
|
|
|
|
((eq charset 'mule-unicode-e000-ffff)
|
|
|
|
|
(+ #xe000 (+ (* (- (nth 1 split) 32) 96)
|
2001-01-16 06:50:23 +00:00
|
|
|
|
(- (nth 2 split) 32))))
|
|
|
|
|
((eq charset 'eight-bit-control)
|
|
|
|
|
char))))))
|
2000-10-30 01:32:44 +00:00
|
|
|
|
|
1997-10-21 10:47:35 +00:00
|
|
|
|
|
2000-12-06 18:48:59 +00:00
|
|
|
|
;; Coding system stuff
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1997-06-10 00:56:15 +00:00
|
|
|
|
;; Coding system is a symbol that has the property `coding-system'.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;
|
1997-06-10 00:56:15 +00:00
|
|
|
|
;; The value of the property `coding-system' is a vector of the
|
|
|
|
|
;; following format:
|
1997-09-25 12:26:38 +00:00
|
|
|
|
;; [TYPE MNEMONIC DOC-STRING PLIST FLAGS]
|
1997-06-10 00:56:15 +00:00
|
|
|
|
;; We call this vector as coding-spec. See comments in src/coding.c
|
2001-02-11 17:07:35 +00:00
|
|
|
|
;; for more detail.
|
1997-06-10 00:56:15 +00:00
|
|
|
|
|
|
|
|
|
(defconst coding-spec-type-idx 0)
|
|
|
|
|
(defconst coding-spec-mnemonic-idx 1)
|
|
|
|
|
(defconst coding-spec-doc-string-idx 2)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(defconst coding-spec-plist-idx 3)
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(defconst coding-spec-flags-idx 4)
|
|
|
|
|
|
1997-10-23 12:05:45 +00:00
|
|
|
|
;; PLIST is a property list of a coding system. To share PLIST among
|
|
|
|
|
;; alias coding systems, a coding system has PLIST in coding-spec
|
|
|
|
|
;; instead of having it in normal property list of Lisp symbol.
|
|
|
|
|
;; Here's a list of coding system properties currently being used.
|
1997-10-21 10:47:35 +00:00
|
|
|
|
;;
|
|
|
|
|
;; o coding-category
|
|
|
|
|
;;
|
|
|
|
|
;; The value is a coding category the coding system belongs to. The
|
2001-02-11 17:07:35 +00:00
|
|
|
|
;; function `make-coding-system' sets this value automatically
|
2000-03-07 06:15:36 +00:00
|
|
|
|
;; unless its argument PROPERTIES specifies this property.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;
|
1997-10-21 10:47:35 +00:00
|
|
|
|
;; o alias-coding-systems
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;
|
1997-10-21 10:47:35 +00:00
|
|
|
|
;; The value is a list of coding systems of the same alias group. The
|
|
|
|
|
;; first element is the coding system made at first, which we call as
|
2000-03-07 06:15:36 +00:00
|
|
|
|
;; `base coding system'. The function `make-coding-system' sets this
|
|
|
|
|
;; value automatically and `define-coding-system-alias' updates it.
|
1997-10-21 10:47:35 +00:00
|
|
|
|
;;
|
2001-01-31 23:56:40 +00:00
|
|
|
|
;; See the documentation of make-coding-system for the meanings of the
|
|
|
|
|
;; following properties.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;;
|
2001-01-31 23:56:40 +00:00
|
|
|
|
;; o post-read-conversion
|
1997-10-21 10:47:35 +00:00
|
|
|
|
;; o pre-write-conversion
|
1998-05-22 09:45:34 +00:00
|
|
|
|
;; o translation-table-for-decode
|
|
|
|
|
;; o translation-table-for-encode
|
2000-07-27 06:08:14 +00:00
|
|
|
|
;; o safe-chars
|
1997-10-23 12:05:45 +00:00
|
|
|
|
;; o safe-charsets
|
1998-05-18 01:01:00 +00:00
|
|
|
|
;; o mime-charset
|
1998-08-02 01:06:57 +00:00
|
|
|
|
;; o valid-codes (meaningful only for a coding system based on CCL)
|
|
|
|
|
|
1997-10-21 10:47:35 +00:00
|
|
|
|
|
|
|
|
|
(defsubst coding-system-spec (coding-system)
|
2001-02-11 17:07:35 +00:00
|
|
|
|
"Return coding-spec of CODING-SYSTEM."
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(get (check-coding-system coding-system) 'coding-system))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defun coding-system-type (coding-system)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
"Return the coding type of CODING-SYSTEM.
|
|
|
|
|
A coding type is an integer value indicating the encoding method
|
|
|
|
|
of CODING-SYSTEM. See the function `make-coding-system' for more detail."
|
|
|
|
|
(aref (coding-system-spec coding-system) coding-spec-type-idx))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defun coding-system-mnemonic (coding-system)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
"Return the mnemonic character of CODING-SYSTEM.
|
1998-06-01 03:01:30 +00:00
|
|
|
|
The mnemonic character of a coding system is used in mode line
|
|
|
|
|
to indicate the coding system. If the arg is nil, return ?-."
|
|
|
|
|
(let ((spec (coding-system-spec coding-system)))
|
|
|
|
|
(if spec (aref spec coding-spec-mnemonic-idx) ?-)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(defun coding-system-doc-string (coding-system)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
"Return the documentation string for CODING-SYSTEM."
|
|
|
|
|
(aref (coding-system-spec coding-system) coding-spec-doc-string-idx))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1997-09-25 12:26:38 +00:00
|
|
|
|
(defun coding-system-plist (coding-system)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
"Return the property list of CODING-SYSTEM."
|
|
|
|
|
(aref (coding-system-spec coding-system) coding-spec-plist-idx))
|
1997-09-25 12:26:38 +00:00
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(defun coding-system-flags (coding-system)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
"Return `flags' of CODING-SYSTEM.
|
|
|
|
|
A `flags' of a coding system is a vector of length 32 indicating detailed
|
|
|
|
|
information of a coding system. See the function `make-coding-system'
|
|
|
|
|
for more detail."
|
|
|
|
|
(aref (coding-system-spec coding-system) coding-spec-flags-idx))
|
|
|
|
|
|
|
|
|
|
(defun coding-system-get (coding-system prop)
|
|
|
|
|
"Extract a value from CODING-SYSTEM's property list for property PROP."
|
|
|
|
|
(plist-get (coding-system-plist coding-system) prop))
|
|
|
|
|
|
|
|
|
|
(defun coding-system-put (coding-system prop val)
|
|
|
|
|
"Change value in CODING-SYSTEM's property list PROP to VAL."
|
|
|
|
|
(let ((plist (coding-system-plist coding-system)))
|
|
|
|
|
(if plist
|
|
|
|
|
(plist-put plist prop val)
|
|
|
|
|
(aset (coding-system-spec coding-system) coding-spec-plist-idx
|
|
|
|
|
(list prop val)))))
|
|
|
|
|
|
|
|
|
|
(defun coding-system-category (coding-system)
|
2001-03-01 18:19:09 +00:00
|
|
|
|
"Return the coding category of CODING-SYSTEM.
|
|
|
|
|
See also `coding-category-list'."
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(coding-system-get coding-system 'coding-category))
|
|
|
|
|
|
|
|
|
|
(defun coding-system-base (coding-system)
|
|
|
|
|
"Return the base coding system of CODING-SYSTEM.
|
1998-01-22 01:42:20 +00:00
|
|
|
|
A base coding system is what made by `make-coding-system'.
|
|
|
|
|
Any alias nor subsidiary coding systems are not base coding system."
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(car (coding-system-get coding-system 'alias-coding-systems)))
|
|
|
|
|
|
|
|
|
|
(defalias 'coding-system-parent 'coding-system-base)
|
2000-06-01 05:07:32 +00:00
|
|
|
|
(make-obsolete 'coding-system-parent 'coding-system-base "20.3")
|
1997-10-21 10:47:35 +00:00
|
|
|
|
|
|
|
|
|
;; Coding system also has a property `eol-type'.
|
|
|
|
|
;;
|
|
|
|
|
;; This property indicates how the coding system handles end-of-line
|
|
|
|
|
;; format. The value is integer 0, 1, 2, or a vector of three coding
|
|
|
|
|
;; systems. Each integer value 0, 1, and 2 indicates the format of
|
|
|
|
|
;; end-of-line LF, CRLF, and CR respectively. A vector value
|
|
|
|
|
;; indicates that the format of end-of-line should be detected
|
|
|
|
|
;; automatically. Nth element of the vector is the subsidiary coding
|
|
|
|
|
;; system whose `eol-type' property is N.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(defun coding-system-eol-type (coding-system)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
"Return eol-type of CODING-SYSTEM.
|
|
|
|
|
An eol-type is integer 0, 1, 2, or a vector of coding systems.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1997-10-21 10:47:35 +00:00
|
|
|
|
Integer values 0, 1, and 2 indicate a format of end-of-line; LF,
|
|
|
|
|
CRLF, and CR respectively.
|
|
|
|
|
|
|
|
|
|
A vector value indicates that a format of end-of-line should be
|
|
|
|
|
detected automatically. Nth element of the vector is the subsidiary
|
|
|
|
|
coding system whose eol-type is N."
|
|
|
|
|
(get coding-system 'eol-type))
|
1997-06-18 13:21:23 +00:00
|
|
|
|
|
1999-02-08 09:50:26 +00:00
|
|
|
|
(defun coding-system-lessp (x y)
|
|
|
|
|
(cond ((eq x 'no-conversion) t)
|
|
|
|
|
((eq y 'no-conversion) nil)
|
|
|
|
|
((eq x 'emacs-mule) t)
|
|
|
|
|
((eq y 'emacs-mule) nil)
|
|
|
|
|
((eq x 'undecided) t)
|
|
|
|
|
((eq y 'undecided) nil)
|
|
|
|
|
(t (let ((c1 (coding-system-mnemonic x))
|
|
|
|
|
(c2 (coding-system-mnemonic y)))
|
|
|
|
|
(or (< (downcase c1) (downcase c2))
|
|
|
|
|
(and (not (> (downcase c1) (downcase c2)))
|
|
|
|
|
(< c1 c2)))))))
|
|
|
|
|
|
|
|
|
|
(defun add-to-coding-system-list (coding-system)
|
2001-02-11 17:07:35 +00:00
|
|
|
|
"Add CODING-SYSTEM to `coding-system-list' while keeping it sorted."
|
1999-02-08 09:50:26 +00:00
|
|
|
|
(if (or (null coding-system-list)
|
|
|
|
|
(coding-system-lessp coding-system (car coding-system-list)))
|
|
|
|
|
(setq coding-system-list (cons coding-system coding-system-list))
|
|
|
|
|
(let ((len (length coding-system-list))
|
|
|
|
|
mid (tem coding-system-list))
|
|
|
|
|
(while (> len 1)
|
|
|
|
|
(setq mid (nthcdr (/ len 2) tem))
|
|
|
|
|
(if (coding-system-lessp (car mid) coding-system)
|
|
|
|
|
(setq tem mid
|
|
|
|
|
len (- len (/ len 2)))
|
|
|
|
|
(setq len (/ len 2))))
|
|
|
|
|
(setcdr tem (cons coding-system (cdr tem))))))
|
|
|
|
|
|
1999-02-18 13:11:24 +00:00
|
|
|
|
(defun coding-system-list (&optional base-only)
|
2000-07-27 06:08:14 +00:00
|
|
|
|
"Return a list of all existing non-subsidiary coding systems.
|
|
|
|
|
If optional arg BASE-ONLY is non-nil, only base coding systems are listed.
|
|
|
|
|
The value doesn't include subsidiary coding systems which are what
|
|
|
|
|
made from bases and aliases automatically for various end-of-line
|
|
|
|
|
formats (e.g. iso-latin-1-unix, koi8-r-dos)."
|
1999-02-18 13:11:24 +00:00
|
|
|
|
(let* ((codings (copy-sequence coding-system-list))
|
|
|
|
|
(tail (cons nil codings)))
|
|
|
|
|
;; Remove subsidiary coding systems (eol variants) and alias
|
|
|
|
|
;; coding systems (if necessary).
|
|
|
|
|
(while (cdr tail)
|
|
|
|
|
(let* ((coding (car (cdr tail)))
|
|
|
|
|
(aliases (coding-system-get coding 'alias-coding-systems)))
|
|
|
|
|
(if (or
|
|
|
|
|
;; CODING is an eol variant if not in ALIASES.
|
|
|
|
|
(not (memq coding aliases))
|
|
|
|
|
;; CODING is an alias if it is not car of ALIASES.
|
|
|
|
|
(and base-only (not (eq coding (car aliases)))))
|
|
|
|
|
(setcdr tail (cdr (cdr tail)))
|
|
|
|
|
(setq tail (cdr tail)))))
|
|
|
|
|
codings))
|
|
|
|
|
|
2000-07-27 06:08:14 +00:00
|
|
|
|
(defun register-char-codings (coding-system safe-chars)
|
|
|
|
|
(let ((general (char-table-extra-slot char-coding-system-table 0)))
|
|
|
|
|
(if (eq safe-chars t)
|
|
|
|
|
(or (memq coding-system general)
|
|
|
|
|
(set-char-table-extra-slot char-coding-system-table 0
|
|
|
|
|
(cons coding-system general)))
|
|
|
|
|
(map-char-table
|
|
|
|
|
(function
|
|
|
|
|
(lambda (key val)
|
|
|
|
|
(if (and (>= key 128) val)
|
|
|
|
|
(let ((codings (aref char-coding-system-table key)))
|
|
|
|
|
(or (memq coding-system codings)
|
|
|
|
|
(aset char-coding-system-table key
|
|
|
|
|
(cons coding-system codings)))))))
|
|
|
|
|
safe-chars))))
|
|
|
|
|
|
|
|
|
|
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(defun make-subsidiary-coding-system (coding-system)
|
2001-02-11 17:07:35 +00:00
|
|
|
|
"Make subsidiary coding systems (eol-type variants) of CODING-SYSTEM."
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(let ((coding-spec (coding-system-spec coding-system))
|
|
|
|
|
(subsidiaries (vector (intern (format "%s-unix" coding-system))
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(intern (format "%s-dos" coding-system))
|
|
|
|
|
(intern (format "%s-mac" coding-system))))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(i 0)
|
|
|
|
|
temp)
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(while (< i 3)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(put (aref subsidiaries i) 'coding-system coding-spec)
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(put (aref subsidiaries i) 'eol-type i)
|
1999-02-08 09:50:26 +00:00
|
|
|
|
(add-to-coding-system-list (aref subsidiaries i))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(setq coding-system-alist
|
|
|
|
|
(cons (list (symbol-name (aref subsidiaries i)))
|
|
|
|
|
coding-system-alist))
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(setq i (1+ i)))
|
|
|
|
|
subsidiaries))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2001-01-16 10:37:43 +00:00
|
|
|
|
(defun transform-make-coding-system-args (name type &optional doc-string props)
|
|
|
|
|
"For internal use only.
|
|
|
|
|
Transform XEmacs style args for `make-coding-system' to Emacs style.
|
|
|
|
|
Value is a list of transformed arguments."
|
|
|
|
|
(let ((mnemonic (string-to-char (or (plist-get props 'mnemonic) "?")))
|
|
|
|
|
(eol-type (plist-get props 'eol-type))
|
|
|
|
|
properties tmp)
|
|
|
|
|
(cond
|
|
|
|
|
((eq eol-type 'lf) (setq eol-type 'unix))
|
|
|
|
|
((eq eol-type 'crlf) (setq eol-type 'dos))
|
|
|
|
|
((eq eol-type 'cr) (setq eol-type 'mac)))
|
|
|
|
|
(if (setq tmp (plist-get props 'post-read-conversion))
|
|
|
|
|
(setq properties (plist-put properties 'post-read-conversion tmp)))
|
|
|
|
|
(if (setq tmp (plist-get props 'pre-write-conversion))
|
|
|
|
|
(setq properties (plist-put properties 'pre-write-conversion tmp)))
|
|
|
|
|
(cond
|
2001-02-06 23:39:26 +00:00
|
|
|
|
((eq type 'shift-jis)
|
|
|
|
|
`(,name 1 ,mnemonic ,doc-string () ,properties ,eol-type))
|
|
|
|
|
((eq type 'iso2022) ; This is not perfect.
|
|
|
|
|
(if (plist-get props 'escape-quoted)
|
|
|
|
|
(error "escape-quoted is not supported: %S"
|
|
|
|
|
`(,name ,type ,doc-string ,props)))
|
|
|
|
|
(let ((g0 (plist-get props 'charset-g0))
|
|
|
|
|
(g1 (plist-get props 'charset-g1))
|
|
|
|
|
(g2 (plist-get props 'charset-g2))
|
|
|
|
|
(g3 (plist-get props 'charset-g3))
|
|
|
|
|
(use-roman
|
|
|
|
|
(and
|
|
|
|
|
(eq (cadr (assoc 'latin-jisx0201
|
|
|
|
|
(plist-get props 'input-charset-conversion)))
|
|
|
|
|
'ascii)
|
|
|
|
|
(eq (cadr (assoc 'ascii
|
|
|
|
|
(plist-get props 'output-charset-conversion)))
|
|
|
|
|
'latin-jisx0201)))
|
|
|
|
|
(use-oldjis
|
|
|
|
|
(and
|
|
|
|
|
(eq (cadr (assoc 'japanese-jisx0208-1978
|
|
|
|
|
(plist-get props 'input-charset-conversion)))
|
|
|
|
|
'japanese-jisx0208)
|
|
|
|
|
(eq (cadr (assoc 'japanese-jisx0208
|
|
|
|
|
(plist-get props 'output-charset-conversion)))
|
|
|
|
|
'japanese-jisx0208-1978))))
|
|
|
|
|
(if (charsetp g0)
|
|
|
|
|
(if (plist-get props 'force-g0-on-output)
|
|
|
|
|
(setq g0 `(nil ,g0))
|
|
|
|
|
(setq g0 `(,g0 t))))
|
|
|
|
|
(if (charsetp g1)
|
|
|
|
|
(if (plist-get props 'force-g1-on-output)
|
|
|
|
|
(setq g1 `(nil ,g1))
|
|
|
|
|
(setq g1 `(,g1 t))))
|
|
|
|
|
(if (charsetp g2)
|
|
|
|
|
(if (plist-get props 'force-g2-on-output)
|
|
|
|
|
(setq g2 `(nil ,g2))
|
|
|
|
|
(setq g2 `(,g2 t))))
|
|
|
|
|
(if (charsetp g3)
|
|
|
|
|
(if (plist-get props 'force-g3-on-output)
|
|
|
|
|
(setq g3 `(nil ,g3))
|
|
|
|
|
(setq g3 `(,g3 t))))
|
|
|
|
|
`(,name 2 ,mnemonic ,doc-string
|
|
|
|
|
(,g0 ,g1 ,g2 ,g3
|
|
|
|
|
,(plist-get props 'short)
|
|
|
|
|
,(not (plist-get props 'no-ascii-eol))
|
|
|
|
|
,(not (plist-get props 'no-ascii-cntl))
|
|
|
|
|
,(plist-get props 'seven)
|
|
|
|
|
t
|
|
|
|
|
,(not (plist-get props 'lock-shift))
|
|
|
|
|
,use-roman
|
|
|
|
|
,use-oldjis
|
|
|
|
|
,(plist-get props 'no-iso6429)
|
|
|
|
|
nil nil nil nil)
|
|
|
|
|
,properties ,eol-type)))
|
|
|
|
|
((eq type 'big5)
|
|
|
|
|
`(,name 3 ,mnemonic ,doc-string () ,properties ,eol-type))
|
2001-01-16 10:37:43 +00:00
|
|
|
|
((eq type 'ccl)
|
2001-02-06 23:39:26 +00:00
|
|
|
|
`(,name 4 ,mnemonic ,doc-string
|
2001-01-16 10:37:43 +00:00
|
|
|
|
(,(plist-get props 'decode) . ,(plist-get props 'encode))
|
2001-02-06 23:39:26 +00:00
|
|
|
|
,properties ,eol-type))
|
2001-01-16 10:37:43 +00:00
|
|
|
|
(t
|
2001-02-06 23:39:26 +00:00
|
|
|
|
(error "unsupported XEmacs style make-coding-style arguments: %S"
|
2001-01-16 10:37:43 +00:00
|
|
|
|
`(,name ,type ,doc-string ,props))))))
|
|
|
|
|
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(defun make-coding-system (coding-system type mnemonic doc-string
|
2000-03-07 06:15:36 +00:00
|
|
|
|
&optional
|
|
|
|
|
flags
|
|
|
|
|
properties
|
|
|
|
|
eol-type)
|
1998-04-20 02:11:52 +00:00
|
|
|
|
"Define a new coding system CODING-SYSTEM (symbol).
|
2001-02-11 17:07:35 +00:00
|
|
|
|
Remaining arguments are TYPE, MNEMONIC, DOC-STRING, FLAGS (optional),
|
1998-01-22 01:42:20 +00:00
|
|
|
|
and PROPERTIES (optional) which construct a coding-spec of CODING-SYSTEM
|
1997-10-23 12:05:45 +00:00
|
|
|
|
in the following format:
|
1997-10-21 10:47:35 +00:00
|
|
|
|
[TYPE MNEMONIC DOC-STRING PLIST FLAGS]
|
1998-04-20 02:11:52 +00:00
|
|
|
|
|
|
|
|
|
TYPE is an integer value indicating the type of the coding system as follows:
|
1997-02-20 07:02:49 +00:00
|
|
|
|
0: Emacs internal format,
|
|
|
|
|
1: Shift-JIS (or MS-Kanji) used mainly on Japanese PC,
|
|
|
|
|
2: ISO-2022 including many variants,
|
|
|
|
|
3: Big5 used mainly on Chinese PC,
|
1997-08-28 10:49:48 +00:00
|
|
|
|
4: private, CCL programs provide encoding/decoding algorithm,
|
2001-02-11 17:07:35 +00:00
|
|
|
|
5: Raw-text, which means that text contains random 8-bit codes.
|
1997-10-21 10:47:35 +00:00
|
|
|
|
|
1998-04-20 02:11:52 +00:00
|
|
|
|
MNEMONIC is a character to be displayed on mode line for the coding system.
|
1997-10-21 10:47:35 +00:00
|
|
|
|
|
1998-04-20 02:11:52 +00:00
|
|
|
|
DOC-STRING is a documentation string for the coding system.
|
1997-10-21 10:47:35 +00:00
|
|
|
|
|
1998-04-20 02:11:52 +00:00
|
|
|
|
FLAGS specifies more detailed information of the coding system as follows:
|
1997-08-10 04:07:03 +00:00
|
|
|
|
|
1998-04-20 02:11:52 +00:00
|
|
|
|
If TYPE is 2 (ISO-2022), FLAGS is a list of these elements:
|
1997-02-20 07:02:49 +00:00
|
|
|
|
CHARSET0, CHARSET1, CHARSET2, CHARSET3, SHORT-FORM,
|
|
|
|
|
ASCII-EOL, ASCII-CNTL, SEVEN, LOCKING-SHIFT, SINGLE-SHIFT,
|
1997-08-10 04:07:03 +00:00
|
|
|
|
USE-ROMAN, USE-OLDJIS, NO-ISO6429, INIT-BOL, DESIGNATION-BOL,
|
1997-08-17 01:04:47 +00:00
|
|
|
|
SAFE, ACCEPT-LATIN-EXTRA-CODE.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
CHARSETn are character sets initially designated to Gn graphic registers.
|
|
|
|
|
If CHARSETn is nil, Gn is never used.
|
|
|
|
|
If CHARSETn is t, Gn can be used but nothing designated initially.
|
|
|
|
|
If CHARSETn is a list of character sets, those character sets are
|
|
|
|
|
designated to Gn on output, but nothing designated to Gn initially.
|
1998-09-18 13:10:40 +00:00
|
|
|
|
But, character set `ascii' can be designated only to G0.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
SHORT-FORM non-nil means use short designation sequence on output.
|
|
|
|
|
ASCII-EOL non-nil means designate ASCII to g0 at end of line on output.
|
|
|
|
|
ASCII-CNTL non-nil means designate ASCII to g0 before control codes and
|
|
|
|
|
SPACE on output.
|
|
|
|
|
SEVEN non-nil means use 7-bit code only on output.
|
|
|
|
|
LOCKING-SHIFT non-nil means use locking-shift.
|
|
|
|
|
SINGLE-SHIFT non-nil means use single-shift.
|
|
|
|
|
USE-ROMAN non-nil means designate JIS0201-1976-Roman instead of ASCII.
|
|
|
|
|
USE-OLDJIS non-nil means designate JIS0208-1976 instead of JIS0208-1983.
|
|
|
|
|
NO-ISO6429 non-nil means not use ISO6429's direction specification.
|
1997-02-26 13:01:42 +00:00
|
|
|
|
INIT-BOL non-nil means any designation state is assumed to be reset
|
|
|
|
|
to initial at each beginning of line on output.
|
|
|
|
|
DESIGNATION-BOL non-nil means designation sequences should be placed
|
|
|
|
|
at beginning of line on output.
|
1997-10-23 12:05:45 +00:00
|
|
|
|
SAFE non-nil means convert unsafe characters to `?' on output.
|
2000-07-27 06:08:14 +00:00
|
|
|
|
Characters not specified in the property `safe-charsets' nor
|
|
|
|
|
`safe-chars' are unsafe.
|
1997-08-17 01:04:47 +00:00
|
|
|
|
ACCEPT-LATIN-EXTRA-CODE non-nil means code-detection routine accepts
|
|
|
|
|
a code specified in `latin-extra-code-table' (which see) as a valid
|
|
|
|
|
code of the coding system.
|
1997-08-10 04:07:03 +00:00
|
|
|
|
|
1998-04-20 02:11:52 +00:00
|
|
|
|
If TYPE is 4 (private), FLAGS should be a cons of CCL programs, for
|
|
|
|
|
decoding and encoding. CCL programs should be specified by their
|
|
|
|
|
symbols.
|
1998-01-22 01:42:20 +00:00
|
|
|
|
|
2001-01-31 23:51:49 +00:00
|
|
|
|
PROPERTIES is an alist of properties vs the corresponding values. The
|
|
|
|
|
following properties are recognized:
|
|
|
|
|
|
|
|
|
|
o post-read-conversion
|
|
|
|
|
|
|
|
|
|
The value is a function to call after some text is inserted and
|
|
|
|
|
decoded by the coding system itself and before any functions in
|
2001-02-11 17:07:35 +00:00
|
|
|
|
`after-insert-functions' are called. The argument of this
|
|
|
|
|
function is the same as for a function in
|
|
|
|
|
`after-insert-file-functions', i.e. LENGTH of the text inserted,
|
|
|
|
|
with point at the head of the text to be decoded.
|
2001-01-31 23:51:49 +00:00
|
|
|
|
|
|
|
|
|
o pre-write-conversion
|
|
|
|
|
|
|
|
|
|
The value is a function to call after all functions in
|
|
|
|
|
`write-region-annotate-functions' and `buffer-file-format' are
|
|
|
|
|
called, and before the text is encoded by the coding system itself.
|
2001-02-21 14:58:35 +00:00
|
|
|
|
The arguments to this function are the same as those of a function
|
|
|
|
|
in `write-region-annotate-functions', i.e. FROM and TO, specifying
|
2001-02-11 17:07:35 +00:00
|
|
|
|
a region of text.
|
2001-01-31 23:51:49 +00:00
|
|
|
|
|
|
|
|
|
o translation-table-for-decode
|
|
|
|
|
|
|
|
|
|
The value is a translation table to be applied on decoding. See
|
|
|
|
|
the function `make-translation-table' for the format of translation
|
2001-02-11 17:07:35 +00:00
|
|
|
|
table. This is not applicable to type 4 (CCL-based) coding systems.
|
2001-01-31 23:51:49 +00:00
|
|
|
|
|
|
|
|
|
o translation-table-for-encode
|
|
|
|
|
|
2001-02-11 17:07:35 +00:00
|
|
|
|
The value is a translation table to be applied on encoding. This is
|
|
|
|
|
not applicable to type 4 (CCL-based) coding systems.
|
2001-01-31 23:51:49 +00:00
|
|
|
|
|
|
|
|
|
o safe-chars
|
|
|
|
|
|
|
|
|
|
The value is a char table. If a character has non-nil value in it,
|
|
|
|
|
the character is safely supported by the coding system. This
|
|
|
|
|
overrides the specification of safe-charsets.
|
|
|
|
|
|
|
|
|
|
o safe-charsets
|
2001-02-11 17:07:35 +00:00
|
|
|
|
|
2001-01-31 23:51:49 +00:00
|
|
|
|
The value is a list of charsets safely supported by the coding
|
|
|
|
|
system. The value t means that all charsets Emacs handles are
|
|
|
|
|
supported. Even if some charset is not in this list, it doesn't
|
2001-02-11 17:07:35 +00:00
|
|
|
|
mean that the charset can't be encoded in the coding system;
|
|
|
|
|
it just means that some other receiver of text encoded
|
2001-01-31 23:51:49 +00:00
|
|
|
|
in the coding system won't be able to handle that charset.
|
|
|
|
|
|
|
|
|
|
o mime-charset
|
|
|
|
|
|
|
|
|
|
The value is a symbol of which name is `MIME-charset' parameter of
|
|
|
|
|
the coding system.
|
|
|
|
|
|
|
|
|
|
o valid-codes (meaningful only for a coding system based on CCL)
|
|
|
|
|
|
|
|
|
|
The value is a list to indicate valid byte ranges of the encoded
|
|
|
|
|
file. Each element of the list is an integer or a cons of integer.
|
|
|
|
|
In the former case, the integer value is a valid byte code. In the
|
|
|
|
|
latter case, the integers specifies the range of valid byte codes.
|
|
|
|
|
|
1998-01-22 01:42:20 +00:00
|
|
|
|
These properties are set in PLIST, a property list. This function
|
|
|
|
|
also sets properties `coding-category' and `alias-coding-systems'
|
|
|
|
|
automatically.
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2000-03-07 06:15:36 +00:00
|
|
|
|
EOL-TYPE specifies the EOL type of the coding-system in one of the
|
|
|
|
|
following formats:
|
|
|
|
|
|
|
|
|
|
o symbol (unix, dos, or mac)
|
|
|
|
|
|
|
|
|
|
The symbol `unix' means Unix-like EOL (LF), `dos' means
|
|
|
|
|
DOS-like EOL (CRLF), and `mac' means MAC-like EOL (CR).
|
|
|
|
|
|
|
|
|
|
o number (0, 1, or 2)
|
|
|
|
|
|
|
|
|
|
The number 0, 1, and 2 mean UNIX, DOS, and MAC-like EOL
|
|
|
|
|
respectively.
|
|
|
|
|
|
|
|
|
|
o vector of coding-systems of length 3
|
|
|
|
|
|
|
|
|
|
The EOL type is detected automatically for the coding system.
|
|
|
|
|
And, according to the detected EOL type, one of the coding
|
|
|
|
|
systems in the vector is selected. Elements of the vector
|
2000-08-16 20:17:39 +00:00
|
|
|
|
corresponds to Unix-like EOL, DOS-like EOL, and Mac-like EOL
|
2000-03-07 06:15:36 +00:00
|
|
|
|
in this order.
|
|
|
|
|
|
1998-04-20 02:11:52 +00:00
|
|
|
|
Kludgy features for backward compatibility:
|
|
|
|
|
|
|
|
|
|
1. If TYPE is 4 and car or cdr of FLAGS is a vector, the vector is
|
|
|
|
|
treated as a compiled CCL code.
|
|
|
|
|
|
|
|
|
|
2. If PROPERTIES is just a list of character sets, the list is set as
|
|
|
|
|
a value of `safe-charsets' in PLIST."
|
2001-01-16 10:37:43 +00:00
|
|
|
|
|
|
|
|
|
;; For compatiblity with XEmacs, we check the type of TYPE. If it
|
2001-01-25 13:00:13 +00:00
|
|
|
|
;; is a symbol, perhaps, this function is called with XEmacs-style
|
|
|
|
|
;; arguments. Here, try to transform that kind of arguments to
|
2001-01-16 10:37:43 +00:00
|
|
|
|
;; Emacs style.
|
|
|
|
|
(if (symbolp type)
|
|
|
|
|
(let ((args (transform-make-coding-system-args coding-system type
|
|
|
|
|
mnemonic doc-string)))
|
|
|
|
|
(setq coding-system (car args)
|
2001-01-23 17:35:03 +00:00
|
|
|
|
type (nth 1 args)
|
2001-01-16 10:37:43 +00:00
|
|
|
|
mnemonic (nth 2 args)
|
|
|
|
|
doc-string (nth 3 args)
|
|
|
|
|
flags (nth 4 args)
|
|
|
|
|
properties (nth 5 args)
|
|
|
|
|
eol-type (nth 6 args))))
|
|
|
|
|
|
1997-10-21 10:47:35 +00:00
|
|
|
|
;; Set a value of `coding-system' property.
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(let ((coding-spec (make-vector 5 nil))
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(no-initial-designation t)
|
|
|
|
|
(no-alternative-designation t)
|
2001-01-09 02:30:03 +00:00
|
|
|
|
(accept-latin-extra-code nil)
|
1997-06-18 12:55:09 +00:00
|
|
|
|
coding-category)
|
1997-08-28 10:49:48 +00:00
|
|
|
|
(if (or (not (integerp type)) (< type 0) (> type 5))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(error "TYPE argument must be 0..5"))
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(if (or (not (integerp mnemonic)) (<= mnemonic ? ) (> mnemonic 127))
|
2001-02-11 17:07:35 +00:00
|
|
|
|
(error "MNEMONIC argument must be an ASCII printable character"))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(aset coding-spec coding-spec-type-idx type)
|
|
|
|
|
(aset coding-spec coding-spec-mnemonic-idx mnemonic)
|
|
|
|
|
(aset coding-spec coding-spec-doc-string-idx
|
2000-04-01 11:58:23 +00:00
|
|
|
|
(purecopy (if (stringp doc-string) doc-string "")))
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(cond ((= type 0)
|
|
|
|
|
(setq coding-category 'coding-category-emacs-mule))
|
|
|
|
|
((= type 1)
|
|
|
|
|
(setq coding-category 'coding-category-sjis))
|
|
|
|
|
((= type 2) ; ISO2022
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(let ((i 0)
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(vec (make-vector 32 nil))
|
1998-10-14 12:41:02 +00:00
|
|
|
|
(g1-designation nil)
|
|
|
|
|
(fl flags))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(while (< i 4)
|
1998-10-14 12:41:02 +00:00
|
|
|
|
(let ((charset (car fl)))
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(if (and no-initial-designation
|
|
|
|
|
(> i 0)
|
|
|
|
|
(or (charsetp charset)
|
|
|
|
|
(and (consp charset)
|
|
|
|
|
(charsetp (car charset)))))
|
|
|
|
|
(setq no-initial-designation nil))
|
|
|
|
|
(if (charsetp charset)
|
|
|
|
|
(if (= i 1) (setq g1-designation charset))
|
|
|
|
|
(if (consp charset)
|
|
|
|
|
(let ((tail charset)
|
|
|
|
|
elt)
|
|
|
|
|
(while tail
|
|
|
|
|
(setq elt (car tail))
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(if (eq elt t)
|
|
|
|
|
(setq no-alternative-designation nil)
|
|
|
|
|
(if (and elt (not (charsetp elt)))
|
|
|
|
|
(error "Invalid charset: %s" elt)))
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(setq tail (cdr tail)))
|
|
|
|
|
(setq g1-designation (car charset)))
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(if charset
|
|
|
|
|
(if (eq charset t)
|
|
|
|
|
(setq no-alternative-designation nil)
|
|
|
|
|
(error "Invalid charset: %s" charset)))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(aset vec i charset))
|
1998-10-14 12:41:02 +00:00
|
|
|
|
(setq fl (cdr fl) i (1+ i)))
|
|
|
|
|
(while (and (< i 32) fl)
|
|
|
|
|
(aset vec i (car fl))
|
2001-01-09 02:30:03 +00:00
|
|
|
|
(if (and (= i 16) ; ACCEPT-LATIN-EXTRA-CODE
|
|
|
|
|
(car fl))
|
|
|
|
|
(setq accept-latin-extra-code t))
|
1998-10-14 12:41:02 +00:00
|
|
|
|
(setq fl (cdr fl) i (1+ i)))
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(aset coding-spec 4 vec)
|
|
|
|
|
(setq coding-category
|
|
|
|
|
(if (aref vec 8) ; Use locking-shift.
|
1997-07-15 08:24:47 +00:00
|
|
|
|
(or (and (aref vec 7) 'coding-category-iso-7-else)
|
|
|
|
|
'coding-category-iso-8-else)
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(if (aref vec 7) ; 7-bit only.
|
|
|
|
|
(if (aref vec 9) ; Use single-shift.
|
1997-07-15 08:24:47 +00:00
|
|
|
|
'coding-category-iso-7-else
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(if no-alternative-designation
|
|
|
|
|
'coding-category-iso-7-tight
|
|
|
|
|
'coding-category-iso-7))
|
1998-05-21 01:46:39 +00:00
|
|
|
|
(if (or no-initial-designation
|
|
|
|
|
(not no-alternative-designation))
|
1997-07-15 08:24:47 +00:00
|
|
|
|
'coding-category-iso-8-else
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(if (and (charsetp g1-designation)
|
|
|
|
|
(= (charset-dimension g1-designation) 2))
|
|
|
|
|
'coding-category-iso-8-2
|
|
|
|
|
'coding-category-iso-8-1)))))))
|
|
|
|
|
((= type 3)
|
|
|
|
|
(setq coding-category 'coding-category-big5))
|
|
|
|
|
((= type 4) ; private
|
1998-08-02 01:06:57 +00:00
|
|
|
|
(setq coding-category 'coding-category-ccl)
|
1998-04-20 02:11:52 +00:00
|
|
|
|
(if (not (consp flags))
|
|
|
|
|
(error "Invalid FLAGS argument for TYPE 4 (CCL)")
|
|
|
|
|
(let ((decoder (check-ccl-program
|
|
|
|
|
(car flags)
|
|
|
|
|
(intern (format "%s-decoder" coding-system))))
|
|
|
|
|
(encoder (check-ccl-program
|
|
|
|
|
(cdr flags)
|
|
|
|
|
(intern (format "%s-encoder" coding-system)))))
|
|
|
|
|
(if (and decoder encoder)
|
|
|
|
|
(aset coding-spec 4 (cons decoder encoder))
|
|
|
|
|
(error "Invalid FLAGS argument for TYPE 4 (CCL)")))))
|
1997-08-28 10:49:48 +00:00
|
|
|
|
(t ; i.e. (= type 5)
|
|
|
|
|
(setq coding-category 'coding-category-raw-text)))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
|
|
|
|
|
(let ((plist (list 'coding-category coding-category
|
1998-01-22 01:42:20 +00:00
|
|
|
|
'alias-coding-systems (list coding-system))))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(if no-initial-designation
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(plist-put plist 'no-initial-designation t))
|
|
|
|
|
(if (and properties
|
|
|
|
|
(or (eq properties t)
|
|
|
|
|
(not (consp (car properties)))))
|
|
|
|
|
;; In the old version, the arg PROPERTIES is a list to be
|
|
|
|
|
;; set in PLIST as a value of property `safe-charsets'.
|
2000-07-27 06:08:14 +00:00
|
|
|
|
(setq properties (list (cons 'safe-charsets properties))))
|
|
|
|
|
;; In the current version PROPERTIES is a property list.
|
|
|
|
|
;; Reflect it into PLIST one by one while handling safe-chars
|
|
|
|
|
;; specially.
|
|
|
|
|
(let ((safe-charsets (cdr (assq 'safe-charsets properties)))
|
|
|
|
|
(safe-chars (cdr (assq 'safe-chars properties)))
|
|
|
|
|
(l properties)
|
|
|
|
|
prop val)
|
|
|
|
|
;; If only safe-charsets is specified, make a char-table from
|
|
|
|
|
;; it, and store that char-table as the value of `safe-chars'.
|
|
|
|
|
(if (and (not safe-chars) safe-charsets)
|
|
|
|
|
(let (charset)
|
|
|
|
|
(if (eq safe-charsets t)
|
|
|
|
|
(setq safe-chars t)
|
|
|
|
|
(setq safe-chars (make-char-table 'safe-chars))
|
|
|
|
|
(while safe-charsets
|
|
|
|
|
(setq charset (car safe-charsets)
|
|
|
|
|
safe-charsets (cdr safe-charsets))
|
|
|
|
|
(cond ((eq charset 'ascii)) ; just ignore
|
|
|
|
|
((eq charset 'eight-bit-control)
|
|
|
|
|
(let ((i 128))
|
|
|
|
|
(while (< i 160)
|
|
|
|
|
(aset safe-chars i t)
|
|
|
|
|
(setq i (1+ i)))))
|
|
|
|
|
((eq charset 'eight-bit-graphic)
|
|
|
|
|
(let ((i 160))
|
|
|
|
|
(while (< i 256)
|
|
|
|
|
(aset safe-chars i t)
|
|
|
|
|
(setq i (1+ i)))))
|
|
|
|
|
(t
|
2001-01-09 02:30:03 +00:00
|
|
|
|
(aset safe-chars (make-char charset) t))))
|
|
|
|
|
(if accept-latin-extra-code
|
|
|
|
|
(let ((i 128))
|
|
|
|
|
(while (< i 160)
|
|
|
|
|
(if (aref latin-extra-code-table i)
|
|
|
|
|
(aset safe-chars i t))
|
|
|
|
|
(setq i (1+ i))))))
|
2000-07-27 06:08:14 +00:00
|
|
|
|
(setq l (cons (cons 'safe-chars safe-chars) l))))
|
|
|
|
|
(while l
|
|
|
|
|
(setq prop (car (car l)) val (cdr (car l)) l (cdr l))
|
|
|
|
|
(if (eq prop 'safe-chars)
|
|
|
|
|
(progn
|
2000-10-30 01:32:44 +00:00
|
|
|
|
(if (and (symbolp val)
|
|
|
|
|
(get val 'translation-table))
|
|
|
|
|
(setq safe-chars (get val 'translation-table)))
|
|
|
|
|
(register-char-codings coding-system safe-chars)
|
|
|
|
|
(setq val safe-chars)))
|
2000-07-27 06:08:14 +00:00
|
|
|
|
(plist-put plist prop val)))
|
2000-03-07 06:15:36 +00:00
|
|
|
|
;; The property `coding-category' may have been set differently
|
|
|
|
|
;; through PROPERTIES.
|
|
|
|
|
(setq coding-category (plist-get plist 'coding-category))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(aset coding-spec coding-spec-plist-idx plist))
|
1997-06-18 12:55:09 +00:00
|
|
|
|
(put coding-system 'coding-system coding-spec)
|
|
|
|
|
(put coding-category 'coding-systems
|
|
|
|
|
(cons coding-system (get coding-category 'coding-systems))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
2000-03-07 06:15:36 +00:00
|
|
|
|
;; Next, set a value of `eol-type' property.
|
2000-06-19 05:15:04 +00:00
|
|
|
|
(if (not eol-type)
|
2000-03-07 06:15:36 +00:00
|
|
|
|
;; If EOL-TYPE is nil, set a vector of subsidiary coding
|
|
|
|
|
;; systems, each corresponds to a coding system for the detected
|
|
|
|
|
;; EOL format.
|
|
|
|
|
(setq eol-type (make-subsidiary-coding-system coding-system)))
|
|
|
|
|
(setq eol-type
|
|
|
|
|
(cond ((or (eq eol-type 'unix) (null eol-type))
|
|
|
|
|
0)
|
|
|
|
|
((eq eol-type 'dos)
|
|
|
|
|
1)
|
|
|
|
|
((eq eol-type 'mac)
|
|
|
|
|
2)
|
|
|
|
|
((or (and (vectorp eol-type)
|
|
|
|
|
(= (length eol-type) 3))
|
|
|
|
|
(and (numberp eol-type)
|
|
|
|
|
(and (>= eol-type 0)
|
|
|
|
|
(<= eol-type 2))))
|
|
|
|
|
eol-type)
|
|
|
|
|
(t
|
|
|
|
|
(error "Invalid EOL-TYPE spec:%S" eol-type))))
|
|
|
|
|
(put coding-system 'eol-type eol-type)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
|
|
|
|
|
;; At last, register CODING-SYSTEM in `coding-system-list' and
|
|
|
|
|
;; `coding-system-alist'.
|
1999-02-08 09:50:26 +00:00
|
|
|
|
(add-to-coding-system-list coding-system)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(setq coding-system-alist (cons (list (symbol-name coding-system))
|
1998-01-22 01:42:20 +00:00
|
|
|
|
coding-system-alist))
|
1998-10-14 12:41:02 +00:00
|
|
|
|
|
|
|
|
|
;; For a coding system of cateogory iso-8-1 and iso-8-2, create
|
|
|
|
|
;; XXX-with-esc variants.
|
|
|
|
|
(let ((coding-category (coding-system-category coding-system)))
|
|
|
|
|
(if (or (eq coding-category 'coding-category-iso-8-1)
|
|
|
|
|
(eq coding-category 'coding-category-iso-8-2))
|
|
|
|
|
(let ((esc (intern (concat (symbol-name coding-system) "-with-esc")))
|
2000-07-27 06:08:14 +00:00
|
|
|
|
(doc (format "Same as %s but can handle any charsets by ISO's escape sequences." coding-system))
|
|
|
|
|
(safe-charsets (assq 'safe-charsets properties))
|
|
|
|
|
(mime-charset (assq 'mime-charset properties)))
|
|
|
|
|
(if safe-charsets
|
|
|
|
|
(setcdr safe-charsets t)
|
|
|
|
|
(setq properties (cons (cons 'safe-charsets t) properties)))
|
|
|
|
|
(if mime-charset
|
|
|
|
|
(setcdr mime-charset nil))
|
1998-10-14 12:41:02 +00:00
|
|
|
|
(make-coding-system esc type mnemonic doc
|
|
|
|
|
(if (listp (car flags))
|
|
|
|
|
(cons (append (car flags) '(t)) (cdr flags))
|
|
|
|
|
(cons (list (car flags) t) (cdr flags)))
|
2000-07-27 06:08:14 +00:00
|
|
|
|
properties))))
|
1998-10-14 12:41:02 +00:00
|
|
|
|
|
1998-01-22 01:42:20 +00:00
|
|
|
|
coding-system)
|
1997-06-10 00:56:15 +00:00
|
|
|
|
|
1997-07-01 23:10:44 +00:00
|
|
|
|
(defun define-coding-system-alias (alias coding-system)
|
1997-08-05 07:05:12 +00:00
|
|
|
|
"Define ALIAS as an alias for coding system CODING-SYSTEM."
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(put alias 'coding-system (coding-system-spec coding-system))
|
|
|
|
|
(nconc (coding-system-get alias 'alias-coding-systems) (list alias))
|
1999-02-08 09:50:26 +00:00
|
|
|
|
(add-to-coding-system-list alias)
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(setq coding-system-alist (cons (list (symbol-name alias))
|
|
|
|
|
coding-system-alist))
|
|
|
|
|
(let ((eol-type (coding-system-eol-type coding-system)))
|
|
|
|
|
(if (vectorp eol-type)
|
|
|
|
|
(put alias 'eol-type (make-subsidiary-coding-system alias))
|
|
|
|
|
(put alias 'eol-type eol-type))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
(defun set-buffer-file-coding-system (coding-system &optional force)
|
1997-08-05 07:05:12 +00:00
|
|
|
|
"Set the file coding-system of the current buffer to CODING-SYSTEM.
|
|
|
|
|
This means that when you save the buffer, it will be converted
|
|
|
|
|
according to CODING-SYSTEM. For a list of possible values of CODING-SYSTEM,
|
|
|
|
|
use \\[list-coding-systems].
|
|
|
|
|
|
|
|
|
|
If the buffer's previous file coding-system value specifies end-of-line
|
|
|
|
|
conversion, and CODING-SYSTEM does not specify one, CODING-SYSTEM is
|
|
|
|
|
merged with the already-specified end-of-line conversion.
|
2000-06-10 02:17:40 +00:00
|
|
|
|
|
|
|
|
|
If the buffer's previous file coding-system value specifies text
|
|
|
|
|
conversion, and CODING-SYSTEM does not specify one, CODING-SYSTEM is
|
|
|
|
|
merged with the already-specified text conversion.
|
|
|
|
|
|
|
|
|
|
However, if the optional prefix argument FORCE is non-nil, then
|
|
|
|
|
CODING-SYSTEM is used exactly as specified.
|
1999-12-06 04:53:04 +00:00
|
|
|
|
|
|
|
|
|
This marks the buffer modified so that the succeeding \\[save-buffer]
|
|
|
|
|
surely saves the buffer with CODING-SYSTEM. From a program, if you
|
|
|
|
|
don't want to mark the buffer modified, just set the variable
|
|
|
|
|
`buffer-file-coding-system' directly."
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(interactive "zCoding system for visited file (default, nil): \nP")
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(check-coding-system coding-system)
|
2000-06-12 00:04:43 +00:00
|
|
|
|
(if (and coding-system buffer-file-coding-system (null force))
|
2000-06-15 00:32:21 +00:00
|
|
|
|
(let ((base (coding-system-base buffer-file-coding-system))
|
|
|
|
|
(eol (coding-system-eol-type buffer-file-coding-system)))
|
|
|
|
|
;; If CODING-SYSTEM doesn't specify text conversion, merge
|
|
|
|
|
;; with that of buffer-file-coding-system.
|
|
|
|
|
(if (eq (coding-system-base coding-system) 'undecided)
|
|
|
|
|
(setq coding-system (coding-system-change-text-conversion
|
|
|
|
|
coding-system base)))
|
|
|
|
|
;; If CODING-SYSTEM doesn't specify eol conversion, merge with
|
|
|
|
|
;; that of buffer-file-coding-system.
|
|
|
|
|
(if (and (vectorp (coding-system-eol-type coding-system))
|
|
|
|
|
(numberp eol) (>= eol 0) (<= eol 2))
|
|
|
|
|
(setq coding-system (coding-system-change-eol-conversion
|
|
|
|
|
coding-system eol)))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(setq buffer-file-coding-system coding-system)
|
|
|
|
|
(set-buffer-modified-p t)
|
|
|
|
|
(force-mode-line-update))
|
|
|
|
|
|
1997-08-05 07:05:12 +00:00
|
|
|
|
(defvar default-terminal-coding-system nil
|
|
|
|
|
"Default value for the terminal coding system.
|
|
|
|
|
This is normally set according to the selected language environment.
|
|
|
|
|
See also the command `set-terminal-coding-system'.")
|
|
|
|
|
|
1997-05-28 03:35:33 +00:00
|
|
|
|
(defun set-terminal-coding-system (coding-system)
|
|
|
|
|
"Set coding system of your terminal to CODING-SYSTEM.
|
1997-08-05 07:05:12 +00:00
|
|
|
|
All text output to the terminal will be encoded
|
|
|
|
|
with the specified coding system.
|
|
|
|
|
For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
|
|
|
|
|
The default is determined by the selected language environment
|
|
|
|
|
or by the previous use of this command."
|
|
|
|
|
(interactive
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(list (let ((default (if (and (not (terminal-coding-system))
|
|
|
|
|
default-terminal-coding-system)
|
|
|
|
|
default-terminal-coding-system)))
|
|
|
|
|
(read-coding-system
|
|
|
|
|
(format "Coding system for terminal display (default, %s): "
|
|
|
|
|
default)
|
|
|
|
|
default))))
|
1997-08-05 07:05:12 +00:00
|
|
|
|
(if (and (not coding-system)
|
|
|
|
|
(not (terminal-coding-system)))
|
|
|
|
|
(setq coding-system default-terminal-coding-system))
|
|
|
|
|
(if coding-system
|
2001-02-11 17:07:35 +00:00
|
|
|
|
(setq default-terminal-coding-system coding-system))
|
1997-05-28 03:35:33 +00:00
|
|
|
|
(set-terminal-coding-system-internal coding-system)
|
|
|
|
|
(redraw-frame (selected-frame)))
|
|
|
|
|
|
1997-08-05 07:05:12 +00:00
|
|
|
|
(defvar default-keyboard-coding-system nil
|
|
|
|
|
"Default value of the keyboard coding system.
|
|
|
|
|
This is normally set according to the selected language environment.
|
|
|
|
|
See also the command `set-keyboard-coding-system'.")
|
|
|
|
|
|
1997-05-28 03:35:33 +00:00
|
|
|
|
(defun set-keyboard-coding-system (coding-system)
|
1997-08-05 07:05:12 +00:00
|
|
|
|
"Set coding system for keyboard input to CODING-SYSTEM.
|
|
|
|
|
In addition, this command enables Encoded-kbd minor mode.
|
2000-12-18 17:10:08 +00:00
|
|
|
|
\(If CODING-SYSTEM is nil, Encoded-kbd mode is turned off -- see
|
|
|
|
|
`encoded-kbd-mode'.)
|
1997-08-05 07:05:12 +00:00
|
|
|
|
For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems].
|
|
|
|
|
The default is determined by the selected language environment
|
|
|
|
|
or by the previous use of this command."
|
|
|
|
|
(interactive
|
1997-09-05 05:43:29 +00:00
|
|
|
|
(list (let ((default (if (and (not (keyboard-coding-system))
|
|
|
|
|
default-keyboard-coding-system)
|
|
|
|
|
default-keyboard-coding-system)))
|
|
|
|
|
(read-coding-system
|
|
|
|
|
(format "Coding system for keyboard input (default, %s): "
|
|
|
|
|
default)
|
|
|
|
|
default))))
|
1997-08-05 07:05:12 +00:00
|
|
|
|
(if (and (not coding-system)
|
|
|
|
|
(not (keyboard-coding-system)))
|
|
|
|
|
(setq coding-system default-keyboard-coding-system))
|
|
|
|
|
(if coding-system
|
|
|
|
|
(setq default-keyboard-coding-system coding-system))
|
1997-05-28 03:35:33 +00:00
|
|
|
|
(set-keyboard-coding-system-internal coding-system)
|
2001-07-31 09:50:56 +00:00
|
|
|
|
(setq keyboard-coding-system coding-system)
|
1997-05-28 03:35:33 +00:00
|
|
|
|
(encoded-kbd-mode (if coding-system 1 0)))
|
|
|
|
|
|
2000-12-18 17:10:08 +00:00
|
|
|
|
(defcustom keyboard-coding-system nil
|
|
|
|
|
"Specify coding system for keyboard input.
|
|
|
|
|
If you set this on a terminal which can't distinguish Meta keys from
|
|
|
|
|
8-bit characters, you will have to use ESC to type Meta characters.
|
|
|
|
|
See Info node `Specify Coding' and Info node `Single-Byte Character Support'.
|
|
|
|
|
|
|
|
|
|
Setting this variable directly does not take effect;
|
|
|
|
|
use either M-x customize or \\[set-keyboard-coding-system]."
|
|
|
|
|
:type '(coding-system :tag "Coding system")
|
|
|
|
|
:link '(info-link "(emacs)Specify Coding")
|
|
|
|
|
:link '(info-link "(emacs)Single-Byte Character Support")
|
|
|
|
|
:set (lambda (symbol value)
|
|
|
|
|
;; Don't load encoded-kbd-mode unnecessarily.
|
|
|
|
|
(if (or value (boundp 'encoded-kbd-mode))
|
|
|
|
|
(set-keyboard-coding-system value)
|
|
|
|
|
(set-default 'keyboard-coding-system nil))) ; must initialize
|
|
|
|
|
:version "21.1"
|
|
|
|
|
:group 'keyboard
|
|
|
|
|
:group 'mule)
|
|
|
|
|
|
1997-05-28 03:35:33 +00:00
|
|
|
|
(defun set-buffer-process-coding-system (decoding encoding)
|
1997-08-05 07:05:12 +00:00
|
|
|
|
"Set coding systems for the process associated with the current buffer.
|
1997-05-28 03:35:33 +00:00
|
|
|
|
DECODING is the coding system to be used to decode input from the process,
|
1997-08-05 07:05:12 +00:00
|
|
|
|
ENCODING is the coding system to be used to encode output to the process.
|
|
|
|
|
|
|
|
|
|
For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems]."
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(interactive
|
2000-08-19 12:37:39 +00:00
|
|
|
|
"zCoding-system for output from the process: \nzCoding-system for input to the process: ")
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(let ((proc (get-buffer-process (current-buffer))))
|
|
|
|
|
(if (null proc)
|
2001-02-11 17:07:35 +00:00
|
|
|
|
(error "No process")
|
1997-05-28 03:35:33 +00:00
|
|
|
|
(check-coding-system decoding)
|
|
|
|
|
(check-coding-system encoding)
|
|
|
|
|
(set-process-coding-system proc decoding encoding)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(force-mode-line-update))
|
|
|
|
|
|
1998-07-27 05:39:15 +00:00
|
|
|
|
(defalias 'set-clipboard-coding-system 'set-selection-coding-system)
|
|
|
|
|
|
1998-07-12 05:58:47 +00:00
|
|
|
|
(defun set-selection-coding-system (coding-system)
|
1998-05-18 01:01:00 +00:00
|
|
|
|
"Make CODING-SYSTEM used for communicating with other X clients .
|
|
|
|
|
When sending or receiving text via cut_buffer, selection, and clipboard,
|
|
|
|
|
the text is encoded or decoded by CODING-SYSTEM."
|
1998-08-15 01:28:14 +00:00
|
|
|
|
(interactive "zCoding system for X selection: ")
|
1998-05-18 01:01:00 +00:00
|
|
|
|
(check-coding-system coding-system)
|
1998-07-12 05:58:47 +00:00
|
|
|
|
(setq selection-coding-system coding-system))
|
1998-05-18 01:01:00 +00:00
|
|
|
|
|
1998-09-06 14:31:49 +00:00
|
|
|
|
;; Coding system lastly specified by the command
|
1998-08-15 01:28:14 +00:00
|
|
|
|
;; set-next-selection-coding-system.
|
|
|
|
|
(defvar last-next-selection-coding-system nil)
|
|
|
|
|
|
|
|
|
|
(defun set-next-selection-coding-system (coding-system)
|
|
|
|
|
"Make CODING-SYSTEM used for the next communication with other X clients.
|
|
|
|
|
This setting is effective for the next communication only."
|
|
|
|
|
(interactive
|
|
|
|
|
(list (read-coding-system
|
|
|
|
|
(if last-next-selection-coding-system
|
|
|
|
|
(format "Coding system for the next X selection (default, %S): "
|
|
|
|
|
last-next-selection-coding-system)
|
|
|
|
|
"Coding system for the next X selection: ")
|
|
|
|
|
last-next-selection-coding-system)))
|
|
|
|
|
(if coding-system
|
|
|
|
|
(setq last-next-selection-coding-system coding-system)
|
|
|
|
|
(setq coding-system last-next-selection-coding-system))
|
|
|
|
|
(check-coding-system coding-system)
|
|
|
|
|
|
|
|
|
|
(setq next-selection-coding-system coding-system))
|
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(defun set-coding-priority (arg)
|
2001-02-11 17:07:35 +00:00
|
|
|
|
"Set priority of coding categories according to ARG.
|
|
|
|
|
ARG is a list of coding categories ordered by priority."
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(let ((l arg)
|
|
|
|
|
(current-list (copy-sequence coding-category-list)))
|
1998-09-06 14:31:49 +00:00
|
|
|
|
;; Check the validity of ARG while deleting coding categories in
|
1998-01-22 01:42:20 +00:00
|
|
|
|
;; ARG from CURRENT-LIST. We assume that CODING-CATEGORY-LIST
|
|
|
|
|
;; contains all coding categories.
|
|
|
|
|
(while l
|
|
|
|
|
(if (or (null (get (car l) 'coding-category-index))
|
|
|
|
|
(null (memq (car l) current-list)))
|
|
|
|
|
(error "Invalid or duplicated element in argument: %s" arg))
|
|
|
|
|
(setq current-list (delq (car l) current-list))
|
|
|
|
|
(setq l (cdr l)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; Update `coding-category-list' and return it.
|
1998-05-25 08:08:51 +00:00
|
|
|
|
(setq coding-category-list (append arg current-list))
|
|
|
|
|
(set-coding-priority-internal)))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
|
|
|
|
;;; FILE I/O
|
|
|
|
|
|
2000-12-06 18:48:59 +00:00
|
|
|
|
(defcustom auto-coding-alist
|
1999-05-02 13:41:07 +00:00
|
|
|
|
'(("\\.\\(arc\\|zip\\|lzh\\|zoo\\|jar\\|tar\\|tgz\\)\\'" . no-conversion)
|
2001-06-07 13:56:38 +00:00
|
|
|
|
("\\.\\(gz\\|Z\\|bz\\|bz2\\|gpg\\)\\'" . no-conversion))
|
1998-07-25 04:23:13 +00:00
|
|
|
|
"Alist of filename patterns vs corresponding coding systems.
|
|
|
|
|
Each element looks like (REGEXP . CODING-SYSTEM).
|
1998-07-25 04:48:35 +00:00
|
|
|
|
A file whose name matches REGEXP is decoded by CODING-SYSTEM on reading.
|
1998-07-25 04:23:13 +00:00
|
|
|
|
|
1998-07-25 20:56:15 +00:00
|
|
|
|
The settings in this alist take priority over `coding:' tags
|
|
|
|
|
in the file (see the function `set-auto-coding')
|
2000-12-06 18:48:59 +00:00
|
|
|
|
and the contents of `file-coding-system-alist'."
|
|
|
|
|
:group 'files
|
|
|
|
|
:group 'mule
|
|
|
|
|
:type '(repeat (cons (regexp :tag "File name regexp")
|
|
|
|
|
(symbol :tag "Coding system"))))
|
1998-07-25 04:23:13 +00:00
|
|
|
|
|
2001-05-16 10:36:54 +00:00
|
|
|
|
(defcustom auto-coding-regexp-alist
|
|
|
|
|
'(("^BABYL OPTIONS:[ \t]*-\\*-[ \t]*rmail[ \t]*-\\*-" . no-conversion))
|
|
|
|
|
"Alist of patterns vs corresponding coding systems.
|
|
|
|
|
Each element looks like (REGEXP . CODING-SYSTEM).
|
|
|
|
|
A file whose first bytes match REGEXP is decoded by CODING-SYSTEM on reading.
|
|
|
|
|
|
|
|
|
|
The settings in this alist take priority over `coding:' tags
|
|
|
|
|
in the file (see the function `set-auto-coding')
|
|
|
|
|
and the contents of `file-coding-system-alist'."
|
|
|
|
|
:group 'files
|
|
|
|
|
:group 'mule
|
|
|
|
|
:type '(repeat (cons (regexp :tag "Regexp")
|
|
|
|
|
(symbol :tag "Coding system"))))
|
|
|
|
|
|
1998-07-06 01:52:48 +00:00
|
|
|
|
(defvar set-auto-coding-for-load nil
|
|
|
|
|
"Non-nil means look for `load-coding' property instead of `coding'.
|
|
|
|
|
This is used for loading and byte-compiling Emacs Lisp files.")
|
|
|
|
|
|
1999-04-08 22:27:44 +00:00
|
|
|
|
(defun auto-coding-alist-lookup (filename)
|
|
|
|
|
"Return the coding system specified by `auto-coding-alist' for FILENAME."
|
|
|
|
|
(let ((alist auto-coding-alist)
|
1999-04-11 16:26:11 +00:00
|
|
|
|
(case-fold-search (memq system-type '(vax-vms windows-nt ms-dos)))
|
1999-04-08 22:27:44 +00:00
|
|
|
|
coding-system)
|
|
|
|
|
(while (and alist (not coding-system))
|
|
|
|
|
(if (string-match (car (car alist)) filename)
|
|
|
|
|
(setq coding-system (cdr (car alist)))
|
|
|
|
|
(setq alist (cdr alist))))
|
|
|
|
|
coding-system))
|
|
|
|
|
|
2001-05-16 10:36:54 +00:00
|
|
|
|
|
|
|
|
|
(defun auto-coding-from-file-contents (size)
|
|
|
|
|
"Determine a coding system from the contents of the current buffer.
|
|
|
|
|
The current buffer contains SIZE bytes starting at point.
|
|
|
|
|
Value is either a coding system or nil."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(let ((alist auto-coding-regexp-alist)
|
|
|
|
|
coding-system)
|
|
|
|
|
(while (and alist (not coding-system))
|
|
|
|
|
(let ((regexp (car (car alist))))
|
|
|
|
|
(when (re-search-forward regexp (+ (point) size) t)
|
|
|
|
|
(setq coding-system (cdr (car alist)))))
|
|
|
|
|
(setq alist (cdr alist)))
|
|
|
|
|
coding-system)))
|
|
|
|
|
|
|
|
|
|
|
1998-07-25 04:23:13 +00:00
|
|
|
|
(defun set-auto-coding (filename size)
|
|
|
|
|
"Return coding system for a file FILENAME of which SIZE bytes follow point.
|
1998-07-06 01:52:48 +00:00
|
|
|
|
These bytes should include at least the first 1k of the file
|
|
|
|
|
and the last 3k of the file, but the middle may be omitted.
|
1997-09-01 07:19:38 +00:00
|
|
|
|
|
2001-05-16 10:36:54 +00:00
|
|
|
|
It checks FILENAME against the variable `auto-coding-alist'. If
|
|
|
|
|
FILENAME doesn't match any entries in the variable, it checks the
|
|
|
|
|
contents of the current buffer following point against
|
|
|
|
|
`auto-coding-regexp-alist'. If no match is found, it checks for a
|
|
|
|
|
`coding:' tag in the first one or two lines following point. If no
|
|
|
|
|
`coding:' tag is found, it checks for local variables list in the last
|
|
|
|
|
3K bytes out of the SIZE bytes.
|
1997-09-01 07:19:38 +00:00
|
|
|
|
|
|
|
|
|
The return value is the specified coding system,
|
|
|
|
|
or nil if nothing specified.
|
1997-08-22 01:22:49 +00:00
|
|
|
|
|
1998-04-23 21:57:25 +00:00
|
|
|
|
The variable `set-auto-coding-function' (which see) is set to this
|
1997-08-22 01:22:49 +00:00
|
|
|
|
function by default."
|
2001-05-16 10:36:54 +00:00
|
|
|
|
(or (auto-coding-alist-lookup filename)
|
|
|
|
|
(auto-coding-from-file-contents size)
|
|
|
|
|
(let* ((case-fold-search t)
|
|
|
|
|
(head-start (point))
|
|
|
|
|
(head-end (+ head-start (min size 1024)))
|
|
|
|
|
(tail-start (+ head-start (max (- size 3072) 0)))
|
|
|
|
|
(tail-end (+ head-start size))
|
|
|
|
|
coding-system head-found tail-found pos)
|
|
|
|
|
;; Try a short cut by searching for the string "coding:"
|
|
|
|
|
;; and for "unibyte:" at the head and tail of SIZE bytes.
|
|
|
|
|
(setq head-found (or (search-forward "coding:" head-end t)
|
|
|
|
|
(search-forward "unibyte:" head-end t)))
|
|
|
|
|
(if (and head-found (> head-found tail-start))
|
|
|
|
|
;; Head and tail are overlapped.
|
|
|
|
|
(setq tail-found head-found)
|
|
|
|
|
(goto-char tail-start)
|
|
|
|
|
(setq tail-found (or (search-forward "coding:" tail-end t)
|
|
|
|
|
(search-forward "unibyte:" tail-end t))))
|
|
|
|
|
|
|
|
|
|
;; At first check the head.
|
|
|
|
|
(when head-found
|
|
|
|
|
(goto-char head-start)
|
|
|
|
|
(setq pos (re-search-forward "[\n\r]" head-end t))
|
|
|
|
|
(if (and pos
|
|
|
|
|
(= (char-after head-start) ?#)
|
|
|
|
|
(= (char-after (1+ head-start)) ?!))
|
|
|
|
|
;; If the file begins with "#!" (exec interpreter magic),
|
|
|
|
|
;; look for coding frobs in the first two lines. You cannot
|
|
|
|
|
;; necessarily put them in the first line of such a file
|
|
|
|
|
;; without screwing up the interpreter invocation.
|
|
|
|
|
(setq pos (search-forward "\n" head-end t)))
|
|
|
|
|
(if pos (setq head-end pos))
|
|
|
|
|
(when (< head-found head-end)
|
1998-07-25 04:23:13 +00:00
|
|
|
|
(goto-char head-start)
|
2001-05-16 10:36:54 +00:00
|
|
|
|
(when (and set-auto-coding-for-load
|
|
|
|
|
(re-search-forward
|
|
|
|
|
"-\\*-\\(.*;\\)?[ \t]*unibyte:[ \t]*\\([^ ;]+\\)"
|
|
|
|
|
head-end t))
|
|
|
|
|
(setq coding-system 'raw-text))
|
|
|
|
|
(when (and (not coding-system)
|
|
|
|
|
(re-search-forward
|
|
|
|
|
"-\\*-\\(.*;\\)?[ \t]*coding:[ \t]*\\([^ ;]+\\)"
|
|
|
|
|
head-end t))
|
|
|
|
|
(setq coding-system (intern (match-string 2)))
|
|
|
|
|
(or (coding-system-p coding-system)
|
|
|
|
|
(setq coding-system nil)))))
|
|
|
|
|
|
|
|
|
|
;; If no coding: tag in the head, check the tail.
|
|
|
|
|
(when (and tail-found (not coding-system))
|
|
|
|
|
(goto-char tail-start)
|
|
|
|
|
(search-forward "\n\^L" nil t)
|
|
|
|
|
(if (re-search-forward
|
|
|
|
|
"^\\(.*\\)[ \t]*Local Variables:[ \t]*\\(.*\\)$" tail-end t)
|
|
|
|
|
;; The prefix is what comes before "local variables:" in its
|
|
|
|
|
;; line. The suffix is what comes after "local variables:"
|
|
|
|
|
;; in its line.
|
|
|
|
|
(let* ((prefix (regexp-quote (match-string 1)))
|
|
|
|
|
(suffix (regexp-quote (match-string 2)))
|
|
|
|
|
(re-coding
|
|
|
|
|
(concat
|
|
|
|
|
"^" prefix
|
|
|
|
|
"[ \t]*coding[ \t]*:[ \t]*\\([^ \t]+\\)[ \t]*"
|
|
|
|
|
suffix "$"))
|
|
|
|
|
(re-unibyte
|
|
|
|
|
(concat
|
|
|
|
|
"^" prefix
|
|
|
|
|
"[ \t]*unibyte[ \t]*:[ \t]*\\([^ \t]+\\)[ \t]*"
|
|
|
|
|
suffix "$"))
|
|
|
|
|
(re-end
|
|
|
|
|
(concat "^" prefix "[ \t]*end *:[ \t]*" suffix "$"))
|
|
|
|
|
(pos (point)))
|
|
|
|
|
(re-search-forward re-end tail-end 'move)
|
|
|
|
|
(setq tail-end (point))
|
|
|
|
|
(goto-char pos)
|
|
|
|
|
(when (and set-auto-coding-for-load
|
|
|
|
|
(re-search-forward re-unibyte tail-end t))
|
|
|
|
|
(setq coding-system 'raw-text))
|
|
|
|
|
(when (and (not coding-system)
|
|
|
|
|
(re-search-forward re-coding tail-end t))
|
|
|
|
|
(setq coding-system (intern (match-string 1)))
|
|
|
|
|
(or (coding-system-p coding-system)
|
|
|
|
|
(setq coding-system nil))))))
|
|
|
|
|
coding-system)))
|
1997-09-01 07:19:38 +00:00
|
|
|
|
|
|
|
|
|
(setq set-auto-coding-function 'set-auto-coding)
|
1997-08-22 01:22:49 +00:00
|
|
|
|
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(defun after-insert-file-set-buffer-file-coding-system (inserted)
|
2001-02-11 17:07:35 +00:00
|
|
|
|
"Set `buffer-file-coding-system' of current buffer after text is inserted."
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(if last-coding-system-used
|
|
|
|
|
(let ((coding-system
|
|
|
|
|
(find-new-buffer-file-coding-system last-coding-system-used))
|
|
|
|
|
(modified-p (buffer-modified-p)))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(when coding-system
|
2000-06-14 08:02:05 +00:00
|
|
|
|
(set-buffer-file-coding-system coding-system t)
|
1998-11-16 01:17:06 +00:00
|
|
|
|
(if (and enable-multibyte-characters
|
|
|
|
|
(or (eq coding-system 'no-conversion)
|
1998-05-12 23:09:35 +00:00
|
|
|
|
(eq (coding-system-type coding-system) 5))
|
2000-06-08 11:12:03 +00:00
|
|
|
|
;; If buffer was unmodified and the size is the
|
|
|
|
|
;; same as INSERTED, we must be visiting it.
|
|
|
|
|
(not modified-p)
|
|
|
|
|
(= (buffer-size) inserted))
|
1998-05-12 23:09:35 +00:00
|
|
|
|
;; For coding systems no-conversion and raw-text...,
|
|
|
|
|
;; edit the buffer as unibyte.
|
1998-11-16 01:17:06 +00:00
|
|
|
|
(let ((pos-byte (position-bytes (+ (point) inserted))))
|
|
|
|
|
(set-buffer-multibyte nil)
|
|
|
|
|
(setq inserted (- pos-byte (position-bytes (point))))))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(set-buffer-modified-p modified-p))))
|
1998-11-16 01:17:06 +00:00
|
|
|
|
inserted)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1998-03-02 20:01:46 +00:00
|
|
|
|
(add-hook 'after-insert-file-functions
|
|
|
|
|
'after-insert-file-set-buffer-file-coding-system)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1997-06-10 00:56:15 +00:00
|
|
|
|
;; The coding-spec and eol-type of coding-system returned is decided
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; independently in the following order.
|
|
|
|
|
;; 1. That of buffer-file-coding-system locally bound.
|
|
|
|
|
;; 2. That of CODING.
|
|
|
|
|
|
|
|
|
|
(defun find-new-buffer-file-coding-system (coding)
|
|
|
|
|
"Return a coding system for a buffer when a file of CODING is inserted.
|
1997-05-12 06:56:25 +00:00
|
|
|
|
The local variable `buffer-file-coding-system' of the current buffer
|
|
|
|
|
is set to the returned value.
|
1999-04-06 19:53:10 +00:00
|
|
|
|
Return nil if there's no need to set `buffer-file-coding-system'."
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(let (local-coding local-eol
|
1997-09-17 06:41:41 +00:00
|
|
|
|
found-coding found-eol
|
1997-02-20 07:02:49 +00:00
|
|
|
|
new-coding new-eol)
|
|
|
|
|
(if (null coding)
|
|
|
|
|
;; Nothing found about coding.
|
|
|
|
|
nil
|
|
|
|
|
|
1997-09-17 06:41:41 +00:00
|
|
|
|
;; Get information of `buffer-file-coding-system' in LOCAL-EOL
|
|
|
|
|
;; and LOCAL-CODING.
|
|
|
|
|
(setq local-eol (coding-system-eol-type buffer-file-coding-system))
|
|
|
|
|
(if (null (numberp local-eol))
|
|
|
|
|
;; But eol-type is not yet set.
|
|
|
|
|
(setq local-eol nil))
|
1997-10-21 10:47:35 +00:00
|
|
|
|
(if (and buffer-file-coding-system
|
|
|
|
|
(not (eq (coding-system-type buffer-file-coding-system) t)))
|
|
|
|
|
;; This is not `undecided'.
|
|
|
|
|
(setq local-coding (coding-system-base buffer-file-coding-system)))
|
1997-09-17 06:41:41 +00:00
|
|
|
|
|
|
|
|
|
(if (and (local-variable-p 'buffer-file-coding-system)
|
|
|
|
|
local-eol local-coding)
|
1997-02-20 07:02:49 +00:00
|
|
|
|
;; The current buffer has already set full coding-system, we
|
|
|
|
|
;; had better not change it.
|
|
|
|
|
nil
|
|
|
|
|
|
1997-06-10 00:56:15 +00:00
|
|
|
|
(setq found-eol (coding-system-eol-type coding))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(if (null (numberp found-eol))
|
1998-08-04 10:27:45 +00:00
|
|
|
|
;; But eol-type is not found.
|
|
|
|
|
;; If EOL conversions are inhibited, force unix eol-type.
|
|
|
|
|
(setq found-eol (if inhibit-eol-conversion 0)))
|
1998-08-02 01:06:57 +00:00
|
|
|
|
(if (eq (coding-system-type coding) t)
|
|
|
|
|
(setq found-coding 'undecided)
|
|
|
|
|
(setq found-coding (coding-system-base coding)))
|
|
|
|
|
|
|
|
|
|
(if (and (not found-eol) (eq found-coding 'undecided))
|
|
|
|
|
;; No valid coding information found.
|
|
|
|
|
nil
|
|
|
|
|
|
|
|
|
|
;; Some coding information (eol or text) found.
|
|
|
|
|
|
|
|
|
|
;; The local setting takes precedence over the found one.
|
|
|
|
|
(setq new-coding (if (local-variable-p 'buffer-file-coding-system)
|
|
|
|
|
(or local-coding found-coding)
|
|
|
|
|
(or found-coding local-coding)))
|
|
|
|
|
(setq new-eol (if (local-variable-p 'buffer-file-coding-system)
|
|
|
|
|
(or local-eol found-eol)
|
|
|
|
|
(or found-eol local-eol)))
|
|
|
|
|
|
|
|
|
|
(let ((eol-type (coding-system-eol-type new-coding)))
|
|
|
|
|
(if (and (numberp new-eol) (vectorp eol-type))
|
|
|
|
|
(aref eol-type new-eol)
|
|
|
|
|
new-coding)))))))
|
1997-02-20 07:02:49 +00:00
|
|
|
|
|
1997-07-20 01:31:41 +00:00
|
|
|
|
(defun modify-coding-system-alist (target-type regexp coding-system)
|
|
|
|
|
"Modify one of look up tables for finding a coding system on I/O operation.
|
1997-07-22 23:41:34 +00:00
|
|
|
|
There are three of such tables, `file-coding-system-alist',
|
|
|
|
|
`process-coding-system-alist', and `network-coding-system-alist'.
|
1997-07-20 01:31:41 +00:00
|
|
|
|
|
|
|
|
|
TARGET-TYPE specifies which of them to modify.
|
1997-07-22 23:41:34 +00:00
|
|
|
|
If it is `file', it affects `file-coding-system-alist' (which see).
|
|
|
|
|
If it is `process', it affects `process-coding-system-alist' (which see).
|
1998-09-06 14:31:49 +00:00
|
|
|
|
If it is `network', it affects `network-coding-system-alist' (which see).
|
1997-07-20 01:31:41 +00:00
|
|
|
|
|
|
|
|
|
REGEXP is a regular expression matching a target of I/O operation.
|
|
|
|
|
The target is a file name if TARGET-TYPE is `file', a program name if
|
|
|
|
|
TARGET-TYPE is `process', or a network service name or a port number
|
|
|
|
|
to connect to if TARGET-TYPE is `network'.
|
|
|
|
|
|
|
|
|
|
CODING-SYSTEM is a coding system to perform code conversion on the I/O
|
1997-07-22 23:41:34 +00:00
|
|
|
|
operation, or a cons cell (DECODING . ENCODING) specifying the coding systems
|
|
|
|
|
for decoding and encoding respectively,
|
|
|
|
|
or a function symbol which, when called, returns such a cons cell."
|
1997-07-20 01:31:41 +00:00
|
|
|
|
(or (memq target-type '(file process network))
|
|
|
|
|
(error "Invalid target type: %s" target-type))
|
|
|
|
|
(or (stringp regexp)
|
|
|
|
|
(and (eq target-type 'network) (integerp regexp))
|
|
|
|
|
(error "Invalid regular expression: %s" regexp))
|
|
|
|
|
(if (symbolp coding-system)
|
|
|
|
|
(if (not (fboundp coding-system))
|
|
|
|
|
(progn
|
|
|
|
|
(check-coding-system coding-system)
|
|
|
|
|
(setq coding-system (cons coding-system coding-system))))
|
|
|
|
|
(check-coding-system (car coding-system))
|
|
|
|
|
(check-coding-system (cdr coding-system)))
|
|
|
|
|
(cond ((eq target-type 'file)
|
|
|
|
|
(let ((slot (assoc regexp file-coding-system-alist)))
|
|
|
|
|
(if slot
|
|
|
|
|
(setcdr slot coding-system)
|
|
|
|
|
(setq file-coding-system-alist
|
|
|
|
|
(cons (cons regexp coding-system)
|
|
|
|
|
file-coding-system-alist)))))
|
|
|
|
|
((eq target-type 'process)
|
|
|
|
|
(let ((slot (assoc regexp process-coding-system-alist)))
|
|
|
|
|
(if slot
|
|
|
|
|
(setcdr slot coding-system)
|
|
|
|
|
(setq process-coding-system-alist
|
|
|
|
|
(cons (cons regexp coding-system)
|
|
|
|
|
process-coding-system-alist)))))
|
|
|
|
|
(t
|
|
|
|
|
(let ((slot (assoc regexp network-coding-system-alist)))
|
|
|
|
|
(if slot
|
|
|
|
|
(setcdr slot coding-system)
|
|
|
|
|
(setq network-coding-system-alist
|
|
|
|
|
(cons (cons regexp coding-system)
|
|
|
|
|
network-coding-system-alist)))))))
|
|
|
|
|
|
1998-05-18 01:01:00 +00:00
|
|
|
|
(defun make-translation-table (&rest args)
|
2001-02-21 14:58:35 +00:00
|
|
|
|
"Make a translation table from arguments.
|
|
|
|
|
A translation table is a char table intended for for character
|
|
|
|
|
translation in CCL programs.
|
|
|
|
|
|
|
|
|
|
Each argument is a list of elemnts of the form (FROM . TO), where FROM
|
|
|
|
|
is a character to be translated to TO.
|
1997-05-16 00:58:57 +00:00
|
|
|
|
|
1998-05-25 07:23:08 +00:00
|
|
|
|
FROM can be a generic character (see `make-char'). In this case, TO is
|
|
|
|
|
a generic character containing the same number of characters, or a
|
|
|
|
|
ordinary character. If FROM and TO are both generic characters, all
|
1998-05-18 01:01:00 +00:00
|
|
|
|
characters belonging to FROM are translated to characters belonging to TO
|
2001-01-23 01:36:19 +00:00
|
|
|
|
without changing their position code(s).
|
|
|
|
|
|
|
|
|
|
The arguments and forms in each argument are processed in the given
|
|
|
|
|
order, and if a previous form already translates TO to some other
|
|
|
|
|
character, say TO-ALT, FROM is also translated to TO-ALT."
|
1998-05-22 09:45:34 +00:00
|
|
|
|
(let ((table (make-char-table 'translation-table))
|
1997-05-12 06:56:25 +00:00
|
|
|
|
revlist)
|
|
|
|
|
(while args
|
|
|
|
|
(let ((elts (car args)))
|
|
|
|
|
(while elts
|
1997-05-16 00:58:57 +00:00
|
|
|
|
(let* ((from (car (car elts)))
|
|
|
|
|
(from-i 0) ; degree of freedom of FROM
|
|
|
|
|
(from-rev (nreverse (split-char from)))
|
|
|
|
|
(to (cdr (car elts)))
|
|
|
|
|
(to-i 0) ; degree of freedom of TO
|
|
|
|
|
(to-rev (nreverse (split-char to))))
|
|
|
|
|
;; Check numbers of heading 0s in FROM-REV and TO-REV.
|
|
|
|
|
(while (eq (car from-rev) 0)
|
|
|
|
|
(setq from-i (1+ from-i) from-rev (cdr from-rev)))
|
|
|
|
|
(while (eq (car to-rev) 0)
|
|
|
|
|
(setq to-i (1+ to-i) to-rev (cdr to-rev)))
|
|
|
|
|
(if (and (/= from-i to-i) (/= to-i 0))
|
|
|
|
|
(error "Invalid character pair (%d . %d)" from to))
|
1998-05-18 01:01:00 +00:00
|
|
|
|
;; If we have already translated TO to TO-ALT, FROM should
|
|
|
|
|
;; also be translated to TO-ALT. But, this is only if TO
|
|
|
|
|
;; is a generic character or TO-ALT is not a generic
|
1997-05-16 00:58:57 +00:00
|
|
|
|
;; character.
|
|
|
|
|
(let ((to-alt (aref table to)))
|
|
|
|
|
(if (and to-alt
|
|
|
|
|
(or (> to-i 0) (not (generic-char-p to-alt))))
|
|
|
|
|
(setq to to-alt)))
|
|
|
|
|
(if (> from-i 0)
|
|
|
|
|
(set-char-table-default table from to)
|
|
|
|
|
(aset table from to))
|
1998-05-18 01:01:00 +00:00
|
|
|
|
;; If we have already translated some chars to FROM, they
|
|
|
|
|
;; should also be translated to TO.
|
1997-05-12 06:56:25 +00:00
|
|
|
|
(let ((l (assq from revlist)))
|
|
|
|
|
(if l
|
|
|
|
|
(let ((ch (car l)))
|
|
|
|
|
(setcar l to)
|
|
|
|
|
(setq l (cdr l))
|
|
|
|
|
(while l
|
|
|
|
|
(aset table ch to)
|
|
|
|
|
(setq l (cdr l)) ))))
|
|
|
|
|
;; Now update REVLIST.
|
|
|
|
|
(let ((l (assq to revlist)))
|
|
|
|
|
(if l
|
|
|
|
|
(setcdr l (cons from (cdr l)))
|
|
|
|
|
(setq revlist (cons (list to from) revlist)))))
|
|
|
|
|
(setq elts (cdr elts))))
|
|
|
|
|
(setq args (cdr args)))
|
|
|
|
|
;; Return TABLE just created.
|
|
|
|
|
table))
|
|
|
|
|
|
1998-08-02 01:06:57 +00:00
|
|
|
|
(defun make-translation-table-from-vector (vec)
|
|
|
|
|
"Make translation table from decoding vector VEC.
|
|
|
|
|
VEC is an array of 256 elements to map unibyte codes to multibyte characters.
|
|
|
|
|
See also the variable `nonascii-translation-table'."
|
|
|
|
|
(let ((table (make-char-table 'translation-table))
|
|
|
|
|
(rev-table (make-char-table 'translation-table))
|
|
|
|
|
(i 0)
|
|
|
|
|
ch)
|
|
|
|
|
(while (< i 256)
|
|
|
|
|
(setq ch (aref vec i))
|
|
|
|
|
(aset table i ch)
|
|
|
|
|
(if (>= ch 256)
|
|
|
|
|
(aset rev-table ch i))
|
|
|
|
|
(setq i (1+ i)))
|
|
|
|
|
(set-char-table-extra-slot table 0 rev-table)
|
|
|
|
|
table))
|
|
|
|
|
|
1998-05-22 09:45:34 +00:00
|
|
|
|
(defun define-translation-table (symbol &rest args)
|
2001-02-21 14:58:35 +00:00
|
|
|
|
"Define SYMBOL as the name of translation table made by ARGS.
|
|
|
|
|
This sets up information so that the table can be used for
|
|
|
|
|
translations in a CCL program.
|
1998-05-18 01:01:00 +00:00
|
|
|
|
|
2001-02-21 14:58:35 +00:00
|
|
|
|
If the first element of ARGS is a char-table whose purpose is
|
|
|
|
|
`translation-table', just define SYMBOL to name it. (Note that this
|
|
|
|
|
function does not bind SYMBOL.)
|
1998-11-26 08:12:12 +00:00
|
|
|
|
|
2001-02-21 14:58:35 +00:00
|
|
|
|
Any other ARGS should be suitable as arguments of the function
|
1998-11-26 08:12:12 +00:00
|
|
|
|
`make-translation-table' (which see).
|
1998-05-18 01:01:00 +00:00
|
|
|
|
|
1998-05-25 07:23:08 +00:00
|
|
|
|
This function sets properties `translation-table' and
|
2001-02-11 17:07:35 +00:00
|
|
|
|
`translation-table-id' of SYMBOL to the created table itself and the
|
|
|
|
|
identification number of the table respectively. It also registers
|
|
|
|
|
the table in `translation-table-vector'."
|
1998-11-26 08:12:12 +00:00
|
|
|
|
(let ((table (if (and (char-table-p (car args))
|
|
|
|
|
(eq (char-table-subtype (car args))
|
|
|
|
|
'translation-table))
|
|
|
|
|
(car args)
|
|
|
|
|
(apply 'make-translation-table args)))
|
1998-05-22 09:45:34 +00:00
|
|
|
|
(len (length translation-table-vector))
|
1998-01-22 01:42:20 +00:00
|
|
|
|
(id 0)
|
1998-05-18 01:01:00 +00:00
|
|
|
|
(done nil))
|
1998-05-22 09:45:34 +00:00
|
|
|
|
(put symbol 'translation-table table)
|
1998-05-18 01:01:00 +00:00
|
|
|
|
(while (not done)
|
|
|
|
|
(if (>= id len)
|
1998-05-22 09:45:34 +00:00
|
|
|
|
(setq translation-table-vector
|
|
|
|
|
(vconcat translation-table-vector (make-vector len nil))))
|
|
|
|
|
(let ((slot (aref translation-table-vector id)))
|
1998-05-18 01:01:00 +00:00
|
|
|
|
(if (or (not slot)
|
|
|
|
|
(eq (car slot) symbol))
|
|
|
|
|
(progn
|
1998-05-22 09:45:34 +00:00
|
|
|
|
(aset translation-table-vector id (cons symbol table))
|
1998-11-26 08:12:12 +00:00
|
|
|
|
(setq done t))
|
|
|
|
|
(setq id (1+ id)))))
|
1998-05-22 09:45:34 +00:00
|
|
|
|
(put symbol 'translation-table-id id)
|
1998-01-22 01:42:20 +00:00
|
|
|
|
id))
|
|
|
|
|
|
1999-12-15 00:40:48 +00:00
|
|
|
|
(put 'with-category-table 'lisp-indent-function 1)
|
|
|
|
|
|
|
|
|
|
(defmacro with-category-table (category-table &rest body)
|
|
|
|
|
`(let ((current-category-table (category-table)))
|
|
|
|
|
(set-category-table ,category-table)
|
|
|
|
|
(unwind-protect
|
|
|
|
|
(progn ,@body)
|
|
|
|
|
(set-category-table current-category-table))))
|
|
|
|
|
|
1997-02-26 13:01:42 +00:00
|
|
|
|
;;; Initialize some variables.
|
|
|
|
|
|
|
|
|
|
(put 'use-default-ascent 'char-table-extra-slots 0)
|
|
|
|
|
(setq use-default-ascent (make-char-table 'use-default-ascent))
|
1997-08-10 04:07:03 +00:00
|
|
|
|
(put 'ignore-relative-composition 'char-table-extra-slots 0)
|
|
|
|
|
(setq ignore-relative-composition
|
|
|
|
|
(make-char-table 'ignore-relative-composition))
|
1997-02-26 13:01:42 +00:00
|
|
|
|
|
|
|
|
|
;;;
|
1997-02-20 07:02:49 +00:00
|
|
|
|
(provide 'mule)
|
|
|
|
|
|
|
|
|
|
;;; mule.el ends here
|