Ymacs Reloaded
Hello. Here's an Ymacs update, after 12 years. Remember Ymacs? It's an Emacs-like editor that works in the browser. Here is what's new.
-
Zero dependencies. Ymacs no longer requires my old DynarchLIB toolkit. The minified and gzipped payload is under 50K, which is pretty small by today standards. Along with this change I modernized the code to use ES6 features (e.g. classes, modules), improved theming and added a simple build system based on Parcel.
-
Improved isearch, query-replace. This took a surprising amount of fiddling, but finally, it's Good™. It has “lazy highlighting”, stats (current/count), regexp, word, case folding, lax whitespace. Query-replace is new (old Ymacs didn't have it). Supports similar-case in replacements, regexp replacement variables, bound to selection when active, etc. — with the standard Emacs keybindings, except for C-w 😢 which see below.
-
Integration with the OS clipboard using the Clipboard API. Just press C-v to paste from operating system; Ymacs' own cut/copy functions will update the OS clipboard as well. In Chrome it works out of the box (it might ask for permission once). In Firefox it's a bit of a headache for now, but should be okay soon (support in Web pages has just been released, although it seems it was available for some years in extensions).
-
Improved language support. For example we now have a HTML mode with support for embedded JS and CSS (proper syntax highlighting and indentation); various fixes in JS and Lisp modes; improved paren matching, paredit-like functions; etc.
-
Stability and performance improvements, other smaller stuff.
Get Ymacs from github.com/mishoo/ymacs. Check the Ymacs section on this website for some building/usage information.
The Ctrl-w situation
When I started Ymacs, browsers allowed websites to receive pretty much any key combination, and life was good. But after a while, Chrome decided to forbid sites from catching some keys (Chromium: issue 1, issue 2), and a few years later Firefox followed suit (Firefox: issue 1, issue 2), “to prevent abuse”. 🤦
Customizable keyboard shortcuts was routine feature for a 30kb video game in the 80'es; you'd think it should be a solved problem in today's browsers. Yet, despite people asking for a solution for years, despite that there are literally 1.5 BILLION results for google browser prevent ctrl-w from closing tab, here we are in 2024 — Ctrl-w kills the tab and you cannot disable nor configure this.
We are powerless against this insanity, of course. Ymacs doesn't even get notice that Ctrl-w has been pressed. So I defined alternate combinations for situations where you'd normally use C-w:
-
C-Delete, C-k or M-d for “copy region as kill” (“cut” to clipboard), when the selection is on.
-
S-C-s (that's Shift-Ctrl-s) for isearch-yank-word. This also starts isearch mode if it wasn't already on.
Oh, you will press Ctrl-w! Ymacs imitates Emacs so well, and if you work on anything serious you will get into the zone, finger memory will take over and —bang!— all of a sudden, whatever it was that you were working on will have vanished, leaving you blinking stupidly for a few seconds as the horror of what just happened fully sinks in, and then you start cursing every idiot who thought killing the tab on Ctrl-w and making it impossible to configure was a good idea.
This is terribly frustrating, as you can see, so you add a beforeunload handler, so the browser will at least warn before closing the tab. But please note that even with this handler, if your fingers press C-w twice (say, if you wanted to yank two words in isearch) Firefox will still murder the tab without waiting for your pitiful confirmation, and there is nothing you can do about it.
If you need Ctrl-n or Ctrl-t, you are similarly out of luck, but at least the hard-coded action is a little less malign.
This opens Ymacs with the content of this blog post (the code that runs on click is at the bottom). You can't save, obviously.