# Sift：一个能真正读懂 Lisp 的格式化器

Original title: Sift: The Lisp formatter I kept trying to write (+lint and LSP)

> Hacker News story 50736409 · language: zh · submitted 2026-12-02
> Web version: https://zeli.app/zh/story/50736409
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 32 · by [jjba23](<https://news.ycombinator.com/user?id=jjba23>) · 💬 36
[original](<https://jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/>) · [HN discussion](<https://news.ycombinator.com/item?id=50736409>)

## Summary

我花了数年时间试图为 Lisp 家族打造一套统一的工具，最终诞生了 Sift。它不再依赖正则猜测，而是真正解析 Scheme、Racket、Emacs Lisp 和 Common Lisp 的语法树。Sift 集格式化、Linter 和 LSP 语言服务器于一身，拥有超过 95 条规则，支持从命令行到浏览器的全场景运行。它解决了不同编辑器缩进不一致、CI 与本地环境冲突的痛点，确保代码风格在任何地方都保持一致。从键盘宏的失败尝试到 Guile 的终极实现，Sift 证明了工具应当理解代码结构，而非仅仅处理字符串。

## Key quote

> 这是多年来我一直试图写出的程序，现在我终于完成了它。

## HN discussion (36 comments)

### [chriswarbo](<https://news.ycombinator.com/item?id=50749205>)

> 我发现在写 Lisp 时，https://github.com/shcv/parenmedic 这个工具非常有用。
>
> 它会将缩进与括号进行比对，如果两者不一致就会报错。它不关心缩进的具体数量（像 I-expressions/Wisp 等工具那样），只要求：在打开括号后的行必须增加缩进；在关闭括号后的行必须减少缩进；同级行的缩进量必须相同。
>
> 我发现，相比于单纯统计开括号和闭括号是否平衡，这种方法在定位问题根源上要准确得多；例如，后者往往要等到文件末尾才能发现缺失的闭括号。这对 LLM 尤其有用，因为它们在数括号方面表现极差。
>
> 不幸的是，有些情况下自动缩进工具（例如 elisp-autofmt）会导致 parenmedic 报错。一个补救办法是通过插入行注释来改变自动缩进工具的行为，但这并非理想方案。
>
> 我不禁好奇，Sift 是否会（有意或无意地）遵守 parenmedic 所要求的规则？

### [aidenn0](<https://news.ycombinator.com/item?id=50751342>)

> 冷知识：你可以从命令行运行 emacs 来格式化代码。Emacs 对 EL 和 CL 的格式化效果很好（TFA 中甚至提到了这一点，但被驳回认为不适合用于流水线）。我不使用 scheme，但我假设它对 scheme/racket 的格式化效果也不错？

### [cheshire_cat](<https://news.ycombinator.com/item?id=50747492>)

> 是我太 paranoid 了，还是这段文字读起来非常像 LLM 写的？

### [bjoli](<https://news.ycombinator.com/item?id=50749304>)

> 我曾试图为我正在凭感觉（vibe coding）开发的一种带有类型的、类似 nl 的 sexpr 语言，确定一套通用的格式化方案。
>
> 这意外地很难。我最终主要复制了可以通过 raco（racket 的命令行工具）使用的算法。它的速度并不快，每个核心每秒大约只能处理 10 行代码，但生成的结果足够好。我不得不把一些东西留给用户处理，但大概只有 5 种形式。

### [joshmarlow](<https://news.ycombinator.com/item?id=50749226>)

> 最近我又开始折腾 common lisp 了（通过 VSCode），一直在寻找类似这样的工具！这个周末打算去玩玩它。

---

## Cite

- Page: https://zeli.app/zh/story/50736409
- Date: 2026-12-02
- Source: jointhefreeworld.org (https://jointhefreeworld.org/blog/articles/lisps/sift-the-lisp-formatter-i-kept-trying-to-write/)
- Hacker News: https://news.ycombinator.com/item?id=50736409

## Other languages

- en: https://zeli.app/story/50736409 · markdown: https://zeli.app/story/50736409.md
- ja: https://zeli.app/ja/story/50736409 · markdown: https://zeli.app/ja/story/50736409.md
- ko: https://zeli.app/ko/story/50736409 · markdown: https://zeli.app/ko/story/50736409.md
- de: https://zeli.app/de/story/50736409 · markdown: https://zeli.app/de/story/50736409.md
- es: https://zeli.app/es/story/50736409 · markdown: https://zeli.app/es/story/50736409.md
- ru: https://zeli.app/ru/story/50736409 · markdown: https://zeli.app/ru/story/50736409.md
