From 2cfe3cae36cb9054b37a351de0d7b60a0e5bd4ca Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 30 Mar 2017 10:38:56 +0100 Subject: [PATCH] Add an InsertDelete hook --- README.asciidoc | 2 ++ doc/manpages/hooks.asciidoc | 4 ++++ src/commands.cc | 2 +- src/input_handler.cc | 6 ++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.asciidoc b/README.asciidoc index 256c8146..5cf32d7d 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -1415,6 +1415,8 @@ existing hooks are: * `InsertKey`: A key is received in insert mode, the key is used for filtering * `InsertChar`: A character is inserted in insert mode, the character is used for filtering + * `InsertDelete`: A character is deleted in insert mode, the character deleted + by the main selection is used for filtering * `InsertMove`: The cursor moved (without inserting) in insert mode, the key that triggered the move is used for filtering * `WinCreate`: A window was created, the filtering text is the buffer name diff --git a/doc/manpages/hooks.asciidoc b/doc/manpages/hooks.asciidoc index 27639257..d88f52b9 100644 --- a/doc/manpages/hooks.asciidoc +++ b/doc/manpages/hooks.asciidoc @@ -68,6 +68,10 @@ Default hooks a character is received in insert mode, the character is used for filtering +*InsertDelete*:: + a character is deleted in insert mode, the character deleted by + the main selection is used for filtering + *InsertMove*:: the cursor moved (without inserting) in insert mode, the key that triggered the move is used for filtering diff --git a/src/commands.cc b/src/commands.cc index ec8cd6ca..2c21c78d 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -761,7 +761,7 @@ const CommandDesc remove_highlighter_cmd = { static constexpr auto hooks = { "BufCreate", "BufNewFile", "BufOpenFile", "BufClose", "BufWritePost", "BufWritePre", "BufOpenFifo", "BufCloseFifo", "BufReadFifo", "BufSetOption", - "InsertBegin", "InsertChar", "InsertEnd", "InsertIdle", "InsertKey", + "InsertBegin", "InsertChar", "InsertDelete", "InsertEnd", "InsertIdle", "InsertKey", "InsertMove", "InsertCompletionHide", "InsertCompletionShow", "KakBegin", "KakEnd", "FocusIn", "FocusOut", "RuntimeError", "NormalBegin", "NormalEnd", "NormalIdle", "NormalKey", "RawKey", diff --git a/src/input_handler.cc b/src/input_handler.cc index b25e4174..b9a1653c 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1067,8 +1067,14 @@ public: auto pos = sel.cursor(); sels.emplace_back(buffer.char_prev(pos)); } + auto& main = context().selections().main(); + String main_char = buffer.string(buffer.char_prev(main.cursor()), + main.cursor()); if (not sels.empty()) SelectionList{buffer, std::move(sels)}.erase(); + + if (not main_char.empty()) + context().hooks().run_hook("InsertDelete", main_char, context()); } else if (key == Key::Delete) {