aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Yavner2004-01-24 17:39:47 +0000
committerJonathan Yavner2004-01-24 17:39:47 +0000
commit728345f8b15055d2d9b8273b87f674399f8c41e5 (patch)
tree2b02fe222fe82efbffe82232a92a3b24cb89a728
parent2528f9c4a681cabd8038411807ddd2128d5e3dbb (diff)
downloademacs-728345f8b15055d2d9b8273b87f674399f8c41e5.tar.gz
emacs-728345f8b15055d2d9b8273b87f674399f8c41e5.zip
For `format', make source and documentation match.
-rw-r--r--lispref/strings.texi52
-rw-r--r--src/editfns.c39
2 files changed, 55 insertions, 36 deletions
diff --git a/lispref/strings.texi b/lispref/strings.texi
index 7cc182cc058..60a74313a85 100644
--- a/lispref/strings.texi
+++ b/lispref/strings.texi
@@ -798,19 +798,18 @@ operation} error.
798@cindex numeric prefix 798@cindex numeric prefix
799@cindex field width 799@cindex field width
800@cindex padding 800@cindex padding
801 All the specification characters allow an optional numeric prefix 801 All the specification characters allow an optional ``width'', which
802between the @samp{%} and the character. The optional numeric prefix 802is a digit-string between the @samp{%} and the character. If the
803defines the minimum width for the object. If the printed 803printed representation of the object contains fewer characters than
804representation of the object contains fewer characters than this, then 804this width, then it is padded. The padding is on the left if the
805it is padded. The padding is on the left if the prefix is positive 805prefix is positive (or starts with zero) and on the right if the
806(or starts with zero) and on the right if the prefix is negative. The 806prefix is negative. The padding character is normally a space, but if
807padding character is normally a space, but if the numeric prefix 807the width starts with a zero, zeros are used for padding. Some of
808starts with a zero, zeros are used for padding. Some of these 808these conventions are ignored for specification characters for which
809conventions are ignored for specification characters for which they do 809they do not make sense. That is, %s, %S and %c accept a width
810not make sense. That is, %s, %S and %c accept a numeric prefix
811starting with 0, but still pad with @emph{spaces} on the left. Also, 810starting with 0, but still pad with @emph{spaces} on the left. Also,
812%% accepts a numeric prefix, but ignores it. Here are some examples 811%% accepts a width, but ignores it. Here are some examples of
813of padding: 812padding:
814 813
815@example 814@example
816(format "%06d is padded on the left with zeros" 123) 815(format "%06d is padded on the left with zeros" 123)
@@ -820,10 +819,9 @@ of padding:
820 @result{} "123 is padded on the right" 819 @result{} "123 is padded on the right"
821@end example 820@end example
822 821
823 @code{format} never truncates an object's printed representation, no 822If the width is too small, @code{format} does not truncate the
824matter what width you specify. Thus, you can use a numeric prefix to 823object's printed representation. Thus, you can use a width to specify
825specify a minimum spacing between columns with no risk of losing 824a minimum spacing between columns with no risk of losing information.
826information.
827 825
828 In the following three examples, @samp{%7s} specifies a minimum width 826 In the following three examples, @samp{%7s} specifies a minimum width
829of 7. In the first case, the string inserted in place of @samp{%7s} has 827of 7. In the first case, the string inserted in place of @samp{%7s} has
@@ -851,6 +849,28 @@ not truncated. In the third case, the padding is on the right.
851@end group 849@end group
852@end smallexample 850@end smallexample
853 851
852 All the specification characters allow an optional ``precision''
853before the character (after the width, if present). The precision is
854a decimal-point @samp{.} followed by a digit-string. For the
855floating-point specifications (%e, %f, %g), the precision specifies
856how many decimal places to show; if zero, the decimal-point itself is
857also omitted. For %s and %S, the precision truncates the string to
858the given width, so @code{"%.3s"} shows only the first three
859characters of the representation for @var{object}. Precision is
860ignored for other specification characters.
861
862Immediately after the % and before the optional width and precision,
863you can put certain ``flag'' characters.
864
865A space @var{" "} inserts a space for positive numbers (otherwise
866nothing is inserted for positive numbers). This flag is ignored
867except for %d, %e, %f, %g.
868
869The flag @var{"#"} indicates ``alternate form''. For %o it ensures
870that the result begins with a 0. For %x and %X the result is prefixed
871with ``0x'' or ``0X''. For %e, %f, and %g a decimal point is always
872shown even if the precision is zero.
873
854@node Case Conversion 874@node Case Conversion
855@comment node-name, next, previous, up 875@comment node-name, next, previous, up
856@section Case Conversion in Lisp 876@section Case Conversion in Lisp
diff --git a/src/editfns.c b/src/editfns.c
index a636c35a464..d3039ca0273 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3193,6 +3193,10 @@ It may contain %-sequences meaning to substitute the next argument.
3193 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number. 3193 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.
3194Use %% to put a single % into the output. 3194Use %% to put a single % into the output.
3195 3195
3196The basic structure of a %-sequence is
3197 % <flags> <width> <precision> character
3198where flags is [- #0]+, width is [0-9]+, and precision is .[0-9]+
3199
3196usage: (format STRING &rest OBJECTS) */) 3200usage: (format STRING &rest OBJECTS) */)
3197 (nargs, args) 3201 (nargs, args)
3198 int nargs; 3202 int nargs;
@@ -3300,7 +3304,7 @@ usage: (format STRING &rest OBJECTS) */)
3300 3304
3301 where 3305 where
3302 3306
3303 flags ::= [#-* 0]+ 3307 flags ::= [- #0]+
3304 field-width ::= [0-9]+ 3308 field-width ::= [0-9]+
3305 precision ::= '.' [0-9]* 3309 precision ::= '.' [0-9]*
3306 3310
@@ -3312,14 +3316,7 @@ usage: (format STRING &rest OBJECTS) */)
3312 digits to print after the '.' for floats, or the max. 3316 digits to print after the '.' for floats, or the max.
3313 number of chars to print from a string. */ 3317 number of chars to print from a string. */
3314 3318
3315 /* NOTE the handling of specifiers here differs in some ways 3319 while (index ("-0# ", *format))
3316 from the libc model. There are bugs in this code that lead
3317 to incorrect formatting when flags recognized by C but
3318 neither parsed nor rejected here are used. Further
3319 revisions will be made soon. */
3320
3321 /* incorrect list of flags to skip; will be fixed */
3322 while (index ("-*# 0", *format))
3323 ++format; 3320 ++format;
3324 3321
3325 if (*format >= '0' && *format <= '9') 3322 if (*format >= '0' && *format <= '9')
@@ -3403,7 +3400,7 @@ usage: (format STRING &rest OBJECTS) */)
3403 if (*format == 'c') 3400 if (*format == 'c')
3404 { 3401 {
3405 if (! SINGLE_BYTE_CHAR_P (XINT (args[n])) 3402 if (! SINGLE_BYTE_CHAR_P (XINT (args[n]))
3406 /* Note: No one can remeber why we have to treat 3403 /* Note: No one can remember why we have to treat
3407 the character 0 as a multibyte character here. 3404 the character 0 as a multibyte character here.
3408 But, until it causes a real problem, let's 3405 But, until it causes a real problem, let's
3409 don't change it. */ 3406 don't change it. */
@@ -3494,17 +3491,19 @@ usage: (format STRING &rest OBJECTS) */)
3494 discarded[format - format_start] = 1; 3491 discarded[format - format_start] = 1;
3495 format++; 3492 format++;
3496 3493
3497 /* Process a numeric arg and skip it. */ 3494 while (index("-0# ", *format))
3498 /* NOTE atoi is the wrong thing to use here; will be fixed */ 3495 {
3496 if (*format == '-')
3497 {
3498 negative = 1;
3499 }
3500 discarded[format - format_start] = 1;
3501 ++format;
3502 }
3503
3499 minlen = atoi (format); 3504 minlen = atoi (format);
3500 if (minlen < 0) 3505
3501 minlen = - minlen, negative = 1; 3506 while ((*format >= '0' && *format <= '9') || *format == '.')
3502
3503 /* NOTE the parsing here is not consistent with the first
3504 pass, and neither attempt is what we want to do. Will be
3505 fixed. */
3506 while ((*format >= '0' && *format <= '9')
3507 || *format == '-' || *format == ' ' || *format == '.')
3508 { 3507 {
3509 discarded[format - format_start] = 1; 3508 discarded[format - format_start] = 1;
3510 format++; 3509 format++;