]> git.eshelyaron.com Git - emacs.git/commitdiff
Add `kill-xwidget'
authorPo Lu <luangruo@yahoo.com>
Sun, 14 Nov 2021 05:02:41 +0000 (13:02 +0800)
committerPo Lu <luangruo@yahoo.com>
Sun, 14 Nov 2021 09:42:16 +0000 (17:42 +0800)
* doc/lispref/display.texi (Xwidgets): Document 'kill-xwidget'.
* src/xwidget.c (kill_xwidget, Fkill_xwidget): New function.
(syms_of_xwidget): Define new subr.
(kill_buffer_xwidgets): Use `kill_xwidget' instead.

doc/lispref/display.texi
src/xwidget.c

index a8a7837a4a0d593c9984e872a3ed1ec74ce498ad..3ab29dc5912e16c7e4099f53021e8ad8875511d1 100644 (file)
@@ -6806,10 +6806,11 @@ widget that the newly created widget should share settings and
 subprocesses with.
 
 The xwidget that is returned will be killed alongside its buffer
-(@pxref{Killing Buffers}).  Once it is killed, the xwidget may
-continue to exist as a Lisp object and act as a @code{display}
-property until all references to it are gone, but most actions that
-can be performed on live xwidgets will no longer be available.
+(@pxref{Killing Buffers}).  You can also kill it using
+@code{xwidget-kill}.  Once it is killed, the xwidget may continue to
+exist as a Lisp object and act as a @code{display} property until all
+references to it are gone, but most actions that can be performed on
+live xwidgets will no longer be available.
 @end defun
 
 @defun xwidgetp object
@@ -6822,6 +6823,11 @@ This function returns @code{t} if @var{object} is an xwidget that
 hasn't been killed, and @code{nil} otherwise.
 @end defun
 
+@defun kill-xwidget xwidget
+This function kills @var{xwidget}, by removing it from its buffer and
+releasing window system resources it holds.
+@end defun
+
 @defun xwidget-plist xwidget
 This function returns the property list of @var{xwidget}.
 @end defun
index 609a231d4bbe82742de9eeb345c88f438b869a0c..344016ed744a86b38820534452984166137c9d45 100644 (file)
@@ -76,6 +76,8 @@ allocate_xwidget_view (void)
 
 static struct xwidget_view *xwidget_view_lookup (struct xwidget *,
                                                 struct window *);
+static void kill_xwidget (struct xwidget *);
+
 #ifdef USE_GTK
 static void webkit_view_load_changed_cb (WebKitWebView *,
                                          WebKitLoadEvent,
@@ -2386,6 +2388,25 @@ using `xwidget-webkit-search'.  */)
   return Qnil;
 }
 
+DEFUN ("kill-xwidget", Fkill_xwidget, Skill_xwidget,
+       1, 1, 0,
+       doc: /* Kill the specified XWIDGET.
+This releases all window system resources associated with XWIDGET,
+removes it from `xwidget-list', and detaches it from its buffer.  */)
+  (Lisp_Object xwidget)
+{
+  struct xwidget *xw;
+
+  CHECK_LIVE_XWIDGET (xwidget);
+  xw = XXWIDGET (xwidget);
+
+  block_input ();
+  kill_xwidget (xw);
+  unblock_input ();
+
+  return Qnil;
+}
+
 #ifdef USE_GTK
 DEFUN ("xwidget-webkit-load-html", Fxwidget_webkit_load_html,
        Sxwidget_webkit_load_html, 2, 3, 0,
@@ -2468,6 +2489,7 @@ syms_of_xwidget (void)
 #ifdef USE_GTK
   defsubr (&Sxwidget_webkit_load_html);
 #endif
+  defsubr (&Skill_xwidget);
 
   DEFSYM (QCxwidget, ":xwidget");
   DEFSYM (QCtitle, ":title");
@@ -2708,6 +2730,40 @@ kill_frame_xwidget_views (struct frame *f)
 }
 #endif
 
+static void
+kill_xwidget (struct xwidget *xw)
+{
+#ifdef USE_GTK
+  xw->buffer = Qnil;
+
+  if (xw->widget_osr && xw->widgetwindow_osr)
+    {
+      gtk_widget_destroy (xw->widget_osr);
+      gtk_widget_destroy (xw->widgetwindow_osr);
+    }
+
+  if (xw->find_text)
+    xfree (xw->find_text);
+
+  if (!NILP (xw->script_callbacks))
+    {
+      for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++)
+       {
+         Lisp_Object cb = AREF (xw->script_callbacks, idx);
+         if (!NILP (cb))
+           xfree (xmint_pointer (XCAR (cb)));
+         ASET (xw->script_callbacks, idx, Qnil);
+       }
+    }
+
+  xw->widget_osr = NULL;
+  xw->widgetwindow_osr = NULL;
+  xw->find_text = NULL;
+#elif defined NS_IMPL_COCOA
+  nsxwidget_kill (xw);
+#endif
+}
+
 /* Kill all xwidget in BUFFER.  */
 void
 kill_buffer_xwidgets (Lisp_Object buffer)
@@ -2721,31 +2777,8 @@ kill_buffer_xwidgets (Lisp_Object buffer)
       {
         CHECK_LIVE_XWIDGET (xwidget);
         struct xwidget *xw = XXWIDGET (xwidget);
-       xw->buffer = Qnil;
-
-#ifdef USE_GTK
-        if (xw->widget_osr && xw->widgetwindow_osr)
-          {
-            gtk_widget_destroy (xw->widget_osr);
-            gtk_widget_destroy (xw->widgetwindow_osr);
-          }
-       if (xw->find_text)
-         xfree (xw->find_text);
-       if (!NILP (xw->script_callbacks))
-         for (ptrdiff_t idx = 0; idx < ASIZE (xw->script_callbacks); idx++)
-           {
-             Lisp_Object cb = AREF (xw->script_callbacks, idx);
-             if (!NILP (cb))
-               xfree (xmint_pointer (XCAR (cb)));
-             ASET (xw->script_callbacks, idx, Qnil);
-           }
 
-       xw->widget_osr = NULL;
-       xw->widgetwindow_osr = NULL;
-       xw->find_text = NULL;
-#elif defined NS_IMPL_COCOA
-        nsxwidget_kill (xw);
-#endif
+       kill_xwidget (xw);
       }
     }
 }