iwelch
September 16, 2018, 3:53pm
1
on macos and linux, copy
julia> x=2
julia> x + 1
into the copy-paste buffer.
obviously, this should not be pasted into a running REPL, because each line starts with julia>
.
except , the REPL is smart enough to recognize this somehow. in fact, on paste, the paste-buffer julia>
does not show up on the screen.
typing the code into the REPL does not work. the 'julia> ’ becomes visible, and then it does not work.
so, how does this feature work? is this special paste functionality in the julia REPL?
3 Likes
How did I not notice that this works until now? This wants to be part of the discourse FAQ/PSA, amazing.
1 Like
JuliaLang:master
← JuliaLang:kc/remove_repl_prompt
opened 11:52PM - 24 Jul 16 UTC
It is common to encounter example code that is posted with the REPL prefix inclu… ded (typically `julia>`). This occurs in manual, doc tests and in forum posts etc. Usually one wants to quickly run this code in the REPL but then has to manually remove all the prompt prefixes first which can be a bit annoying.
This PR simply checks if the statement being evaluated in the REPL starts with the REPL prefix and in that case removes it.
As an example pasting this code block:
``` jl
julia> const x = 1;
julia> function foo(x)
return x + 1
end;
julia> type X
x::Int
end;
```
will be equivalent to pasting it without the `julia>` prefixes.
This is also implemented for the other REPL modes.
fixes https://github.com/JuliaLang/julia/issues/16383
The Julia REPL · The Julia Language last paragraph.
10 Likes
iwelch
September 16, 2018, 4:34pm
4
this is a great feature addition. love it. alas, why did it now work when I typed it:
julia> julia> x=2
> (generic function with 1 method)
julia> julia> x=2
> (generic function with 1 method)
similarly. it does not work with julia source code:
$ cat test.jl
julia> x=2
julia> x=x+1
julia> println(x)
^D
$ julia test.jl
ERROR: LoadError: UndefVarError: x not defined
Stacktrace:
It is only active when pasting (and the terminal supports detecting paste, bracketed paste mode ).
2 Likes
iwelch
September 16, 2018, 4:37pm
6
great. mille grazie. I did not know that terminal-paste-detection-passthrough existed.
tk3369
September 16, 2018, 4:45pm
7
This is a good reminder to take a look at the doc. I have never really spent the time in going through the key bindings before.
I found some surprises for myself.
Setting a mark and coming back to it (C-space and C-x C-x)
Moving forward/backward by word (M-f and M-b)
Transpose characters! (C-t, and I had fun C-t all the way to move a char to the end of line)
etc.
But some functions don’t work (I’m using Mac):
M-left/right arrow does not indent/deindent. Instead, it moves cursor left/right a word similar to M-f and M-b
C-/ does nothing but C-_ works properly.
We should also add ]
for entering the package manager mode in the doc.
Liso
September 16, 2018, 4:46pm
8
Doesn’t Base.REPL.enable_promptpaste(::Bool)
needs to be replaced by REPL.enable_promptpaste(::Bool)
in julia 1.0 doc?
Yes. But the whole option should probably just be removed.
As in just enable it unconditionally?
Yeah, I don’t think anyone has ever disabled it. I think the only reason to disable it is if you wanted to define >
using the infix method which doesn’t seem too likely:
julia> julia> x = 3
> (generic function with 1 method)
julia> "foo" > :bar
3
Liso
September 16, 2018, 5:11pm
12
BTW if I want to have my own prompt and use this feature I have to use something like:
repl.interface.modes[1].prompt="julia> #=$VERSION=# "
Then I will have (not very nice prompt):
julia> #=1.0.1-pre.4=# a = 3
3
And if I copy+paste it works (but is even more ugly):
julia> #=1.0.1-pre.4=# #=1.0.1-pre.4=# a = 3
3
I would rather see something more flexible:
# maybe julia[any string without '>']>
julia 1.0.1-pre.4>
# or maybe julia([any string without '>'])>
julia( 1.0.1-pre.4 )>
Liso
September 16, 2018, 5:17pm
13
This one also doesn’t work:
(v1.0) pkg> add package
# copy+paste it
julia> (v1.0) pkg> add package
ERROR: syntax: missing comma or ) in argument list
# or
(v1.0) pkg> (v1.0) pkg> add package
ERROR: expected command. instead got [(v1.0)]
It is only active for julia>
.
I just tried if this works at all under WIN11 (Julia 1.8.5) and failed.
Older windows terminals are too broken for this to work, strongly recommend using a newer terminal (which is the default in newer windows versions).
1 Like
I just tried it using the (relatively) new “Windows Terminal” and it still did not work. I assumed this is what you meant (as opposed to the old cmd or powershell terminals). Is Windows Terminal the new terminal you meant or is there something else instead?
It wasn’t working for me a year ago in Win 11 PowerShell, and it still doesn’t work with the latest PS update.
Hmm. @kristoffer.carlsson do you know why it doesn’t work on Windows?
Keno
April 15, 2023, 12:51am
21