aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorPaul Eggert2015-08-14 15:50:35 -0700
committerPaul Eggert2015-08-14 15:55:57 -0700
commit244c801689d2f7a80480d83cd7d092d4762ebe08 (patch)
tree6a07abc8b26966002de304b3546f3ccbebb2c865 /doc
parent293775f10555f7da7e61ed8dbdb78d72f30f7e2d (diff)
downloademacs-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.texi12
-rw-r--r--doc/lispref/strings.texi73
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
348string in Emacs Lisp. 348string 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
353The value of this variable specifies the style 352The 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
355quotes. If the variable's value is @code{curve}, the style is 354quotes. @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
358apostrophes. If the value is @code{grave}, the style is @t{`like
359this'} with grave accent and apostrophe. The default value @code{nil}
360acts like @code{curve} if curved single quotes are displayable, and
361like @code{grave} otherwise.
362@end defvar
363 355
364@defun substitute-command-keys string 356@defun substitute-command-keys string
365This function scans @var{string} for the above special sequences and 357This 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
805in how they use the result of formatting. 805in how they use the result of formatting.
806 806
807@defun format string &rest objects 807@defun format string &rest objects
808This function returns a new string that is made by copying 808This 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
810in the copy with encodings of the corresponding @var{objects}. The 810in the copy with encodings of the corresponding @var{objects}. The
811arguments @var{objects} are the computed values to be formatted. 811arguments @var{objects} are the computed values to be formatted.
812 812
813The characters in @var{string}, other than the format specifications, 813The characters in @var{string}, other than the format specifications,
814are copied directly into the output, including their text properties, 814are copied directly into the output, including their text properties,
815if any. 815if 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 825and quotation marks, each format specification says how to represent
823one of the values to be formatted (one of the arguments @var{objects}). 826one of the arguments @var{objects}. For example, if there
827is a @samp{%d} in @var{string}, the @code{format} function replaces it
828with the decimal representation of the integer to be formatted.
824For example: 829For 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{’}
839characters as format
834specifications, you should @emph{never} pass an arbitrary string as 840specifications, you should @emph{never} pass an arbitrary string as
835the first argument. This is particularly true when the string is 841the first argument. This is particularly true when the string is
836generated by some Lisp code. Unless the string is @emph{known} to 842generated by some Lisp code. Unless the string is @emph{known} to
837never include any @samp{%} characters, pass @code{"%s"}, described 843never include any of the three special characters, pass @code{"%s"}, described
838below, as the first argument, and the string as the second, like this: 844below, as the first argument, and the string as the second, like this:
839 845
840@example 846@example
@@ -908,20 +914,30 @@ is shorter.
908Replace the specification with a single @samp{%}. This format 914Replace the specification with a single @samp{%}. This format
909specification is unusual in that it does not use a value. For example, 915specification 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
922Replace the specification with a left or right quote, respectively.
923Although typically a curved single quotation mark stands for itself,
924other 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
914operation} error. 929operation} error.
915 930
916 Here are several examples: 931 Here are several examples, which assume the typical quoting style
932where 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
936between the @samp{%} and the specification character. If the printed 952between the @samp{%} and the specification character. If the printed
937representation of the object contains fewer characters than this 953representation of the object contains fewer characters than this
938width, @code{format} extends it with padding. The width specifier is 954width, @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:
948If the width is too small, @code{format} does not truncate the 964If the width is too small, @code{format} does not truncate the
949object's printed representation. Thus, you can use a width to specify 965object's printed representation. Thus, you can use a width to specify
950a minimum spacing between columns with no risk of losing information. 966a minimum spacing between columns with no risk of losing information.
951In the following three examples, @samp{%7s} specifies a minimum width 967In the following two examples, @samp{%7s} specifies a minimum width
952of 7. In the first case, the string inserted in place of @samp{%7s} 968of 7. In the first case, the string inserted in place of @samp{%7s}
953has only 3 letters, and needs 4 blank spaces as padding. In the 969has only 3 letters, and needs 4 blank spaces as padding. In the
954second case, the string @code{"specification"} is 13 letters wide but 970second 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}
1014before the character (after the width, if present). The precision is 1030before the character (after the width, if present). The precision is
1015a decimal-point @samp{.} followed by a digit-string. For the 1031a decimal-point @samp{.} followed by a digit-string. For the
1016floating-point specifications (@samp{%e}, @samp{%f}, @samp{%g}), the 1032floating-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
1022characters. 1038characters.
1023 1039
1040@defvar text-quoting-style
1041@cindex curved quotes
1042@cindex curly quotes
1043This variable specifies the style @code{format} uses when generating
1044left 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
1047apostrophes. If the value is @code{grave}, the style is @t{`like
1048this'} with grave accent and apostrophe. The default value @code{nil}
1049acts like @code{curve} if curved single quotes are displayable, and
1050like @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