Use the new wrap-line' in
scribble/eval'.
This might have output that is a little better in cases where the wrapped string is longer than `maxlen', for example, with an input of: " x xxxxxxxxxxxxxxxx..." and wrapping at 10 characters, the output was " x\nxxxxxxxxxx\nxxxxxx..." and now it's " x xxxx\nxxxxxxxxxx\nxx..." original commit: efda1706d87045cbe2882c9c4b77b34a72e3594b
This commit is contained in:
parent
63427f262e
commit
c3d02f1416
|
@ -6,7 +6,8 @@
|
||||||
racket/pretty ;; attached into new namespace via anchor
|
racket/pretty ;; attached into new namespace via anchor
|
||||||
racket/sandbox racket/promise racket/port
|
racket/sandbox racket/promise racket/port
|
||||||
racket/gui/dynamic
|
racket/gui/dynamic
|
||||||
(for-syntax racket/base))
|
(for-syntax racket/base)
|
||||||
|
scribble/text/wrap)
|
||||||
|
|
||||||
(provide interaction
|
(provide interaction
|
||||||
interaction0
|
interaction0
|
||||||
|
@ -102,19 +103,12 @@
|
||||||
(loop #f (cons v (or (add-string string-accum line-accum) null))
|
(loop #f (cons v (or (add-string string-accum line-accum) null))
|
||||||
flow-accum)]))))
|
flow-accum)]))))
|
||||||
|
|
||||||
;; This is probably good to make into some library function at some
|
|
||||||
;; point (but in that case will need to improve, eg, wrapped lines
|
|
||||||
;; should start at the same indentation level, etc)
|
|
||||||
(define (string->wrapped-lines str)
|
(define (string->wrapped-lines str)
|
||||||
(define (wrap-line str)
|
(wrap-line str maxlen
|
||||||
(if ((string-length str) . <= . maxlen)
|
(λ (word fits)
|
||||||
(if (equal? str "") '() (list str))
|
(if ((string-length word) . > . maxlen)
|
||||||
(let* ([m (cond [(regexp-match-positions #px"^.*\\S(\\s+).*" str 0 maxlen)
|
(values (substring word 0 fits) (substring word fits) #f)
|
||||||
=> cadr]
|
(values #f word #f)))))
|
||||||
[else (cons maxlen maxlen)])]
|
|
||||||
[r (wrap-line (substring str (cdr m)))])
|
|
||||||
(if (= 0 (car m)) r (cons (substring str 0 (car m)) r)))))
|
|
||||||
(append-map wrap-line (regexp-split #px"\\s*\n" str)))
|
|
||||||
|
|
||||||
(define (interleave inset? title expr-paras val-list+outputs)
|
(define (interleave inset? title expr-paras val-list+outputs)
|
||||||
(let ([lines
|
(let ([lines
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
;; element is used for the rest. For example, (cons 72 70) indicates a width
|
;; element is used for the rest. For example, (cons 72 70) indicates a width
|
||||||
;; of 72 characters for the first line, and 70 for the rest.
|
;; of 72 characters for the first line, and 70 for the rest.
|
||||||
;;
|
;;
|
||||||
;; `split-word' controls what happens when a word is split: it is ivoked with
|
;; `split-word' controls what happens when a word is split: it is invoked with
|
||||||
;; the word that is to be split, and an integer indicating how many characters
|
;; the word that is to be split, and an integer indicating how many characters
|
||||||
;; could fit on the first line. In most cases the string will be just a word,
|
;; could fit on the first line. In most cases the string will be just a word,
|
||||||
;; but if it was the first/last word with only spaces before/after it, then the
|
;; but if it was the first/last word with only spaces before/after it, then the
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
;; words; spaces between a word that moves to the next line and the preceding
|
;; words; spaces between a word that moves to the next line and the preceding
|
||||||
;; word are usually dropped, but they can be preserved too if the first result
|
;; word are usually dropped, but they can be preserved too if the first result
|
||||||
;; is "" rather than #f (and same for the space between a word that stays on
|
;; is "" rather than #f (and same for the space between a word that stays on
|
||||||
;; the same line when the following word moves doen). If the first result is
|
;; the same line when the following word moves down). If the first result is
|
||||||
;; `#f' and it was the only word on the line, then the line that would
|
;; `#f' and it was the only word on the line, then the line that would
|
||||||
;; otherwise be empty is dropped. Note that depending on what `split-word'
|
;; otherwise be empty is dropped. Note that depending on what `split-word'
|
||||||
;; chooses to do, the result may still have lines that are longer than `width'
|
;; chooses to do, the result may still have lines that are longer than `width'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user