From: Eli Zaretskii <eliz@gnu.org>
To: "Noé Lopez" <noe@xn--no-cja.eu>
Cc: emacs-devel@gnu.org
Subject: Re: Calling interactive lisp functions from C
Date: Sun, 22 Sep 2024 21:03:28 +0300 [thread overview]
Message-ID: <86r09bh8gf.fsf@gnu.org> (raw)
In-Reply-To: <87v7yn63tu.fsf@> (emacs-devel@gnu.org)
> 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?
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.
next parent reply other threads:[~2024-09-22 18:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87v7yn63tu.fsf@>
2024-09-22 18:03 ` Eli Zaretskii [this message]
2024-09-22 18:24 ` Calling interactive lisp functions from C Eli Zaretskii
2024-09-22 20:22 ` Noé Lopez via Emacs development discussions.
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86r09bh8gf.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=emacs-devel@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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).