[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling interactive lisp functions from C
From: |
Noé Lopez |
Subject: |
Re: Calling interactive lisp functions from C |
Date: |
Sun, 22 Sep 2024 22:22:15 +0200 |
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.