Commit d37ef0f6 authored by Dave Love's avatar Dave Love
Browse files

Doc fixes.

(unencodable-char-position): New.
(select-safe-coding-system): Use it to indicate problematic
characters and add extra explanation.  Avoid checking auto-coding
for compressed files.
(leim-list-header): Add coding cookie.
(input-method-verbose-flag): Modify :type.
(locale-language-names): Add bs, wa.  Modify cy.
parent 1fba7919
...@@ -269,7 +269,7 @@ wrong, use this command again to toggle back to the right mode." ...@@ -269,7 +269,7 @@ wrong, use this command again to toggle back to the right mode."
cmd (key-binding keyseq t)) cmd (key-binding keyseq t))
(not (eq cmd 'universal-argument-other-key))) (not (eq cmd 'universal-argument-other-key)))
(let ((current-prefix-arg prefix-arg) (let ((current-prefix-arg prefix-arg)
;; Have to bind `last-command-char' here so that ;; Have to bind `last-command-char' here so that
;; `digit-argument', for isntance, can compute the ;; `digit-argument', for isntance, can compute the
;; prefix arg. ;; prefix arg.
(last-command-char (aref keyseq 0))) (last-command-char (aref keyseq 0)))
...@@ -297,7 +297,7 @@ This sets the following coding systems: ...@@ -297,7 +297,7 @@ This sets the following coding systems:
o coding system of a newly created buffer o coding system of a newly created buffer
o default coding system for subprocess I/O o default coding system for subprocess I/O
This also sets the following values: This also sets the following values:
o default value used as file-name-coding-system for converting file names. o default value used as `file-name-coding-system' for converting file names.
o default value for the command `set-terminal-coding-system' (not on MSDOS) o default value for the command `set-terminal-coding-system' (not on MSDOS)
o default value for the command `set-keyboard-coding-system'." o default value for the command `set-keyboard-coding-system'."
(check-coding-system coding-system) (check-coding-system coding-system)
...@@ -426,6 +426,7 @@ non-nil, it is used to sort CODINGS in the different way than above." ...@@ -426,6 +426,7 @@ non-nil, it is used to sort CODINGS in the different way than above."
(defun find-coding-systems-region (from to) (defun find-coding-systems-region (from to)
"Return a list of proper coding systems to encode a text between FROM and TO. "Return a list of proper coding systems to encode a text between FROM and TO.
If FROM is a string, find coding systems in that instead of the buffer.
All coding systems in the list can safely encode any multibyte characters All coding systems in the list can safely encode any multibyte characters
in the text. in the text.
...@@ -552,8 +553,15 @@ proper one is suggested as the default. ...@@ -552,8 +553,15 @@ proper one is suggested as the default.
The list of `buffer-file-coding-system' of the current buffer and the The list of `buffer-file-coding-system' of the current buffer and the
most preferred coding system (if it corresponds to a MIME charset) is most preferred coding system (if it corresponds to a MIME charset) is
treated as the default coding system list. Among them, the first one treated as the default coding system list. Among them, the first one
that safely encodes the text is silently selected and returned without that safely encodes the text is normally selected silently and
any user interaction. See also the command `prefer-coding-system'. returned without any user interaction. See also the command
`prefer-coding-system'.
However, the user is queried if the chosen coding system is
inconsistent with what would be selected by `set-auto-coding' from
coding cookies &c. if the contents of the region were read from a
file. (That could lead to data corruption in a file subsequently
re-visited and edited.)
Optional 3rd arg DEFAULT-CODING-SYSTEM specifies a coding system or a Optional 3rd arg DEFAULT-CODING-SYSTEM specifies a coding system or a
list of coding systems to be prepended to the default coding system list of coding systems to be prepended to the default coding system
...@@ -653,63 +661,72 @@ and TO is ignored." ...@@ -653,63 +661,72 @@ and TO is ignored."
;; Make sure the offending buffer is displayed. ;; Make sure the offending buffer is displayed.
(or (stringp from) (or (stringp from)
(pop-to-buffer bufname)) (pop-to-buffer bufname))
;; Then ask users to select one form CODINGS. (save-excursion
(unwind-protect (goto-char (unencodable-char-position
(save-window-excursion from to (mapcar #'car default-coding-system)))
(with-output-to-temp-buffer "*Warning*" ;; Then ask users to select one form CODINGS.
(save-excursion (unwind-protect
(set-buffer standard-output) (save-window-excursion
(if (not default-coding-system) (with-output-to-temp-buffer "*Warning*"
(insert "No default coding systems to try for " (save-excursion
(if (stringp from) (set-buffer standard-output)
(format "string \"%s\"." from) (if (not default-coding-system)
(format "buffer `%s'." bufname))) (insert "No default coding systems to try for "
(insert (if (stringp from)
"These default coding systems were tried to encode" (format "string \"%s\"." from)
(if (stringp from) (format "buffer `%s'." bufname)))
(concat " \"" (if (> (length from) 10) (insert
(concat (substring from 0 10) "...\"") "These default coding systems were tried to encode"
(concat from "\""))) (if (stringp from)
(format " text\nin the buffer `%s'" bufname)) (concat " \"" (if (> (length from) 10)
":\n") (concat (substring from 0 10) "...\"")
(concat from "\"")))
(format " text\nin the buffer `%s'" bufname))
":\n")
(let ((pos (point))
(fill-prefix " "))
(mapcar (function (lambda (x)
(princ " ") (princ (car x))))
default-coding-system)
(insert "\n")
(fill-region-as-paragraph pos (point)))
(if (consp coding-system)
(insert (format "%s safely encodes the target text,\n"
(car coding-system))
"\
but it is not recommended for encoding text in this context,
e.g., for sending an email message.\n")
(insert "\
However, none of them safely encodes the target text.
The first problematic character is at point in the displayed buffer,\n"
(substitute-command-keys "\
and \\[universal-argument] \\[what-cursor-position] will give information about it.\n"))))
(insert (if (consp coding-system)
"\nSelect the above, or "
"\nSelect ")
"\
one of the following safe coding systems, or edit the buffer:\n")
(let ((pos (point)) (let ((pos (point))
(fill-prefix " ")) (fill-prefix " "))
(mapcar (function (lambda (x) (mapcar (function (lambda (x) (princ " ") (princ x)))
(princ " ") (princ (car x)))) codings)
default-coding-system)
(insert "\n") (insert "\n")
(fill-region-as-paragraph pos (point))) (fill-region-as-paragraph pos (point)))))
(insert
(if (consp coding-system) ;; Read a coding system.
(concat (format "%s safely encodes the target text,\n" (if (consp coding-system)
(car coding-system)) (setq codings (cons (car coding-system) codings)))
"but it is not recommended for encoding text in this context,\n" (let* ((safe-names (mapcar (lambda (x) (list (symbol-name x)))
"e.g., for sending an email message.\n") codings))
"However, none of them safely encodes the target text.\n"))) (name (completing-read
(insert (if (consp coding-system) (format "Select coding system (default %s): "
"\nSelect the above, or " (car codings))
"\nSelect ") safe-names nil t nil nil
"one of the following safe coding systems:\n") (car (car safe-names)))))
(let ((pos (point)) (setq last-coding-system-specified (intern name)
(fill-prefix " ")) coding-system last-coding-system-specified)))
(mapcar (function (lambda (x) (princ " ") (princ x))) (kill-buffer "*Warning*"))))
codings)
(insert "\n")
(fill-region-as-paragraph pos (point)))))
;; Read a coding system.
(if (consp coding-system)
(setq codings (cons (car coding-system) codings)))
(let* ((safe-names (mapcar (lambda (x) (list (symbol-name x)))
codings))
(name (completing-read
(format "Select coding system (default %s): "
(car codings))
safe-names nil t nil nil
(car (car safe-names)))))
(setq last-coding-system-specified (intern name)
coding-system last-coding-system-specified)))
(kill-buffer "*Warning*")))
(if (vectorp (coding-system-eol-type coding-system)) (if (vectorp (coding-system-eol-type coding-system))
(let ((eol (coding-system-eol-type buffer-file-coding-system))) (let ((eol (coding-system-eol-type buffer-file-coding-system)))
...@@ -732,6 +749,10 @@ and TO is ignored." ...@@ -732,6 +749,10 @@ and TO is ignored."
(set-auto-coding (or file buffer-file-name "") (set-auto-coding (or file buffer-file-name "")
(buffer-size)))))) (buffer-size))))))
(if (and auto-cs (if (and auto-cs
;; Don't barf if writing a compressed file, say.
;; This check perhaps isn't ideal, but is probably
;; the best thing to do.
(not (auto-coding-alist-lookup (or file buffer-file-name "")))
(not (coding-system-equal (coding-system-base coding-system) (not (coding-system-equal (coding-system-base coding-system)
(coding-system-base auto-cs)))) (coding-system-base auto-cs))))
(unless (yes-or-no-p (unless (yes-or-no-p
...@@ -741,6 +762,46 @@ and try again)? " coding-system auto-cs)) ...@@ -741,6 +762,46 @@ and try again)? " coding-system auto-cs))
(error "Save aborted"))))) (error "Save aborted")))))
coding-system)) coding-system))
(defun unencodable-char-position (start end coding-system)
"Return position of first un-encodable character in a region.
START and END specfiy the region and CODING-SYSTEM specifies the
encoding to check. Return nil if CODING-SYSTEM does encode the region.
CODING-SYSTEM may also be a list of coding systems, in which case return
the first position not encodable by any of them.
This function is fairly slow."
;; Use recursive calls in the binary chop below, since we're
;; O(logN), and the call overhead shouldn't be a bottleneck.
(unless enable-multibyte-characters
(error "Unibyte buffer"))
;; Recurse if list of coding systems.
(if (consp coding-system)
(let ((end end) res)
(dolist (elt coding-system (and res (>= res 0) res))
(let ((pos (unencodable-char-position start end elt)))
(if pos
(setq end pos
res pos)))))
;; Skip ASCII initially.
(save-excursion
(goto-char start)
(skip-chars-forward "\000-\177" end)
(setq start (point))
(unless (= start end)
(setq coding-system (coding-system-base coding-system)) ; canonicalize
(let ((codings (find-coding-systems-region start end)))
(unless (or (equal codings '(undecided))
(memq coding-system
(find-coding-systems-region start end)))
;; Binary chop.
(if (= start (1- end))
start
(or (unencodable-char-position start (/ (+ start end) 2)
coding-system)
(unencodable-char-position (/ (+ start end) 2) end
coding-system)))))))))
(setq select-safe-coding-system-function 'select-safe-coding-system) (setq select-safe-coding-system-function 'select-safe-coding-system)
(defun select-message-coding-system () (defun select-message-coding-system ()
...@@ -760,7 +821,7 @@ it asks the user to select a proper coding system." ...@@ -760,7 +821,7 @@ it asks the user to select a proper coding system."
default-sendmail-coding-system default-sendmail-coding-system
default-buffer-file-coding-system))) default-buffer-file-coding-system)))
(if (eq coding 'no-conversion) (if (eq coding 'no-conversion)
;; We should never use no-conversion for outgoing mails. ;; We should never use no-conversion for outgoing mail.
(setq coding nil)) (setq coding nil))
(if (fboundp select-safe-coding-system-function) (if (fboundp select-safe-coding-system-function)
(funcall select-safe-coding-system-function (funcall select-safe-coding-system-function
...@@ -783,9 +844,9 @@ Meaningful values for KEY include ...@@ -783,9 +844,9 @@ Meaningful values for KEY include
is meant for, and how to use it. is meant for, and how to use it.
charset value is a list of the character sets used by this charset value is a list of the character sets used by this
language environment. language environment.
sample-text value is one line of text, sample-text value is an expression which is evalled to generate
written using those character sets, a line of text written using characters appropriate
appropriate for this language environment. for this language environment.
setup-function value is a function to call to switch to this setup-function value is a function to call to switch to this
language environment. language environment.
exit-function value is a function to call to leave this exit-function value is a function to call to leave this
...@@ -862,7 +923,7 @@ ALIST is an alist of KEY and INFO values. See the documentation of ...@@ -862,7 +923,7 @@ ALIST is an alist of KEY and INFO values. See the documentation of
`language-info-alist' for the meanings of KEY and INFO. `language-info-alist' for the meanings of KEY and INFO.
Optional arg PARENTS is a list of parent menu names; it specifies Optional arg PARENTS is a list of parent menu names; it specifies
where to put this language environment in the where to put this language environment in the
Describe Language Environment and Set Language Environment menus. Describe Language Environment and Set Language Environment menus.
For example, (\"European\") means to put this language environment For example, (\"European\") means to put this language environment
in the European submenu in each of those two menus." in the European submenu in each of those two menus."
...@@ -929,7 +990,7 @@ This returns a language environment name as a string." ...@@ -929,7 +990,7 @@ This returns a language environment name as a string."
name))) name)))
;;; Multilingual input methods. ;;; Multilingual input methods.
(defgroup leim nil (defgroup leim nil
"LEIM: Libraries of Emacs Input Methods." "LEIM: Libraries of Emacs Input Methods."
:group 'mule) :group 'mule)
...@@ -940,7 +1001,7 @@ in the format of Lisp expression for registering each input method. ...@@ -940,7 +1001,7 @@ in the format of Lisp expression for registering each input method.
Emacs loads this file at startup time.") Emacs loads this file at startup time.")
(defvar leim-list-header (format (defvar leim-list-header (format
";;; %s -- list of LEIM (Library of Emacs Input Method) ";;; %s -- list of LEIM (Library of Emacs Input Method) -*-coding: iso-2022-7bit;-*-
;; ;;
;; This file contains a list of LEIM (Library of Emacs Input Method) ;; This file contains a list of LEIM (Library of Emacs Input Method)
;; methods in the same directory as this file. Loading this file ;; methods in the same directory as this file. Loading this file
...@@ -1182,7 +1243,7 @@ and enable that one. The default is the most recent input method specified ...@@ -1182,7 +1243,7 @@ and enable that one. The default is the most recent input method specified
default t)) default t))
default)) default))
(unless default-input-method (unless default-input-method
(prog1 (prog1
(setq default-input-method current-input-method) (setq default-input-method current-input-method)
(when (interactive-p) (when (interactive-p)
(customize-mark-as-set 'default-input-method))))))) (customize-mark-as-set 'default-input-method)))))))
...@@ -1207,7 +1268,7 @@ and enable that one. The default is the most recent input method specified ...@@ -1207,7 +1268,7 @@ and enable that one. The default is the most recent input method specified
(activate-input-method input-method) (activate-input-method input-method)
(describe-current-input-method)) (describe-current-input-method))
(activate-input-method current)) (activate-input-method current))
(error (error
(activate-input-method current) (activate-input-method current)
(help-setup-xref (list #'describe-input-method input-method) (help-setup-xref (list #'describe-input-method input-method)
(interactive-p)) (interactive-p))
...@@ -1273,7 +1334,8 @@ guidance, but simple input methods give it only when you are not in ...@@ -1273,7 +1334,8 @@ guidance, but simple input methods give it only when you are not in
the minibuffer. the minibuffer.
See also the variable `input-method-highlight-flag'." See also the variable `input-method-highlight-flag'."
:type '(choice (const t) (const nil) (const complex-only) (const default)) :type '(choice (const :tag "Always" t) (const :tag "Never" nil)
(const complex-only) (const default))
:group 'mule) :group 'mule)
(defcustom input-method-highlight-flag t (defcustom input-method-highlight-flag t
...@@ -1378,7 +1440,7 @@ to using the function `set-language-environment'." ...@@ -1378,7 +1440,7 @@ to using the function `set-language-environment'."
The default status is as follows: The default status is as follows:
The default value of buffer-file-coding-system is nil. The default value of `buffer-file-coding-system' is nil.
The default coding system for process I/O is nil. The default coding system for process I/O is nil.
The default value for the command `set-terminal-coding-system' is nil. The default value for the command `set-terminal-coding-system' is nil.
The default value for the command `set-keyboard-coding-system' is nil. The default value for the command `set-keyboard-coding-system' is nil.
...@@ -1429,7 +1491,7 @@ The default status is as follows: ...@@ -1429,7 +1491,7 @@ The default status is as follows:
coding-category-iso-7 coding-category-iso-7
coding-category-iso-7-else coding-category-iso-7-else
coding-category-iso-8-else coding-category-iso-8-else
coding-category-emacs-mule coding-category-emacs-mule
coding-category-raw-text coding-category-raw-text
coding-category-sjis coding-category-sjis
coding-category-big5 coding-category-big5
...@@ -1451,7 +1513,7 @@ The default status is as follows: ...@@ -1451,7 +1513,7 @@ The default status is as follows:
(let ((output-coding (let ((output-coding
;; When bootstrapping, coding-systems are not defined yet, so ;; When bootstrapping, coding-systems are not defined yet, so
;; we need to catch the error from check-coding-system. ;; we need to catch the error from check-coding-system.
(condition-case nil (condition-case nil
(coding-system-change-text-conversion (coding-system-change-text-conversion
(car default-process-coding-system) 'undecided) (car default-process-coding-system) 'undecided)
(coding-system-error 'undecided))) (coding-system-error 'undecided)))
...@@ -1602,7 +1664,7 @@ specifies the character set for the major languages of Western Europe." ...@@ -1602,7 +1664,7 @@ specifies the character set for the major languages of Western Europe."
"Do various coding system setups for language environment LANGUAGE-NAME. "Do various coding system setups for language environment LANGUAGE-NAME.
The optional arg EOL-TYPE specifies the eol-type of the default value The optional arg EOL-TYPE specifies the eol-type of the default value
of buffer-file-coding-system set by this function." of `buffer-file-coding-system' set by this function."
(let* ((priority (get-language-info language-name 'coding-priority)) (let* ((priority (get-language-info language-name 'coding-priority))
(default-coding (car priority))) (default-coding (car priority)))
(if priority (if priority
...@@ -1618,8 +1680,8 @@ of buffer-file-coding-system set by this function." ...@@ -1618,8 +1680,8 @@ of buffer-file-coding-system set by this function."
(setq priority (cdr priority) categories (cdr categories))) (setq priority (cdr priority) categories (cdr categories)))
(update-coding-systems-internal))))) (update-coding-systems-internal)))))
;; Print all arguments with `princ', then print "\n".
(defsubst princ-list (&rest args) (defsubst princ-list (&rest args)
"Print all arguments with `princ', then print \"\n\"."
(while args (princ (car args)) (setq args (cdr args))) (while args (princ (car args)) (setq args (cdr args)))
(princ "\n")) (princ "\n"))
...@@ -1763,10 +1825,11 @@ of buffer-file-coding-system set by this function." ...@@ -1763,10 +1825,11 @@ of buffer-file-coding-system set by this function."
; bn Bengali, Bangla ; bn Bengali, Bangla
("bo" . "Tibetan") ("bo" . "Tibetan")
("br" . "Latin-1") ; Breton ("br" . "Latin-1") ; Breton
("bs" . "Latin-2") ; Bosnian
("ca" . "Latin-1") ; Catalan ("ca" . "Latin-1") ; Catalan
; co Corsican ; co Corsican
("cs" . "Czech") ("cs" . "Czech")
("cy" . "Latin-8") ; Welsh ("cy" . "Welsh") ; Welsh
("da" . "Latin-1") ; Danish ("da" . "Latin-1") ; Danish
("de" . "German") ("de" . "German")
; dz Bhutani ; dz Bhutani
...@@ -1777,7 +1840,7 @@ of buffer-file-coding-system set by this function." ...@@ -1777,7 +1840,7 @@ of buffer-file-coding-system set by this function."
("es" . "Spanish") ("es" . "Spanish")
("et" . "Latin-4") ; Estonian ("et" . "Latin-4") ; Estonian
("eu" . "Latin-1") ; Basque ("eu" . "Latin-1") ; Basque
; fa Persian ; fa Persian glibc uses utf-8
("fi" . "Latin-1") ; Finnish ("fi" . "Latin-1") ; Finnish
; fj Fiji ; fj Fiji
("fo" . "Latin-1") ; Faroese ("fo" . "Latin-1") ; Faroese
...@@ -1788,7 +1851,7 @@ of buffer-file-coding-system set by this function." ...@@ -1788,7 +1851,7 @@ of buffer-file-coding-system set by this function."
("gl" . "Latin-1") ; Galician ("gl" . "Latin-1") ; Galician
; gn Guarani ; gn Guarani
; gu Gujarati ; gu Gujarati
("gv" . "Latin-8") ; Manx Gaelic ("gv" . "Latin-8") ; Manx Gaelic glibc uses 8859-1
; ha Hausa ; ha Hausa
("he" . "Hebrew") ("he" . "Hebrew")
("hi" . "Devanagari") ; Hindi glibc uses utf-8 ("hi" . "Devanagari") ; Hindi glibc uses utf-8
...@@ -1886,6 +1949,7 @@ of buffer-file-coding-system set by this function." ...@@ -1886,6 +1949,7 @@ of buffer-file-coding-system set by this function."
("uz" . "Latin-1") ; Uzbek ("uz" . "Latin-1") ; Uzbek
("vi" . "Vietnamese") ; glibc uses utf-8 ("vi" . "Vietnamese") ; glibc uses utf-8
; vo Volapuk ; vo Volapuk
("wa" . "Latin-1") ; Walloon
; wo Wolof ; wo Wolof
; xh Xhosa ; xh Xhosa
("yi" . "Windows-1255") ; Yiddish ("yi" . "Windows-1255") ; Yiddish
...@@ -1991,7 +2055,7 @@ For example, the locale name \"ja_JP.EUC\" might name a locale ...@@ -1991,7 +2055,7 @@ For example, the locale name \"ja_JP.EUC\" might name a locale
for Japanese in Japan using the `japanese-iso-8bit' coding-system. for Japanese in Japan using the `japanese-iso-8bit' coding-system.
If LOCALE-NAME is nil, its value is taken from the environment If LOCALE-NAME is nil, its value is taken from the environment
variables LC_ALL, LC_CTYLE and LANG (the first one that is set). variables LC_ALL, LC_CTYPE and LANG (the first one that is set).
The locale names supported by your system can typically be found in a The locale names supported by your system can typically be found in a
directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME directory named `/usr/share/locale' or `/usr/lib/locale'. LOCALE-NAME
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment