diff options
| author | Eli Zaretskii | 2017-01-10 20:02:37 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2017-01-10 20:02:37 +0200 |
| commit | 0e35405a92be502ab3851890fc4eb660842fd3a9 (patch) | |
| tree | 058b4ee76a6b4aef7b5fd04e85a8723bc4ed3f31 | |
| parent | c2fd04c8d504b601471fe7c13011bc39abc6b921 (diff) | |
| download | emacs-0e35405a92be502ab3851890fc4eb660842fd3a9.tar.gz emacs-0e35405a92be502ab3851890fc4eb660842fd3a9.zip | |
Improve documentation of coding-systems
* doc/lispref/nonascii.texi (Coding System Basics): Mention
'prefer-utf-8'. Index it and 'undecided'.
(Encoding and I/O): Fix a typo.
(User-Chosen Coding Systems): Improve the documentation of
ACCEPT-DEFAULT-P argument to select-safe-coding-system. Document
select-safe-coding-system-function.
(Specifying Coding Systems): Document coding-system-require-warning.
| -rw-r--r-- | doc/lispref/nonascii.texi | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/doc/lispref/nonascii.texi b/doc/lispref/nonascii.texi index ab8f2fc94fb..e3cb5d0d369 100644 --- a/doc/lispref/nonascii.texi +++ b/doc/lispref/nonascii.texi | |||
| @@ -1002,10 +1002,14 @@ alternative encodings for the same characters; for example, there are | |||
| 1002 | three coding systems for the Cyrillic (Russian) alphabet: ISO, | 1002 | three coding systems for the Cyrillic (Russian) alphabet: ISO, |
| 1003 | Alternativnyj, and KOI8. | 1003 | Alternativnyj, and KOI8. |
| 1004 | 1004 | ||
| 1005 | @vindex undecided@r{ coding system} | ||
| 1006 | @vindex prefer-utf-8@r{ coding system} | ||
| 1005 | Every coding system specifies a particular set of character code | 1007 | Every coding system specifies a particular set of character code |
| 1006 | conversions, but the coding system @code{undecided} is special: it | 1008 | conversions, but the coding system @code{undecided} is special: it |
| 1007 | leaves the choice unspecified, to be chosen heuristically for each | 1009 | leaves the choice unspecified, to be chosen heuristically for each |
| 1008 | file, based on the file's data. | 1010 | file, based on the file's data. The coding system @code{prefer-utf-8} |
| 1011 | is like @code{undecided}, but it prefers to choose @code{utf-8} when | ||
| 1012 | possible. | ||
| 1009 | 1013 | ||
| 1010 | In general, a coding system doesn't guarantee roundtrip identity: | 1014 | In general, a coding system doesn't guarantee roundtrip identity: |
| 1011 | decoding a byte sequence using coding system, then encoding the | 1015 | decoding a byte sequence using coding system, then encoding the |
| @@ -1109,7 +1113,7 @@ encode the buffer contents. | |||
| 1109 | (@pxref{Specifying Coding Systems}), or implicitly using a default | 1113 | (@pxref{Specifying Coding Systems}), or implicitly using a default |
| 1110 | mechanism (@pxref{Default Coding Systems}). But these methods may not | 1114 | mechanism (@pxref{Default Coding Systems}). But these methods may not |
| 1111 | completely specify what to do. For example, they may choose a coding | 1115 | completely specify what to do. For example, they may choose a coding |
| 1112 | system such as @code{undefined} which leaves the character code | 1116 | system such as @code{undecided} which leaves the character code |
| 1113 | conversion to be determined from the data. In these cases, the I/O | 1117 | conversion to be determined from the data. In these cases, the I/O |
| 1114 | operation finishes the job of choosing a coding system. Very often | 1118 | operation finishes the job of choosing a coding system. Very often |
| 1115 | you will want to find out afterwards which coding system was chosen. | 1119 | you will want to find out afterwards which coding system was chosen. |
| @@ -1411,19 +1415,21 @@ Otherwise, it asks the user to choose from a list of coding systems | |||
| 1411 | which can encode all the text, and returns the user's choice. | 1415 | which can encode all the text, and returns the user's choice. |
| 1412 | 1416 | ||
| 1413 | @var{default-coding-system} can also be a list whose first element is | 1417 | @var{default-coding-system} can also be a list whose first element is |
| 1414 | t and whose other elements are coding systems. Then, if no coding | 1418 | @code{t} and whose other elements are coding systems. Then, if no coding |
| 1415 | system in the list can handle the text, @code{select-safe-coding-system} | 1419 | system in the list can handle the text, @code{select-safe-coding-system} |
| 1416 | queries the user immediately, without trying any of the three | 1420 | queries the user immediately, without trying any of the three |
| 1417 | alternatives described above. | 1421 | alternatives described above. This is handy for checking only the |
| 1418 | 1422 | coding systems in the list. | |
| 1419 | The optional argument @var{accept-default-p}, if non-@code{nil}, | 1423 | |
| 1420 | should be a function to determine whether a coding system selected | 1424 | The optional argument @var{accept-default-p} determines whether a |
| 1421 | without user interaction is acceptable. @code{select-safe-coding-system} | 1425 | coding system selected without user interaction is acceptable. If |
| 1422 | calls this function with one argument, the base coding system of the | 1426 | it's omitted or @code{nil}, such a silent selection is always |
| 1423 | selected coding system. If @var{accept-default-p} returns @code{nil}, | 1427 | acceptable. If it is non-@code{nil}, it should be a function; |
| 1424 | @code{select-safe-coding-system} rejects the silently selected coding | 1428 | @code{select-safe-coding-system} calls this function with one |
| 1425 | system, and asks the user to select a coding system from a list of | 1429 | argument, the base coding system of the selected coding system. If |
| 1426 | possible candidates. | 1430 | the function returns @code{nil}, @code{select-safe-coding-system} |
| 1431 | rejects the silently selected coding system, and asks the user to | ||
| 1432 | select a coding system from a list of possible candidates. | ||
| 1427 | 1433 | ||
| 1428 | @vindex select-safe-coding-system-accept-default-p | 1434 | @vindex select-safe-coding-system-accept-default-p |
| 1429 | If the variable @code{select-safe-coding-system-accept-default-p} is | 1435 | If the variable @code{select-safe-coding-system-accept-default-p} is |
| @@ -1444,6 +1450,18 @@ similar functions). If it detects an apparent inconsistency, | |||
| 1444 | coding system. | 1450 | coding system. |
| 1445 | @end defun | 1451 | @end defun |
| 1446 | 1452 | ||
| 1453 | @defvar select-safe-coding-system-function | ||
| 1454 | This variable names the function to be called to request the user to | ||
| 1455 | select a proper coding system for encoding text when the default | ||
| 1456 | coding system for an output operation cannot safely encode that text. | ||
| 1457 | The default value of this variable is @code{select-safe-coding-system}. | ||
| 1458 | Emacs primitives that write text to files, such as | ||
| 1459 | @code{write-region}, or send text to other processes, such as | ||
| 1460 | @code{process-send-region}, normally call the value of this variable, | ||
| 1461 | unless @code{coding-system-for-write} is bound to a non-@code{nil} | ||
| 1462 | value (@pxref{Specifying Coding Systems}). | ||
| 1463 | @end defvar | ||
| 1464 | |||
| 1447 | Here are two functions you can use to let the user specify a coding | 1465 | Here are two functions you can use to let the user specify a coding |
| 1448 | system, with completion. @xref{Completion}. | 1466 | system, with completion. @xref{Completion}. |
| 1449 | 1467 | ||
| @@ -1704,7 +1722,9 @@ including @code{file-coding-system-alist}, | |||
| 1704 | @defvar coding-system-for-write | 1722 | @defvar coding-system-for-write |
| 1705 | This works much like @code{coding-system-for-read}, except that it | 1723 | This works much like @code{coding-system-for-read}, except that it |
| 1706 | applies to output rather than input. It affects writing to files, | 1724 | applies to output rather than input. It affects writing to files, |
| 1707 | as well as sending output to subprocesses and net connections. | 1725 | as well as sending output to subprocesses and net connections. It |
| 1726 | also applies to encoding command-line arguments with which Emacs | ||
| 1727 | invokes subprocesses. | ||
| 1708 | 1728 | ||
| 1709 | When a single operation does both input and output, as do | 1729 | When a single operation does both input and output, as do |
| 1710 | @code{call-process-region} and @code{start-process}, both | 1730 | @code{call-process-region} and @code{start-process}, both |
| @@ -1712,6 +1732,23 @@ When a single operation does both input and output, as do | |||
| 1712 | affect it. | 1732 | affect it. |
| 1713 | @end defvar | 1733 | @end defvar |
| 1714 | 1734 | ||
| 1735 | @defvar coding-system-require-warning | ||
| 1736 | Binding @code{coding-system-for-write} to a non-@code{nil} value | ||
| 1737 | prevents output primitives from calling the function specified by | ||
| 1738 | @code{select-safe-coding-system-function} (@pxref{User-Chosen Coding | ||
| 1739 | Systems}). This is because @kbd{C-x RET c} | ||
| 1740 | (@code{universal-coding-system-argument}) works by binding | ||
| 1741 | @code{coding-system-for-write}, and Emacs should obey user selection. | ||
| 1742 | If a Lisp program binds @code{coding-system-for-write} to a value that | ||
| 1743 | might not be safe for encoding the text to be written, it can also bind | ||
| 1744 | @code{coding-system-require-warning} to a non-@code{nil} value, which | ||
| 1745 | will force the output primitives to check the encoding by calling the | ||
| 1746 | value of @code{select-safe-coding-system-function} even though | ||
| 1747 | @code{coding-system-for-write} is non-@code{nil}. Alternatively, call | ||
| 1748 | @code{select-safe-coding-system} explicitly before using the specified | ||
| 1749 | encoding. | ||
| 1750 | @end defvar | ||
| 1751 | |||
| 1715 | @defopt inhibit-eol-conversion | 1752 | @defopt inhibit-eol-conversion |
| 1716 | When this variable is non-@code{nil}, no end-of-line conversion is done, | 1753 | When this variable is non-@code{nil}, no end-of-line conversion is done, |
| 1717 | no matter which coding system is specified. This applies to all the | 1754 | no matter which coding system is specified. This applies to all the |