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

REPL: allow editing current input in editor (via Meta-e) #33759

Merged
merged 5 commits into from
May 12, 2022

Conversation

rfourquet
Copy link
Member

The REPL editing features are decent, but as the multi-line input grows, it can be convenient to quicly jump to your favorite editor... let's make this feature available trough Meta-e.

In the current state, we open a temporary file with the REPL's current input, call edit() on this file, and then load the REPL input buffer with its new content. If the file has been modified, we execute directly the code, otherwise we assume that the user changed her mind and we restore the input buffer as it was before the call to edit(). Suggestions welcome for this particular behavior (*).

It's easy to try this feature out without having to recompile Julia, by putting the three new functions in your startup.jl file, together with

import REPL, InteractiveUtils
using REPL.LineEdit: buffer, _newline, refresh_line, commit_line

And adding the keybinding, e.g.

atreplinit() do repl
    repl.options =
        REPL.Options(extra_keymap =
                     Dict("\ee" => (s,o...) -> edit_input(s)))
end

(*) This is currently implemented with a call to ctime, but might be more safe by comparing the content of the buffers before/after. For some reason, there is a little bug: if the first time the feature is used, the file is not updated, the input is still executed; but this doesn't happen when I put the new functions in my startup.jl file and run master (as described above).

@rfourquet rfourquet added stdlib:REPL Julia's REPL (Read Eval Print Loop) needs docs Documentation for this change is required labels Nov 4, 2019
@KristofferC KristofferC force-pushed the rf/repl/edit_input branch 2 times, most recently from e793bb8 to 1866262 Compare May 9, 2022 12:32
@KristofferC
Copy link
Sponsor Member

KristofferC commented May 9, 2022

This seems like a pretty useful feature. I rebased and added a commit that tried to use a bit less of the IOBuffer internals (it looked a bit scary to me) and also implements the

This is currently implemented with a call to ctime, but might be more safe by comparing the content of the buffers before/after.

suggestion. What do you think @rfourquet?

This is quite hard to test though. We could (just to simplify testing) allow passing in a "file modifying function" which by default is the Interactiveutils.edit but can be "mocked" by the REPL tests?

@KristofferC
Copy link
Sponsor Member

I've added docs and a test to this, should be good to go from my p.o.v.

@KristofferC KristofferC removed the needs docs Documentation for this change is required label May 11, 2022
@KristofferC KristofferC merged commit 6f4ce97 into master May 12, 2022
@KristofferC KristofferC deleted the rf/repl/edit_input branch May 12, 2022 11:50
@KristofferC
Copy link
Sponsor Member

This seems to only work with terminal editors for now.

@fredrikekre
Copy link
Member

I feel like this would be nicer if it didn't execute the code on exit so that you can exit the editor, check variables or w/e in the REPL, and then jump back into the editor.

@gitboy16
Copy link
Contributor

This features does not work for me on windows. It opens a notepad file in temp folder, asks me if i want to create the file (i say yes) i edit the file, saves it and nothing happens.

@StefanKarpinski
Copy link
Sponsor Member

Posting on an old PR isn't a good way to file an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib:REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants