The package mode is persistent. Once you hit
] Julia is in package mode until one hits the backspace.
I find that a bit annoying at times. Especially when I do something in package mode, forget about it, and then try to execute some code in the editor and it pastes it into the package mode making a huge mess.
You can press up, home and backspace to put what you last wrote into the Julia REPL instead.
Of course. But I mean the case I do
and now I want to type command which is not a package command, and it is not in the history.
Then, according to my understanding of the workings of the package mode, I have to hit backspace to jump out of the package mode.
I wish it wasn’t. I frequently want to do
] add SomeNewPackage
and then leave the window alone for a minute. Is there a way to queue up these two commands? I can enter the second one, but the backspace to get out of package mode is not saved, so it doesn’t work.
(I know I can type
using Pkg; Pkg.add("..." but I don’t.)
I’m fine with this, although I do find it weird that
pkg persists whereas
shell does not. That has tripped me up before.
This is really strange, and as I do not use the shell I had not perceived until now. I would prefer all modes had the same behaviour.
Yes, this discussion around persistence of modes in the REPL happened in the past. The overall message as far as I remember is that
shell mode is not persistent to avoid users spending too much time outside Julia writing shell commands when Julia provides most utilities one would need from a shell. The
package mode on the other hand is more persistent because one is usually interested in typing at least two commands in a workflow:
activate . and
intantiate. Also, we usually start a project by typing a bunch of
add Bar, so having to re-enter package mode all the time would be annoying.
@PetrKryslUCSD I think your issue is really about the editor or IDE behavior? I have this issue as well now in VS Code where whenever we press
Ctrl+Enter to send the code to the REPL, it sends it without checking if the REPL is in
package mode. This wasn’t an issue in Juno for example.
Well, for me the point where I started thinking about this was as I was designing the https://github.com/PetrKryslUCSD/REPLHistory.jl package. I realized I couldn’t properly handle
history that contained
]... commands. In particular, there is no command to jump out of the package mode (it is a keystroke, not recorded in the command history). So when the history is printed and contains a
]..., the user must selectively pick the commands to execute. It is not possible to simply copy and paste into the REPL. The package-mode persistence
will wreak havoc with the execution.
Maybe both of our gripes can be solved by recording the backspace necessary to exit Pkg mode?
Interesting. Almost all my use of the REPL shell mode is in the pattern
In this pattern, the opposite of the current behavior (only shell mode being persistent) would be the least keystrokes. Even so, I never even noticed the inconsistency between the modes until reading about it now.
Would it be possible to replace
pkg"..." in the history?
I thought of that. Sort of “do what I meant” instead of “do what I did”.
I think I would have to parse the command and emit a rewrite. Including required use of PackageSpec…
A decent (and much simpler) solution might be to have a command to quit the package mode. I could then emit each package command that starts with
] followed by a package-mode quitting command.
Yes, this would be great. If it is only for package mode (to return to Julia mode) it should not be too hard to implement, and not break anything.