mirror of
https://github.com/neovim/neovim.git
synced 2026-07-10 19:39:38 +00:00
Merge pull request #29436 from zeertzjq/vim-9.1.0507
vim-patch:9.1.{0507,0511}: CursorMovedC autocommand
This commit is contained in:
@@ -522,6 +522,14 @@ CursorMoved After the cursor was moved in Normal or Visual
|
||||
Careful: This is triggered very often, don't
|
||||
do anything that the user does not expect or
|
||||
that is slow.
|
||||
*CursorMovedC*
|
||||
CursorMovedC After the cursor was moved in the command
|
||||
line while the text in the command line hasn't
|
||||
changed. Be careful not to mess up the
|
||||
command line, it may cause Vim to lock up.
|
||||
<afile> is set to a single character,
|
||||
indicating the type of command-line.
|
||||
|cmdwin-char|
|
||||
*CursorMovedI*
|
||||
CursorMovedI After the cursor was moved in Insert mode.
|
||||
Not triggered when the popup menu is visible.
|
||||
|
||||
@@ -36,6 +36,7 @@ return {
|
||||
'CursorHold', -- cursor in same position for a while
|
||||
'CursorHoldI', -- idem, in Insert mode
|
||||
'CursorMoved', -- cursor was moved
|
||||
'CursorMovedC', -- cursor was moved in Cmdline mode
|
||||
'CursorMovedI', -- cursor was moved in Insert mode
|
||||
'DiagnosticChanged', -- diagnostics in a buffer were modified
|
||||
'DiffUpdated', -- diffs have been updated
|
||||
|
||||
@@ -1700,19 +1700,33 @@ bool apply_autocmds_group(event_T event, char *fname, char *fname_io, bool force
|
||||
} else {
|
||||
sfname = xstrdup(fname);
|
||||
// Don't try expanding the following events.
|
||||
if (event == EVENT_CMDLINECHANGED || event == EVENT_CMDLINEENTER
|
||||
|| event == EVENT_CMDLINELEAVE || event == EVENT_CMDUNDEFINED
|
||||
|| event == EVENT_CMDWINENTER || event == EVENT_CMDWINLEAVE
|
||||
|| event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
|
||||
|| event == EVENT_DIRCHANGED || event == EVENT_DIRCHANGEDPRE
|
||||
|| event == EVENT_FILETYPE || event == EVENT_FUNCUNDEFINED
|
||||
|| event == EVENT_MENUPOPUP || event == EVENT_MODECHANGED
|
||||
|| event == EVENT_OPTIONSET || event == EVENT_QUICKFIXCMDPOST
|
||||
|| event == EVENT_QUICKFIXCMDPRE || event == EVENT_REMOTEREPLY
|
||||
|| event == EVENT_SIGNAL || event == EVENT_SPELLFILEMISSING
|
||||
|| event == EVENT_SYNTAX || event == EVENT_TABCLOSED
|
||||
|| event == EVENT_USER || event == EVENT_WINCLOSED
|
||||
|| event == EVENT_WINRESIZED || event == EVENT_WINSCROLLED) {
|
||||
if (event == EVENT_CMDLINECHANGED
|
||||
|| event == EVENT_CMDLINEENTER
|
||||
|| event == EVENT_CMDLINELEAVE
|
||||
|| event == EVENT_CMDUNDEFINED
|
||||
|| event == EVENT_CURSORMOVEDC
|
||||
|| event == EVENT_CMDWINENTER
|
||||
|| event == EVENT_CMDWINLEAVE
|
||||
|| event == EVENT_COLORSCHEME
|
||||
|| event == EVENT_COLORSCHEMEPRE
|
||||
|| event == EVENT_DIRCHANGED
|
||||
|| event == EVENT_DIRCHANGEDPRE
|
||||
|| event == EVENT_FILETYPE
|
||||
|| event == EVENT_FUNCUNDEFINED
|
||||
|| event == EVENT_MENUPOPUP
|
||||
|| event == EVENT_MODECHANGED
|
||||
|| event == EVENT_OPTIONSET
|
||||
|| event == EVENT_QUICKFIXCMDPOST
|
||||
|| event == EVENT_QUICKFIXCMDPRE
|
||||
|| event == EVENT_REMOTEREPLY
|
||||
|| event == EVENT_SIGNAL
|
||||
|| event == EVENT_SPELLFILEMISSING
|
||||
|| event == EVENT_SYNTAX
|
||||
|| event == EVENT_TABCLOSED
|
||||
|| event == EVENT_USER
|
||||
|| event == EVENT_WINCLOSED
|
||||
|| event == EVENT_WINRESIZED
|
||||
|| event == EVENT_WINSCROLLED) {
|
||||
fname = xstrdup(fname);
|
||||
autocmd_fname_full = true; // don't expand it later
|
||||
} else {
|
||||
|
||||
@@ -133,7 +133,8 @@ typedef struct {
|
||||
int did_wild_list; // did wild_list() recently
|
||||
int wim_index; // index in wim_flags[]
|
||||
int save_msg_scroll;
|
||||
int save_State; // remember State when called
|
||||
int save_State; // remember State when called
|
||||
int prev_cmdpos;
|
||||
char *save_p_icm;
|
||||
int some_key_typed; // one of the keys was typed
|
||||
// mouse drag and release events are ignored, unless they are
|
||||
@@ -223,6 +224,12 @@ static int cmdpreview_ns = 0;
|
||||
static const char e_active_window_or_buffer_changed_or_deleted[]
|
||||
= N_("E199: Active window or buffer changed or deleted");
|
||||
|
||||
static void trigger_cmd_autocmd(int typechar, event_T evt)
|
||||
{
|
||||
char typestr[2] = { (char)typechar, NUL };
|
||||
apply_autocmds(evt, typestr, typestr, false, curbuf);
|
||||
}
|
||||
|
||||
static void save_viewstate(win_T *wp, viewstate_T *vs)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
@@ -684,6 +691,7 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear
|
||||
.indent = indent,
|
||||
.save_msg_scroll = msg_scroll,
|
||||
.save_State = State,
|
||||
.prev_cmdpos = -1,
|
||||
.ignore_drag_release = true,
|
||||
};
|
||||
CommandLineState *s = &state;
|
||||
@@ -2175,6 +2183,11 @@ static int command_line_handle_key(CommandLineState *s)
|
||||
|
||||
static int command_line_not_changed(CommandLineState *s)
|
||||
{
|
||||
// Trigger CursorMovedC autocommands.
|
||||
if (ccline.cmdpos != s->prev_cmdpos) {
|
||||
trigger_cmd_autocmd(get_cmdline_type(), EVENT_CURSORMOVEDC);
|
||||
s->prev_cmdpos = ccline.cmdpos;
|
||||
}
|
||||
// Incremental searches for "/" and "?":
|
||||
// Enter command_line_not_changed() when a character has been read but the
|
||||
// command line did not change. Then we only search and redraw if something
|
||||
@@ -2649,6 +2662,7 @@ static void do_autocmd_cmdlinechanged(int firstc)
|
||||
|
||||
static int command_line_changed(CommandLineState *s)
|
||||
{
|
||||
s->prev_cmdpos = ccline.cmdpos;
|
||||
// Trigger CmdlineChanged autocommands.
|
||||
do_autocmd_cmdlinechanged(s->firstc > 0 ? s->firstc : '-');
|
||||
|
||||
@@ -4177,6 +4191,7 @@ static int set_cmdline_pos(int pos)
|
||||
} else {
|
||||
new_cmdpos = pos;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -4303,7 +4318,6 @@ static int open_cmdwin(void)
|
||||
win_T *old_curwin = curwin;
|
||||
int i;
|
||||
garray_T winsizes;
|
||||
char typestr[2];
|
||||
int save_restart_edit = restart_edit;
|
||||
int save_State = State;
|
||||
bool save_exmode = exmode_active;
|
||||
@@ -4446,9 +4460,7 @@ static int open_cmdwin(void)
|
||||
cmdwin_result = 0;
|
||||
|
||||
// Trigger CmdwinEnter autocommands.
|
||||
typestr[0] = (char)cmdwin_type;
|
||||
typestr[1] = NUL;
|
||||
apply_autocmds(EVENT_CMDWINENTER, typestr, typestr, false, curbuf);
|
||||
trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER);
|
||||
if (restart_edit != 0) { // autocmd with ":startinsert"
|
||||
stuffcharReadbuff(K_NOP);
|
||||
}
|
||||
@@ -4466,7 +4478,7 @@ static int open_cmdwin(void)
|
||||
const bool save_KeyTyped = KeyTyped;
|
||||
|
||||
// Trigger CmdwinLeave autocommands.
|
||||
apply_autocmds(EVENT_CMDWINLEAVE, typestr, typestr, false, curbuf);
|
||||
trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE);
|
||||
|
||||
// Restore KeyTyped in case it is modified by autocommands
|
||||
KeyTyped = save_KeyTyped;
|
||||
|
||||
@@ -2010,6 +2010,29 @@ func Test_Cmdline()
|
||||
au! CmdlineEnter
|
||||
au! CmdlineLeave
|
||||
let &shellslash = save_shellslash
|
||||
|
||||
au! CursorMovedC : let g:pos += [getcmdpos()]
|
||||
let g:pos = []
|
||||
call feedkeys(":hello\<Left>\<C-R>=''\<CR>\<Left>\<Right>\<Esc>", 'xt')
|
||||
call assert_equal([5, 4, 5], g:pos)
|
||||
let g:pos = []
|
||||
call feedkeys(":12345678\<C-R>=setcmdpos(3)??''\<CR>\<Esc>", 'xt')
|
||||
call assert_equal([3], g:pos)
|
||||
let g:pos = []
|
||||
call feedkeys(":12345678\<C-R>=setcmdpos(3)??''\<CR>\<Left>\<Esc>", 'xt')
|
||||
call assert_equal([3, 2], g:pos)
|
||||
au! CursorMovedC
|
||||
|
||||
" setcmdpos() is no-op inside an autocommand
|
||||
au! CursorMovedC : let g:pos += [getcmdpos()] | call setcmdpos(1)
|
||||
let g:pos = []
|
||||
call feedkeys(":hello\<Left>\<Left>\<Esc>", 'xt')
|
||||
call assert_equal([5, 4], g:pos)
|
||||
au! CursorMovedC
|
||||
|
||||
unlet g:entered
|
||||
unlet g:left
|
||||
unlet g:pos
|
||||
endfunc
|
||||
|
||||
" Test for BufWritePre autocommand that deletes or unloads the buffer.
|
||||
|
||||
Reference in New Issue
Block a user