summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt11
-rw-r--r--runtime/doc/usr_41.txt2
-rw-r--r--src/edit.c2
-rw-r--r--src/evalfunc.c32
-rw-r--r--src/fileio.c2
-rw-r--r--src/getchar.c6
-rw-r--r--src/globals.h4
-rw-r--r--src/message.c8
-rw-r--r--src/normal.c6
-rw-r--r--src/ops.c8
-rw-r--r--src/screen.c8
-rw-r--r--src/testdir/test_functions.vim25
-rw-r--r--src/version.c2
13 files changed, 94 insertions, 22 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index de4bb0260d..905074c8b9 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2302,6 +2302,8 @@ range({expr} [, {max} [, {stride}]])
List items from {expr} to {max}
readfile({fname} [, {binary} [, {max}]])
List get list of lines from file {fname}
+reg_executing() Number get the executing register name
+reg_recording() String get the recording register name
reltime([{start} [, {end}]]) List get time value
reltimefloat({time}) Float turn the time value into a Float
reltimestr({time}) String turn time value into a String
@@ -6558,6 +6560,15 @@ readfile({fname} [, {binary} [, {max}]])
the result is an empty list.
Also see |writefile()|.
+reg_executing() *reg_executing()*
+ Returns the single letter name of the register being executed.
+ Returns an empty string when no register is being executed.
+ See |@|.
+
+reg_recording() *reg_recording()*
+ Returns the single letter name of the register being recorded.
+ Returns an empty string string when not recording. See |q|.
+
reltime([{start} [, {end}]]) *reltime()*
Return an item that represents a time value. The format of
the item depends on the system. It can be passed to
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index 279dd20c7b..f891f441cf 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -1018,6 +1018,8 @@ Various: *various-functions*
getreg() get contents of a register
getregtype() get type of a register
setreg() set contents and type of a register
+ reg_executing() return the name of the register being executed
+ reg_recording() return the name of the register being recorded
shiftwidth() effective value of 'shiftwidth'
diff --git a/src/edit.c b/src/edit.c
index ef4c98d29b..1ae8e2db44 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -8698,7 +8698,7 @@ ins_esc(
* When recording or for CTRL-O, need to display the new mode.
* Otherwise remove the mode message.
*/
- if (Recording || restart_edit != NUL)
+ if (reg_recording != 0 || restart_edit != NUL)
showmode();
else if (p_smd)
MSG("");
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 46e55b3fd2..90aa2efd50 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -306,6 +306,8 @@ static void f_pyxeval(typval_T *argvars, typval_T *rettv);
#endif
static void f_range(typval_T *argvars, typval_T *rettv);
static void f_readfile(typval_T *argvars, typval_T *rettv);
+static void f_reg_executing(typval_T *argvars, typval_T *rettv);
+static void f_reg_recording(typval_T *argvars, typval_T *rettv);
static void f_reltime(typval_T *argvars, typval_T *rettv);
#ifdef FEAT_FLOAT
static void f_reltimefloat(typval_T *argvars, typval_T *rettv);
@@ -754,6 +756,8 @@ static struct fst
#endif
{"range", 1, 3, f_range},
{"readfile", 1, 3, f_readfile},
+ {"reg_executing", 0, 0, f_reg_executing},
+ {"reg_recording", 0, 0, f_reg_recording},
{"reltime", 0, 2, f_reltime},
#ifdef FEAT_FLOAT
{"reltimefloat", 1, 1, f_reltimefloat},
@@ -8697,6 +8701,34 @@ f_readfile(typval_T *argvars, typval_T *rettv)
fclose(fd);
}
+ static void
+return_register(int regname, typval_T *rettv)
+{
+ char_u buf[2] = {0, 0};
+
+ buf[0] = (char_u)regname;
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = vim_strsave(buf);
+}
+
+/*
+ * "reg_executing()" function
+ */
+ static void
+f_reg_executing(typval_T *argvars UNUSED, typval_T *rettv)
+{
+ return_register(reg_executing, rettv);
+}
+
+/*
+ * "reg_recording()" function
+ */
+ static void
+f_reg_recording(typval_T *argvars UNUSED, typval_T *rettv)
+{
+ return_register(reg_recording, rettv);
+}
+
#if defined(FEAT_RELTIME)
static int list2proftime(typval_T *arg, proftime_T *tm);
diff --git a/src/fileio.c b/src/fileio.c
index d34605ca78..428e408249 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -9274,7 +9274,7 @@ trigger_cursorhold(void)
if (!did_cursorhold
&& has_cursorhold()
- && !Recording
+ && reg_recording == 0
&& typebuf.tb_len == 0
#ifdef FEAT_INS_EXPAND
&& !ins_compl_active()
diff --git a/src/getchar.c b/src/getchar.c
index 1f7c7d1be6..ddb23dd5c1 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -1244,7 +1244,7 @@ gotchars(char_u *chars, int len)
int todo = len;
/* remember how many chars were last recorded */
- if (Recording)
+ if (reg_recording != 0)
last_recorded_len += len;
buf[1] = NUL;
@@ -1254,7 +1254,7 @@ gotchars(char_u *chars, int len)
c = *s++;
updatescript(c);
- if (Recording)
+ if (reg_recording != 0)
{
buf[0] = c;
add_buff(&recordbuff, buf, 1L);
@@ -2007,7 +2007,7 @@ vgetorpeek(int advance)
init_typebuf();
start_stuff();
if (advance && typebuf.tb_maplen == 0)
- Exec_reg = FALSE;
+ reg_executing = 0;
do
{
/*
diff --git a/src/globals.h b/src/globals.h
index d5320d7272..22199c90a6 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -933,8 +933,8 @@ EXTERN long opcount INIT(= 0); /* count for pending operator */
EXTERN int exmode_active INIT(= 0); /* zero, EXMODE_NORMAL or EXMODE_VIM */
EXTERN int ex_no_reprint INIT(= FALSE); /* no need to print after z or p */
-EXTERN int Recording INIT(= FALSE); /* TRUE when recording into a reg. */
-EXTERN int Exec_reg INIT(= FALSE); /* TRUE when executing a register */
+EXTERN int reg_recording INIT(= 0); /* register for recording or zero */
+EXTERN int reg_executing INIT(= 0); /* register being executed or zero */
EXTERN int no_mapping INIT(= FALSE); /* currently no mapping allowed */
EXTERN int no_zero_mapping INIT(= 0); /* mapping zero not allowed */
diff --git a/src/message.c b/src/message.c
index f9ae0e91f0..9384aa6233 100644
--- a/src/message.c
+++ b/src/message.c
@@ -1025,7 +1025,7 @@ wait_return(int redraw)
int oldState;
int tmpState;
int had_got_int;
- int save_Recording;
+ int save_reg_recording;
FILE *save_scriptout;
if (redraw == TRUE)
@@ -1103,16 +1103,16 @@ wait_return(int redraw)
/* Temporarily disable Recording. If Recording is active, the
* character will be recorded later, since it will be added to the
* typebuf after the loop */
- save_Recording = Recording;
+ save_reg_recording = reg_recording;
save_scriptout = scriptout;
- Recording = FALSE;
+ reg_recording = 0;
scriptout = NULL;
c = safe_vgetc();
if (had_got_int && !global_busy)
got_int = FALSE;
--no_mapping;
--allow_keys;
- Recording = save_Recording;
+ reg_recording = save_reg_recording;
scriptout = save_scriptout;
#ifdef FEAT_CLIPBOARD
diff --git a/src/normal.c b/src/normal.c
index 3b958a5b59..58f7a7a965 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -871,8 +871,8 @@ getcount:
|| (nv_cmds[idx].cmd_flags & NV_NCH_ALW) == NV_NCH_ALW
|| (ca.cmdchar == 'q'
&& oap->op_type == OP_NOP
- && !Recording
- && !Exec_reg)
+ && reg_recording == 0
+ && reg_executing == 0)
|| ((ca.cmdchar == 'a' || ca.cmdchar == 'i')
&& (oap->op_type != OP_NOP || VIsual_active))))
{
@@ -9324,7 +9324,7 @@ nv_record(cmdarg_T *cap)
#endif
/* (stop) recording into a named register, unless executing a
* register */
- if (!Exec_reg && do_record(cap->nchar) == FAIL)
+ if (reg_executing == 0 && do_record(cap->nchar) == FAIL)
clearopbeep(cap->oap);
}
}
diff --git a/src/ops.c b/src/ops.c
index 9af466b3f3..1bc51d8480 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -1091,14 +1091,14 @@ do_record(int c)
yankreg_T *old_y_previous, *old_y_current;
int retval;
- if (Recording == FALSE) /* start recording */
+ if (reg_recording == 0) /* start recording */
{
/* registers 0-9, a-z and " are allowed */
if (c < 0 || (!ASCII_ISALNUM(c) && c != '"'))
retval = FAIL;
else
{
- Recording = c;
+ reg_recording = c;
showmode();
regname = c;
retval = OK;
@@ -1111,7 +1111,7 @@ do_record(int c)
* needs to be removed again to put it in a register. exec_reg then
* adds the escaping back later.
*/
- Recording = FALSE;
+ reg_recording = 0;
MSG("");
p = get_recorded();
if (p == NULL)
@@ -1318,7 +1318,7 @@ do_execreg(
== FAIL)
return FAIL;
}
- Exec_reg = TRUE; /* disable the 'q' command */
+ reg_executing = regname == 0 ? '"' : regname; // disable "q" command
}
return retval;
}
diff --git a/src/screen.c b/src/screen.c
index e26bb44ee2..f2c58bee78 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -10255,7 +10255,7 @@ showmode(void)
&& ((State & INSERT)
|| restart_edit
|| VIsual_active));
- if (do_mode || Recording)
+ if (do_mode || reg_recording != 0)
{
/*
* Don't show mode right now, when not redrawing or inside a mapping.
@@ -10414,7 +10414,7 @@ showmode(void)
need_clear = TRUE;
}
- if (Recording
+ if (reg_recording != 0
#ifdef FEAT_INS_EXPAND
&& edit_submode == NULL /* otherwise it gets too long */
#endif
@@ -10489,7 +10489,7 @@ clearmode(void)
int save_msg_col = msg_col;
msg_pos_mode();
- if (Recording)
+ if (reg_recording != 0)
recording_mode(HL_ATTR(HLF_CM));
msg_clr_eos();
@@ -10504,7 +10504,7 @@ recording_mode(int attr)
if (!shortmess(SHM_RECORDING))
{
char_u s[4];
- sprintf((char *)s, " @%c", Recording);
+ sprintf((char *)s, " @%c", reg_recording);
MSG_PUTS_ATTR(s, attr);
}
}
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index 97e7e234ad..b76bc78e79 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -923,3 +923,28 @@ func Test_trim()
let chars = join(map(range(1, 0x20) + [0xa0], {n -> nr2char(n)}), '')
call assert_equal("x", trim(chars . "x" . chars))
endfunc
+
+" Test for reg_recording() and reg_executing()
+func Test_reg_executing_and_recording()
+ let s:reg_stat = ''
+ func s:save_reg_stat()
+ let s:reg_stat = reg_recording() . ':' . reg_executing()
+ return ''
+ endfunc
+
+ new
+ call s:save_reg_stat()
+ call assert_equal(':', s:reg_stat)
+ call feedkeys("qa\"=s:save_reg_stat()\<CR>pq", 'xt')
+ call assert_equal('a:', s:reg_stat)
+ call feedkeys("@a", 'xt')
+ call assert_equal(':a', s:reg_stat)
+ call feedkeys("qb@aq", 'xt')
+ call assert_equal('b:a', s:reg_stat)
+ call feedkeys("q\"\"=s:save_reg_stat()\<CR>pq", 'xt')
+ call assert_equal('":', s:reg_stat)
+
+ bwipe!
+ delfunc s:save_reg_stat
+ unlet s:reg_stat
+endfunc
diff --git a/src/version.c b/src/version.c
index b629933ff4..616a169e59 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 20,
+/**/
19,
/**/
18,