Download raw body.
New fasttimes option proposal for vi
Hi,
vi currently only has the ability to set timeouts (keytime, matchtime and escapetime)
in tenths of second. This is ok for normal timeouts, but for escaping to normal mode
it is noticeably laggy. Maybe something like a fast escape option is nice to have.
I provide here a sample patch that implements this adding a `fasttimes` option, which
allows for settings of hundreds of a second.
Cheers
Index: common/key.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/common/key.c,v
retrieving revision 1.20
diff -u -p -r1.20 key.c
--- common/key.c 21 Apr 2022 17:50:29 -0000 1.20
+++ common/key.c 3 Nov 2024 10:01:12 -0000
@@ -619,9 +619,10 @@ newmap: evp = &gp->i_event[gp->i_next];
*/
if (ispartial) {
if (O_ISSET(sp, O_TIMEOUT))
- timeout = (evp->e_value == K_ESCAPE ?
- O_VAL(sp, O_ESCAPETIME) :
- O_VAL(sp, O_KEYTIME)) * 100;
+ timeout = (O_VAL(sp, O_FASTTIMES) ? 10 : 100) *
+ (evp->e_value == K_ESCAPE ?
+ O_VAL(sp, O_ESCAPETIME) :
+ O_VAL(sp, O_KEYTIME));
else
timeout = 0;
goto loop;
Index: common/options.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/common/options.c,v
retrieving revision 1.30
diff -u -p -r1.30 options.c
--- common/options.c 12 Feb 2024 16:42:42 -0000 1.30
+++ common/options.c 3 Nov 2024 10:01:12 -0000
@@ -75,6 +75,8 @@ OPTLIST const optlist[] = {
{"exrc", NULL, OPT_0BOOL, 0},
/* O_EXTENDED 4.4BSD */
{"extended", f_recompile, OPT_0BOOL, 0},
+/* O_FASTTIMES */
+ {"fasttimes", f_fasttimes, OPT_0BOOL, 0},
/* O_FILEC 4.4BSD */
{"filec", NULL, OPT_STR, 0},
/* O_FLASH HPUX */
Index: common/options_f.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/common/options_f.c,v
retrieving revision 1.13
diff -u -p -r1.13 options_f.c
--- common/options_f.c 21 May 2019 09:24:58 -0000 1.13
+++ common/options_f.c 3 Nov 2024 10:01:12 -0000
@@ -68,6 +68,30 @@ f_columns(SCR *sp, OPTION *op, char *str
}
/*
+ * PUBLIC: int f_fasttimes(SCR *, OPTION *, char *, u_long *);
+ */
+int
+f_fasttimes(SCR *sp, OPTION *op, char *str, u_long *valp)
+{
+ if (*valp) {
+ o_set(sp, O_ESCAPETIME, 0, NULL,
+ O_VAL(sp, O_ESCAPETIME) * 10);
+ o_set(sp, O_MATCHTIME, 0, NULL,
+ O_VAL(sp, O_MATCHTIME) * 10);
+ o_set(sp, O_KEYTIME, 0, NULL,
+ O_VAL(sp, O_KEYTIME) * 10);
+ } else {
+ o_set(sp, O_ESCAPETIME, 0, NULL,
+ (O_VAL(sp, O_ESCAPETIME) + 9) / 10);
+ o_set(sp, O_MATCHTIME, 0, NULL,
+ (O_VAL(sp, O_MATCHTIME) + 9) / 10);
+ o_set(sp, O_KEYTIME, 0, NULL,
+ (O_VAL(sp, O_KEYTIME) + 9) / 10);
+ }
+ return (0);
+}
+
+/*
* PUBLIC: int f_lines(SCR *, OPTION *, char *, u_long *);
*/
int
Index: docs/help
===================================================================
RCS file: /cvs/src/usr.bin/vi/docs/help,v
retrieving revision 1.8
diff -u -p -r1.8 help
--- docs/help 8 Aug 2016 15:09:33 -0000 1.8
+++ docs/help 3 Nov 2024 10:01:12 -0000
@@ -212,7 +212,7 @@ cedit="" noleftright print=""
columns=80 lines=36 prompt nosourceany wrapmargin=0
comment nolisp readonly tabstop=8 wrapscan
noedcompatible nolist noredraw taglength=0 nowriteany
-escapetime=1 lock remap tags="tags"
+escapetime=1 lock remap tags="tags" fasttimes
noerrorbells magic report=5 term="xterm"
exrc matchtime=7 ruler noterse
noextended mesg scroll=17 notildeop
Index: docs/USD.doc/vi.man/vi.1
===================================================================
RCS file: /cvs/src/usr.bin/vi/docs/USD.doc/vi.man/vi.1,v
retrieving revision 1.85
diff -u -p -r1.85 vi.1
--- docs/USD.doc/vi.man/vi.1 24 Apr 2024 15:15:40 -0000 1.85
+++ docs/USD.doc/vi.man/vi.1 3 Nov 2024 10:01:13 -0000
@@ -2372,6 +2372,13 @@ rather than basic regular expressions
See
.Xr re_format 7
for more information on regular expressions.
+.It Cm fasttimes Bq off
+Change
+.Cm keytime ,
+.Cm escapetime
+and
+.Cm matchtime
+to hundreds of a second instead of tenths.
.It Cm filec Bq Aq tab
Set the character to perform file path completion on the colon command line.
.It Cm flash Bq off
Index: docs/USD.doc/vi.ref/set.opt.roff
===================================================================
RCS file: /cvs/src/usr.bin/vi/docs/USD.doc/vi.ref/set.opt.roff,v
retrieving revision 1.14
diff -u -p -r1.14 set.opt.roff
--- docs/USD.doc/vi.ref/set.opt.roff 25 Apr 2024 05:26:41 -0000 1.14
+++ docs/USD.doc/vi.ref/set.opt.roff 3 Nov 2024 10:01:13 -0000
@@ -479,6 +479,15 @@ the first character of the line,
otherwise,
.CO vi
will perform file name expansion.
+.KY fasttimes
+.IP "fasttimes [off]"
+This option causes
+.OP keytime ,
+.OP matchtime
+and
+.OP escapetime
+to be changed to refer to hundreds of a second instead of the usual tenths.
+When set or unset, the timeouts are also adjusted.
.KY flash
.IP "flash [off]"
This option causes the screen to flash instead of beeping the keyboard,
Index: docs/USD.doc/vi.ref/spell.ok
===================================================================
RCS file: /cvs/src/usr.bin/vi/docs/USD.doc/vi.ref/spell.ok,v
retrieving revision 1.6
diff -u -p -r1.6 spell.ok
--- docs/USD.doc/vi.ref/spell.ok 6 Jan 2016 22:41:53 -0000 1.6
+++ docs/USD.doc/vi.ref/spell.ok 3 Nov 2024 10:01:13 -0000
@@ -163,6 +163,7 @@ exrc
ext
exu
exusage
+fasttimes
fcntl
fg
fi
Index: include/com_extern.h
===================================================================
RCS file: /cvs/src/usr.bin/vi/include/com_extern.h,v
retrieving revision 1.16
diff -u -p -r1.16 com_extern.h
--- include/com_extern.h 21 May 2019 09:24:58 -0000 1.16
+++ include/com_extern.h 3 Nov 2024 10:01:13 -0000
@@ -68,6 +68,7 @@ int opts_copy(SCR *, SCR *);
void opts_free(SCR *);
int f_altwerase(SCR *, OPTION *, char *, u_long *);
int f_columns(SCR *, OPTION *, char *, u_long *);
+int f_fasttimes(SCR *, OPTION *, char *, u_long *);
int f_lines(SCR *, OPTION *, char *, u_long *);
int f_paragraph(SCR *, OPTION *, char *, u_long *);
int f_print(SCR *, OPTION *, char *, u_long *);
Index: vi/v_txt.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/vi/v_txt.c,v
retrieving revision 1.36
diff -u -p -r1.36 v_txt.c
--- vi/v_txt.c 26 Dec 2022 19:16:04 -0000 1.36
+++ vi/v_txt.c 3 Nov 2024 10:01:13 -0000
@@ -2726,8 +2726,9 @@ txt_showmatch(SCR *sp, TEXT *tp)
return (1);
/* Wait for timeout or character arrival. */
- return (v_event_get(sp,
- NULL, O_VAL(sp, O_MATCHTIME) * 100, EC_TIMEOUT));
+ return (v_event_get(sp, NULL,
+ O_VAL(sp, O_MATCHTIME) * (O_VAL(sp, O_FASTTIMES) ? 10 : 100),
+ EC_TIMEOUT));
}
/*
New fasttimes option proposal for vi