scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

JLine 3: resolve status of `history` and `h?` commands #12268

Open SethTisue opened 4 years ago

SethTisue commented 4 years ago

commented-out code in the PR:

    // TODO maybe just drop these commands, as jline subsumes them -- before reenabling, finish scala.tools.nsc.interpreter.jline.HistoryAdaptor
     //historyCommand,
     //cmd("h?", "<string>", "search the history", searchHistory),
lrytz commented 4 years ago

@dwijnand notes that jshell has an edit command that actually works reliably and is useful. though it's more relevant in java given it's verbosity. our edit works or not if you're lukcy.

SethTisue commented 4 years ago

control-R already works for searching history. (this was true in JLine 2 as well.)

dwijnand commented 4 years ago

Details: in jshell /edit works with my settings of EDITOR=vim while with scala I need to set EDITOR=mvim to have something that works.

hvesalai commented 4 years ago

emacs-sbt-mode uses the history commands as well and also expects the commands run from emacs to be there (i.e. when jline is off, I guess)

SethTisue commented 4 years ago

I've made this ticket history-only, labeled it a blocker, and moved the edit stuff to a new ticket (#700)

SethTisue commented 4 years ago

now that I take a second, slower look at this I see that :history shows the history (optional numeric argument of how many entries to show) and :h? is for searching it:

scala 2.13.1> 2 + 2
res0: Int = 4

scala 2.13.1> 3 + 4
res1: Int = 7

scala 2.13.1> 5 + 6
res2: Int = 11

scala 2.13.1> :history
  1  2 + 2
  2  3 + 4
  3  5 + 6
  4  :history

scala 2.13.1> :h? 5
3 5 + 6
5 :h? 5

scala 2.13.1> :history 2
  5  :h? 5
  6  :history 2
SethTisue commented 4 years ago

@hvesalai I see that emacs-sbt-mode reads ~/.scala_history; note that we're changing it to ~/.scala_history_jline3

you write "uses the history commands as well" and I'm puzzled about that. I'm looking in the sbt-emacs-mode source code and I see that it uses :completions, but I do not see that it uses either :history or :h?

based on my observations, I'm removing the "blocker" label from this, but I can add it back if you can confirm that it's specifically :history and/or :h? that you want/need

SethTisue commented 4 years ago

Another thing I hadn't understood before: in JLine 3, history search is connected to up-arrow. So if you type e.g. pr and then hit up arrow, it starts cycling through previous entries that begin with pr. Dotty and Ammonite both support this. It doesn't make :h? useless, I guess, but the need for it to exist is now less.

It already works in our PR, too. (Perhaps not perfectly?)