Skip to content

Commit 9c3cb36

Browse files
Merge branch 'ScottPJones-spj/editdef'
2 parents 90fe14d + e90a7b5 commit 9c3cb36

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

base/LineEdit.jl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,26 @@ function commit_line(s)
13261326
state(s, mode(s)).ias = InputAreaState(0, 0)
13271327
end
13281328

1329+
"""
1330+
`Base.LineEdit.tabwidth` controls the presumed tab width of code pasted into the REPL.
1331+
1332+
You can modify it by doing `eval(Base.LineEdit, :(tabwidth = 4))`, for example.
1333+
1334+
Must satisfy `0 < tabwidth <= 16`.
1335+
"""
1336+
global tabwidth = 8
1337+
1338+
function bracketed_paste(s)
1339+
ps = state(s, mode(s))
1340+
input = readuntil(ps.terminal, "\e[201~")[1:(end-6)]
1341+
input = replace(input, '\r', '\n')
1342+
if position(buffer(s)) == 0
1343+
indent = Base.indentation(input; tabwidth=tabwidth)[1]
1344+
input = Base.unindent(input[(indent+1):end], indent; tabwidth=tabwidth)
1345+
end
1346+
input
1347+
end
1348+
13291349
const default_keymap =
13301350
AnyDict(
13311351
# Tab
@@ -1429,13 +1449,7 @@ AnyDict(
14291449
"\e[3~" => (s,o...)->edit_delete(s),
14301450
# Bracketed Paste Mode
14311451
"\e[200~" => (s,o...)->begin
1432-
ps = state(s, mode(s))
1433-
input = readuntil(ps.terminal, "\e[201~")[1:(end-6)]
1434-
input = replace(input, '\r', '\n')
1435-
if position(buffer(s)) == 0
1436-
indent = Base.indentation(input; tabwidth=4)[1]
1437-
input = Base.unindent(input[(indent+1):end], indent; tabwidth=4)
1438-
end
1452+
input = bracketed_paste(s)
14391453
edit_insert(s, input)
14401454
end,
14411455
"^T" => (s,o...)->edit_transpose(s)

base/REPL.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,15 +784,9 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep
784784

785785
# Bracketed Paste Mode
786786
"\e[200~" => (s,o...)->begin
787-
ps = LineEdit.state(s, LineEdit.mode(s))
788-
input = readuntil(ps.terminal, "\e[201~")[1:(end-6)]
789-
input = replace(input, '\r', '\n')
790-
if position(LineEdit.buffer(s)) == 0
791-
indent = Base.indentation(input; tabwidth=4)[1]
792-
input = Base.unindent(lstrip(input), indent; tabwidth=4)
793-
end
787+
input = LineEdit.bracketed_paste(s)
794788
buf = copy(LineEdit.buffer(s))
795-
edit_insert(buf,input)
789+
edit_insert(buf, input)
796790
string = takebuf_string(buf)
797791
curspos = position(LineEdit.buffer(s))
798792
pos = 0

0 commit comments

Comments
 (0)