Skip to content

Commit

Permalink
only remove prompt prefix in bracket paste
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jul 25, 2016
1 parent 741b41d commit 14ff02f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1302,9 +1302,14 @@ Must satisfy `0 < tabwidth <= 16`.
"""
global tabwidth = 8

const STANDARD_REPL_PROMPTS = ["julia> ", "help?> ", "shell> "]

function bracketed_paste(s)
ps = state(s, mode(s))
input = readuntil(ps.terminal, "\e[201~")[1:(end-6)]
if ps.p.prompt in STANDARD_REPL_PROMPTS && startswith(input, ps.p.prompt)
input = input[sizeof(ps.p.prompt)+1:end]
end
input = replace(input, '\r', '\n')
if position(buffer(s)) == 0
indent = Base.indentation(input; tabwidth=tabwidth)[1]
Expand Down
14 changes: 12 additions & 2 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,18 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
oldpos = start(input)
firstline = true
while !done(input, oldpos) # loop until all lines have been executed
if startswith(input, "julia> ")
input = input[8:end]
# Check if the next statement starts with "julia> ", in that case
# skip it.
# First skip and count newline characters
c = oldpos
while c <= sizeof(input) && input[c] == '\n'
c = nextind(input, c)
end
n_newlines = c - oldpos
# Skip over prompt prefix if statement starts with it
jl_prompt_len = 7
if c + jl_prompt_len <= sizeof(input) && input[c:c+jl_prompt_len-1] == "julia> "
oldpos += jl_prompt_len + n_newlines
end
ast, pos = Base.syntax_deprecation_warnings(false) do
Base.parse(input, oldpos, raise=false)
Expand Down

0 comments on commit 14ff02f

Please sign in to comment.