From: Grégoire Jadi Date: Mon, 24 Jun 2013 08:22:45 +0000 (+0200) Subject: Handle xwidgets like processes and delete them when their buffer is killed. X-Git-Tag: emacs-25.0.90~2896 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=da95bc007d161d6d901b7600120a97fd2f54ce4b;p=emacs.git Handle xwidgets like processes and delete them when their buffer is killed. * lisp/xwidget.el (xwidget-kill-buffer-query-function): New function to query a user before killing a buffer with xwidgets in it. This function is stored in `kill-buffer-query-functions' and called from `kill-buffer'. * src/buffer.c (Fkill_buffer): Call `kill_buffer_xwidgets'. * src/xwidget.c (kill_buffer_xwidgets): Delete xwidgets attached to the specified buffer. * src/xwidget.h (kill_buffer_xwidgets): Add definition. --- diff --git a/lisp/xwidget.el b/lisp/xwidget.el index 9be7c4a60ff..4d2453e9d2d 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el @@ -454,6 +454,16 @@ It can be retrieved with `(xwidget-get XWIDGET PROPNAME)'." ;;(add-hook 'window-configuration-change-hook 'xwidget-cleanup) (add-hook 'window-configuration-change-hook 'xwidget-delete-zombies) +(defun xwidget-kill-buffer-query-function () + "Ask beforek illing a buffer that has xwidgets." + (let ((xwidgets (get-buffer-xwidgets (current-buffer)))) + (or (not xwidgets) + (yes-or-no-p + (format "Buffer %S has xwidgets; kill it? " + (buffer-name (current-buffer))))))) + +(add-hook 'kill-buffer-query-functions 'xwidget-kill-buffer-query-function) + ;;killflash is sadly not reliable yet. (defvar xwidget-webkit-kill-flash-oneshot t) (defun xwidget-webkit-kill-flash () diff --git a/src/buffer.c b/src/buffer.c index abebdf21135..4e0dbe778ef 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -44,6 +44,10 @@ along with GNU Emacs. If not, see . */ #include "keymap.h" #include "frame.h" +#ifdef HAVE_XWIDGETS +#include "xwidget.h" +#endif /* HAVE_XWIDGETS */ + struct buffer *current_buffer; /* The current buffer. */ /* First buffer in chain of all buffers (in reverse order of creation). @@ -1835,6 +1839,11 @@ cleaning up all windows currently displaying the buffer to be killed. */) kill_buffer_processes (buffer); UNGCPRO; +#ifdef HAVE_XWIDGETS + GCPRO1 (buffer); + kill_buffer_xwidgets (buffer); + UNGCPRO; +#endif /* HAVE_XWIDGETS */ /* Killing buffer processes may run sentinels which may have killed our buffer. */ if (!BUFFER_LIVE_P (b)) diff --git a/src/xwidget.c b/src/xwidget.c index ed7ea98fb42..57d27a2b3c7 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -202,7 +202,7 @@ TYPE is a symbol which can take one of the following values: //should work a bit like "make-button"(make-button BEG END &rest PROPERTIES) // arg "type" and fwd should be keyword args eventually //(make-xwidget 3 3 'button "oei" 31 31 nil) - //(xwidget-info (car xwidget-alist)) + //(xwidget-info (car xwidget-list)) struct xwidget* xw = allocate_xwidget(); Lisp_Object val; xw->type = type; @@ -1619,7 +1619,7 @@ syms_of_xwidget (void) DEFSYM (QCplist, ":plist"); - DEFVAR_LISP ("xwidget-alist", Vxwidget_list, doc: /*xwidgets list*/); + DEFVAR_LISP ("xwidget-list", Vxwidget_list, doc: /*xwidgets list*/); Vxwidget_list = Qnil; DEFVAR_LISP ("xwidget-view-alist", Vxwidget_view_alist, doc: /*xwidget views list*/); @@ -1845,4 +1845,18 @@ xwidget_end_redisplay (struct window *w, struct glyph_matrix *matrix) } } +/* Kill all xwidget in BUFFER. */ +void +kill_buffer_xwidgets (Lisp_Object buffer) +{ + Lisp_Object tail, xw; + + for (tail = Fget_buffer_xwidgets (buffer); CONSP (tail); tail = XCDR (tail)) + { + xw = XCAR (tail); + Vxwidget_list = Fdelq (xw, Vxwidget_list); + /* TODO free the GTK things in xw */ + } +} + #endif /* HAVE_XWIDGETS */ diff --git a/src/xwidget.h b/src/xwidget.h index 3ca9dbe0e1a..530b087796c 100644 --- a/src/xwidget.h +++ b/src/xwidget.h @@ -107,4 +107,6 @@ struct xwidget* lookup_xwidget (Lisp_Object spec); #define XG_XWIDGET "emacs_xwidget" #define XG_XWIDGET_VIEW "emacs_xwidget_view" void xwidget_view_delete_all_in_window( struct window *w ); + +void kill_buffer_xwidgets (Lisp_Object buffer); #endif /* XWIDGET_H_INCLUDED */