1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix behaviour of tabs in raw Bourne Shell-like editing mode

When neither '-o emacs' nor '-o vi' is active, there were a couple
of bugs with entering tab characters:
1. Tab completion was erroneously left active. The cause of this
   was that raw Bourne edit mode is handled by ed_viread() in vi.c
   on shells with wide character support, instead of the default
   ed_read() in edit.c, and the former failed to check if vi mode
   is active when processing tab characters.
2. When entering literal tab characters, the cursor was moved to
   the right only one character, instead of the amount of
   characters corresponding to the tab.

src/cmd/ksh93/edit/vi.c: getline():
- Before processing '\t' (tab) for command completion, check that
  the 'vi' shell option (SH_VI) is active.

src/cmd/ksh93/edit/edit.c: ed_virt_to_phys():
- When translating literal tabs to on-terminal spaces and when
  recalculating the cursor position, remove erroneous checks for
  SH_VI; this is also needed in raw Bourne mode. According to my
  own testing, this has no effect on emacs mode (knock on wood).

src/cmd/ksh93/tests/pty.sh:
- Add two regression tests. An odd race condition reveals itself in
  either pty or in ksh's raw/Bourne edit mode; see comment in test.
  Effect is we have to expect either literal tabs or tabs expanded
  to spaces, until that is tracked down and fixed.

Fixes #43.
This commit is contained in:
Martijn Dekker 2020-06-26 07:19:58 +02:00
parent 4cecde1dd3
commit 8c705bf3b7
4 changed files with 47 additions and 5 deletions

View file

@ -470,5 +470,40 @@ u ^/tmp/fakehome/testfile\r?\n$
!
rm -r /tmp/fakehome
# err_exit #
LC_ALL=C tst $LINENO <<"!"
L raw Bourne mode literal tab characters with wide characters disabled
# This gets handled by ed_read() in edit.c; it does not expand tab
# characters on the command line.
w set +o vi +o emacs
p :test-2:
w true /de\tv/nu\tl\tl
r ^:test-2: true /de\tv/nu\tl\tl\r\n$
p :test-3:
!
# err_exit #
LC_ALL=C.UTF-8 tst $LINENO <<"!"
L raw Bourne mode literal tab characters with wide characters enabled
# This gets handled by ed_viread() in vi.c (even though vi mode is off);
# it expands tab characters to spaces on the command line.
w set +o vi +o emacs
p :test-2:
w true /de\tv/nu\tl\tl
# TODO: there is some race condition in either pty or in ksh's default edit
# mode, which causes it to expect/generate either tabs ('\t') or expanded
# spaces, randomly, intermittently. This is functionally equivalent as it
# only affects either pty or (invisibly) the editing command line, so not a
# high priority. Until this is tracked down and fixed, accept both.
r ^:test-2: true (/de\tv/nu\tl\tl|/de v/nu l l)\r\n$
p :test-3:
!
# ======
exit $((Errors<125?Errors:125))