aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jan Kanis <jan.code@jankanis.nl>2012-12-20 01:11:55 +0100
committerGravatar Jan Kanis <jan.code@jankanis.nl>2012-12-20 16:13:00 +0100
commitaf3059ab2ad4ccbfec3c0789b198388cc90fbcbb (patch)
tree053a7fd1e81254acfa5406f08976ca5059f152d9
parent1f0ae8b06d7e10d2a12cfd28efb3032af7b4d2f1 (diff)
Allow 'emit' to accept event arguments
-rw-r--r--builtin.cpp10
-rw-r--r--doc_src/emit.txt9
-rw-r--r--event.cpp17
-rw-r--r--event.h4
-rw-r--r--parser.cpp5
-rw-r--r--tests/test9.out2
6 files changed, 19 insertions, 28 deletions
diff --git a/builtin.cpp b/builtin.cpp
index f8eec3f2..a25110f6 100644
--- a/builtin.cpp
+++ b/builtin.cpp
@@ -1010,15 +1010,15 @@ static int builtin_emit(parser_t &parser, wchar_t **argv)
}
- for (; woptind < argc; woptind++)
+ wcstring_list_t args;
+ wchar_t *eventname = argv[woptind];
+ for (woptind++; woptind < argc; woptind++)
{
- event_fire_generic(argv[woptind]);
+ args.push_back(argv[woptind]);
}
+ event_fire_generic(eventname, &args);
return STATUS_BUILTIN_OK;
-
-
-
}
diff --git a/doc_src/emit.txt b/doc_src/emit.txt
index f2821748..c0faab82 100644
--- a/doc_src/emit.txt
+++ b/doc_src/emit.txt
@@ -1,11 +1,11 @@
\section emit emit - Emit a generic event
\subsection block-synopsis Synopsis
- <tt>emit EVENT_NAME</tt>
+ <tt>emit EVENT_NAME [ARGUMENTS...]</tt>
\subsection emit-description Description
-The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers.
+The emit builtin fires a generic fish event. Such events can be caught by special functions called event handlers. The arguments are passed to the event handlers as function arguments.
\subsection emit-example Example
@@ -13,7 +13,8 @@ The following code first defines an event handler for the generic
event named 'test_event', and then emits an event of that type.
<pre>function event_test --on-event test_event
- echo event test!!!
+ echo event test: $argv
end
-emit test_event</pre> \ No newline at end of file
+emit test_event something
+</pre>
diff --git a/event.cpp b/event.cpp
index e4f452e0..8c61ebd0 100644
--- a/event.cpp
+++ b/event.cpp
@@ -689,26 +689,15 @@ void event_free(event_t *e)
delete e;
}
-
-void event_fire_generic_internal(const wchar_t *name, ...)
+void event_fire_generic(const wchar_t *name, wcstring_list_t *args)
{
- va_list va;
- wchar_t *arg;
-
CHECK(name,);
event_t ev(EVENT_GENERIC);
ev.str_param1 = name;
- ev.arguments.reset(new wcstring_list_t);
- va_start(va, name);
- while ((arg=va_arg(va, wchar_t *))!= 0)
- {
- ev.arguments->push_back(arg);
- }
- va_end(va);
-
+ if (args)
+ ev.arguments.reset(new wcstring_list_t(*args));
event_fire(&ev);
- ev.arguments.reset(NULL);
}
event_t event_t::signal_event(int sig)
diff --git a/event.h b/event.h
index 034dafab..56d076be 100644
--- a/event.h
+++ b/event.h
@@ -173,8 +173,6 @@ wcstring event_get_desc(const event_t *e);
/**
Fire a generic event with the specified name
*/
-#define event_fire_generic( ... ) event_fire_generic_internal( __VA_ARGS__, NULL )
-
-void event_fire_generic_internal(const wchar_t *name,...);
+void event_fire_generic(const wchar_t *name, wcstring_list_t *args = NULL);
#endif
diff --git a/parser.cpp b/parser.cpp
index 0f8950f0..f022f3ea 100644
--- a/parser.cpp
+++ b/parser.cpp
@@ -2077,6 +2077,7 @@ int parser_t::parse_job(process_t *p,
int tmp;
const wchar_t *cmd = args.at(0).completion.c_str();
+ wcstring_list_t event_args;
/*
We couldn't find the specified command.
@@ -2157,7 +2158,9 @@ int parser_t::parse_job(process_t *p,
current_tokenizer_pos=tmp;
job_set_flag(j, JOB_SKIP, 1);
- event_fire_generic(L"fish_command_not_found", (wchar_t *)(args.at(0).completion.c_str()));
+
+ event_args.push_back(args.at(0).completion);
+ event_fire_generic(L"fish_command_not_found", &event_args);
proc_set_last_status(err==ENOENT?STATUS_UNKNOWN_COMMAND:STATUS_NOT_EXECUTABLE);
}
}
diff --git a/tests/test9.out b/tests/test9.out
index 863e82f5..779f9a84 100644
--- a/tests/test9.out
+++ b/tests/test9.out
@@ -1,2 +1,2 @@
before:test1
-received event test3 with args:
+received event test3 with args: foo bar