[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Callbacks from modules
From: |
Ivan Andrus |
Subject: |
Re: Callbacks from modules |
Date: |
Thu, 26 Nov 2015 20:23:48 -0700 |
On Nov 26, 2015, at 8:43 AM, Eli Zaretskii <address@hidden> wrote:
>
>> From: Ivan Andrus <address@hidden>
>> Date: Wed, 25 Nov 2015 23:08:48 -0700
>>
>> I’ve started writing an Emacs module to access NSSpeechSynthesizer on OS X
>> (and
>> maybe GNUStep though I haven’t tested it there). I’ve been using the
>> mod-test
>> module as an example and I have it working reasonably well except that I
>> don’t
>> have any idea how to run a callback.
>>
>> When the synthesizer is done speaking it sends an Objective-C message
>> speechSynthesizer:didFinishSpeaking. From there I would like to run an
>> elisp
>> hook, say `ns-speech-finished-speaking-hook`. How can I do this? Do I have
>> to
>> squirrel away a pointer to an emacs_env somehow? I tried naively storing
>> env
>> from a previous call but, not surprisingly, the pointer is invalid when I
>> try
>> to use it.
>
> How would you do that in Emacs's core code? A module is just a
> (limited) extension of the Emacs core, so when you ask such questions,
> you should first think how Emacs core does that.
I did a version of this (in core) some time ago by adding a new event type. I
wasn’t ever happy with it and for various reasons I think it makes more sense
as a module.
> Anyway, I assume you have a C callback in your module that is
> triggered by the speechSynthesizer:didFinishSpeaking message, is that
> right?
Yes.
> Then one way would be to have that callback set a flag,
> provide a Lisp-callable function that returns the flag, and then start
> a timer that will test the flag and call your Lisp callback when the
> flag is set.
I was hoping to avoid polling, since the use case I have would like to start
reading again as soon as the previous version finishes.
> Another, perhaps simpler, possibility would be to have the module
> provide a Lisp-callable function that will register a Lisp callback.
> Then your C callback will simply call that Lisp function.
I don’t understand how I would implement this option, though it sounds like
what I was hoping for. In order to call a lisp function, don’t I need an
emacs_env?
> Would any of these do the job?
I hope so. :-) I’ll probably try the timer option.
Thanks,
Ivan
Re: Callbacks from modules, Philipp Stephani, 2015/11/26
Re: Callbacks from modules, Tom Tromey, 2015/11/26
Re: Callbacks from modules, Eli Zaretskii, 2015/11/27