Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rf/autoindentpaste improvements #30755

Merged
merged 5 commits into from
Mar 8, 2019
Merged

Rf/autoindentpaste improvements #30755

merged 5 commits into from
Mar 8, 2019

Conversation

oheil
Copy link
Contributor

@oheil oheil commented Jan 18, 2019

Improvements based on rf/autoindentpaste
https://github.com/JuliaLang/julia/tree/rf/autoindentpaste

For additional issues which are solved by this PR see
https://discourse.julialang.org/t/repl-copy-paste-and-auto-indent-in-julia-0-7/10230
e.g. pasting a mix of space and tabs and empty lines at once still break autoindentation

This PR replaces the PR of @rfourquet:
#29129

rfourquet and others added 4 commits October 5, 2018 10:10
On some Windows terminals, pasting is not recognized as such.
This happens also with tmux' builtin paste.
In those cases, auto-indent is better disabled, as we want
to preserve the original indentation of the code being pasted.

This fix is quite a hack, but seems to work: using time(), if
the next character after a newline is being inserted very fast,
assume this was with paste, and cancel the insertion of the
spaces done by auto-indent.

I couldn't insert two characters in a raw within less than
about 0.03 or 0.02 seconds, so the threshold for "very fast"
is set to 0.0005, but this is an option which can changed.
* don't include refresh_line in the timings
* use a separate autoindent variable, as we want to undo indent in case of paste only
  for auto-indented code (although currently in the REPL code this function is never
  called with a positive argument)
…one. Paste of mixed space/tabs/empty lines is now more reliable.
@oheil
Copy link
Contributor Author

oheil commented Jan 18, 2019

pain... I will check for this :-(
Fixed :-)

@@ -680,6 +682,27 @@ edit_splice!(s, ins::AbstractString) = edit_splice!(s, region(s), ins)
function edit_insert(s::PromptState, c)
push_undo(s)
buf = s.input_buffer

if ! options(s).auto_indent_bracketed_paste
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !options(s).auto_indent_bracketed_paste

@@ -680,6 +682,27 @@ edit_splice!(s, ins::AbstractString) = edit_splice!(s, region(s), ins)
function edit_insert(s::PromptState, c)
push_undo(s)
buf = s.input_buffer

if ! options(s).auto_indent_bracketed_paste
pos=position(buf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pos = position(buf)

@musm
Copy link
Contributor

musm commented Mar 6, 2019

bump, this is an annoying issue when using the terminal.

@KristofferC
Copy link
Sponsor Member

Yeah, I was planning on trying this out and merging this. Will do so now.

@musm
Copy link
Contributor

musm commented Mar 6, 2019

I just tested this out, situation is improved but it's still not pasting everything in properly

@musm
Copy link
Contributor

musm commented Mar 6, 2019

E.g. sometimes it pastes and indents it correctly other times it does whatever it wants to...

@musm
Copy link
Contributor

musm commented Mar 6, 2019

I haven't tested the original PR that this is based on, however.

@oheil
Copy link
Contributor Author

oheil commented Mar 7, 2019

E.g. sometimes it pastes and indents it correctly other times it does whatever it wants to...

Can you give some examples? Maybe there are still cases which fail.
It could also be a timing problem, because detection of copy&paste is based on a time measurement.

@musm
Copy link
Contributor

musm commented Mar 7, 2019

@oheil All I did was copy some code and repeatedly paste it into the terminal.
The first time it didn't indent things correctly, but then it would sporadically paste it correctly and also incorrectly.

@oheil
Copy link
Contributor Author

oheil commented Mar 8, 2019

I guess it could be the timing. If you like to, you may try out other thresholds, using e.g.
Base.active_repl.options.auto_indent_time_threshold = 0.01
the current value is 0.005. The higher the value the higher is the chance that auto_indent is detected. If it is too high, normal keyboard input could be missinterpreted as copy&past and than auto_indent would be bad.

@KristofferC
Copy link
Sponsor Member

I think we should try this for a while, it doesn't seem any worse locally. If it leads to problems we can revert but things like this pretty much have to be tested in the wild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants