* how to make a hook function and call from C?
@ 2008-05-08 20:44 joakim
2008-05-09 1:25 ` Stefan Monnier
2008-05-09 11:13 ` Richard M Stallman
0 siblings, 2 replies; 7+ messages in thread
From: joakim @ 2008-05-08 20:44 UTC (permalink / raw)
To: emacs-devel
I want to call lisp inside a gtk widget signal handler:
------------------------------------------------
xw->widget=GTK_WIDGET(gtk_button_new_with_label ( xw->title));
g_signal_connect (G_OBJECT (xw->widget), "clicked", G_CALLBACK (hello), xw);
...
static void hello( GtkWidget *widget,
gpointer data )
{
printf ("button clicked %d\n",data);
Lisp_Object args[2];
struct xwidget* xw=( struct xwidget*)data;
/* FIXME i have no particular idea how to call lisp yet
args[0] = data->message_hook;
args[1] = arg;
Ffuncall (2, args);
*/
// call0(intern("xwidget-dummy-hook")); //crashes even if fn exists
// call0(intern("beep")); //"beep" seems to not crash and not do anything but "info" crashes
}
-----------------------------------------------
When I click the button, the "hello" function is reached, but
I cant figure out how to call a lisp function.
- Are there any similar examples in the codebase somewhere?
- I would like xw->message_hook to contain a lisp hook, settable from the
lisp level. How do I set this up at the C level?
- Should I use Ffuncall to call my new hook or what?
--
Joakim Verona
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to make a hook function and call from C?
2008-05-08 20:44 how to make a hook function and call from C? joakim
@ 2008-05-09 1:25 ` Stefan Monnier
2008-05-09 15:56 ` joakim
2008-05-09 11:13 ` Richard M Stallman
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2008-05-09 1:25 UTC (permalink / raw)
To: joakim; +Cc: emacs-devel
> I want to call lisp inside a gtk widget signal handler:
> ------------------------------------------------
xw-> widget=GTK_WIDGET(gtk_button_new_with_label ( xw->title));
> g_signal_connect (G_OBJECT (xw->widget), "clicked", G_CALLBACK (hello), xw);
> ...
> static void hello( GtkWidget *widget,
> gpointer data )
> {
> printf ("button clicked %d\n",data);
> Lisp_Object args[2];
> struct xwidget* xw=( struct xwidget*)data;
> /* FIXME i have no particular idea how to call lisp yet
> args[0] = data->message_hook;
> args[1] = arg;
> Ffuncall (2, args);
> */
> // call0(intern("xwidget-dummy-hook")); //crashes even if fn exists
> // call0(intern("beep")); //"beep" seems to not crash and not do anything but "info" crashes
> }
> -----------------------------------------------
> When I click the button, the "hello" function is reached, but
> I cant figure out how to call a lisp function.
> - Are there any similar examples in the codebase somewhere?
> - I would like xw->message_hook to contain a lisp hook, settable from the
> lisp level. How do I set this up at the C level?
> - Should I use Ffuncall to call my new hook or what?
You can't run Elisp code just at any random time. There are times when
it's safe to do so, and other times when it's not. E.g. if the code may
run while in the middle of any other function (including redisplay, for
example), then you cannot safely run Elisp code from it.
If it is safe, you can call Elisp via `call0', `call1', `Ffuncall',
`Feval', `safe_eval', ...
If it is not safe, you can either create a new event, which will then be
handled by the usual event-handling (i.e. like a key press) via keymaps.
Or you can also add it to pending_funcalls.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to make a hook function and call from C?
2008-05-09 1:25 ` Stefan Monnier
@ 2008-05-09 15:56 ` joakim
2008-05-09 17:06 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: joakim @ 2008-05-09 15:56 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> If it is not safe, you can either create a new event, which will then be
> handled by the usual event-handling (i.e. like a key press) via keymaps.
> Or you can also add it to pending_funcalls.
I will admit I'm not too familiar with emacs event code.
This is my current try:
the signal handler for the gtk widget:
static void hello( GtkWidget *widget,
gpointer data )
{
struct xwidget* xw=( struct xwidget*)data;
Lisp_Object frame;
printf ("button clicked xw:%d id:%d\n",xw,xw->id);
struct input_event event;
EVENT_INIT (event);
event.kind = XWIDGET_EVENT;
FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (xw->widget), XG_FRAME_DATA);
XSETFRAME (frame, f);
event.frame_or_window = Qnil;//frame; //how to get the frame here?
event.arg = Qnil; //add some data describing the xwidget
kbd_buffer_store_event (&event);
}
in make_lispy_event()
...
case XWIDGET_EVENT:
printf("cool, an xwidget event arrived in make_lispy_event!\n");
return event->arg;
...
then in my elisp test code after all widgets are setup:
...
(message "event:%s"(read-key-sequence "wait for event"))
The XWIDGET_EVENT arrives in make_lispy_event(), but then my
elisp doesnt trigger.
Any hints of where in the sources to look for example code?
>
>
> Stefan
--
Joakim Verona
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to make a hook function and call from C?
2008-05-09 15:56 ` joakim
@ 2008-05-09 17:06 ` Stefan Monnier
2008-05-09 22:01 ` joakim
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2008-05-09 17:06 UTC (permalink / raw)
To: joakim; +Cc: emacs-devel
> in make_lispy_event()
> ...
> case XWIDGET_EVENT:
> printf("cool, an xwidget event arrived in make_lispy_event!\n");
> return event->arg;
> ...
> then in my elisp test code after all widgets are setup:
> ...
> (message "event:%s"(read-key-sequence "wait for event"))
Maybe the problem is that you use a nil event. Try something else.
Also look at C-h l to see the events received.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to make a hook function and call from C?
2008-05-09 17:06 ` Stefan Monnier
@ 2008-05-09 22:01 ` joakim
0 siblings, 0 replies; 7+ messages in thread
From: joakim @ 2008-05-09 22:01 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> in make_lispy_event()
>> ...
>> case XWIDGET_EVENT:
>> printf("cool, an xwidget event arrived in make_lispy_event!\n");
>> return event->arg;
>> ...
>
>> then in my elisp test code after all widgets are setup:
>> ...
>> (message "event:%s"(read-key-sequence "wait for event"))
>
> Maybe the problem is that you use a nil event. Try something else.
> Also look at C-h l to see the events received.
Thanks, this helped!
Now I'm able to sucessfully bind an event handler to a gtk button press,
and when a gtk socket is ready. I was then able to automaticaly start
an embedded video player in emacs when the socket was ready to receive.
>
>
> Stefan
--
Joakim Verona
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: how to make a hook function and call from C?
2008-05-08 20:44 how to make a hook function and call from C? joakim
2008-05-09 1:25 ` Stefan Monnier
@ 2008-05-09 11:13 ` Richard M Stallman
2008-05-09 14:31 ` Stefan Monnier
1 sibling, 1 reply; 7+ messages in thread
From: Richard M Stallman @ 2008-05-09 11:13 UTC (permalink / raw)
To: joakim; +Cc: emacs-devel
I want to call lisp inside a gtk widget signal handler:
You must not do that. At present, it would cause crashes.
Stefan has a change that would run signal handler code outside signal
handlers. Maybe with that change this would become ok, for some
purposes. But not for a command that is meant to switch buffers, such
as `info'. If that happens in the middle of some other program,
it will confuse that other program.
The right way to do THIS case, at least, is to generate an input
event. Maybe that is the best way to handle all of these callbacks.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-05-09 22:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-08 20:44 how to make a hook function and call from C? joakim
2008-05-09 1:25 ` Stefan Monnier
2008-05-09 15:56 ` joakim
2008-05-09 17:06 ` Stefan Monnier
2008-05-09 22:01 ` joakim
2008-05-09 11:13 ` Richard M Stallman
2008-05-09 14:31 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.