
Show HN: Portal – Native Ghostty and Web View as Emacs Buffers
A portal from Emacs to the rest of the computer: native macOS views inside Emacs panes.
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
A portal from Emacs to the rest of the computer: native macOS views inside Emacs panes.
Portal is, as the name suggests, a portal from Emacs to the rest of the computer. It puts native macOS views inside Emacs panes, so a buffer can show a real web page or a real terminal as if it were ordinary buffer content.
That's it. Portal is a set of primitives. The things I built on top (Excalidraw, Markdown and HTML previews, quick terminals) are my preferences, and they're small on purpose. The primitives are the point: you can build your own things on them.
I wanted to stay in Emacs. Emacs can't do everything a browser or a terminal app can, and the in-Emacs alternatives (xwidget-webkit, terminal emulators drawn with Emacs text) are slow or don't work well on macOS. Instead of bringing those things into Emacs text, Portal puts the real native views in the pane and lets Emacs manage them.
Portal needs GNU Emacs 31.1 or newer, built for macOS's graphical NS interface with dynamic modules, plus Swift 6.2+ (Xcode), CMake and Ninja. Bun is optional; the build fetches a pinned one if you don't have it. Add it to your config:
(use-package portal :vc (:url "https://github.com/xiaoxinghu/portal" :rev :newest))
Then M-x portal-about. The first time, Portal offers to build its native part, which downloads a pinned GhosttyKit, so no Zig is needed. Run portal-about again once it's ready and you should see an animated portal in a native web view, with your Portal and Emacs versions. Click it or press RET to enter it, ⌘. to come back to Emacs. The install guide covers straight.el, building from a clone, and troubleshooting.
Every view follows the same rules, whatever renders it:
Because the view belongs to a buffer, everything Emacs already does with buffers (display-buffer rules, consult-buffer, window layouts) works on web pages and terminals too.
The web view is the system WKWebView, the engine Safari uses. It loads any http, https, file or data URL:
(portal-open-url "https://example.com") (portal-render-html "mockup.html") (portal-render-markdown "PLAN.md")
Behind it is a small Bun server, the app host. Emacs starts it on demand, one per Emacs process, bound to localhost with a fresh access token. It ships as a standalone binary, so you don't need Bun or Node at runtime. Pages served by the app host are hosted apps, and they get a bridge to their buffer: the page posts JSON with window.portalBridge.postMessage, Emacs receives it as plists, and portal-web-send sends messages back. A web UI can talk to Emacs directly, without a server of its own.
The terminal view is Ghostty, through GhosttyKit, rendered natively in the pane. Emacs doesn't draw a single character of it, which is why it feels like Ghostty and not like a terminal emulated inside Emacs.
The primitive is just "a Ghostty terminal in a buffer". From Lisp you can run any program in one:
(portal-terminal-start (expand-file-name "~/code/site") "claude" '())
What I built on top of it: portal-terminal for a shell in the current pane, terminals grouped by project, a quick scratch terminal per project in a panel at the bottom of the frame, Consult and Embark integration, and themes set from Elisp.
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。
