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

Add new 'nobackslashctrl' shell option; other minor editor tweaks

The following emacs editor 'feature' kept making me want to go back
to bash. I forget a backslash escape in a command somewhere. So I
go back to insert it. I type the \, then want to go forward. My
right arrow key, instead of moving the cursor, then replaces my
backslash with garbage. Why? The backslash escapes the following
control character at the editor level and inserts it literally.

The vi editor has a variant of this which is much less harmful. It
only works in insert mode and the backslash only escapes the next
kill or erase character.

In both editors, this feature is completely redundant with the
'stty lnext' character which is ^V by default -- and works better
as well because it also escapes ^C, ^J (linefeed) and ^M (Return).

 [In fact, you could even issue 'stty lnext \\' and get a much more
 consistent version of this feature on any shell. You have to type
 two backslashes to enter one, but it won't kill your cursor keys.]

If it were up to me alone, I'd simply remove this misfeature from
both editors. However, it is long-standing documented behaviour.
It's in the 1995 book. Plus, POSIX specifies the vi variant of it.

So, this adds a shell option instead. It was quite trivial to do.
Now I can 'set --nobackslashctrl' in my ~/.kshrc. What a relief!

Note: To keep .kshrc compatibile with older ksh versions, use:
    command set --nobackslashctrl 2>/dev/null

src/cmd/ksh93/include/shell.h,
src/cmd/ksh93/data/options.c:
- Add new SH_NOBACKSLCTRL/"nobackslashctrl" long-form option. The
  "no" prefix shows it to the user as "backslashctrl" which is on
  by default. This avoids unexpectedly changing historic behaviour.

src/cmd/ksh93/edit/emacs.c: ed_emacsread(),
src/cmd/ksh93/edit/vi.c: getline():
- Only set the flag for special backslash handling if
  SH_NOBACKSLCTRL is off.

src/cmd/ksh93/sh.1,
src/cmd/ksh93/data/builtins.c:
- Document the new option (as "backslashctrl", on by default).

Other minor tweaks:

src/cmd/ksh93/edit/edit.c:
- ed_setup(): Add fallback #error if no tput method is set. This
  should never be triggered; it's to catch future editing mistakes.
- escape(): cntl('\t') is nonsense as '\t' is already a control
  character, so change this to just '\t'.
- xcommands(): Let's enable the ^X^D command for debugging
  information on non-release builds.

src/cmd/ksh93/features/cmds:
- The tput feature tests assumed a functioning terminal in $TERM.
  However, for all we know we might be compiling with no tty and
  TERM=dumb. The tput commands won't work then. So set TERM=ansi
  to use a standard default.
This commit is contained in:
Martijn Dekker 2021-02-16 00:07:03 +00:00
parent 786a549e49
commit 24598fed7c
10 changed files with 51 additions and 7 deletions

View file

@ -4964,7 +4964,9 @@ Multiply parameter of next command by 4.
.PP
.TP 10
.BI \e
Escape next character.
If the
.B backslashctrl
shell option is on (which is the default setting), this escapes the next character.
Editing characters, the user's erase, kill and
interrupt (normally
.BR ^? )
@ -4976,6 +4978,9 @@ The
.B \e
removes the next character's
editing features (if any).
See also
.I lnext
which is not subject to any shell option.
.PP
.TP 10
.B M-^V
@ -5074,7 +5079,9 @@ On some systems the \f3viraw\fP option
may be required for this to work.
.TP 10
.BI \e
Escape the next
If the
.B backslashctrl
shell option is on (which is the default setting), this escapes the next
.I erase
or
.I kill
@ -7004,6 +7011,20 @@ The following argument can be one of the following option names:
Same as
.BR \-a .
.TP 8
.B backslashctrl
The backslash character
.B \\\\
escapes the next control character in the
.B emacs
built-in editor and the next
.I erase
or
.I kill
character in the
.B vi
built-in editor.
On by default.
.TP 8
.B bgnice
All background jobs are run at a lower priority.
This is the default mode.