mu4e & xwidget / webkit

1,216 views
Skip to first unread message

Dirk-Jan C. Binnema

unread,
Jan 23, 2016, 10:38:24 AM1/23/16
to mu-di...@googlegroups.com
Hi all,

Hope you've all recovered from the festivities surrounding the mu 0.9.16
release :-). Of course, things don't stop there.

If you're using emacs' development version - ie. the latest from the
'emacs-25' branch, you may have noticed the merging of the
xwidget-branch, which is allows for embedding various gtk+ widgets
inside emacs, and it includes a webkit widget as an example of that.

Now, how hard would it be for mu4e to use that? Not very hard, it seems;
see the below snippet, which is just a small variation on
`mu4e-action-view-in-browser`. If you add it to your configuration,
typing `a x` in the message view allows you to view messages in their
full html-glory inside emacs (see attached screenshot).

This is a bit crude - ultimately, a better solution would be to use a
mu4e-specific email widget, such as the one in toys/mug. That would
require a bit of work still. But regardless, I've found it quite useful,
and a good alternative for `mu4e-view-action-view-in-browser`.

--8<---------------cut here---------------start------------->8---
;; works only for emacs with xwidget support

(defun my-mu4e-action-view-with-xwidget (msg)
"View the body of the message inside xwidget-webkit."
(unless (fboundp 'xwidget-webkit-browse-url)
(mu4e-error "No xwidget support available"))
(let* ((html (mu4e-message-field msg :body-html))
(txt (mu4e-message-field msg :body-txt))
(tmpfile (format "%s%x.html" temporary-file-directory (random t))))
(unless (or html txt)
(mu4e-error "No body part for this message"))
(with-temp-buffer
;; simplistic -- but note that it's only an example...
(insert (or html (concat "<pre>" txt "</pre>")))
(write-file tmpfile)
(xwidget-webkit-browse-url (concat "file://" tmpfile) t))))

(add-to-list 'mu4e-view-actions
'("xViewXWidget" . my-mu4e-action-view-with-xwidget) t)
--8<---------------cut here---------------end--------------->8---

Kind regards,
Dirk.

mu4e-xwidget.png

Nicolas Richard

unread,
Jan 25, 2016, 8:36:16 AM1/25/16
to mu-di...@googlegroups.com
Hi,

Thanks for the snippet !

Dirk-Jan C. Binnema writes:
> (defun my-mu4e-action-view-with-xwidget (msg)
> "View the body of the message inside xwidget-webkit."
> (unless (fboundp 'xwidget-webkit-browse-url)
> (mu4e-error "No xwidget support available"))

I have a build without xwidget support, but I do have a function
xwidget-webkit-browse-url nevertheless. The error is :

Debugger entered--Lisp error: (void-function make-xwidget)
make-xwidget(1 1 webkit-osr "*xwidget-webkit*<2>" 1000 1000 nil)
xwidget-insert(1 webkit-osr "*xwidget-webkit*<2>" 1000 1000)
xwidget-webkit-new-session("file:///tmp/24d164f71e1f136.html")
xwidget-webkit-browse-url("file:///tmp/24d164f71e1f136.html" t)

thus testing for make-xwidget might work better.

--
Nicolas

Dirk-Jan C. Binnema

unread,
Jan 25, 2016, 2:48:55 PM1/25/16
to mu-di...@googlegroups.com
This seems like a little niggle in xwidget itself; I guess testing
for some xwidget implementation detail is not the way to go. Anyway,
xwidget is /really/ new, so there will be changes...

Kind regards,
Dirk.


--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

Peter Tran-Jørgensen

unread,
Oct 20, 2016, 10:04:24 AM10/20/16
to mu-discuss
Thanks for this. When using the configuration above xwidget leaves a lot of buffers around

 C-x C-b.

 *%  *xwidget webkit...        30 xwidget-webkit   
 *%  *xwidget webkit...        30 xwidget-webkit   
 *%  *xwidget-webkit*          30 xwidget-webkit   
 *%  *xwidget-webkit...        30 xwidget-webkit   
..

Is there a clever way to make sure they get killed after viewing the message?

Thanks in advance!

Peter Tran-Jørgensen

unread,
Oct 20, 2016, 10:53:21 AM10/20/16
to mu-discuss
I should mention that I'm experiencing the same when I use

(add-to-list 'mu4e-view-actions 
             '("xViewXWidget" . mu4e-action-view-with-xwidget) t) 

Dirk-Jan C. Binnema

unread,
Oct 22, 2016, 1:43:22 PM10/22/16
to mu-di...@googlegroups.com

On Thursday Oct 20 2016, Peter Tran-Jørgensen wrote:

> Thanks for this. When using the configuration above xwidget leaves a lot of
> buffers around
>
> C-x C-b.
>
> *% *xwidget webkit... 30 xwidget-webkit
> *% *xwidget webkit... 30 xwidget-webkit
> *% *xwidget-webkit* 30 xwidget-webkit
> *% *xwidget-webkit... 30 xwidget-webkit
> ..
>
> Is there a clever way to make sure they get killed after viewing the
> message?

mu4e writes a temp file, and then hands it off to xwidget; so you can
use whatever xwidget supports for that, including changing the key
bindings. (DOn't have an xwidget-enabled emacs handy, but I'm sure you
can figure it out :-)
Reply all
Reply to author
Forward
0 new messages