aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2015-08-18 23:04:58 -0700
committerPaul Eggert2015-08-18 23:14:08 -0700
commit67de1b6fa752df913ae00537234d1a18bca2543f (patch)
treeabb61f8f7eed292dbcc61ebca1b912ade02dde4b
parent85bc107458601e305445d7ec6f5b209c01f5db0c (diff)
downloademacs-67de1b6fa752df913ae00537234d1a18bca2543f.tar.gz
emacs-67de1b6fa752df913ae00537234d1a18bca2543f.zip
New q flag for ‘format’
* doc/lispref/processes.texi (Sentinels): Don't hardwire grave quoting style in example. * doc/lispref/strings.texi (Formatting Strings): * etc/NEWS: Document new q flag. * src/editfns.c (Fformat): Implement it.
-rw-r--r--doc/lispref/processes.texi4
-rw-r--r--doc/lispref/strings.texi9
-rw-r--r--etc/NEWS13
-rw-r--r--src/editfns.c78
4 files changed, 84 insertions, 20 deletions
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi
index 2bc6a1843c4..98b3dfb9e3a 100644
--- a/doc/lispref/processes.texi
+++ b/doc/lispref/processes.texi
@@ -1720,13 +1720,13 @@ sentinel, the eventual call to the sentinel will use the new one.
1720@group 1720@group
1721(defun msg-me (process event) 1721(defun msg-me (process event)
1722 (princ 1722 (princ
1723 (format "Process: %s had the event `%s'" process event))) 1723 (format "Process: %s had the event %s" process event)))
1724(set-process-sentinel (get-process "shell") 'msg-me) 1724(set-process-sentinel (get-process "shell") 'msg-me)
1725 @result{} msg-me 1725 @result{} msg-me
1726@end group 1726@end group
1727@group 1727@group
1728(kill-process (get-process "shell")) 1728(kill-process (get-process "shell"))
1729 @print{} Process: #<process shell> had the event `killed' 1729 @print{} Process: #<process shell> had the event killed
1730 @result{} #<process shell> 1730 @result{} #<process shell>
1731@end group 1731@end group
1732@end smallexample 1732@end smallexample
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index 30933387b20..8de1473b83d 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -936,7 +936,7 @@ where curved single quotes stand for themselves:
936(format "The name of this buffer is ‘%s’." (buffer-name)) 936(format "The name of this buffer is ‘%s’." (buffer-name))
937 @result{} "The name of this buffer is ‘strings.texi’." 937 @result{} "The name of this buffer is ‘strings.texi’."
938 938
939(format "The buffer object prints as %s." (current-buffer)) 939(format "The buffer object prints as %qs." (current-buffer))
940 @result{} "The buffer object prints as ‘strings.texi’." 940 @result{} "The buffer object prints as ‘strings.texi’."
941 941
942(format "The octal value of %d is %o, 942(format "The octal value of %d is %o,
@@ -1011,13 +1011,16 @@ specifier, if any, to be inserted on the right rather than the left.
1011If both @samp{-} and @samp{0} are present, the @samp{0} flag is 1011If both @samp{-} and @samp{0} are present, the @samp{0} flag is
1012ignored. 1012ignored.
1013 1013
1014 The flag @samp{q} quotes the printed representation as per the
1015variable @samp{text-quoting-style} described below.
1016
1014@example 1017@example
1015@group 1018@group
1016(format "%06d is padded on the left with zeros" 123) 1019(format "%06d is padded on the left with zeros" 123)
1017 @result{} "000123 is padded on the left with zeros" 1020 @result{} "000123 is padded on the left with zeros"
1018 1021
1019(format "%-6d is padded on the right" 123) 1022(format "%q-6d is padded on the right" 123)
1020 @result{} "123 is padded on the right" 1023 @result{} "123 is padded on the right"
1021 1024
1022(format "The word ‘%-7s’ actually has %d letters in it." 1025(format "The word ‘%-7s’ actually has %d letters in it."
1023 "foo" (length "foo")) 1026 "foo" (length "foo"))
diff --git a/etc/NEWS b/etc/NEWS
index ec3d25c4870..6058f221464 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -912,12 +912,17 @@ create a string, and may return its first argument if the argument
912already has the correct value. 912already has the correct value.
913 913
914+++ 914+++
915** New ‘format’ flag ‘q’
916The new ‘q’ flag causes ‘format’ to quote the output representation as
917per the value of ‘text quoting-style’. E.g., (format "%qs failed"
918"foo") might return "‘foo’ failed".
919
920+++
915** substitute-command-keys now replaces quotes. 921** substitute-command-keys now replaces quotes.
916That is, it converts documentation strings' quoting style as per the 922That is, it converts documentation strings' quoting style as per the
917value of ‘text-quoting-style’ as described above. Doc strings in 923value of ‘text-quoting-style’. Doc strings in source code can use
918source code can use either curved quotes or grave accent and 924either curved quotes or grave accent and apostrophe. As before,
919apostrophe. As before, isolated apostrophes and characters preceded 925isolated apostrophes and characters preceded by \= are output as-is.
920by \= are output as-is.
921 926
922+++ 927+++
923** The character classes [:alpha:] and [:alnum:] in regular expressions 928** The character classes [:alpha:] and [:alnum:] in regular expressions
diff --git a/src/editfns.c b/src/editfns.c
index ed57d8aee09..0e1b0c8f01d 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3822,7 +3822,7 @@ specifiers, as follows:
3822 3822
3823 %<flags><width><precision>character 3823 %<flags><width><precision>character
3824 3824
3825where flags is [+ #-0]+, width is [0-9]+, and precision is .[0-9]+ 3825where flags is [+ #-0q]+, width is [0-9]+, and precision is .[0-9]+
3826 3826
3827The + flag character inserts a + before any positive number, while a 3827The + flag character inserts a + before any positive number, while a
3828space inserts a space before any positive number; these flags only 3828space inserts a space before any positive number; these flags only
@@ -3835,6 +3835,9 @@ The # flag means to use an alternate display form for %o, %x, %X, %e,
3835for %e, %f, and %g, it causes a decimal point to be included even if 3835for %e, %f, and %g, it causes a decimal point to be included even if
3836the precision is zero. 3836the precision is zero.
3837 3837
3838The q flag means to quote the printed representation as per
3839‘text-quoting-style’. E.g., "%qs" is equivalent to "‘%s’".
3840
3838The width specifier supplies a lower limit for the length of the 3841The width specifier supplies a lower limit for the length of the
3839printed representation. The padding, if any, normally goes on the 3842printed representation. The padding, if any, normally goes on the
3840left, but it goes on the right if the - flag is present. The padding 3843left, but it goes on the right if the - flag is present. The padding
@@ -3973,11 +3976,12 @@ usage: (format STRING &rest OBJECTS) */)
3973 digits to print after the '.' for floats, or the max. 3976 digits to print after the '.' for floats, or the max.
3974 number of chars to print from a string. */ 3977 number of chars to print from a string. */
3975 3978
3976 bool minus_flag = 0; 3979 bool minus_flag = false;
3977 bool plus_flag = 0; 3980 bool plus_flag = false;
3978 bool space_flag = 0; 3981 bool space_flag = false;
3979 bool sharp_flag = 0; 3982 bool sharp_flag = false;
3980 bool zero_flag = 0; 3983 bool zero_flag = false;
3984 bool quote_flag = false;
3981 ptrdiff_t field_width; 3985 ptrdiff_t field_width;
3982 bool precision_given; 3986 bool precision_given;
3983 uintmax_t precision = UINTMAX_MAX; 3987 uintmax_t precision = UINTMAX_MAX;
@@ -3988,11 +3992,12 @@ usage: (format STRING &rest OBJECTS) */)
3988 { 3992 {
3989 switch (*++format) 3993 switch (*++format)
3990 { 3994 {
3991 case '-': minus_flag = 1; continue; 3995 case '-': minus_flag = true; continue;
3992 case '+': plus_flag = 1; continue; 3996 case '+': plus_flag = true; continue;
3993 case ' ': space_flag = 1; continue; 3997 case ' ': space_flag = true; continue;
3994 case '#': sharp_flag = 1; continue; 3998 case '#': sharp_flag = true; continue;
3995 case '0': zero_flag = 1; continue; 3999 case '0': zero_flag = true; continue;
4000 case 'q': quote_flag = true; continue;
3996 } 4001 }
3997 break; 4002 break;
3998 } 4003 }
@@ -4121,6 +4126,20 @@ usage: (format STRING &rest OBJECTS) */)
4121 if (convbytes && multibyte && ! STRING_MULTIBYTE (args[n])) 4126 if (convbytes && multibyte && ! STRING_MULTIBYTE (args[n]))
4122 convbytes = count_size_as_multibyte (SDATA (args[n]), nbytes); 4127 convbytes = count_size_as_multibyte (SDATA (args[n]), nbytes);
4123 4128
4129 if (quote_flag)
4130 {
4131 convbytes += 2;
4132 if (quoting_style == CURVE_QUOTING_STYLE)
4133 {
4134 if (!multibyte)
4135 {
4136 multibyte = true;
4137 goto retry;
4138 }
4139 convbytes += 4;
4140 }
4141 }
4142
4124 padding = width < field_width ? field_width - width : 0; 4143 padding = width < field_width ? field_width - width : 0;
4125 4144
4126 if (max_bufsize - padding <= convbytes) 4145 if (max_bufsize - padding <= convbytes)
@@ -4128,6 +4147,27 @@ usage: (format STRING &rest OBJECTS) */)
4128 convbytes += padding; 4147 convbytes += padding;
4129 if (convbytes <= buf + bufsize - p) 4148 if (convbytes <= buf + bufsize - p)
4130 { 4149 {
4150
4151 if (quote_flag)
4152 {
4153 switch (quoting_style)
4154 {
4155 case CURVE_QUOTING_STYLE:
4156 memcpy (p, uLSQM, 3);
4157 p += 3;
4158 break;
4159
4160 case GRAVE_QUOTING_STYLE:
4161 *p++ = '`';
4162 break;
4163
4164 case STRAIGHT_QUOTING_STYLE:
4165 *p++ = '\'';
4166 break;
4167 }
4168 nchars++;
4169 }
4170
4131 if (! minus_flag) 4171 if (! minus_flag)
4132 { 4172 {
4133 memset (p, ' ', padding); 4173 memset (p, ' ', padding);
@@ -4157,6 +4197,22 @@ usage: (format STRING &rest OBJECTS) */)
4157 nchars += padding; 4197 nchars += padding;
4158 } 4198 }
4159 4199
4200 if (quote_flag)
4201 {
4202 switch (quoting_style)
4203 {
4204 case CURVE_QUOTING_STYLE:
4205 memcpy (p, uRSQM, 3);
4206 p += 3;
4207 break;
4208
4209 default:
4210 *p++ = '\'';
4211 break;
4212 }
4213 nchars++;
4214 }
4215
4160 /* If this argument has text properties, record where 4216 /* If this argument has text properties, record where
4161 in the result string it appears. */ 4217 in the result string it appears. */
4162 if (string_intervals (args[n])) 4218 if (string_intervals (args[n]))