mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(autocmd): populate v:event in RecordingLeave (#16828)
This commit is contained in:
parent
a45b578dbe
commit
f65b0d4236
@ -840,6 +840,9 @@ RecordingLeave When a macro stops recording.
|
|||||||
register.
|
register.
|
||||||
|reg_recorded()| is only updated after this
|
|reg_recorded()| is only updated after this
|
||||||
event.
|
event.
|
||||||
|
Sets these |v:event| keys:
|
||||||
|
regcontents
|
||||||
|
regname
|
||||||
*SessionLoadPost*
|
*SessionLoadPost*
|
||||||
SessionLoadPost After loading the session file created using
|
SessionLoadPost After loading the session file created using
|
||||||
the |:mksession| command.
|
the |:mksession| command.
|
||||||
|
@ -915,10 +915,29 @@ int do_record(int c)
|
|||||||
apply_autocmds(EVENT_RECORDINGENTER, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_RECORDINGENTER, NULL, NULL, false, curbuf);
|
||||||
}
|
}
|
||||||
} else { // stop recording
|
} else { // stop recording
|
||||||
|
save_v_event_T save_v_event;
|
||||||
|
// Set the v:event dictionary with information about the recording.
|
||||||
|
dict_T *dict = get_v_event(&save_v_event);
|
||||||
|
|
||||||
|
// The recorded text contents.
|
||||||
|
p = get_recorded();
|
||||||
|
if (p != NULL) {
|
||||||
|
// Remove escaping for CSI and K_SPECIAL in multi-byte chars.
|
||||||
|
vim_unescape_csi(p);
|
||||||
|
(void)tv_dict_add_str(dict, S_LEN("regcontents"), (const char *)p);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name of requested register, or empty string for unnamed operation.
|
||||||
|
char buf[NUMBUFLEN+2];
|
||||||
|
buf[0] = (char)regname;
|
||||||
|
buf[1] = NUL;
|
||||||
|
(void)tv_dict_add_str(dict, S_LEN("regname"), buf);
|
||||||
|
|
||||||
// Get the recorded key hits. K_SPECIAL and CSI will be escaped, this
|
// Get the recorded key hits. K_SPECIAL and CSI will be escaped, this
|
||||||
// needs to be removed again to put it in a register. exec_reg then
|
// needs to be removed again to put it in a register. exec_reg then
|
||||||
// adds the escaping back later.
|
// adds the escaping back later.
|
||||||
apply_autocmds(EVENT_RECORDINGLEAVE, NULL, NULL, false, curbuf);
|
apply_autocmds(EVENT_RECORDINGLEAVE, NULL, NULL, false, curbuf);
|
||||||
|
restore_v_event(dict, &save_v_event);
|
||||||
reg_recorded = reg_recording;
|
reg_recorded = reg_recording;
|
||||||
reg_recording = 0;
|
reg_recording = 0;
|
||||||
if (ui_has(kUIMessages)) {
|
if (ui_has(kUIMessages)) {
|
||||||
@ -926,13 +945,9 @@ int do_record(int c)
|
|||||||
} else {
|
} else {
|
||||||
msg("");
|
msg("");
|
||||||
}
|
}
|
||||||
p = get_recorded();
|
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
retval = FAIL;
|
retval = FAIL;
|
||||||
} else {
|
} else {
|
||||||
// Remove escaping for CSI and K_SPECIAL in multi-byte chars.
|
|
||||||
vim_unescape_csi(p);
|
|
||||||
|
|
||||||
// We don't want to change the default register here, so save and
|
// We don't want to change the default register here, so save and
|
||||||
// restore the current register name.
|
// restore the current register name.
|
||||||
old_y_previous = y_previous;
|
old_y_previous = y_previous;
|
||||||
|
@ -11,7 +11,7 @@ describe('RecordingEnter', function()
|
|||||||
source_vim [[
|
source_vim [[
|
||||||
let g:recorded = 0
|
let g:recorded = 0
|
||||||
autocmd RecordingEnter * let g:recorded += 1
|
autocmd RecordingEnter * let g:recorded += 1
|
||||||
execute "normal! qqyyq"
|
call feedkeys("qqyyq", 'xt')
|
||||||
]]
|
]]
|
||||||
eq(1, eval('g:recorded'))
|
eq(1, eval('g:recorded'))
|
||||||
end)
|
end)
|
||||||
@ -20,7 +20,7 @@ describe('RecordingEnter', function()
|
|||||||
source_vim [[
|
source_vim [[
|
||||||
let g:recording = ''
|
let g:recording = ''
|
||||||
autocmd RecordingEnter * let g:recording = reg_recording()
|
autocmd RecordingEnter * let g:recording = reg_recording()
|
||||||
execute "normal! qqyyq"
|
call feedkeys("qqyyq", 'xt')
|
||||||
]]
|
]]
|
||||||
eq('q', eval('g:recording'))
|
eq('q', eval('g:recording'))
|
||||||
end)
|
end)
|
||||||
@ -32,7 +32,7 @@ describe('RecordingLeave', function()
|
|||||||
source_vim [[
|
source_vim [[
|
||||||
let g:recorded = 0
|
let g:recorded = 0
|
||||||
autocmd RecordingLeave * let g:recorded += 1
|
autocmd RecordingLeave * let g:recorded += 1
|
||||||
execute "normal! qqyyq"
|
call feedkeys("qqyyq", 'xt')
|
||||||
]]
|
]]
|
||||||
eq(1, eval('g:recorded'))
|
eq(1, eval('g:recorded'))
|
||||||
end)
|
end)
|
||||||
@ -43,10 +43,30 @@ describe('RecordingLeave', function()
|
|||||||
let g:recording = ''
|
let g:recording = ''
|
||||||
autocmd RecordingLeave * let g:recording = reg_recording()
|
autocmd RecordingLeave * let g:recording = reg_recording()
|
||||||
autocmd RecordingLeave * let g:recorded = reg_recorded()
|
autocmd RecordingLeave * let g:recorded = reg_recorded()
|
||||||
execute "normal! qqyyq"
|
call feedkeys("qqyyq", 'xt')
|
||||||
]]
|
]]
|
||||||
eq('q', eval 'g:recording')
|
eq('q', eval 'g:recording')
|
||||||
eq('', eval 'g:recorded')
|
eq('', eval 'g:recorded')
|
||||||
eq('q', eval 'reg_recorded()')
|
eq('q', eval 'reg_recorded()')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('populates v:event', function()
|
||||||
|
source_vim [[
|
||||||
|
let g:regname = ''
|
||||||
|
let g:regcontents = ''
|
||||||
|
autocmd RecordingLeave * let g:regname = v:event.regname
|
||||||
|
autocmd RecordingLeave * let g:regcontents = v:event.regcontents
|
||||||
|
call feedkeys("qqyyq", 'xt')
|
||||||
|
]]
|
||||||
|
eq('q', eval 'g:regname')
|
||||||
|
eq('yy', eval 'g:regcontents')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('resets v:event', function()
|
||||||
|
source_vim [[
|
||||||
|
autocmd RecordingLeave * let g:event = v:event
|
||||||
|
call feedkeys("qqyyq", 'xt')
|
||||||
|
]]
|
||||||
|
eq(0, eval 'len(v:event)')
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user