|
7 | 7 | images/compile-time |
8 | 8 | string-constants |
9 | 9 | pict |
| 10 | + simple-tree-text-markup/data |
10 | 11 | (for-syntax images/icons/control images/icons/style)) |
11 | 12 |
|
12 | 13 | (provide |
|
137 | 138 | (define stepper-sub-text% |
138 | 139 | (class f:text:standard-style-list% |
139 | 140 |
|
140 | | - (init-field exps highlight-color show-inexactness? print-boolean-long-form?) |
| 141 | + (init-field exps highlight-color |
| 142 | + language-pretty-print-size-hook |
| 143 | + language-pretty-print-print-hook |
| 144 | + show-inexactness? print-boolean-long-form?) |
141 | 145 |
|
142 | 146 | (inherit insert get-style-list set-style-list change-style highlight-range last-position lock erase |
143 | 147 | begin-edit-sequence end-edit-sequence get-start-position select-all clear) |
|
178 | 182 | (inherit get-dc) |
179 | 183 |
|
180 | 184 | (define/private (format-sexp sexp) |
181 | | - (define text-port (open-output-text-editor this)) |
182 | | - |
| 185 | + (define text-port |
| 186 | + (open-output-text-editor this 'end |
| 187 | + ; need to handle number-markup |
| 188 | + (lambda (x) |
| 189 | + (if (number-markup? x) |
| 190 | + (f:number-snip:number->string/snip (number-markup-number x) |
| 191 | + #:exact-prefix (number-markup-exact-prefix x) |
| 192 | + #:inexact-prefix (number-markup-inexact-prefix x) |
| 193 | + #:fraction-view (number-markup-fraction-view x)) |
| 194 | + x)))) |
| 195 | + |
183 | 196 | (parameterize |
184 | 197 | ([pretty-print-show-inexactness show-inexactness?] |
185 | 198 | [pretty-print-columns pretty-printed-width] |
|
202 | 215 | (let-values ([(xw dc dc2 dc3) (send dc get-text-extent "x")]) |
203 | 216 | (max 1 (inexact->exact (ceiling (/ (unbox wbox) xw))))))] |
204 | 217 | [(and looked-up (not (eq? looked-up 'non-confusable))) |
205 | | - (string-length (format "~s" (car looked-up)))] |
206 | | - [else #f])))] |
| 218 | + (or |
| 219 | + ; note that this may return #f, but we still want the print-hook to handle it |
| 220 | + (language-pretty-print-size-hook (car looked-up) display? port) |
| 221 | + (string-length (format "~s" (car looked-up))))] |
| 222 | + [else |
| 223 | + (language-pretty-print-size-hook value display? port)])))] |
207 | 224 |
|
208 | 225 | [pretty-print-print-hook |
209 | 226 | ; this print-hook is called for confusable highlights and for images. |
210 | 227 | (lambda (value display? port) |
211 | | - (let ([to-display (cond |
212 | | - [(hash-ref highlight-table value (lambda () #f)) => car] |
213 | | - [else value])]) |
| 228 | + (let ([looked-up (hash-ref highlight-table value (lambda () #f))]) |
214 | 229 | (cond |
215 | | - [(is-a? to-display snip%) |
216 | | - (write-special (send to-display copy) port) (set-last-style)] |
| 230 | + [(is-a? value snip%) |
| 231 | + (write-special (send value copy) port) (set-last-style)] |
| 232 | + [(and looked-up (not (eq? looked-up 'non-confusable))) |
| 233 | + ; we have to call the size hook *again* to find |
| 234 | + ; out if the underlying pretty-print-print-hook |
| 235 | + ; can handle this |
| 236 | + (define to-display (car looked-up)) |
| 237 | + (if (language-pretty-print-size-hook to-display display? port) |
| 238 | + (language-pretty-print-print-hook to-display display? port) |
| 239 | + (write-string (format "~s" to-display) port))] |
217 | 240 | [else |
218 | | - ;; there's already code somewhere else to handle this; this seems like a bit of a hack. |
219 | | - (when (and (number? to-display) (inexact? to-display) (pretty-print-show-inexactness)) |
220 | | - (write-string "#i" port)) |
221 | | - (write-string (format "~s" to-display) port)])))] |
| 241 | + (language-pretty-print-print-hook value display? port)])))] |
| 242 | + |
222 | 243 | [pretty-print-print-line |
223 | 244 | (lambda (number port old-length dest-columns) |
224 | 245 | (when (and number (not (eq? number 0))) |
|
254 | 275 | (select-all) |
255 | 276 | (clear) |
256 | 277 | (reset-style) |
| 278 | + (define start (get-start-position)) |
257 | 279 | (for ([exp stripped-exps] [i (in-naturals)]) |
258 | 280 | (unless (= i 0) |
259 | 281 | (insert #\newline)) |
260 | 282 | (format-sexp exp)) |
| 283 | + (define end (get-start-position)) |
| 284 | + (change-style (send (get-style-list) find-named-style "Standard") |
| 285 | + start end) |
261 | 286 | (end-edit-sequence) |
262 | 287 | (lock #t)) |
263 | 288 |
|
|
348 | 373 | (define stepper-text% |
349 | 374 | (class f:text:standard-style-list% |
350 | 375 |
|
351 | | - (init-field left-side right-side show-inexactness? print-boolean-long-form?) |
| 376 | + (init-field left-side right-side show-inexactness? print-boolean-long-form? |
| 377 | + language-pretty-print-size-hook language-pretty-print-print-hook) |
352 | 378 |
|
353 | 379 | (inherit find-snip insert change-style highlight-range last-position lock erase auto-wrap |
354 | 380 | begin-edit-sequence end-edit-sequence get-start-position get-style-list set-style-list |
|
415 | 441 | (make-object stepper-sub-error-text% error-or-exps)] |
416 | 442 | [else |
417 | 443 | (make-object stepper-sub-text% |
418 | | - error-or-exps highlight-color show-inexactness? |
419 | | - print-boolean-long-form?)]))) |
| 444 | + error-or-exps highlight-color |
| 445 | + language-pretty-print-size-hook |
| 446 | + language-pretty-print-print-hook |
| 447 | + show-inexactness? |
| 448 | + print-boolean-long-form?)]))) |
420 | 449 |
|
421 | 450 | (setup-editor-snip before-snip left-side 'stepper:redex-highlight-color) |
422 | 451 | (setup-editor-snip after-snip right-side 'stepper:reduct-highlight-color) |
|
0 commit comments