Let parser::set_var_and_fire fire the event directly

The vector here gives us *nothing*
This commit is contained in:
Fabian Homborg 2021-10-26 17:03:45 +02:00
parent d9f094db1a
commit da201ee8ac
3 changed files with 17 additions and 4 deletions

View file

@ -517,6 +517,16 @@ event_t event_t::variable(wcstring name, wcstring_list_t args) {
return evt; return evt;
} }
// static
event_t event_t::variable_erase(wcstring name) {
return event_t::variable(name, {L"VARIABLE", L"ERASE", name});
}
// static
event_t event_t::variable_set(wcstring name) {
return event_t::variable(name, {L"VARIABLE", L"SET", name});
}
// static // static
event_t event_t::process_exit(pid_t pid, int status) { event_t event_t::process_exit(pid_t pid, int status) {
event_t evt{event_type_t::process_exit}; event_t evt{event_type_t::process_exit};

View file

@ -107,6 +107,10 @@ struct event_t {
/// Create an event_type_t::variable event. /// Create an event_type_t::variable event.
static event_t variable(wcstring name, wcstring_list_t args); static event_t variable(wcstring name, wcstring_list_t args);
/// Create an event_type_t::variable event with the args for erasing a variable.
static event_t variable_erase(wcstring name);
/// Create an event_type_t::variable event with the args for setting a variable.
static event_t variable_set(wcstring name);
/// Create a PROCESS_EXIT event. /// Create a PROCESS_EXIT event.
static event_t process_exit(pid_t pid, int status); static event_t process_exit(pid_t pid, int status);

View file

@ -102,10 +102,9 @@ parser_t &parser_t::principal_parser() {
} }
int parser_t::set_var_and_fire(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals) { int parser_t::set_var_and_fire(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals) {
std::vector<event_t> events; int res = vars().set(key, mode, std::move(vals), nullptr);
int res = vars().set(key, mode, std::move(vals), &events); if (res == ENV_OK) {
for (const auto &evt : events) { event_fire(*this, event_t::variable_set(key));
event_fire(*this, evt);
} }
return res; return res;
} }