diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 3 | ||||
-rw-r--r-- | src/nvim/ops.c | 23 | ||||
-rw-r--r-- | test/functional/autocmd/recording_spec.lua | 28 |
3 files changed, 46 insertions, 8 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 3df8d5ced4..46d9a3b57a 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -840,6 +840,9 @@ RecordingLeave When a macro stops recording. register. |reg_recorded()| is only updated after this event. + Sets these |v:event| keys: + regcontents + regname *SessionLoadPost* SessionLoadPost After loading the session file created using the |:mksession| command. diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 6c2db1e9ac..013a78bdac 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -915,10 +915,29 @@ int do_record(int c) apply_autocmds(EVENT_RECORDINGENTER, NULL, NULL, false, curbuf); } } 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 // needs to be removed again to put it in a register. exec_reg then // adds the escaping back later. apply_autocmds(EVENT_RECORDINGLEAVE, NULL, NULL, false, curbuf); + restore_v_event(dict, &save_v_event); reg_recorded = reg_recording; reg_recording = 0; if (ui_has(kUIMessages)) { @@ -926,13 +945,9 @@ int do_record(int c) } else { msg(""); } - p = get_recorded(); if (p == NULL) { retval = FAIL; } 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 // restore the current register name. old_y_previous = y_previous; diff --git a/test/functional/autocmd/recording_spec.lua b/test/functional/autocmd/recording_spec.lua index 81152758de..b9aec774f1 100644 --- a/test/functional/autocmd/recording_spec.lua +++ b/test/functional/autocmd/recording_spec.lua @@ -11,7 +11,7 @@ describe('RecordingEnter', function() source_vim [[ let g:recorded = 0 autocmd RecordingEnter * let g:recorded += 1 - execute "normal! qqyyq" + call feedkeys("qqyyq", 'xt') ]] eq(1, eval('g:recorded')) end) @@ -20,7 +20,7 @@ describe('RecordingEnter', function() source_vim [[ let g:recording = '' autocmd RecordingEnter * let g:recording = reg_recording() - execute "normal! qqyyq" + call feedkeys("qqyyq", 'xt') ]] eq('q', eval('g:recording')) end) @@ -32,7 +32,7 @@ describe('RecordingLeave', function() source_vim [[ let g:recorded = 0 autocmd RecordingLeave * let g:recorded += 1 - execute "normal! qqyyq" + call feedkeys("qqyyq", 'xt') ]] eq(1, eval('g:recorded')) end) @@ -43,10 +43,30 @@ describe('RecordingLeave', function() let g:recording = '' autocmd RecordingLeave * let g:recording = reg_recording() autocmd RecordingLeave * let g:recorded = reg_recorded() - execute "normal! qqyyq" + call feedkeys("qqyyq", 'xt') ]] eq('q', eval 'g:recording') eq('', eval 'g:recorded') eq('q', eval 'reg_recorded()') 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) |