add #:name argument to {transplant,relocate}-{input,output}-port
This commit is contained in:
parent
9bd70260b7
commit
cd2898675f
|
@ -478,11 +478,12 @@ the result port does not affect writing directly to @racket[out].}
|
||||||
[line (or/c exact-positive-integer? #f)]
|
[line (or/c exact-positive-integer? #f)]
|
||||||
[column (or/c exact-nonnegative-integer? #f)]
|
[column (or/c exact-nonnegative-integer? #f)]
|
||||||
[position exact-positive-integer?]
|
[position exact-positive-integer?]
|
||||||
[close? any/c #t])
|
[close? any/c #t]
|
||||||
|
[#:name name (object-name out)])
|
||||||
input-port?]{
|
input-port?]{
|
||||||
|
|
||||||
Produces an input port that is equivalent to @racket[in] except in how
|
Produces an input port that is equivalent to @racket[in] except in how
|
||||||
it reports location information. The resulting port's content starts
|
it reports location information (and possibly its name). The resulting port's content starts
|
||||||
with the remaining content of @racket[in], and it starts at the given
|
with the remaining content of @racket[in], and it starts at the given
|
||||||
line, column, and position. A @racket[#f] for the line or column means
|
line, column, and position. A @racket[#f] for the line or column means
|
||||||
that the line and column will always be reported as @racket[#f].
|
that the line and column will always be reported as @racket[#f].
|
||||||
|
@ -501,14 +502,19 @@ not increment when data is read from @racket[in].
|
||||||
|
|
||||||
If @racket[close?] is true, then closing the resulting port also
|
If @racket[close?] is true, then closing the resulting port also
|
||||||
closes @racket[in]. If @racket[close?] is @racket[#f], then closing
|
closes @racket[in]. If @racket[close?] is @racket[#f], then closing
|
||||||
the resulting port does not close @racket[in].}
|
the resulting port does not close @racket[in].
|
||||||
|
|
||||||
|
The @racket[name] argument is used as the name for the resulting port;
|
||||||
|
the default value keeps the same name as @racket[in].
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@defproc[(relocate-output-port [out output-port?]
|
@defproc[(relocate-output-port [out output-port?]
|
||||||
[line (or/c exact-positive-integer? #f)]
|
[line (or/c exact-positive-integer? #f)]
|
||||||
[column (or/c exact-nonnegative-integer? #f)]
|
[column (or/c exact-nonnegative-integer? #f)]
|
||||||
[position exact-positive-integer?]
|
[position exact-positive-integer?]
|
||||||
[close? any/c #t])
|
[close? any/c #t]
|
||||||
|
[#:name name (object-name out)])
|
||||||
output-port?]{
|
output-port?]{
|
||||||
|
|
||||||
Like @racket[relocate-input-port], but for output ports.}
|
Like @racket[relocate-input-port], but for output ports.}
|
||||||
|
@ -524,7 +530,8 @@ Like @racket[relocate-input-port], but for output ports.}
|
||||||
#f)]
|
#f)]
|
||||||
[init-pos exact-positive-integer?]
|
[init-pos exact-positive-integer?]
|
||||||
[close? any/c #t]
|
[close? any/c #t]
|
||||||
[count-lines! (-> any) void])
|
[count-lines! (-> any) void]
|
||||||
|
[#:name name (object-name out)])
|
||||||
input-port?]{
|
input-port?]{
|
||||||
|
|
||||||
Like @racket[relocate-input-port], except that arbitrary position
|
Like @racket[relocate-input-port], except that arbitrary position
|
||||||
|
@ -547,7 +554,8 @@ is enabled for the resulting port. The default is @racket[void].}
|
||||||
#f)]
|
#f)]
|
||||||
[init-pos exact-positive-integer?]
|
[init-pos exact-positive-integer?]
|
||||||
[close? any/c #t]
|
[close? any/c #t]
|
||||||
[count-lines! (-> any) void])
|
[count-lines! (-> any) void]
|
||||||
|
[#:name name (object-name out)])
|
||||||
output-port?]{
|
output-port?]{
|
||||||
|
|
||||||
Like @racket[transplant-input-port], but for output ports.}
|
Like @racket[transplant-input-port], but for output ports.}
|
||||||
|
|
|
@ -607,13 +607,14 @@
|
||||||
(eq? buffer-mode 'block)))
|
(eq? buffer-mode 'block)))
|
||||||
|
|
||||||
(define relocate-input-port
|
(define relocate-input-port
|
||||||
(lambda (p line col pos [close? #t])
|
(lambda (p line col pos [close? #t] #:name [name (object-name p)])
|
||||||
(transplant-to-relocate transplant-input-port p line col pos close?)))
|
(transplant-to-relocate transplant-input-port p line col pos close? name)))
|
||||||
|
|
||||||
(define transplant-input-port
|
(define transplant-input-port
|
||||||
(lambda (p location-proc pos [close? #t] [count-lines!-proc void])
|
(lambda (p location-proc pos [close? #t] [count-lines!-proc void]
|
||||||
|
#:name [name (object-name p)])
|
||||||
(make-input-port
|
(make-input-port
|
||||||
(object-name p)
|
name
|
||||||
p ;; redirect `read' to `p'
|
p ;; redirect `read' to `p'
|
||||||
;; Here's the long way to redirect:
|
;; Here's the long way to redirect:
|
||||||
#;
|
#;
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
(lambda (special)
|
(lambda (special)
|
||||||
(wrap-evt always-evt (lambda (x) #t)))))))
|
(wrap-evt always-evt (lambda (x) #t)))))))
|
||||||
|
|
||||||
(define (transplant-to-relocate transplant p line col pos close?)
|
(define (transplant-to-relocate transplant p line col pos close? name)
|
||||||
(let-values ([(init-l init-c init-p) (port-next-location p)])
|
(let-values ([(init-l init-c init-p) (port-next-location p)])
|
||||||
(transplant
|
(transplant
|
||||||
p
|
p
|
||||||
|
@ -42,18 +42,19 @@
|
||||||
c))
|
c))
|
||||||
(and p init-p (+ p (- init-p) pos)))))
|
(and p init-p (+ p (- init-p) pos)))))
|
||||||
pos
|
pos
|
||||||
close?)))
|
close?
|
||||||
|
#:name name)))
|
||||||
|
|
||||||
(define relocate-output-port
|
(define relocate-output-port
|
||||||
(lambda (p line col pos [close? #t])
|
(lambda (p line col pos [close? #t] #:name [name (object-name p)])
|
||||||
(transplant-to-relocate
|
(transplant-to-relocate
|
||||||
transplant-output-port
|
transplant-output-port
|
||||||
p line col pos close?)))
|
p line col pos close? name)))
|
||||||
|
|
||||||
(define transplant-output-port
|
(define transplant-output-port
|
||||||
(lambda (p location-proc pos [close? #t] [count-lines!-proc void])
|
(lambda (p location-proc pos [close? #t] [count-lines!-proc void] #:name [name (object-name p)])
|
||||||
(make-output-port
|
(make-output-port
|
||||||
(object-name p)
|
name
|
||||||
p
|
p
|
||||||
p ; `write' just redirects to `p'
|
p ; `write' just redirects to `p'
|
||||||
;; Here's the slow way to redirect:
|
;; Here's the slow way to redirect:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user