Skip to content

Commit

Permalink
Support get(io, :compact, false) and get(io, :multiline, false)
Browse files Browse the repository at this point in the history
These are the two other IOContext proporties at the moment.
limit_output() was used to mean both limit=true and compact=true.
  • Loading branch information
nalimilan committed Jun 11, 2016
1 parent 8021737 commit f2b2b68
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Currently, the `@compat` macro supports the following syntaxes:

* `@compat Dict{Foo,Bar}(foo => bar, baz => qux)` - type-declared `Dict` construction. (Also works for `DataStructures.OrderedDict`)

* `@compat(get(io, :limit, false))` to detect whether compressed output has been requested (performs useful work only on `v"0.5.0-dev+1936"`, defaults to `false` otherwise)
* `@compat(get(io, s, false))`, with `s` equal to `:limit`, `:compact` or `:multiline`, to detect the corresponding print settings (performs useful work only on Julia 0.5, defaults to `false` otherwise)

* `@compat split(str, splitter; keywords...)` - the Julia 0.4-style keyword-based `split` function

Expand Down
12 changes: 11 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ function rewrite_iocontext!(expr::Expr)
if expr.head == :call && expr.args[1] == :get
key = expr.args[3]
if (((isa(key, QuoteNode) && key.value == :limit) ||
(isa(key, Expr) && key.head == :quote && key.args[1] == :limit))
(isa(key, Expr) && key.head == :quote && key.args[1] == :limit) ||
((isa(key, QuoteNode) && key.value == :compact) ||
(isa(key, Expr) && key.head == :quote && key.args[1] == :compact)))
&& expr.args[4] == false)
if VERSION >= v"0.5.0-dev+1936" && VERSION < v"0.5.0-dev+4305"
expr.args[1] = :(Base.limit_output)
Expand All @@ -276,6 +278,14 @@ function rewrite_iocontext!(expr::Expr)
expr.args[1] = false
deleteat!(expr.args, 3:4)
end
elseif (((isa(key, QuoteNode) && key.value == :multiline) ||
(isa(key, Expr) && key.head == :quote && key.args[1] == :multiline))
&& expr.args[4] == true)
if VERSION < v"0.5.0-dev+4305"
expr.head = :quote
expr.args[1] = true
deleteat!(expr.args, 3:4)
end
end
end
expr
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1188,3 +1188,5 @@ end

io = IOBuffer()
@test @compat(get(io, :limit, false)) == false
@test @compat(get(io, :compact, false)) == false
@test @compat(get(io, :multiline, false)) == false

0 comments on commit f2b2b68

Please sign in to comment.