From 68a27af56ec4d4afb290b32be945297c36050ab7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 4 Nov 2013 18:51:31 +0000 Subject: [PATCH] Use InsertChar hook for char insertion, and InsertKey for key press --- src/client.cc | 4 +++- src/rc/cpp.kak | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/client.cc b/src/client.cc index b2e5a259..5ccba1ee 100644 --- a/src/client.cc +++ b/src/client.cc @@ -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) diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak index 1db0ca5a..ad841cf6 100644 --- a/src/rc/cpp.kak +++ b/src/rc/cpp.kak @@ -18,11 +18,11 @@ hook global WinSetOption filetype=cpp %~ addhl -group cpp-highlight regex "^\h*?#.*?(?s\h+$d } } - hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft ks^\h+yjP } ] # preserve previous line indent - hook window InsertKey \n -id cpp-hooks %[ try %[ exec -draft k[{(]\h*$j ] ] # indent after lines ending with { or ( - hook window InsertKey \} -id cpp-hooks %[ try %[ exec -draft ^\h+\}$< ] ] # deindent on insert } alone on a line - hook window InsertKey \n -id cpp-hooks %[ try %{ exec -draft ks\h+$d } ] # cleanup trailing white space son previous line + hook window InsertEnd .* -id cpp-hooks %{ try %{ exec -draft s\h+$d } } # cleanup trailing whitespaces when exiting insert mode + hook window InsertChar \n -id cpp-hooks %[ try %{ exec -draft ks^\h+yjP } ] # preserve previous line indent + hook window InsertChar \n -id cpp-hooks %[ try %[ exec -draft k[{(]\h*$j ] ] # indent after lines ending with { or ( + hook window InsertChar \} -id cpp-hooks %[ try %[ exec -draft ^\h+\}$< ] ] # deindent on insert } alone on a line + hook window InsertChar \n -id cpp-hooks %[ try %{ exec -draft ks\h+$d } ] # cleanup trailing white space son previous line ~ hook global WinSetOption filetype=(?!cpp).* %{