all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ivan Andrus <darthandrus@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Callbacks from modules
Date: Thu, 26 Nov 2015 20:23:48 -0700	[thread overview]
Message-ID: <C84B3EF3-49B8-4489-9B30-0ACB7C229E22@gmail.com> (raw)
In-Reply-To: <83si3svk91.fsf@gnu.org>

On Nov 26, 2015, at 8:43 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Ivan Andrus <darthandrus@gmail.com>
>> 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


  parent reply	other threads:[~2015-11-27  3:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-26  6:08 Callbacks from modules Ivan Andrus
2015-11-26 15:43 ` Eli Zaretskii
2015-11-26 16:17   ` joakim
2015-11-26 16:33     ` Eli Zaretskii
2015-11-26 17:01       ` Philipp Stephani
2015-11-26 17:19         ` Eli Zaretskii
2015-11-27  3:23   ` Ivan Andrus [this message]
2015-11-27  8:29     ` Eli Zaretskii
2015-11-27 17:30       ` Ivan Andrus
2015-11-26 18:16 ` Philipp Stephani
2015-11-26 18:41   ` Eli Zaretskii
2015-11-26 18:44     ` Philipp Stephani
2015-11-27  3:35       ` Ivan Andrus
2015-11-27  8:30         ` Eli Zaretskii
2015-11-27 17:31           ` Ivan Andrus
2015-11-27  4:22     ` Tom Tromey
2015-11-27  8:35       ` Eli Zaretskii
2015-11-30 14:03         ` Ted Zlatanov
2015-11-30 15:58           ` Eli Zaretskii
2015-11-30 16:52           ` John Wiegley
2015-11-27  4:20   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C84B3EF3-49B8-4489-9B30-0ACB7C229E22@gmail.com \
    --to=darthandrus@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.