aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lispref/strings.texi71
1 files changed, 38 insertions, 33 deletions
diff --git a/lispref/strings.texi b/lispref/strings.texi
index e1824518abd..23f679d5bb9 100644
--- a/lispref/strings.texi
+++ b/lispref/strings.texi
@@ -821,18 +821,19 @@ operation} error.
821 821
822@cindex field width 822@cindex field width
823@cindex padding 823@cindex padding
824 All the specification characters allow an optional ``width,'' which 824 A specification can have a @dfn{width}, which is a signed decimal
825is a digit-string between the @samp{%} and the character. If the 825number between the @samp{%} and the specification character. If the
826printed representation of the object contains fewer characters than 826printed representation of the object contains fewer characters than
827this width, then it is padded. The padding is on the left if the 827this width, @code{format} extends it with padding. The padding goes
828width is positive (or starts with zero) and on the right if the 828on the left if the width is positive (or starts with zero) and on the
829width is negative. The padding character is normally a space, but if 829right if the width is negative. The padding character is normally a
830the width starts with a zero, zeros are used for padding. Some of 830space, but it's @samp{0} if the width starts with a zero.
831these conventions are ignored for specification characters for which 831
832they do not make sense. That is, @samp{%s}, @samp{%S} and @samp{%c} 832 Some of these conventions are ignored for specification characters
833accept a width starting with 0, but still pad with @emph{spaces} on 833for which they do not make sense. That is, @samp{%s}, @samp{%S} and
834the left. Also, @samp{%%} accepts a width, but ignores it. Here are 834@samp{%c} accept a width starting with 0, but still pad with
835some examples of padding: 835@emph{spaces} on the left. Also, @samp{%%} accepts a width, but
836ignores it. Here are some examples of padding:
836 837
837@example 838@example
838(format "%06d is padded on the left with zeros" 123) 839(format "%06d is padded on the left with zeros" 123)
@@ -842,15 +843,16 @@ some examples of padding:
842 @result{} "123 is padded on the right" 843 @result{} "123 is padded on the right"
843@end example 844@end example
844 845
846@noindent
845If the width is too small, @code{format} does not truncate the 847If the width is too small, @code{format} does not truncate the
846object's printed representation. Thus, you can use a width to specify 848object's printed representation. Thus, you can use a width to specify
847a minimum spacing between columns with no risk of losing information. 849a minimum spacing between columns with no risk of losing information.
848 850
849 In the following three examples, @samp{%7s} specifies a minimum width 851 In the following three examples, @samp{%7s} specifies a minimum
850of 7. In the first case, the string inserted in place of @samp{%7s} has 852width of 7. In the first case, the string inserted in place of
851only 3 letters, so 4 blank spaces are inserted for padding. In the 853@samp{%7s} has only 3 letters, it needs 4 blank spaces as padding. In
852second case, the string @code{"specification"} is 13 letters wide but is 854the second case, the string @code{"specification"} is 13 letters wide
853not truncated. In the third case, the padding is on the right. 855but is not truncated. In the third case, the padding is on the right.
854 856
855@smallexample 857@smallexample
856@group 858@group
@@ -873,32 +875,35 @@ not truncated. In the third case, the padding is on the right.
873@end smallexample 875@end smallexample
874 876
875@cindex precision in format specifications 877@cindex precision in format specifications
876 All the specification characters allow an optional ``precision'' 878 All the specification characters allow an optional @dfn{precision}
877before the character (after the width, if present). The precision is 879before the character (after the width, if present). The precision is
878a decimal-point @samp{.} followed by a digit-string. For the 880a decimal-point @samp{.} followed by a digit-string. For the
879floating-point specifications (@samp{%e}, @samp{%f}, @samp{%g}), the 881floating-point specifications (@samp{%e}, @samp{%f}, @samp{%g}), the
880precision specifies how many decimal places to show; if zero, the 882precision specifies how many decimal places to show; if zero, the
881decimal-point itself is also omitted. For @samp{%s} and @samp{%S}, 883decimal-point itself is also omitted. For @samp{%s} and @samp{%S},
882the precision truncates the string to the given width, so 884the precision truncates the string to the given width, so @samp{%.3s}
883@samp{%.3s} shows only the first three characters of the 885shows only the first three characters of the representation for
884representation for @var{object}. Precision is ignored for other 886@var{object}. Precision has no effect for other specification
885specification characters. 887characters.
886 888
887@cindex flags in format specifications 889@cindex flags in format specifications
888Immediately after the @samp{%} and before the optional width and 890 Immediately after the @samp{%} and before the optional width and
889precision, you can put certain ``flag'' characters. 891precision, you can put certain ``flag'' characters.
890 892
891A space character inserts a space for positive numbers, a plus character 893 @samp{+} as a flag inserts a plus sign before a positive number, so
892inserts a plus sign (otherwise nothing is inserted for positive 894that it always has a sign. A space character as flag inserts a space
893numbers). These flags are ignored except for @samp{%d}, @samp{%e}, 895before a positive number. (Otherwise, positive numbers start with the
894@samp{%f}, @samp{%g}, and if both flags are present the space is 896first digit.) Either of these two flags ensures that positive numbers
895ignored. 897and negative numbers use the same number of columns. These flags are
896 898ignored except for @samp{%d}, @samp{%e}, @samp{%f}, @samp{%g}, and if
897The flag @samp{#} indicates ``alternate form.'' For @samp{%o} it 899both flags are used, the @samp{+} takes precedence.
898ensures that the result begins with a 0. For @samp{%x} and @samp{%X} 900
899the result is prefixed with @samp{0x} or @samp{0X}. For @samp{%e}, 901 The flag @samp{#} specifies an ``alternate form'' which depends on
900@samp{%f}, and @samp{%g} a decimal point is always shown even if the 902the format in use. For @samp{%o} it ensures that the result begins
901precision is zero. 903with a @samp{0}. For @samp{%x} and @samp{%X}, it prefixes the result
904with @samp{0x} or @samp{0X}. For @samp{%e}, @samp{%f}, and @samp{%g},
905the @samp{#} flag means include a decimal point even if the precision
906is zero.
902 907
903@node Case Conversion 908@node Case Conversion
904@comment node-name, next, previous, up 909@comment node-name, next, previous, up