Zulip Chat Archive

Stream: general

Topic: emacs widgets


Kyle Miller (Aug 19 2020 at 18:31):

As one of the emacs+Lean users (and, apparently, as the most recent to PR to lean-mode), I've been thinking a little about how to see some of those widgets that VSCode has. I probably don't have any time to work on it myself in the short term, but maybe it's worth starting this topic to get some ideas how to do it.

Here's one idea from a month ago:
Gabriel Ebner said:

It looks like emacs has a fairly extensible HTML renderer: https://github.com/emacs-mirror/emacs/blob/717b0341aafb9ae9b93395dba1192b12c4459f0c/lisp/net/shr.el It might be feasible to render widgets in emacs, as long as the markup is written carefully.

I'm under the impression widgets are using javascript, which this package can't handle, unfortunately. I remember seeing an emacs lisp implementation of javascript, but it seems like a rather big project to extend shr.el into a more fully-fledged web browser!

Kyle Miller (Aug 19 2020 at 18:31):

Thinking a little outside the box, another way lean-mode could use widgets is to launch a web browser and communicate with it via a socket (maybe based right on top of skewer-mode). Then, lean-mode would push widgets over to the browser to be rendered. Clicking on things in-browser would send a message back to lean-mode to, for example, navigate to a definition, insert some text, or whatever other features I'm missing out on so don't know about them yet.

Gabriel Ebner (Aug 19 2020 at 19:11):

Widgets don't use javascript at all (unless you count the d3.js hacks people were dismissing in the other thread). As long as you can execute some emacs code when the user clicks (presses enter?), then you shouldn't lose any features.

Kyle Miller (Aug 19 2020 at 20:02):

Oh, ok. I made lean-server-process-response dump Lean server messages to a buffer, and I see some of the messages have widget entries (like :widget (:column 11 :id 24227 :line 10)), but there are a lot fewer than I expected. Do you have to tell the Lean server to start sending more widget messages? (And is there a specification for widgets somewhere? I remember seeing a link to at least the Lean definitions of widgets at some point.)

Gabriel Ebner (Aug 19 2020 at 20:04):

lean#443

Kyle Miller (Aug 19 2020 at 20:28):

That's good to see the interaction is done via callbacks defined by WidgetEventHandler.

But, looking at how styling works, the main complexity for the shr.el approach will be in translating all the HTML styling attributes and tachyons.css class names into emacs text styles, since it doesn't support CSS. In case there are difficulties here, hopefully most of the styling is inessential for the UI of the widgets!

The least-work approach seems to be using skewer-mode or one of the other packages that communicate with the web browser to render HTML.

For a longer-term goal of getting widgets in emacs itself, I'd probably follow this plan:

  1. Write the emacs side of the widgets API. (The "controller" in MVC, roughly.)
  2. Connect someskewer-mode-like browser-based UI to this. This would help guide development for step 1.
  3. Once this all works, find another package (shr.el?) to render the elements within emacs.

I think I'd be OK with an info view in an adjacent browser window, so I'm not sure I'd get to step 3, but I'd try to make sure step 1 is implemented in such a way that it'd be ready for whomever has the energy to figure it out.


Last updated: Dec 20 2023 at 11:08 UTC