From: "Noé Lopez via Emacs development discussions." <emacs-devel@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Calling interactive lisp functions from C
Date: Sun, 22 Sep 2024 22:22:15 +0200 [thread overview]
Message-ID: <87ed5be8w8.fsf@xn--no-cja.eu> (raw)
In-Reply-To: <86r09bh8gf.fsf@gnu.org> (message from Eli Zaretskii on Sun, 22 Sep 2024 21:03:28 +0300)
Eli Zaretskii <eliz@gnu.org> writes:
>> Date: Sun, 22 Sep 2024 18:38:53 +0200
>> From: Noé Lopez via "Emacs development discussions." <emacs-devel@gnu.org>
>>
>> I am trying to call the read-file-name function from a C WebKit
>> callback, in this case it is the « run-file-chooser » signal.
>>
>> I came up with this code which works when selecting a file, but aborts
>> emacs when hitting the « cancel » button of the file chooser dialog.
>>
>> static gboolean wpe_run_file_chooser_cb (WebKitWebView *webview,
>> WebKitFileChooserRequest *request,
>> struct xwidget *xw)
>> {
>> /* use read-file-name if only one file is needed, useful for keyboard
>> only usage. */
>> if (!webkit_file_chooser_request_get_select_multiple (request))
>> {
>> /* TODO: we can use webkit_file_chooser_request_get_selected_files
>> * to find a default file name for the prompt. */
>> Lisp_Object file = call4 (Qread_file_name,
>> build_string ("Select file"),
>> Qnil,
>> Qnil,
>> Qt);
>> if (EQ (file, Qnil))
>> {
>> webkit_file_chooser_request_cancel (request);
>> g_message ("canceled file request");
>> }
>> const char *const selected_files[] = { SSDATA (file), NULL };
>> webkit_file_chooser_request_select_files (request, selected_files);
>> return TRUE;
>> }
>> return TRUE;
>> }
>>
>> The callback is activated from a click action in the WebKit buffer, so
>> « waiting_for_input » is true, causing signal_or_quit to abort. Using
>> clear_waiting_for_input changes it to a segmentation fault.
>>
>> What can I do to catch the quit signal? Ideally I need to call a
>> function to notify WebKit of the cancelation, or it will hang.
>
> Did you try to bind inhibit-quit to the value t?
Yes, but Fx_file_dialox, called from read-file-name calls quit directly
without checking inhibit-quit.
> An alternative is not to call read-file-name directly, but instead
> queue an input event that will invoke a command when processed, and
> the command will call read-file-name.
That is probably best, if WebKit supports asynchronous answering for
that signal. I will look into it.
Thanks.
next prev parent reply other threads:[~2024-09-22 20:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87v7yn63tu.fsf@>
2024-09-22 18:03 ` Calling interactive lisp functions from C Eli Zaretskii
2024-09-22 18:24 ` Eli Zaretskii
2024-09-22 20:22 ` Noé Lopez via Emacs development discussions. [this message]
2024-09-22 16:38 Noé Lopez via Emacs development discussions.
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=87ed5be8w8.fsf@xn--no-cja.eu \
--to=emacs-devel@gnu.org \
--cc=eliz@gnu.org \
--cc=noe@xn--no-cja.eu \
/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.