racket / expeditor

Other
9 stars 16 forks source link

Pressing 'up' to recall a multi-line input places cursor on first line #12

Closed plane closed 2 years ago

plane commented 2 years ago

Let's say I type a multi-line input, and hit enter:

> (+ 2
     3)
5

Now if I hit up, it moves my cursor to the end of the first line, after the 2:

> (+ 2|
     3)

I think it should move the cursor to the end instead, like this:

> (+ 2
     3)|

That was the behavior in the old repl, and it feels rather more convenient to me. Other repls also move the cursor to the end, such as the DrRacket repl, Ruby's irb, or Guile with readline.

sorawee commented 2 years ago

I actually kinda like the current behavior.

The main property that I want is, in the history navigation, I should be able to hit "up" and "down" repeatedly, with each "up" and "down" changing the entry to the previous or next one immediately.

In expeditor, "up" and "down" are context sensitive. If you are at the first line, "up" will change to the previous entry. Otherwise, "up" moves the cursor to the previous line.

Positioning the cursor at the end will violate this property when you want to navigate to the previous entry, because you potentially need to hit "up" several times to go to the first line first.

What about other REPLs?

irb

I tried irb. It doesn't really support multiple lines editing. E.g.,

1 +
2

are stored as two different entries. So I think comparing expeditor with irb is kinda pointless.

DrRacket

DrRacket can only use the arrow key for moving the cursor. It can't use the arrow key to navigate the history. So again, comparing expeditor with DrRacket is kinda pointless.

bash

bash's "up" and "down" always mean changing to the previous and next entry. To go to the previous or next line, we must use "left" and "right".

zsh

zsh's "up" and "down" are context sensitive. It does what @plane proposed, and therefore violates the property that I mentioned above.

fish

fish's "up" and "down" are context sensitive. It can either go to the previous entry or move the cursor to the previous line. This is done by having multiple modes. At the beginning, we are in the history navigation mode, and "up" and "down" will change entry. After using "left" or "right" key however, it will change to the other mode, where "up" and "down" move the cursor. I'm not aware of a way to change back to the history navigation mode, but this should be straightforward to implement.

Conclusion

I guess there are two different things here.

  1. For people who want to navigate multiple entries, the current behavior is desirable.
  2. For people who want to edit the previous entry a lot, @plane's proposal is desirable.

Can we have the cake and eat it too? With multiple modes, I think this is possible, but that also complicates stuff.

plane commented 2 years ago

I tried irb. It doesn't really support multiple lines editing. E.g.,

1 +
2

are stored as two different entries. So I think comparing expeditor with irb is kinda pointless.

Try typing

(1 +
  2)
sorawee commented 2 years ago

Yes, I still see the same behavior that I did earlier. Perhaps we have different version of Ruby?

$ ruby --version
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
$ irb --version
WARNING: This version of ruby is included in macOS for compatibility with legacy software.
In future versions of macOS the ruby runtime will not be available by
default, and may require you to install an additional package.

irb 1.0.0 (2018-12-18)
plane commented 2 years ago

irb 1.0.0 (2018-12-18)

Oh, yes, that was added in 2019. I'm using irb 1.2.6.

sorawee commented 2 years ago

I installed a new version of Ruby. So... irb and zsh are in the same category.

plane commented 2 years ago

sorawee wrote:

I guess there are two different things here.

1. For people who want to navigate multiple entries, the current behavior is desirable.

2. For people who want to edit the previous entry a lot, @plane's proposal is desirable.

Can we have the cake and eat it too? With multiple modes, I think this is possible, but that also complicates stuff.

Here is my attempt at making it configurable (leaving the default behavior unchanged): https://github.com/racket/expeditor/pull/15

plane commented 2 years ago

This is now configurable with https://github.com/racket/expeditor/commit/34973c081bdf6ffec0c69c0126d8849a00e012a3