diff --git a/.gitignore b/.gitignore index a0006af1..3c70d1b9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,7 @@ .vimspector.json .vs .vscode -:w -:wq +:* Testing bin bin_32 @@ -24,8 +23,8 @@ debug debug_cov debugvs debugvs32 -is_initialized log +manifests release release_32 release_64 @@ -36,5 +35,4 @@ tmp venv w winget -manifests wingetcreate.exe diff --git a/src/bind/mode/change_mode.cpp b/src/bind/mode/change_mode.cpp index 28603822..a650d21c 100644 --- a/src/bind/mode/change_mode.cpp +++ b/src/bind/mode/change_mode.cpp @@ -37,7 +37,7 @@ namespace vind } auto& ac = core::AutoCmd::get_instance() ; - ac.apply_autocmds(core::get_leave_event(m)) ; + ac.apply(core::get_leave_event(m)) ; if(m == Mode::GUI_VISUAL) { util::click(KEYCODE_MOUSE_LEFT) ; //release holding mouse @@ -57,7 +57,7 @@ namespace vind opt::VCmdLine::print(opt::GeneralMessage("-- GUI NORMAL --")) ; } - ac.apply_autocmds(core::get_enter_event(Mode::GUI_NORMAL)) ; + ac.apply(core::get_enter_event(Mode::GUI_NORMAL)) ; } //ToResident @@ -70,7 +70,7 @@ namespace vind bool vclmodeout) { auto& igate = core::InputGate::get_instance() ; auto& ac = core::AutoCmd::get_instance() ; - ac.apply_autocmds(core::get_leave_event(core::get_global_mode())) ; + ac.apply(core::get_leave_event(core::get_global_mode())) ; igate.close_all_ports() ; igate.unabsorb() ; @@ -79,7 +79,7 @@ namespace vind opt::VCmdLine::print(opt::GeneralMessage("-- RESIDENT --")) ; } - ac.apply_autocmds(core::get_enter_event(core::Mode::RESIDENT)) ; + ac.apply(core::get_enter_event(core::Mode::RESIDENT)) ; } //ToGUIVisual @@ -91,7 +91,7 @@ namespace vind const std::string& UNUSED(args), bool vclmodeout) { auto& ac = core::AutoCmd::get_instance() ; - ac.apply_autocmds(core::get_leave_event(core::get_global_mode())) ; + ac.apply(core::get_leave_event(core::get_global_mode())) ; core::set_global_mode(core::Mode::GUI_VISUAL) ; if(vclmodeout) { @@ -99,7 +99,7 @@ namespace vind } util::press_mousestate(KEYCODE_MOUSE_LEFT) ; - ac.apply_autocmds(core::get_enter_event(core::Mode::GUI_VISUAL)) ; + ac.apply(core::get_enter_event(core::Mode::GUI_VISUAL)) ; } // All instances share TextAreaScanner to keep staticity of sprocess. @@ -123,7 +123,7 @@ namespace vind } auto& ac = core::AutoCmd::get_instance() ; - ac.apply_autocmds(core::get_leave_event(mode)) ; + ac.apply(core::get_leave_event(mode)) ; if(mode == Mode::GUI_NORMAL) { util::click(KEYCODE_MOUSE_LEFT) ; @@ -149,7 +149,7 @@ namespace vind } } - ac.apply_autocmds(core::get_enter_event(Mode::EDI_NORMAL)) ; + ac.apply(core::get_enter_event(Mode::EDI_NORMAL)) ; } //ToInsert @@ -165,7 +165,7 @@ namespace vind auto m = core::get_global_mode() ; auto& ac = core::AutoCmd::get_instance() ; - ac.apply_autocmds(core::get_leave_event(m)) ; + ac.apply(core::get_leave_event(m)) ; if(m == Mode::GUI_NORMAL) { util::click(KEYCODE_MOUSE_LEFT) ; @@ -181,7 +181,7 @@ namespace vind opt::VCmdLine::print(opt::GeneralMessage("-- INSERT --")) ; } - ac.apply_autocmds(core::get_enter_event(Mode::INSERT)) ; + ac.apply(core::get_enter_event(Mode::INSERT)) ; } //ToEdiVisual @@ -193,7 +193,7 @@ namespace vind const std::string& UNUSED(args), bool vclmodeout) { auto& ac = core::AutoCmd::get_instance() ; - ac.apply_autocmds(core::get_leave_event(core::get_global_mode())) ; + ac.apply(core::get_leave_event(core::get_global_mode())) ; select_words() ; core::set_global_mode(core::Mode::EDI_VISUAL) ; @@ -201,7 +201,7 @@ namespace vind opt::VCmdLine::print(opt::GeneralMessage("-- EDI VISUAL --")) ; } - ac.apply_autocmds(core::get_enter_event(core::Mode::EDI_VISUAL)) ; + ac.apply(core::get_enter_event(core::Mode::EDI_VISUAL)) ; } //ToEdiVisualLine @@ -213,7 +213,7 @@ namespace vind const std::string& UNUSED(args), bool vclmodeout) { auto& ac = core::AutoCmd::get_instance() ; - ac.apply_autocmds(core::get_leave_event(core::get_global_mode())) ; + ac.apply(core::get_leave_event(core::get_global_mode())) ; select_line_EOL2BOL() ; core::set_global_mode( @@ -222,7 +222,7 @@ namespace vind opt::VCmdLine::print(opt::GeneralMessage("-- EDI VISUAL LINE--")) ; } - ac.apply_autocmds(core::get_enter_event(core::Mode::EDI_VISUAL)) ; + ac.apply(core::get_enter_event(core::Mode::EDI_VISUAL)) ; } } } diff --git a/src/bind/mode/command_mode.cpp b/src/bind/mode/command_mode.cpp index 06cd4e30..b7e56aec 100644 --- a/src/bind/mode/command_mode.cpp +++ b/src/bind/mode/command_mode.cpp @@ -233,12 +233,12 @@ namespace vind // If the mode is changed, then do nothing. if(core::get_global_mode() == core::Mode::COMMAND) { core::set_global_mode(*m) ; - core::AutoCmd::get_instance().apply_autocmds( + core::AutoCmd::get_instance().apply( core::get_leave_event(core::Mode::COMMAND)) ; } } ; auto m = core::get_global_mode() ; - ac.apply_autocmds(core::get_leave_event(m)) ; + ac.apply(core::get_leave_event(m)) ; std::unique_ptr mode_preserver(new core::Mode(m), return_mode) ; @@ -254,7 +254,7 @@ namespace vind pimpl->hist_idx_ = static_cast(pimpl->hists_.size() - 1) ; auto result = SystemCall::SUCCEEDED ; - ac.apply_autocmds(core::get_enter_event(core::Mode::COMMAND)) ; + ac.apply(core::get_enter_event(core::Mode::COMMAND)) ; while(true) { pimpl->bg_.update() ; diff --git a/src/bind/mode/instant_mode.cpp b/src/bind/mode/instant_mode.cpp index 9d972010..c8f42faf 100644 --- a/src/bind/mode/instant_mode.cpp +++ b/src/bind/mode/instant_mode.cpp @@ -52,8 +52,8 @@ namespace vind auto& ac = core::AutoCmd::get_instance() ; auto m = core::get_global_mode() ; - ac.apply_autocmds(core::get_leave_event(m)) ; - ac.apply_autocmds(core::get_enter_event(core::Mode::GUI_NORMAL)) ; + ac.apply(core::get_leave_event(m)) ; + ac.apply(core::get_enter_event(core::Mode::GUI_NORMAL)) ; core::InputGate::get_instance().close_all_ports_with_refresh() ; core::InstantKeyAbsorber isa{} ; @@ -83,7 +83,7 @@ namespace vind break ; } opt::VCmdLine::reset() ; - ac.apply_autocmds(core::get_enter_event(m)) ; + ac.apply(core::get_enter_event(m)) ; return res ; } diff --git a/src/bind/syscmd/autocmd.cpp b/src/bind/syscmd/autocmd.cpp index 18a6e02e..218a574b 100644 --- a/src/bind/syscmd/autocmd.cpp +++ b/src/bind/syscmd/autocmd.cpp @@ -6,6 +6,7 @@ #include "opt/vcmdline.hpp" #include "util/debug.hpp" #include "util/def.hpp" +#include "util/string.hpp" #include @@ -26,14 +27,19 @@ namespace vind auto [event_str, patcmd] = core::extract_double_args(pargs) ; auto [aupat, cmd] = core::extract_double_args(patcmd) ; - auto event = core::get_autocmd_event(event_str) ; - if(event == core::AutoCmdEvent::UNDEFINED) { - opt::VCmdLine::print( - opt::ErrorMessage("E: Not supported event name")) ; + std::vector events ; + for(const auto& event_str_part : util::split(event_str, ",")) { + auto event = core::get_autocmd_event(event_str_part) ; + if(event == core::AutoCmdEvent::UNDEFINED) { + opt::VCmdLine::print( + opt::ErrorMessage("E: Not supported event name")) ; - core::Logger::get_instance().error( - event_str + " is an unsupported event name.") ; - return ; + core::Logger::get_instance().error( + event_str + " is an unsupported event name.") ; + return ; + } + + events.push_back(event) ; } if(aupat.empty()) { @@ -56,7 +62,9 @@ namespace vind return ; } - core::AutoCmd::get_instance().add_autocmd(event, aupat, cmd) ; + for(const auto event : events) { + core::AutoCmd::get_instance().add(event, aupat, cmd) ; + } } AutoCmdRemove::AutoCmdRemove() @@ -82,29 +90,40 @@ namespace vind return ; } - ac.remove_autocmd(aupat) ; + ac.remove(aupat) ; return ; } - auto event = core::get_autocmd_event(event_str) ; - if(event == core::AutoCmdEvent::UNDEFINED) { - opt::VCmdLine::print( - opt::ErrorMessage("E: Not supported event name")) ; + std::vector events ; + for(const auto& event_str_part : util::split(event_str, ",")) { + auto event = core::get_autocmd_event(event_str_part) ; + if(event == core::AutoCmdEvent::UNDEFINED) { + opt::VCmdLine::print( + opt::ErrorMessage("E: Not supported event name")) ; - core::Logger::get_instance().error( - event_str + " is an unsupported event name.") ; - return ; + core::Logger::get_instance().error( + event_str + " is an unsupported event name.") ; + return ; + } + events.push_back(event) ; } if(aupat.empty()) { - ac.remove_autocmd(event) ; + for(const auto event : events) { + ac.remove(event) ; + } return ; } if(cmd.empty()) { - ac.remove_autocmd(event, aupat) ; + for(const auto event : events) { + ac.remove(event, aupat) ; + } return ; } - ac.remove_autocmd(event, aupat, cmd) ; + + for(const auto event : events) { + ac.remove_and_add(event, aupat, cmd) ; + } } } } diff --git a/src/core/autocmd.cpp b/src/core/autocmd.cpp index c270725f..12088fdc 100644 --- a/src/core/autocmd.cpp +++ b/src/core/autocmd.cpp @@ -119,34 +119,6 @@ namespace seqcmds_.erase(seqcmds_.begin() + idx) ; } - template - void remove_pattern_cmd(T1&& pat, T2&& cmd) { - auto idx = get_pat_index(pat) ; - if(idx < 0) { - return ; - } - - auto& cmds = seqcmds_[idx] ; - - for(std::size_t i = 0 ; i < cmds.size() ; i ++) { - if(cmds[i].size() != cmd.size()) { - continue ; - } - - bool is_same = true ; - for(std::size_t j = 0 ; j < cmd.size() ; j ++) { - if(*(cmds[i][j]) != *(cmd[j])) { - is_same = false ; - break ; - } - } - if(is_same) { - cmds.erase(cmds.begin() + i) ; - return ; - } - } - } - void match_pattern(const std::string& query, std::unordered_set& indices) { for(std::size_t i = 0 ; i < pats_.size() ; i ++) { if(pats_[i].match(query)) { @@ -227,7 +199,7 @@ namespace vind return instance ; } - void AutoCmd::apply_autocmds(AutoCmdEvent event, DWORD procid) { + void AutoCmd::apply(AutoCmdEvent event, DWORD procid) { if(event == AutoCmdEvent::UNDEFINED) { return ; } @@ -306,7 +278,7 @@ namespace vind } } - void AutoCmd::add_autocmd( + void AutoCmd::add( AutoCmdEvent event, const std::string& pattern, const std::string& cmdstr) { @@ -327,32 +299,28 @@ namespace vind evt.add_pattern_cmd(util::A2a(pattern), std::move(cmd)) ; } - void AutoCmd::remove_autocmd(AutoCmdEvent event) { + void AutoCmd::remove(AutoCmdEvent event) { pimpl->events_[static_cast(event)].clear() ; } - void AutoCmd::remove_autocmd( - AutoCmdEvent event, - const std::string& pattern) { + void AutoCmd::remove( + AutoCmdEvent event, + const std::string& pattern) { pimpl->events_[static_cast(event)].remove_pattern(pattern) ; } - void AutoCmd::remove_autocmd(const std::string& pattern) { + void AutoCmd::remove(const std::string& pattern) { for(std::size_t i = 0 ; i < pimpl->events_.size() ; i ++) { pimpl->events_[i].remove_pattern(pattern) ; } } - void AutoCmd::remove_autocmd( - AutoCmdEvent event, - const std::string& pattern, - const std::string& cmdstr) { - - auto cmd = parse_command(cmdstr) ; - if(cmd.empty()) { - return ; - } - pimpl->events_[static_cast(event)].remove_pattern_cmd(pattern, cmd) ; + void AutoCmd::remove_and_add( + AutoCmdEvent event, + const std::string& pattern, + const std::string& cmdstr) { + remove(event, pattern) ; + add(event, pattern, cmdstr) ; } } } diff --git a/src/core/autocmd.hpp b/src/core/autocmd.hpp index 555453f0..8c6f1982 100644 --- a/src/core/autocmd.hpp +++ b/src/core/autocmd.hpp @@ -84,22 +84,22 @@ namespace vind // Perform command automation. // First argument: the event type // Second argument: target window handle, which has default HWND. - void apply_autocmds(AutoCmdEvent event, DWORD procid=0) ; + void apply(AutoCmdEvent event, DWORD procid=0) ; - void add_autocmd( + void add( AutoCmdEvent event, const std::string& pattern, const std::string& cmd) ; - void remove_autocmd(AutoCmdEvent event) ; + void remove(AutoCmdEvent event) ; - void remove_autocmd( + void remove( AutoCmdEvent event, const std::string& pattern) ; - void remove_autocmd(const std::string& pattern) ; + void remove(const std::string& pattern) ; - void remove_autocmd( + void remove_and_add( AutoCmdEvent event, const std::string& pattern, const std::string& cmd) ; diff --git a/src/core/entry.cpp b/src/core/entry.cpp index c481a3d6..c46e8ff9 100644 --- a/src/core/entry.cpp +++ b/src/core/entry.cpp @@ -323,9 +323,9 @@ namespace vind DWORD procid ; if(hwnd && GetWindowThreadProcessId(hwnd, &procid)) { if(pimpl->previous_procid_ != procid) { - ac.apply_autocmds(AutoCmdEvent::APP_LEAVE, pimpl->previous_procid_) ; + ac.apply(AutoCmdEvent::APP_LEAVE, pimpl->previous_procid_) ; pimpl->previous_procid_ = procid ; - ac.apply_autocmds(AutoCmdEvent::APP_ENTER, procid) ; + ac.apply(AutoCmdEvent::APP_ENTER, procid) ; } }