Page MenuHomeFreeBSD

sh: move histedit() call outside of test for bind -
Needs ReviewPublic

Authored by emaste on Aug 19 2024, 5:04 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Oct 28, 12:43 PM
Unknown Object (File)
Sun, Oct 20, 2:26 PM
Unknown Object (File)
Sun, Oct 20, 2:25 PM
Unknown Object (File)
Sun, Oct 20, 2:22 PM
Unknown Object (File)
Oct 5 2024, 2:08 AM
Unknown Object (File)
Oct 3 2024, 6:02 PM
Unknown Object (File)
Oct 2 2024, 4:36 AM
Unknown Object (File)
Oct 1 2024, 8:53 PM
Subscribers
None

Details

Reviewers
bapt
pstef
jilles
Summary

It appears that bind resets vi/emacs mode, so call histedit() after every bind call to make sure the state remains consistent.

This might be a bigger hammer than necessary, or it might be that this should be addressed in libedit itself.

PR: 280889

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

emaste created this revision.

I believe the problem was introduced in 5fe973734866 or ef0d94a3d34c where ^[[A is introduced. I think libedit doesn't have the code to parse that properly. Fortunately it can be replaced with \e.

https://reviews.freebsd.org/P645 is a diff that teaches libedit how to parse it, by the way.

https://reviews.freebsd.org/P645 is a diff that teaches libedit how to parse it, by the way.

That change LGTM if you want to commit it.

https://reviews.freebsd.org/P645 is a diff that teaches libedit how to parse it, by the way.

That change LGTM if you want to commit it.

Unfortunately I was wrong and it actually doesn't change anything except perhaps it improves code clarity.

To quote my email to Christos:

The actual problem is the interaction between vi mode and binding the up
arrow key to anything I tested, including the ed-search-prev-history
that some users demanded from us. Tests are easier for me when I try
ed-prev-char.

cd /tmp ; set -o vi ; bind > before ; bind ^[[A ed-prev-char
bind > after ; diff -Bwu before after

-"^[" -> vi-command-mode
+"^[" -> ed-sequence-lead-in

-"^[[A" -> ed-prev-history
+"^[[A" -> ed-prev-char

Then the vi bindings are gone, for example esc-K.

If I replace ^[[A with -k up, the former change is no longer there and
the latter is listed as a key arrow bind. But the behavior is not the
one I expected: the up key brings previous commands.

I'll try to find some time to think about if this is fixable and how.
But it seems it should be in principle since vi handles the arrow keys
properly in command mode.