REPL, copy/paste and auto indent in julia 0.7

OK, I found a patch which makes it much more reliable for me: compared to the PR code, in the edit_insert_newline function, exchange the order of the last two lines, i.e. change it to:

     refresh_line(s)
     align > 0 && (s.last_newline = time())

You don’t need to recompile the whole Julia to change that, you can overwrite the function with:

import REPL
import REPL.LineEdit: edit_insert, options, buffer, position, char_move_left, char_move_right, edit_splice!, push_undo, edit_insert, prompt_string, beginofline, terminal, refresh_line, PromptState, width, edit_insert_newline, _notspace, _newline

function edit_insert_newline(s::PromptState, align::Int = 0 - options(s).auto_indent)
    push_undo(s)
    buf = buffer(s)
    if align < 0
        beg = beginofline(buf)
        align = min(something(findnext(_notspace, buf.data[beg+1:buf.size], 1), 0) - 1,
                    position(buf) - beg) # indentation must not increase
        align < 0 && (align = buf.size-beg)
    end
    edit_insert(buf, '\n' * ' '^align)
    refresh_line(s)
    align > 0 && (s.last_newline = time())
end
1 Like