emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to make a hook function and call from C?


From: Stefan Monnier
Subject: Re: how to make a hook function and call from C?
Date: Thu, 08 May 2008 21:25:55 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]