Use InsertChar hook for char insertion, and InsertKey for key press
This commit is contained in:
parent
9521413b62
commit
68a27af56e
|
@ -942,6 +942,8 @@ public:
|
|||
else if ( key == ctrl('u'))
|
||||
context().buffer().commit_undo_group();
|
||||
|
||||
context().hooks().run_hook("InsertKey", key_to_str(key), context());
|
||||
|
||||
if (update_completions)
|
||||
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
|
||||
if (moved)
|
||||
|
@ -986,7 +988,7 @@ private:
|
|||
auto& buffer = m_edition.editor().buffer();
|
||||
for (auto& sel : m_edition.editor().selections())
|
||||
buffer.insert(buffer.iterator_at(sel.last()), str);
|
||||
context().hooks().run_hook("InsertKey", str, context());
|
||||
context().hooks().run_hook("InsertChar", str, context());
|
||||
}
|
||||
|
||||
void prepare(InsertMode mode)
|
||||
|
|
|
@ -18,11 +18,11 @@ hook global WinSetOption filetype=cpp %~
|
|||
addhl -group cpp-highlight regex "^\h*?#.*?(?<!\\)$" 0:macro
|
||||
addhl -group cpp-highlight regex "(?<!')\".*?(?<!\\)(\\\\)*\"" 0:string
|
||||
addhl -group cpp-highlight regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" 0:comment
|
||||
hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } }
|
||||
hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s^\h+<ret>yj<a-h>P } ] # preserve previous line indent
|
||||
hook window InsertKey \n -id cpp-hooks %[ try %[ exec -draft k<a-x><a-k>[{(]\h*$<ret>j<a-gt> ] ] # indent after lines ending with { or (
|
||||
hook window InsertKey \} -id cpp-hooks %[ try %[ exec -draft <a-h><a-k>^\h+\}$<ret>< ] ] # deindent on insert } alone on a line
|
||||
hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s\h+$<ret>d } ] # cleanup trailing white space son previous line
|
||||
hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } } # cleanup trailing whitespaces when exiting insert mode
|
||||
hook window InsertChar \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s^\h+<ret>yj<a-h>P } ] # preserve previous line indent
|
||||
hook window InsertChar \n -id cpp-hooks %[ try %[ exec -draft k<a-x><a-k>[{(]\h*$<ret>j<a-gt> ] ] # indent after lines ending with { or (
|
||||
hook window InsertChar \} -id cpp-hooks %[ try %[ exec -draft <a-h><a-k>^\h+\}$<ret>< ] ] # deindent on insert } alone on a line
|
||||
hook window InsertChar \n -id cpp-hooks %[ try %{ exec -draft k<a-x>s\h+$<ret>d } ] # cleanup trailing white space son previous line
|
||||
~
|
||||
|
||||
hook global WinSetOption filetype=(?!cpp).* %{
|
||||
|
|
Loading…
Reference in New Issue
Block a user