Nice weird feature on pasting julia> code

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?

1 Like

How did I not notice that this works until now? This wants to be part of the discourse FAQ/PSA, amazing. last paragraph.


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)


$ julia test.jl
ERROR: LoadError: UndefVarError: x not defined

It is only active when pasting (and the terminal supports detecting paste,

1 Like

great. mille grazie. I did not know that terminal-paste-detection-passthrough existed.

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.

  1. Setting a mark and coming back to it (C-space and C-x C-x)
  2. Moving forward/backward by word (M-f and M-b)
  3. Transpose characters! (C-t, and I had fun C-t all the way to move a char to the end of line)
  4. etc.

But some functions don’t work (I’m using Mac):

  1. M-left/right arrow does not indent/deindent. Instead, it moves cursor left/right a word similar to M-f and M-b
  2. C-/ does nothing but C-_ works properly.

We should also add ] for entering the package manager mode in the doc.

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

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

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

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 )>

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>.