reddit / emacs

xwidget-webkit is a great feature, but it needs your help on MacOS

NDcodes · 2022-10-13 20:56
**UPDATE:** If you’re interested, this is the fork where I’ll be working on this patch: https://github.com/andyjda/emacs/tree/xwidget-patches Feel free to contribute/make suggestions. I tried building the latest version from source, and I'm seeing the same issues as I did when I built using Emacs Plus. It looks like support for xwidget-webkit in MacOS was incorporated for previous versions (the C code shows this), but it hasn't been updated for the latest features. The fixes might not be too difficult: simply add definitions for the functions to interact with Apple's NS framework in addition to GTK. I'm planning on giving it a try, though I need a better understanding of Emacs internals: I made [this post to ask for help regarding the C code](https://www.reddit.com/r/emacs/comments/y6ov65/guidemanual_to_understand_emacs_sourcecode/). ​ **Post from before update:** Hello everyone, this should be particularly interesting if you want to use (or keep using) a browser within Emacs, run Emacs in MacOS, are knowledgeable on Emacs' C code, or any of the above. I've been using xwidget-webkit in Emacs for a while now, thanks to [d12frosted's great Emacs Plus Homebrew formulae](https://github.com/d12frosted/homebrew-emacs-plus) which include it as a build option. If you don't know, this feature allows you to run an instance of a browser from within an Emacs buffer (if you run MacOS, the browser is Safari, though this might be configurable -- I'm not sure). I find it a great and useful feature when browsing code-documentation online or using search engines for quick questions. Recently I've noticed a few bugs, especially after switching to Emacs 29 (pixel-scroll-precision is great!). I've opened [this issue](https://github.com/d12frosted/homebrew-emacs-plus/issues/519) with a brief outline of my diagnosis and possible ways to move forward. Some more details: the 'official' C code for xwidget-webkit is built specifically for GNU/Linux, but people were able to make it work on MacOS using some [patches from another branch](https://github.com/veshboo/emacs/blob/master/src/xwidget.c). These patches haven't been maintained recently and have since fallen out of date with the Emacs Lisp code. It'd be great to get help from someone with more knowledge on Emacs C-code and/or MacOS's Cocoa framework: ideally we could take the earlier patches and update them to bring the feature up-to-date and available 'out-of-the-box' for Mac users. In the meantime, I've been working on [some Emacs-Lisp code](https://github.com/andyjda/emacs-configuration/blob/dev/.emacs.d/custom/packages/my-webkit/my-webkit.el) that fixes some of the bugs (and provides a few additional features). I don't think that Lisp alone can solve the biggest problems: being able to interact with a text-area within a web page is still a pain. But the patch makes the browser much more usable. ​ I've spoken to Emacs Plus' maintainer [d12frosted](https://github.com/d12frosted), and he said he's not very familiar with the feature, but he welcomed me to open the issue. I'm hoping to determine what the interest is in keeping the xwidget-webkit available in MacOS, and the best path forward. If nobody with a good understanding of the C-code is available to help out, I could start by cleaning up my Lisp code and packaging it up for people who would like to fix (some of) the bugs.
tftio · 2022-10-14 02:05
I'll take a look when I get back from vacation.
NDcodes · 2022-10-14 02:25
that'd be great, thanks! feel free to get back to me here or in the opened issue on GitHub
slappy_buddha · 2022-10-14 02:59
I'm all for this - and potentially for helping out on this. One small wrinkle to all this is actually getting the Emacs core dev team to accept a PR that makes any substantial change solely in support of OSX support. It might be a stretch to say that the core dev team is "hostile" towards OSX support - but Richard Stallman has been known repeatedly in the past to "step in" and essentially end discussions/proposals around "generalizing" emacs to support non-linux (and non-free) OSes. I think \*that\* is actually one of the main reasons why OSX support has been "implemented" through patches to the C code, but that implementation has never been merged into emacs core.
NDcodes · 2022-10-14 03:24
That all makes sense. I think for now I'm aiming at a temporary solution via Elisp and C patches; if it's good enough we can then look at the steps necessary to even consider merging it into master. I feel that if we have a patch that makes a feature available to different OSes without breaking anything, it wouldn't be hard to make a good case for merging, but I'm really not too worried about that yet. If you want to help out, that'd be great! You could start by looking at the C code ([Veshboo's patch](https://github.com/veshboo/emacs/blob/master/src/xwidget.c) and how it compares with the latest from [master branch](https://github.com/emacs-mirror/emacs/blob/master/src/xwidget.c)) or the Emacs Lisp [overrides I made](https://github.com/andyjda/emacs-configuration/blob/xwidget-webkit/.emacs.d/custom/packages/my-webkit/my-webkit.el) to 'fix' [xwidget.el](https://github.com/emacs-mirror/emacs/blob/master/lisp/xwidget.el). You can also just try to use the feature on your machine and let me know if your experience matches mine
BlueFlo0d · 2022-10-14 05:28
I'm building from the latest official source with `--with-ns --with-xwidgets` options. It works out of the box, except that a few new APIs added to X11 branch isn't available (like the history related stuff). Still fully usable.
NDcodes · 2022-10-14 12:04
Interesting, thanks! Are you able to do search (“C-s”) on the page? And get the current url (should be “w”)? Can you check the message buffer if there are any complaints about void-function?
NDcodes · 2022-10-14 17:27
u/BlueFlo0d it appears that the problem might be with the emacs-plus formulae, as they don't have `--with-ns` as an option. Can you walk me through your steps to build form official source? I'd like to share these with the emacs-plus maintainer so we can work on a fix
arthurno1 · 2022-10-15 06:18
[Xwidget](https://github.com/jave/xwidget-emacs) is an implementation of embedding X11 windows within each other, which is a part of how X11 works. Xembedd, as it's name suggests let's you embedd an X11 application's windows as part of your own X11 application window and is part of X11 protocol. Thus it works only on X11 platform. Regardless, if you run X11 on Mac, Linux or Windows, you have to incorporate support for the feature in C core if you are going to use it, has nothing to do with RMS.
NDcodes · 2022-10-15 11:46
Apple’s Cocoa framework also lets you embed applications within each other. So people developed a version of xwidget that works with that instead of X11: https://github.com/veshboo/emacs/blob/master/src/xwidget.c To clarify the embed functionality itself works pretty well, but recent changes introduced some bugs. I don’t think there was ever an attempt to include this in master Emacs though, so I wouldn’t worry yet about whether or not it’ll be accepted
cfclrk · 2022-10-18 21:16
Thank you so much for working on this! I use xwidget-webkit on MacOS every day, mostly to view documentation. Hopefully that will become more commonplace soon.