From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Calling interactive lisp functions from C Date: Sun, 22 Sep 2024 21:03:28 +0300 Message-ID: <86r09bh8gf.fsf@gnu.org> References: <87v7yn63tu.fsf@> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40951"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: =?utf-8?Q?No=C3=A9?= Lopez Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 22 20:04:41 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ssQwq-000AUX-Vf for ged-emacs-devel@m.gmane-mx.org; Sun, 22 Sep 2024 20:04:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ssQwE-0007Sw-JA; Sun, 22 Sep 2024 14:04:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ssQwC-0007QG-RE for emacs-devel@gnu.org; Sun, 22 Sep 2024 14:04:00 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ssQwA-0001bz-Ia; Sun, 22 Sep 2024 14:03:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=N7yXuptDdz5QPqUNTVlaJxOuafsyQ1gvQzZ08YUEbx4=; b=iQFoxmpRz9M1cpCwSA47 OUNbQeYx2QoSDOY8tvtwdu46RyvFHjAIVdUIwBAfLRh+/j7qhufMsx+fQQwNsLiRX2yZB91z4/y8S hjwa0RFvyn3wusSpP2PuHYWZoZtV6A96gOSm0WQcd+Cp8muxtay8PFSqbAC3gC9e+3P0kQRZn8u+l R558bktFDF+KdeKxlpsUeAMN/iRaR+diFeLEjSnTY+xxvSHSKqE8USbkHK5MCnRkE0pSQRY49qH5C ZJNGrwE/ka/90+h5nw8YeMm998qMBS0PoKPCmNwqjpp/E9g/QfQHc1Bcj0xeK4FoG4a/lEDEI7YoO YP8OnEJ8J/9P0g==; In-Reply-To: <87v7yn63tu.fsf@> (emacs-devel@gnu.org) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:323932 Archived-At: > Date: Sun, 22 Sep 2024 18:38:53 +0200 > From: Noé Lopez via "Emacs development discussions." > > 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.