Subject: 25.1.50; Allow using a custom callback with xwidget

From: Puneeth Chaganti <[email-masked]>
Date: Mon, 18 Jul 2016 18:00:48 +0530

Hello,

`xwidgets.el' seems to have some commented code that used to allow using
a different callback on each xwidget.  This functionality is useful to
have and this is a patch that uncomments this code.  I've tested the
code, and it seems to work, and I'm not really sure, why this was
commented in the first place.

Thanks!

>From 63d1b53583263065edea3ee53d708693415a6057 Mon Sep 17 00:00:00 2001
From: Puneeth Chaganti <[email-masked]>
Date: Mon, 18 Jul 2016 16:34:24 +0530
Subject: [PATCH 1/2] Use the callback set as widget's property

Revert a commented piece of code, that allows using a different callback
for each xwidget on an event, instead of a single global one.
* lisp/xwidget.el (xwidget-event-handler): Use callback widget property
---
 lisp/xwidget.el | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 7a0ca8b..3434e24 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -172,12 +172,8 @@ xwidget-event-handler
   (let*
       ((xwidget-event-type (nth 1 last-input-event))
        (xwidget (nth 2 last-input-event))
-       ;;(xwidget-callback (xwidget-get xwidget 'callback))
-       ;;TODO stopped working for some reason
-       )
-    ;;(funcall  xwidget-callback xwidget xwidget-event-type)
-    (message "xw callback %s" xwidget)
-    (funcall  'xwidget-webkit-callback xwidget xwidget-event-type)))
+       (xwidget-callback (xwidget-get xwidget 'callback)))
+    (funcall xwidget-callback xwidget xwidget-event-type)))
 
 (defun xwidget-webkit-callback (xwidget xwidget-event-type)
   "Callback for xwidgets.
-- 
2.7.4

>From 095f02a5581c2c5c157ec312a64288b0c675da74 Mon Sep 17 00:00:00 2001
From: Puneeth Chaganti <[email-masked]>
Date: Mon, 18 Jul 2016 17:46:19 +0530
Subject: [PATCH 2/2] Allow specifying the callback if new session

This change makes it easier to create xwidgets with their callbacks that
are invoked by the event handler
* lisp/xwidget.el (xwidget-webkit-new-session): Optional callback arg
---
 lisp/xwidget.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 3434e24..0f6751e 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -416,16 +416,17 @@ xwidget-webkit-fit-width
                                  (car (window-inside-pixel-edges)))
                               1000))
 
-(defun xwidget-webkit-new-session (url)
+(defun xwidget-webkit-new-session (url &optional callback)
   "Create a new webkit session buffer with URL."
   (let*
       ((bufname (generate-new-buffer-name "*xwidget-webkit*"))
+       (callback (or callback #'xwidget-webkit-callback))
        xw)
     (setq xwidget-webkit-last-session-buffer (switch-to-buffer
                                               (get-buffer-create bufname)))
     (insert " 'a' adjusts the xwidget size.")
     (setq xw (xwidget-insert 1 'webkit  bufname 1000 1000))
-    (xwidget-put xw 'callback 'xwidget-webkit-callback)
+    (xwidget-put xw 'callback callback)
     (xwidget-webkit-mode)
     (xwidget-webkit-goto-uri (xwidget-webkit-last-session) url)))
 
-- 
2.7.4