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
...@@ -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,6 +661,9 @@ and TO is ignored." ...@@ -653,6 +661,9 @@ 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))
(save-excursion
(goto-char (unencodable-char-position
from to (mapcar #'car default-coding-system)))
;; Then ask users to select one form CODINGS. ;; Then ask users to select one form CODINGS.
(unwind-protect (unwind-protect
(save-window-excursion (save-window-excursion
...@@ -679,17 +690,23 @@ and TO is ignored." ...@@ -679,17 +690,23 @@ and TO is ignored."
default-coding-system) default-coding-system)
(insert "\n") (insert "\n")
(fill-region-as-paragraph pos (point))) (fill-region-as-paragraph pos (point)))
(insert
(if (consp coding-system) (if (consp coding-system)
(concat (format "%s safely encodes the target text,\n" (insert (format "%s safely encodes the target text,\n"
(car coding-system)) (car coding-system))
"but it is not recommended for encoding text in this context,\n" "\
"e.g., for sending an email message.\n") but it is not recommended for encoding text in this context,
"However, none of them safely encodes the target text.\n"))) 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) (insert (if (consp coding-system)
"\nSelect the above, or " "\nSelect the above, or "
"\nSelect ") "\nSelect ")
"one of the following safe coding systems:\n") "\
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) (princ " ") (princ x))) (mapcar (function (lambda (x) (princ " ") (princ x)))
...@@ -709,7 +726,7 @@ and TO is ignored." ...@@ -709,7 +726,7 @@ and TO is ignored."
(car (car safe-names))))) (car (car safe-names)))))
(setq last-coding-system-specified (intern name) (setq last-coding-system-specified (intern name)
coding-system last-coding-system-specified))) coding-system last-coding-system-specified)))
(kill-buffer "*Warning*"))) (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
...@@ -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
...@@ -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.
...@@ -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