From 4a52d3c57c677b6dd1f831519428ee57611f9cc1 Mon Sep 17 00:00:00 2001
From: Matthew Flatt <mflatt@racket-lang.org>
Date: Sat, 21 Feb 2015 14:12:38 -0700
Subject: [PATCH] racketblock: add "#i" to an inexact number to match source
 span

This heuristic could go slightly wrong, for example causing "10.000"
to render as "#i10.0" instead of "10.0", but it won't affect cases
where the output already matched the input.
---
 scribble-doc/scribblings/scribble/manual.scrbl | 8 ++++++--
 scribble-lib/scribble/racket.rkt               | 9 +++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/scribble-doc/scribblings/scribble/manual.scrbl b/scribble-doc/scribblings/scribble/manual.scrbl
index baf440ad..ca9be304 100644
--- a/scribble-doc/scribblings/scribble/manual.scrbl
+++ b/scribble-doc/scribblings/scribble/manual.scrbl
@@ -206,7 +206,10 @@ produces the output
 with the @racket[(loop (not x))] indented under @racket[define],
 because that's the way it is idented the use of @racket[racketblock].
 Source-location span information is used to preserve @racket[#true]
-versus @racket[#t] and @racket[#false] versus @racket[#f], and
+versus @racket[#t] and @racket[#false] versus @racket[#f]; span
+information is also used heuristically to add @racketvalfont{#i}
+to the start of an inexact number if its printed form would otherwise
+be two characters shorter than the source;
 syntax-object properties are used to preserve square brackets and
 curly braces versus parentheses; otherwise, using syntax objects tends
 to normalize the form of S-expression elements, such as rendering
@@ -299,7 +302,8 @@ A few other escapes are recognized symbolically:
 ]
 
 See also @racketmodname[scribble/comment-reader].
-}
+
+@history[#:changed "1.9" @elem{Added heuristic for adding @racketvalfont{#i} to inexact numbers.}]}
 
 @defform[(RACKETBLOCK maybe-escape datum ...)]{Like @racket[racketblock], but with
 the default expression escape @racket[UNSYNTAX] instead of @racket[unsyntax].}
diff --git a/scribble-lib/scribble/racket.rkt b/scribble-lib/scribble/racket.rkt
index 55116480..55351b85 100644
--- a/scribble-lib/scribble/racket.rkt
+++ b/scribble-lib/scribble/racket.rkt
@@ -248,6 +248,15 @@
                                      (if (equal? (syntax-span c) 6)
                                          "#false"
                                          "#f")]
+                                    [(and (number? sc)
+                                          (inexact? sc))
+                                     (define s (iformat "~s" sc))
+                                     (if (= (string-length s)
+                                            (- (syntax-span c) 2))
+                                         ;; There's no way to know whether the source used #i,
+                                         ;; but it should be ok to include it:
+                                         (string-append "#i" s)
+                                         s)]
                                     [else (iformat "~s" sc)])])
                            (if (and escapes?
                                     (symbol? sc)