REPL: implement "insert last word from previous history entry" #33749
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bind this shell-like feature to the usual "meta-.".
For example, if the previous input was
julia> 1 + 2
, then <Alt-.> (or <meta-.>) will insert2
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 isb)
, 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 ")"). Callword
what we have jumped around till now (b
) andrest
what is between current position and the en of line ()
). Ifrest
contains a balanced number of parenthesis and brackets, and doesn't contain special characters (`
,"
,'
for now), then returnword * rest
, otherwiseword
. In this example, this would returnb
, and with1+f()
it would returnf()
.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 thenpkg> st <Alt-.>
, orusing <Alt-.>
, where<Alt-.>
would insertMyPackage
. Or for exampleusing Random
followed by<M-.>.seed!()
.This implements the last missing feature from #8447.