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: implement "insert last word from previous history entry" #33749

Merged
merged 1 commit into from
Nov 16, 2019

Conversation

rfourquet
Copy link
Member

@rfourquet rfourquet commented Nov 2, 2019

Bind this shell-like feature to the usual "meta-.".

For example, if the previous input was julia> 1 + 2, then <Alt-.> (or <meta-.>) will insert 2 in the current input.

It's not necessary clear what the "last word" should mean. I think that in shells this command considers space-separated words, and also IPython. But the problem is that if the last input is e.g. f(a, b), then the last word is b), which is not very useful. So here I use a slightly different heuristic: go to the end of line, then one word backward (position reaches "before b"), then one word forward (position is between "b" and ")"). Call word what we have jumped around till now (b) and rest what is between current position and the en of line ()). If rest contains a balanced number of parenthesis and brackets, and doesn't contain special characters (`, ", ' for now), then return word * rest, otherwise word. In this example, this would return b, and with 1+f() it would return f().

But most of the time when I try to reach out to this shortcut, it's for simple things which are unambiguous, like when I do for example pkg> up MyPackage and then pkg> st <Alt-.>, or using <Alt-.>, where <Alt-.> would insert MyPackage. Or for example using Random followed by <M-.>.seed!().

This implements the last missing feature from #8447.

@rfourquet rfourquet added the REPL Julia's REPL (Read Eval Print Loop) label Nov 2, 2019
@rfourquet rfourquet force-pushed the rf/repl/insert-last-word branch 2 times, most recently from e10c8ba to 68bc67a Compare November 4, 2019 15:20
Bind this shell-like feature to the usual "meta-.".
@rfourquet rfourquet force-pushed the rf/repl/insert-last-word branch from 68bc67a to d9a4873 Compare November 4, 2019 16:29
@rfourquet
Copy link
Member Author

I will just merge this. The specific behavior can be refined later if needed using input from users.

@rfourquet rfourquet merged commit 6513811 into master Nov 16, 2019
@rfourquet rfourquet deleted the rf/repl/insert-last-word branch November 16, 2019 08:52
KristofferC pushed a commit that referenced this pull request Apr 11, 2020
Bind this shell-like feature to the usual "meta-.".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant