Skip to content

Commit 41eb402

Browse files
committed
move InteractiveUtils to stdlib
1 parent 743d487 commit 41eb402

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1505
-1432
lines changed

base/client.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ function process_options(opts::JLOptions)
305305
# load ~/.juliarc file
306306
startup && load_juliarc()
307307

308+
if repl || is_interactive
309+
# load interactive-only libraries
310+
eval(Main, :(using InteractiveUtils))
311+
end
312+
308313
# process cmds list
309314
for (cmd, arg) in cmds
310315
if cmd == 'e'

base/clipboard.jl

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
# clipboard copy and paste
4+
5+
if Sys.isapple()
6+
function clipboard(x)
7+
open(pipeline(`pbcopy`, stderr=STDERR), "w") do io
8+
print(io, x)
9+
end
10+
end
11+
clipboard() = read(`pbpaste`, String)
12+
13+
elseif Sys.islinux() || Sys.KERNEL === :FreeBSD
14+
_clipboardcmd = nothing
15+
const _clipboardcmds = Dict(
16+
:copy => Dict(
17+
:xsel => Sys.islinux() ?
18+
`xsel --nodetach --input --clipboard` : `xsel -c`,
19+
:xclip => `xclip -silent -in -selection clipboard`,
20+
),
21+
:paste => Dict(
22+
:xsel => Sys.islinux() ?
23+
`xsel --nodetach --output --clipboard` : `xsel -p`,
24+
:xclip => `xclip -quiet -out -selection clipboard`,
25+
)
26+
)
27+
function clipboardcmd()
28+
global _clipboardcmd
29+
_clipboardcmd !== nothing && return _clipboardcmd
30+
for cmd in (:xclip, :xsel)
31+
success(pipeline(`which $cmd`, DevNull)) && return _clipboardcmd = cmd
32+
end
33+
pkgs = @static if Sys.islinux()
34+
"xsel or xclip"
35+
elseif Sys.KERNEL === :FreeBSD
36+
"x11/xsel or x11/xclip"
37+
end
38+
error("no clipboard command found, please install $pkgs")
39+
end
40+
function clipboard(x)
41+
c = clipboardcmd()
42+
cmd = get(_clipboardcmds[:copy], c, nothing)
43+
if cmd === nothing
44+
error("unexpected clipboard command: $c")
45+
end
46+
open(pipeline(cmd, stderr=STDERR), "w") do io
47+
print(io, x)
48+
end
49+
end
50+
function clipboard()
51+
c = clipboardcmd()
52+
cmd = get(_clipboardcmds[:paste], c, nothing)
53+
if cmd === nothing
54+
error("unexpected clipboard command: $c")
55+
end
56+
read(pipeline(cmd, stderr=STDERR), String)
57+
end
58+
59+
elseif Sys.iswindows()
60+
# TODO: these functions leak memory and memory locks if they throw an error
61+
function clipboard(x::AbstractString)
62+
if containsnul(x)
63+
throw(ArgumentError("Windows clipboard strings cannot contain NUL character"))
64+
end
65+
systemerror(:OpenClipboard, 0==ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Cvoid},), C_NULL))
66+
systemerror(:EmptyClipboard, 0==ccall((:EmptyClipboard, "user32"), stdcall, Cint, ()))
67+
x_u16 = cwstring(x)
68+
# copy data to locked, allocated space
69+
p = ccall((:GlobalAlloc, "kernel32"), stdcall, Ptr{UInt16}, (UInt16, Int32), 2, sizeof(x_u16))
70+
systemerror(:GlobalAlloc, p==C_NULL)
71+
plock = ccall((:GlobalLock, "kernel32"), stdcall, Ptr{UInt16}, (Ptr{UInt16},), p)
72+
systemerror(:GlobalLock, plock==C_NULL)
73+
ccall(:memcpy, Ptr{UInt16}, (Ptr{UInt16},Ptr{UInt16},Int), plock, x_u16, sizeof(x_u16))
74+
systemerror(:GlobalUnlock, 0==ccall((:GlobalUnlock, "kernel32"), stdcall, Cint, (Ptr{Cvoid},), plock))
75+
pdata = ccall((:SetClipboardData, "user32"), stdcall, Ptr{UInt16}, (UInt32, Ptr{UInt16}), 13, p)
76+
systemerror(:SetClipboardData, pdata!=p)
77+
ccall((:CloseClipboard, "user32"), stdcall, Cvoid, ())
78+
end
79+
clipboard(x) = clipboard(sprint(print, x)::String)
80+
function clipboard()
81+
systemerror(:OpenClipboard, 0==ccall((:OpenClipboard, "user32"), stdcall, Cint, (Ptr{Cvoid},), C_NULL))
82+
pdata = ccall((:GetClipboardData, "user32"), stdcall, Ptr{UInt16}, (UInt32,), 13)
83+
systemerror(:SetClipboardData, pdata==C_NULL)
84+
systemerror(:CloseClipboard, 0==ccall((:CloseClipboard, "user32"), stdcall, Cint, ()))
85+
plock = ccall((:GlobalLock, "kernel32"), stdcall, Ptr{UInt16}, (Ptr{UInt16},), pdata)
86+
systemerror(:GlobalLock, plock==C_NULL)
87+
# find NUL terminator (0x0000 16-bit code unit)
88+
len = 0
89+
while unsafe_load(plock, len+1) != 0; len += 1; end
90+
# get Vector{UInt16}, transcode data to UTF-8, make a String of it
91+
s = transcode(String, unsafe_wrap(Array, plock, len))
92+
systemerror(:GlobalUnlock, 0==ccall((:GlobalUnlock, "kernel32"), stdcall, Cint, (Ptr{UInt16},), plock))
93+
return s
94+
end
95+
96+
else
97+
clipboard(x="") = error("`clipboard` function not implemented for $(Sys.KERNEL)")
98+
end
99+
100+
101+
"""
102+
clipboard(x)
103+
104+
Send a printed form of `x` to the operating system clipboard ("copy").
105+
"""
106+
clipboard(x)
107+
108+
"""
109+
clipboard() -> AbstractString
110+
111+
Return a string with the contents of the operating system clipboard ("paste").
112+
"""
113+
clipboard()

base/deprecated.jl

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ next(p::Union{Process, ProcessChain}, i::Int) = (getindex(p, i), i + 1)
203203
return i == 1 ? getfield(p, p.openstream) : p
204204
end
205205

206-
# PR #21974
207-
@deprecate versioninfo(verbose::Bool) versioninfo(verbose=verbose)
208-
@deprecate versioninfo(io::IO, verbose::Bool) versioninfo(io, verbose=verbose)
209-
210206
# also remove all support machinery in src for current_module when removing this deprecation
211207
# and make Base.include an error
212208
_current_module() = ccall(:jl_get_current_module, Ref{Module}, ())
@@ -744,14 +740,6 @@ Broadcast.dotview(A::AbstractArray{<:AbstractArray}, args::Integer...) = getinde
744740
nothing
745741
end
746742

747-
@deprecate whos(io::IO, m::Module, pat::Regex) show(io, varinfo(m, pat))
748-
@deprecate whos(io::IO, m::Module) show(io, varinfo(m))
749-
@deprecate whos(io::IO) show(io, varinfo())
750-
@deprecate whos(m::Module, pat::Regex) varinfo(m, pat)
751-
@deprecate whos(m::Module) varinfo(m)
752-
@deprecate whos(pat::Regex) varinfo(pat)
753-
@deprecate whos() varinfo()
754-
755743
# indexing with A[true] will throw an argument error in the future
756744
function to_index(i::Bool)
757745
depwarn("indexing with Bool values is deprecated. Convert the index to an integer first with `Int(i)`.", (:getindex, :setindex!, :view))
@@ -1382,7 +1370,6 @@ export readandwrite
13821370
@deprecate indmax argmax
13831371

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

13881375
# PR 25458
@@ -1402,8 +1389,6 @@ end
14021389
@deprecate Timer(callback, delay, repeat) Time(callback, delay, interval = repeat)
14031390
@deprecate names(m, all) names(m, all = all)
14041391
@deprecate names(m, all, imported) names(m, all = all, imported = imported)
1405-
@deprecate code_native(io, f, types, syntax) code_native(io, f, types, syntax = syntax)
1406-
@deprecate code_native(f, types, syntax) code_native(f, types, syntax = syntax)
14071392
@deprecate eachmatch(re, str, overlap) eachmatch(re, str, overlap = overlap)
14081393
@deprecate matchall(re, str, overlap) matchall(re, str, overlap = overlap)
14091394
@deprecate chop(s, head) chop(s, head = head)
@@ -1418,6 +1403,8 @@ end
14181403

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

1406+
@deprecate which(s::Symbol) which(Main, s)
1407+
14211408
# END 0.7 deprecations
14221409

14231410
# BEGIN 1.0 deprecations

base/docs/Docs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import Base.Meta: quot, isexpr
6464
import Base: Callable, with_output_color
6565
import ..CoreDocs: lazy_iterpolate
6666

67-
export doc, apropos
67+
export doc
6868

6969
# Basic API / Storage
7070

base/download.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
# file downloading
4+
5+
downloadcmd = nothing
6+
if Sys.iswindows()
7+
downloadcmd = :powershell
8+
function download(url::AbstractString, filename::AbstractString)
9+
ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
10+
tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
11+
client = "New-Object System.Net.Webclient"
12+
# in the following we escape ' with '' (see https://ss64.com/ps/syntax-esc.html)
13+
downloadfile = "($client).DownloadFile('$(replace(url, "'" => "''"))', '$(replace(filename, "'" => "''"))')"
14+
run(`$ps -NoProfile -Command "$tls12; $downloadfile"`)
15+
filename
16+
end
17+
else
18+
function download(url::AbstractString, filename::AbstractString)
19+
global downloadcmd
20+
if downloadcmd === nothing
21+
for checkcmd in (:curl, :wget, :fetch)
22+
if success(pipeline(`which $checkcmd`, DevNull))
23+
downloadcmd = checkcmd
24+
break
25+
end
26+
end
27+
end
28+
if downloadcmd == :wget
29+
try
30+
run(`wget -O $filename $url`)
31+
catch
32+
rm(filename) # wget always creates a file
33+
rethrow()
34+
end
35+
elseif downloadcmd == :curl
36+
run(`curl -g -L -f -o $filename $url`)
37+
elseif downloadcmd == :fetch
38+
run(`fetch -f $filename $url`)
39+
else
40+
error("no download agent available; install curl, wget, or fetch")
41+
end
42+
filename
43+
end
44+
end
45+
function download(url::AbstractString)
46+
filename = tempname()
47+
download(url, filename)
48+
end
49+
50+
"""
51+
download(url::AbstractString, [localfile::AbstractString])
52+
53+
Download a file from the given url, optionally renaming it to the given local file name.
54+
Note that this function relies on the availability of external tools such as `curl`, `wget`
55+
or `fetch` to download the file and is provided for convenience. For production use or
56+
situations in which more options are needed, please use a package that provides the desired
57+
functionality instead.
58+
"""
59+
download(url, filename)

base/errorshow.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ function showerror(io::IO, ex::InexactError)
149149
print(io, "InexactError: ", ex.func, '(', ex.T, ", ", ex.val, ')')
150150
end
151151

152+
typesof(args...) = Tuple{Any[ Core.Typeof(a) for a in args ]...}
153+
152154
function showerror(io::IO, ex::MethodError)
153155
# ex.args is a tuple type if it was thrown from `invoke` and is
154156
# a tuple of the arguments otherwise.

base/exports.jl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,6 @@ export
761761
promote,
762762
promote_rule,
763763
promote_type,
764-
subtypes,
765764
instances,
766765
supertype,
767766
typeintersect,
@@ -777,26 +776,17 @@ export
777776
parse,
778777

779778
# help and reflection
780-
apropos,
781-
edit,
782779
code_typed,
783-
code_warntype,
784780
code_lowered,
785-
code_llvm,
786-
code_native,
787781
fullname,
788782
functionloc,
789783
isconst,
790784
isinteractive,
791-
less,
792785
hasmethod,
793786
methods,
794-
methodswith,
795787
nameof,
796788
parentmodule,
797789
names,
798-
varinfo,
799-
versioninfo,
800790
which,
801791
@isdefined,
802792

@@ -1033,17 +1023,6 @@ export
10331023
@elapsed,
10341024
@allocated,
10351025

1036-
# reflection
1037-
@which,
1038-
@edit,
1039-
@functionloc,
1040-
@less,
1041-
@code_typed,
1042-
@code_warntype,
1043-
@code_lowered,
1044-
@code_llvm,
1045-
@code_native,
1046-
10471026
# tasks
10481027
@schedule,
10491028
@sync,

0 commit comments

Comments
 (0)