diff options
| author | Paul Eggert | 2015-08-14 15:50:35 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-08-14 15:55:57 -0700 |
| commit | 244c801689d2f7a80480d83cd7d092d4762ebe08 (patch) | |
| tree | 6a07abc8b26966002de304b3546f3ccbebb2c865 /doc | |
| parent | 293775f10555f7da7e61ed8dbdb78d72f30f7e2d (diff) | |
| download | emacs-244c801689d2f7a80480d83cd7d092d4762ebe08.tar.gz emacs-244c801689d2f7a80480d83cd7d092d4762ebe08.zip | |
Extend ‘format’ to translate curved quotes
This is a followup to the recent doc string change, and deals with
diagnostics and the like. This patch is more conservative than
the doc string change, in that the behavior of ‘format’ changes
only if its first arg contains curved quotes and the user prefers
straight or grave quotes. (Come to think of it, perhaps we should
be similarly conservative with doc strings too, but that can wait.)
The upside of this conservatism is that existing usage is almost
surely unaffected. The downside is that we'll eventually have to
change Emacs's format strings to use curved quotes in places where
the user might want curved quotes, but that's a simple and
mechanical translation that I'm willing to do later. (Bug#21222)
* doc/lispref/help.texi (Keys in Documentation):
Move description of text-quoting-style from here ...
* doc/lispref/strings.texi (Formatting Strings):
... to here, and describe new behavior of ‘format’.
* etc/NEWS: Describe new behavior.
* lisp/calc/calc-help.el (calc-describe-thing):
* lisp/emacs-lisp/derived.el (derived-mode-make-docstring):
* lisp/info.el (Info-find-index-name):
Use ‘concat’ rather than ‘format’ to avoid misinterpretation
of recently-added curved quotes.
* src/doc.c (uLSQM0, uLSQM1, uLSQM2, uRSQM0, uRSQM1, uRSQM2):
Move from here ...
* src/lisp.h: ... to here.
* src/doc.c (text_quoting_style): New function.
(Fsubstitute_command_keys): Use it.
* src/editfns.c (Fformat): Implement new behavior.
* src/lisp.h (enum text_quoting_style): New enum.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/help.texi | 12 | ||||
| -rw-r--r-- | doc/lispref/strings.texi | 73 |
2 files changed, 53 insertions, 32 deletions
diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi index ca8ae3f314a..ab1696e6712 100644 --- a/doc/lispref/help.texi +++ b/doc/lispref/help.texi | |||
| @@ -347,19 +347,11 @@ and @samp{\=\=} puts @samp{\=} into the output. | |||
| 347 | @strong{Please note:} Each @samp{\} must be doubled when written in a | 347 | @strong{Please note:} Each @samp{\} must be doubled when written in a |
| 348 | string in Emacs Lisp. | 348 | string in Emacs Lisp. |
| 349 | 349 | ||
| 350 | @defvar text-quoting-style | ||
| 351 | @cindex curved quotes | 350 | @cindex curved quotes |
| 352 | @cindex curly quotes | 351 | @cindex curly quotes |
| 353 | The value of this variable specifies the style | 352 | The value of the @code{text-quoting-style} variable specifies the style |
| 354 | @code{substitute-command-keys} uses when generating left and right | 353 | @code{substitute-command-keys} uses when generating left and right |
| 355 | quotes. If the variable's value is @code{curve}, the style is | 354 | quotes. @xref{Formatting Strings}, for more information. |
| 356 | @t{‘like this’} with curved single quotes. If the value is | ||
| 357 | @code{straight}, the style is @t{'like this'} with straight | ||
| 358 | apostrophes. If the value is @code{grave}, the style is @t{`like | ||
| 359 | this'} with grave accent and apostrophe. The default value @code{nil} | ||
| 360 | acts like @code{curve} if curved single quotes are displayable, and | ||
| 361 | like @code{grave} otherwise. | ||
| 362 | @end defvar | ||
| 363 | 355 | ||
| 364 | @defun substitute-command-keys string | 356 | @defun substitute-command-keys string |
| 365 | This function scans @var{string} for the above special sequences and | 357 | This function scans @var{string} for the above special sequences and |
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index c2f06079cb6..30933387b20 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi | |||
| @@ -805,22 +805,27 @@ formatting feature described here; they differ from @code{format} only | |||
| 805 | in how they use the result of formatting. | 805 | in how they use the result of formatting. |
| 806 | 806 | ||
| 807 | @defun format string &rest objects | 807 | @defun format string &rest objects |
| 808 | This function returns a new string that is made by copying | 808 | This function returns a string that is equivalent to copying |
| 809 | @var{string} and then replacing any format specification | 809 | @var{string} and then replacing any format specification |
| 810 | in the copy with encodings of the corresponding @var{objects}. The | 810 | in the copy with encodings of the corresponding @var{objects}. The |
| 811 | arguments @var{objects} are the computed values to be formatted. | 811 | arguments @var{objects} are the computed values to be formatted. |
| 812 | 812 | ||
| 813 | The characters in @var{string}, other than the format specifications, | 813 | The characters in @var{string}, other than the format specifications, |
| 814 | are copied directly into the output, including their text properties, | 814 | are copied directly into the output, including their text properties, |
| 815 | if any. | 815 | if any. If the output equals @var{string}, this function may return |
| 816 | @var{string} itself rather than a new copy. | ||
| 816 | @end defun | 817 | @end defun |
| 817 | 818 | ||
| 818 | @cindex @samp{%} in format | 819 | @cindex @samp{%} in format |
| 819 | @cindex format specification | 820 | @cindex format specification |
| 821 | @cindex curved quotes | ||
| 822 | @cindex curly quotes | ||
| 820 | A format specification is a sequence of characters beginning with a | 823 | A format specification is a sequence of characters beginning with a |
| 821 | @samp{%}. Thus, if there is a @samp{%d} in @var{string}, the | 824 | @samp{%} or is a curved single quotation mark. Except for @samp{%%} |
| 822 | @code{format} function replaces it with the printed representation of | 825 | and quotation marks, each format specification says how to represent |
| 823 | one of the values to be formatted (one of the arguments @var{objects}). | 826 | one of the arguments @var{objects}. For example, if there |
| 827 | is a @samp{%d} in @var{string}, the @code{format} function replaces it | ||
| 828 | with the decimal representation of the integer to be formatted. | ||
| 824 | For example: | 829 | For example: |
| 825 | 830 | ||
| 826 | @example | 831 | @example |
| @@ -830,11 +835,12 @@ For example: | |||
| 830 | @end group | 835 | @end group |
| 831 | @end example | 836 | @end example |
| 832 | 837 | ||
| 833 | Since @code{format} interprets @samp{%} characters as format | 838 | Since @code{format} interprets @samp{%}, @samp{‘} and @samp{’} |
| 839 | characters as format | ||
| 834 | specifications, you should @emph{never} pass an arbitrary string as | 840 | specifications, you should @emph{never} pass an arbitrary string as |
| 835 | the first argument. This is particularly true when the string is | 841 | the first argument. This is particularly true when the string is |
| 836 | generated by some Lisp code. Unless the string is @emph{known} to | 842 | generated by some Lisp code. Unless the string is @emph{known} to |
| 837 | never include any @samp{%} characters, pass @code{"%s"}, described | 843 | never include any of the three special characters, pass @code{"%s"}, described |
| 838 | below, as the first argument, and the string as the second, like this: | 844 | below, as the first argument, and the string as the second, like this: |
| 839 | 845 | ||
| 840 | @example | 846 | @example |
| @@ -908,20 +914,30 @@ is shorter. | |||
| 908 | Replace the specification with a single @samp{%}. This format | 914 | Replace the specification with a single @samp{%}. This format |
| 909 | specification is unusual in that it does not use a value. For example, | 915 | specification is unusual in that it does not use a value. For example, |
| 910 | @code{(format "%% %d" 30)} returns @code{"% 30"}. | 916 | @code{(format "%% %d" 30)} returns @code{"% 30"}. |
| 917 | |||
| 918 | @item ‘ | ||
| 919 | @itemx ’ | ||
| 920 | @cindex curved quotes | ||
| 921 | @cindex curly quotes | ||
| 922 | Replace the specification with a left or right quote, respectively. | ||
| 923 | Although typically a curved single quotation mark stands for itself, | ||
| 924 | other quoting styles are available as per the variable | ||
| 925 | @samp{text-quoting-style} described below. | ||
| 911 | @end table | 926 | @end table |
| 912 | 927 | ||
| 913 | Any other format character results in an @samp{Invalid format | 928 | Any other format character after @samp{%} results in an @samp{Invalid format |
| 914 | operation} error. | 929 | operation} error. |
| 915 | 930 | ||
| 916 | Here are several examples: | 931 | Here are several examples, which assume the typical quoting style |
| 932 | where curved single quotes stand for themselves: | ||
| 917 | 933 | ||
| 918 | @example | 934 | @example |
| 919 | @group | 935 | @group |
| 920 | (format "The name of this buffer is %s." (buffer-name)) | 936 | (format "The name of this buffer is ‘%s’." (buffer-name)) |
| 921 | @result{} "The name of this buffer is strings.texi." | 937 | @result{} "The name of this buffer is ‘strings.texi’." |
| 922 | 938 | ||
| 923 | (format "The buffer object prints as %s." (current-buffer)) | 939 | (format "The buffer object prints as ‘%s’." (current-buffer)) |
| 924 | @result{} "The buffer object prints as strings.texi." | 940 | @result{} "The buffer object prints as ‘strings.texi’." |
| 925 | 941 | ||
| 926 | (format "The octal value of %d is %o, | 942 | (format "The octal value of %d is %o, |
| 927 | and the hex value is %x." 18 18 18) | 943 | and the hex value is %x." 18 18 18) |
| @@ -932,7 +948,7 @@ operation} error. | |||
| 932 | 948 | ||
| 933 | @cindex field width | 949 | @cindex field width |
| 934 | @cindex padding | 950 | @cindex padding |
| 935 | A specification can have a @dfn{width}, which is a decimal number | 951 | A @samp{%} specification can have a @dfn{width}, which is a decimal number |
| 936 | between the @samp{%} and the specification character. If the printed | 952 | between the @samp{%} and the specification character. If the printed |
| 937 | representation of the object contains fewer characters than this | 953 | representation of the object contains fewer characters than this |
| 938 | width, @code{format} extends it with padding. The width specifier is | 954 | width, @code{format} extends it with padding. The width specifier is |
| @@ -948,7 +964,7 @@ the width specifier normally consists of spaces inserted on the left: | |||
| 948 | If the width is too small, @code{format} does not truncate the | 964 | If the width is too small, @code{format} does not truncate the |
| 949 | object's printed representation. Thus, you can use a width to specify | 965 | object's printed representation. Thus, you can use a width to specify |
| 950 | a minimum spacing between columns with no risk of losing information. | 966 | a minimum spacing between columns with no risk of losing information. |
| 951 | In the following three examples, @samp{%7s} specifies a minimum width | 967 | In the following two examples, @samp{%7s} specifies a minimum width |
| 952 | of 7. In the first case, the string inserted in place of @samp{%7s} | 968 | of 7. In the first case, the string inserted in place of @samp{%7s} |
| 953 | has only 3 letters, and needs 4 blank spaces as padding. In the | 969 | has only 3 letters, and needs 4 blank spaces as padding. In the |
| 954 | second case, the string @code{"specification"} is 13 letters wide but | 970 | second case, the string @code{"specification"} is 13 letters wide but |
| @@ -956,12 +972,12 @@ is not truncated. | |||
| 956 | 972 | ||
| 957 | @example | 973 | @example |
| 958 | @group | 974 | @group |
| 959 | (format "The word '%7s' has %d letters in it." | 975 | (format "The word ‘%7s’ has %d letters in it." |
| 960 | "foo" (length "foo")) | 976 | "foo" (length "foo")) |
| 961 | @result{} "The word ' foo' has 3 letters in it." | 977 | @result{} "The word ‘ foo’ has 3 letters in it." |
| 962 | (format "The word '%7s' has %d letters in it." | 978 | (format "The word ‘%7s’ has %d letters in it." |
| 963 | "specification" (length "specification")) | 979 | "specification" (length "specification")) |
| 964 | @result{} "The word 'specification' has 13 letters in it." | 980 | @result{} "The word ‘specification’ has 13 letters in it." |
| 965 | @end group | 981 | @end group |
| 966 | @end example | 982 | @end example |
| 967 | 983 | ||
| @@ -1003,14 +1019,14 @@ ignored. | |||
| 1003 | (format "%-6d is padded on the right" 123) | 1019 | (format "%-6d is padded on the right" 123) |
| 1004 | @result{} "123 is padded on the right" | 1020 | @result{} "123 is padded on the right" |
| 1005 | 1021 | ||
| 1006 | (format "The word '%-7s' actually has %d letters in it." | 1022 | (format "The word ‘%-7s’ actually has %d letters in it." |
| 1007 | "foo" (length "foo")) | 1023 | "foo" (length "foo")) |
| 1008 | @result{} "The word 'foo ' actually has 3 letters in it." | 1024 | @result{} "The word ‘foo ’ actually has 3 letters in it." |
| 1009 | @end group | 1025 | @end group |
| 1010 | @end example | 1026 | @end example |
| 1011 | 1027 | ||
| 1012 | @cindex precision in format specifications | 1028 | @cindex precision in format specifications |
| 1013 | All the specification characters allow an optional @dfn{precision} | 1029 | The @samp{%} specification characters allow an optional @dfn{precision} |
| 1014 | before the character (after the width, if present). The precision is | 1030 | before the character (after the width, if present). The precision is |
| 1015 | a decimal-point @samp{.} followed by a digit-string. For the | 1031 | a decimal-point @samp{.} followed by a digit-string. For the |
| 1016 | floating-point specifications (@samp{%e}, @samp{%f}, @samp{%g}), the | 1032 | floating-point specifications (@samp{%e}, @samp{%f}, @samp{%g}), the |
| @@ -1021,6 +1037,19 @@ shows only the first three characters of the representation for | |||
| 1021 | @var{object}. Precision has no effect for other specification | 1037 | @var{object}. Precision has no effect for other specification |
| 1022 | characters. | 1038 | characters. |
| 1023 | 1039 | ||
| 1040 | @defvar text-quoting-style | ||
| 1041 | @cindex curved quotes | ||
| 1042 | @cindex curly quotes | ||
| 1043 | This variable specifies the style @code{format} uses when generating | ||
| 1044 | left and right quotes. If the value is @code{curve}, the style is | ||
| 1045 | @t{‘like this’} with curved single quotes. If the value is | ||
| 1046 | @code{straight}, the style is @t{'like this'} with straight | ||
| 1047 | apostrophes. If the value is @code{grave}, the style is @t{`like | ||
| 1048 | this'} with grave accent and apostrophe. The default value @code{nil} | ||
| 1049 | acts like @code{curve} if curved single quotes are displayable, and | ||
| 1050 | like @code{grave} otherwise. | ||
| 1051 | @end defvar | ||
| 1052 | |||
| 1024 | @node Case Conversion | 1053 | @node Case Conversion |
| 1025 | @section Case Conversion in Lisp | 1054 | @section Case Conversion in Lisp |
| 1026 | @cindex upper case | 1055 | @cindex upper case |