Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move InteractiveUtils to stdlib #25780

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ function process_options(opts::JLOptions)
# load ~/.juliarc file
startup && load_juliarc()

if repl || is_interactive
# load interactive-only libraries
eval(Main, :(using InteractiveUtils))
end

# process cmds list
for (cmd, arg) in cmds
if cmd == 'e'
Expand Down
113 changes: 113 additions & 0 deletions base/clipboard.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# clipboard copy and paste

if Sys.isapple()
function clipboard(x)
open(pipeline(`pbcopy`, stderr=STDERR), "w") do io
print(io, x)
end
end
clipboard() = read(`pbpaste`, String)

elseif Sys.islinux() || Sys.KERNEL === :FreeBSD
_clipboardcmd = nothing
const _clipboardcmds = Dict(
:copy => Dict(
:xsel => Sys.islinux() ?
`xsel --nodetach --input --clipboard` : `xsel -c`,
:xclip => `xclip -silent -in -selection clipboard`,
),
:paste => Dict(
:xsel => Sys.islinux() ?
`xsel --nodetach --output --clipboard` : `xsel -p`,
:xclip => `xclip -quiet -out -selection clipboard`,
)
)
function clipboardcmd()
global _clipboardcmd
_clipboardcmd !== nothing && return _clipboardcmd
for cmd in (:xclip, :xsel)
success(pipeline(`which $cmd`, DevNull)) && return _clipboardcmd = cmd
end
pkgs = @static if Sys.islinux()
"xsel or xclip"
elseif Sys.KERNEL === :FreeBSD
"x11/xsel or x11/xclip"
end
error("no clipboard command found, please install $pkgs")
end
function clipboard(x)
c = clipboardcmd()
cmd = get(_clipboardcmds[:copy], c, nothing)
if cmd === nothing
error("unexpected clipboard command: $c")
end
open(pipeline(cmd, stderr=STDERR), "w") do io
print(io, x)
end
end
function clipboard()
c = clipboardcmd()
cmd = get(_clipboardcmds[:paste], c, nothing)
if cmd === nothing
error("unexpected clipboard command: $c")
end
read(pipeline(cmd, stderr=STDERR), String)
end

elseif Sys.iswindows()
# TODO: these functions leak memory and memory locks if they throw an error
function clipboard(x::AbstractString)
if containsnul(x)
throw(ArgumentError("Windows clipboard strings cannot contain NUL character"))
end
systemerror(:OpenClipboard, 0==ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Cvoid},), C_NULL))
systemerror(:EmptyClipboard, 0==ccall((:EmptyClipboard, "user32"), stdcall, Cint, ()))
x_u16 = cwstring(x)
# copy data to locked, allocated space
p = ccall((:GlobalAlloc, "kernel32"), stdcall, Ptr{UInt16}, (UInt16, Int32), 2, sizeof(x_u16))
systemerror(:GlobalAlloc, p==C_NULL)
plock = ccall((:GlobalLock, "kernel32"), stdcall, Ptr{UInt16}, (Ptr{UInt16},), p)
systemerror(:GlobalLock, plock==C_NULL)
ccall(:memcpy, Ptr{UInt16}, (Ptr{UInt16},Ptr{UInt16},Int), plock, x_u16, sizeof(x_u16))
systemerror(:GlobalUnlock, 0==ccall((:GlobalUnlock, "kernel32"), stdcall, Cint, (Ptr{Cvoid},), plock))
pdata = ccall((:SetClipboardData, "user32"), stdcall, Ptr{UInt16}, (UInt32, Ptr{UInt16}), 13, p)
systemerror(:SetClipboardData, pdata!=p)
ccall((:CloseClipboard, "user32"), stdcall, Cvoid, ())
end
clipboard(x) = clipboard(sprint(print, x)::String)
function clipboard()
systemerror(:OpenClipboard, 0==ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Cvoid},), C_NULL))
pdata = ccall((:GetClipboardData, "user32"), stdcall, Ptr{UInt16}, (UInt32,), 13)
systemerror(:SetClipboardData, pdata==C_NULL)
systemerror(:CloseClipboard, 0==ccall((:CloseClipboard, "user32"), stdcall, Cint, ()))
plock = ccall((:GlobalLock, "kernel32"), stdcall, Ptr{UInt16}, (Ptr{UInt16},), pdata)
systemerror(:GlobalLock, plock==C_NULL)
# find NUL terminator (0x0000 16-bit code unit)
len = 0
while unsafe_load(plock, len+1) != 0; len += 1; end
# get Vector{UInt16}, transcode data to UTF-8, make a String of it
s = transcode(String, unsafe_wrap(Array, plock, len))
systemerror(:GlobalUnlock, 0==ccall((:GlobalUnlock, "kernel32"), stdcall, Cint, (Ptr{UInt16},), plock))
return s
end

else
clipboard(x="") = error("`clipboard` function not implemented for $(Sys.KERNEL)")
end


"""
clipboard(x)
Send a printed form of `x` to the operating system clipboard ("copy").
"""
clipboard(x)

"""
clipboard() -> AbstractString
Return a string with the contents of the operating system clipboard ("paste").
"""
clipboard()
17 changes: 2 additions & 15 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ next(p::Union{Process, ProcessChain}, i::Int) = (getindex(p, i), i + 1)
return i == 1 ? getfield(p, p.openstream) : p
end

# PR #21974
@deprecate versioninfo(verbose::Bool) versioninfo(verbose=verbose)
@deprecate versioninfo(io::IO, verbose::Bool) versioninfo(io, verbose=verbose)

# also remove all support machinery in src for current_module when removing this deprecation
# and make Base.include an error
_current_module() = ccall(:jl_get_current_module, Ref{Module}, ())
Expand Down Expand Up @@ -744,14 +740,6 @@ Broadcast.dotview(A::AbstractArray{<:AbstractArray}, args::Integer...) = getinde
nothing
end

@deprecate whos(io::IO, m::Module, pat::Regex) show(io, varinfo(m, pat))
@deprecate whos(io::IO, m::Module) show(io, varinfo(m))
@deprecate whos(io::IO) show(io, varinfo())
@deprecate whos(m::Module, pat::Regex) varinfo(m, pat)
@deprecate whos(m::Module) varinfo(m)
@deprecate whos(pat::Regex) varinfo(pat)
@deprecate whos() varinfo()

# indexing with A[true] will throw an argument error in the future
function to_index(i::Bool)
depwarn("indexing with Bool values is deprecated. Convert the index to an integer first with `Int(i)`.", (:getindex, :setindex!, :view))
Expand Down Expand Up @@ -1382,7 +1370,6 @@ export readandwrite
@deprecate indmax argmax

@deprecate runtests(tests, ncores; kw...) runtests(tests; ncores = ncores, kw...) false
@deprecate methodswith(typ, supertypes) methodswith(typ, supertypes = supertypes)
@deprecate code_lowered(f, types, generated) code_lowered(f, types, generated = generated)

# PR 25458
Expand All @@ -1402,8 +1389,6 @@ end
@deprecate Timer(callback, delay, repeat) Time(callback, delay, interval = repeat)
@deprecate names(m, all) names(m, all = all)
@deprecate names(m, all, imported) names(m, all = all, imported = imported)
@deprecate code_native(io, f, types, syntax) code_native(io, f, types, syntax = syntax)
@deprecate code_native(f, types, syntax) code_native(f, types, syntax = syntax)
@deprecate eachmatch(re, str, overlap) eachmatch(re, str, overlap = overlap)
@deprecate matchall(re, str, overlap) matchall(re, str, overlap = overlap)
@deprecate chop(s, head) chop(s, head = head)
Expand All @@ -1418,6 +1403,8 @@ end

@deprecate print_with_color(color, args...; kwargs...) printstyled(args...; kwargs..., color=color)

@deprecate which(s::Symbol) which(Main, s)

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
2 changes: 1 addition & 1 deletion base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import Base.Meta: quot, isexpr
import Base: Callable, with_output_color
import ..CoreDocs: lazy_iterpolate

export doc, apropos
export doc

# Basic API / Storage

Expand Down
59 changes: 59 additions & 0 deletions base/download.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# file downloading

downloadcmd = nothing
if Sys.iswindows()
downloadcmd = :powershell
function download(url::AbstractString, filename::AbstractString)
ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
client = "New-Object System.Net.Webclient"
# in the following we escape ' with '' (see https://ss64.com/ps/syntax-esc.html)
downloadfile = "($client).DownloadFile('$(replace(url, "'" => "''"))', '$(replace(filename, "'" => "''"))')"
run(`$ps -NoProfile -Command "$tls12; $downloadfile"`)
filename
end
else
function download(url::AbstractString, filename::AbstractString)
global downloadcmd
if downloadcmd === nothing
for checkcmd in (:curl, :wget, :fetch)
if success(pipeline(`which $checkcmd`, DevNull))
downloadcmd = checkcmd
break
end
end
end
if downloadcmd == :wget
try
run(`wget -O $filename $url`)
catch
rm(filename) # wget always creates a file
rethrow()
end
elseif downloadcmd == :curl
run(`curl -g -L -f -o $filename $url`)
elseif downloadcmd == :fetch
run(`fetch -f $filename $url`)
else
error("no download agent available; install curl, wget, or fetch")
end
filename
end
end
function download(url::AbstractString)
filename = tempname()
download(url, filename)
end

"""
download(url::AbstractString, [localfile::AbstractString])
Download a file from the given url, optionally renaming it to the given local file name.
Note that this function relies on the availability of external tools such as `curl`, `wget`
or `fetch` to download the file and is provided for convenience. For production use or
situations in which more options are needed, please use a package that provides the desired
functionality instead.
"""
download(url, filename)
2 changes: 2 additions & 0 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ function showerror(io::IO, ex::InexactError)
print(io, "InexactError: ", ex.func, '(', ex.T, ", ", ex.val, ')')
end

typesof(args...) = Tuple{Any[ Core.Typeof(a) for a in args ]...}

function showerror(io::IO, ex::MethodError)
# ex.args is a tuple type if it was thrown from `invoke` and is
# a tuple of the arguments otherwise.
Expand Down
21 changes: 0 additions & 21 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ export
promote,
promote_rule,
promote_type,
subtypes,
instances,
supertype,
typeintersect,
Expand All @@ -777,26 +776,17 @@ export
parse,

# help and reflection
apropos,
edit,
code_typed,
code_warntype,
code_lowered,
code_llvm,
code_native,
fullname,
functionloc,
isconst,
isinteractive,
less,
hasmethod,
methods,
methodswith,
nameof,
parentmodule,
names,
varinfo,
versioninfo,
which,
@isdefined,

Expand Down Expand Up @@ -1033,17 +1023,6 @@ export
@elapsed,
@allocated,

# reflection
@which,
@edit,
@functionloc,
@less,
@code_typed,
@code_warntype,
@code_lowered,
@code_llvm,
@code_native,

# tasks
@schedule,
@sync,
Expand Down
Loading