Is anyone still using Emacs?

Is anyone still using Emacs?

还有人在用 Emacs 吗?

In a recent discussion at the orange site sparked by the Emacs 31 Is Around the Corner: The Changes I’m Already Daily Driving article, people were asking themselves “Is anyone still using Emacs?” and then providing their own perspective. For me, the answer is a resounding yes… but the interesting part is that I’m not still using Emacs: I’m actually using Emacs again. And instead of burying my answer to the opening question in a long discussion thread, I thought I’d explain my journey with and without Emacs for the last… almost 30 years. At the end, I’ll unveil the specific feature that I feel gives me superpowers and that keeps me hooked.

在“橙色网站”(Hacker News)上,一篇名为《Emacs 31 即将到来:我已经在日常使用中的变化》的文章引发了讨论,人们纷纷自问“还有人在用 Emacs 吗?”并给出了各自的看法。对我而言,答案是肯定的……但有趣的是,我并不是“一直在用”Emacs,而是“重新开始使用”了它。与其把这个问题的答案埋没在冗长的讨论帖中,不如让我来分享一下过去近 30 年里,我与 Emacs 分分合合的历程。在文末,我将揭晓那个让我感到如获神力、并让我彻底沉迷的特定功能。

From DOS and Windows to Linux

从 DOS 和 Windows 到 Linux

I got into Linux around 1997 via Caldera OpenLinux 1.1. Before then, I had extensively played with Borland Turbo C++ and Visual Basic as a kid so I was heavily accustomed to those fancy IDEs that we lost.

我大约在 1997 年通过 Caldera OpenLinux 1.1 接触到了 Linux。在此之前,我小时候曾大量使用过 Borland Turbo C++ 和 Visual Basic,因此我非常习惯那些我们后来失去的华丽 IDE。

As I got into Linux and found myself in an alien world, I had to buy a couple of introductory books. Yes, books, the printed kind—because that’s how we had to learn new stuff before. Both books talked about Vim and Emacs and presented them as the advanced choices. I found this strange because the IDEs I had used before seemed more complete, but I, being a Windows renegade for some reason, charged ahead. I learned the basics of both editors and went through their tutorials at different times.

当我进入 Linux 这个陌生的世界时,不得不买了几本入门书。没错,就是那种纸质书——因为在那个年代,我们只能通过这种方式学习新知识。两本书都提到了 Vim 和 Emacs,并将它们作为进阶选择。我觉得这很奇怪,因为我之前用过的 IDE 看起来更完善,但出于某种原因,作为一个 Windows 的“叛逃者”,我还是勇往直前。我学习了这两个编辑器的基础知识,并在不同时期完成了它们的教程。

Since then and until roughly 2015, I flip-flopped between Vim and Emacs. At times I used one, and at times I used the other. I favored Emacs for long-running coding sessions but Vim excelled at my pkgsrc work where I had to edit tens of different files in quick succession.

从那时起直到 2015 年左右,我在 Vim 和 Emacs 之间反复横跳。有时用这个,有时用那个。我更倾向于在长时间的编码任务中使用 Emacs,但 Vim 在处理 pkgsrc 工作时表现出色,因为我需要在短时间内快速编辑几十个不同的文件。

The switch to VSCode and IntelliJ

转向 VSCode 和 IntelliJ

Even though Vim and Emacs worked well for me, I missed something. Language integration was poor so I was tempted by the more modern editors that everyone was touting, and especially so as I moved to macOS. I tried a bunch, like the now-defunct Atom and Brackets, but they all felt brittle and overwhelming: they had too many features, too many settings.

尽管 Vim 和 Emacs 用起来不错,但我总觉得少了点什么。它们的语言集成度较差,所以我被大家推崇的更现代的编辑器所吸引,尤其是在我转用 macOS 之后。我尝试过很多,比如现在已经停用的 Atom 和 Brackets,但它们都让我感觉脆弱且臃肿:功能太多,设置也太繁杂。

And then, VSCode arrived in 2015. As I took it for a test drive, it “felt right” from the get-go. It looked modern, was relatively small, and its plain and simple settings editor—read: just a JSON file because there were no settings panels yet!—made me feel like I was in control. I could understand this modern editor and easily tune it to my needs.

接着,VSCode 在 2015 年出现了。当我试用它时,那种“感觉对了”的体验油然而生。它看起来很现代,体积相对较小,而且它那朴素简单的设置编辑器——也就是一个 JSON 文件,因为当时还没有设置面板!——让我感觉一切尽在掌握。我能理解这个现代编辑器,并能轻松地根据自己的需求进行调整。

Soon after, I started learning Go and then Rust, and VSCode’s integration with their corresponding LSPs made that process so much easier: code auto-completion and real-time error highlighting sped up my learning significantly. I stuck with VSCode for these languages and slowly phased Emacs out. I was sold.

不久之后,我开始学习 Go 和 Rust,VSCode 与相应 LSP 的集成让学习过程变得轻松许多:代码自动补全和实时错误高亮极大地加快了我的学习速度。我坚持用 VSCode 来编写这些语言,并慢慢淘汰了 Emacs。我被它彻底征服了。

During that time period, I was also working on Bazel—a Java project—at Google and the natural choice for it was IntelliJ. I had tried to use Emacs for Java development at some point, but IntelliJ was (and still is) so good that it was the only realistic choice.

在那段时间里,我还在 Google 从事 Bazel(一个 Java 项目)的开发,IntelliJ 自然成了首选。我曾尝试过用 Emacs 进行 Java 开发,但 IntelliJ 当时(现在依然)太出色了,它是唯一现实的选择。

My usage of VSCode with its Vim plugin continued through my short stint at Microsoft, where I was working on a C++ codebase and had to connect to remote Windows boxes. Most people used RDP to work on the remote machine “directly”, but I couldn’t stand that workflow: I very much preferred running VSCode on my desktop and using SSH to connect to the remote machine, which is something that VSCode does very well.

我在微软短暂工作期间,依然使用带有 Vim 插件的 VSCode。当时我处理的是 C++ 代码库,需要连接到远程 Windows 机器。大多数人使用 RDP “直接”在远程机器上工作,但我无法忍受那种工作流:我更喜欢在本地桌面上运行 VSCode,并通过 SSH 连接到远程机器,而这正是 VSCode 非常擅长的地方。

Back to (Doom) Emacs

回归 (Doom) Emacs

And then… I moved to Snowflake in 2022 where development used to happen inside an ancient Linux VM and where my day-to-day job was to write shell scripts and Bazel build files: neither VSCode nor IntelliJ were going to save me here, and as I mentioned earlier, I hate the feeling of working within the constraints of a “remote” graphical environment. So my instinct was to go back to SSH and connect to the local VM with it.

后来……我在 2022 年加入了 Snowflake,那里的开发工作是在一个古老的 Linux 虚拟机中进行的,我的日常工作是编写 shell 脚本和 Bazel 构建文件:VSCode 和 IntelliJ 在这里都帮不上忙。正如我之前提到的,我讨厌在“远程”图形环境的限制下工作。所以我的直觉是回到 SSH,用它连接到本地虚拟机。

As I did that, I needed an editor for long work sessions, and the old and trusty Emacs was there waiting for me. But this time around, I didn’t have the patience to set it up. You see: I had accumulated hundreds of lines in my init.el file over the years without understanding much about them, and I wanted to throw it all away and start over… but it all felt like too much work. Maybe destiny brought Doom Emacs my way at the right time.

当我这样做时,我需要一个适合长时间工作的编辑器,而那个古老且可靠的 Emacs 就在那里等着我。但这一次,我没有耐心去配置它。你看:多年来,我的 init.el 文件里积累了数百行代码,我却对它们知之甚少。我想把一切推倒重来……但这感觉工作量太大了。也许是命运在合适的时机把 Doom Emacs 带到了我面前。

You see, Doom Emacs is an Emacs “distribution” where someone has gone through the pain (or joy, I won’t judge) of configuring Emacs from the ground up. More specifically, Doom Emacs offers sane defaults, predefined language integrations, and an experience that welcomes ex-Vimers. It doesn’t claim to be an IDE… but it feels like one to me.

你看,Doom Emacs 是一个 Emacs “发行版”,有人已经替你经历了从零开始配置 Emacs 的痛苦(或者快乐,我不予置评)。更具体地说,Doom Emacs 提供了合理的默认设置、预定义的语言集成,以及对前 Vim 用户非常友好的体验。它并不自称是 IDE……但在我看来,它用起来就像一个 IDE。

Once I set it up, I experienced déjà-vu: Emacs felt right just like VSCode did in 2015. All of a sudden, lots of Emacs features became discoverable via interactive popup menus accessible behind space-based shortcuts that don’t destroy your wrists, and coexisting with the same Vim-style key bindings that I had grown so used to. But what’s more: the configuration felt simple and understandable, spread across just three trivial files: config.el to specify global settings like the theme or the fonts to use, init.el to select which Doom-specific modules need to be enabled, and packages.el to install non-Doom packages.

一旦配置好,我就有了似曾相识的感觉:Emacs 就像 2015 年的 VSCode 一样,感觉对了。突然之间,许多 Emacs 功能可以通过交互式弹出菜单发现,这些菜单可以通过基于空格的快捷键访问,既不会折磨你的手腕,又能与我早已习惯的 Vim 风格键位共存。更重要的是:配置变得简单易懂,仅分布在三个简单的文件中:config.el 用于指定主题或字体等全局设置,init.el 用于选择需要启用的 Doom 特定模块,packages.el 用于安装非 Doom 的插件。

The defaults for these files are reasonable, with plenty of comments to configure the few details you might want to tune.

这些文件的默认设置非常合理,并附有大量注释,方便你调整那些可能想要修改的细节。

With this new setup, I have had the best Emacs experience ever. Thanks to the advances in LSPs (for which we have to thank VSCode) and modern features like tree-sitter, Emacs now feels like an IDE: I get proper language integration for most languages I have to deal with.

有了这套新配置,我获得了有史以来最好的 Emacs 体验。多亏了 LSP 的进步(这一点我们要感谢 VSCode)以及 tree-sitter 等现代特性,Emacs 现在感觉就像一个 IDE:我处理的大多数语言都能获得完善的语言集成。

And the absolute killer feature for me is that I get the exact same development environment no matter what machine I need to work on. It doesn’t matter if it is a MacBook or a Linux laptop, or if I’m connecting to a Linux cloud workstation or even…

对我来说,最核心的杀手级功能是:无论我在哪台机器上工作,都能获得完全相同的开发环境。无论是 MacBook 还是 Linux 笔记本,无论我是连接到 Linux 云工作站,还是……