惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
I
InfoQ
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
美团技术团队
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
Last Week in AI
Last Week in AI
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
G
Google Developers Blog
博客园 - 叶小钗
博客园 - Franky

暗无天日

读:AI Agent 安全日志——从可见性与隐私的两难说起 - 暗无天日 读:AI Agent 生产化——一份从原型到上线的速查清单 - 暗无天日 AI写作的语言指纹——如何让文字不那么像机器 - 暗无天日 读:50 条 Claude Code 技巧——一个工程经理的六个月使用心得 读:AI 辅助开发为什么让 E2E 测试更有价值 - 暗无天日 读:在Emacs中使用Claude Code(Spacemacs适配版) - 暗无天日 Claude Code 背后的工程哲学——读 Agent Harness Engineering 读:Agent Harness Engineering——AI 智能体不只是模型,还有套件 - 暗无天日 browser-harness:让 AI 直接接管你的浏览器 - 暗无天日 读:Security-First CI/CD —— DevSecOps 自动化实践指南 TIL: 数字小键盘的小数点陷阱与行内算术求值 - 暗无天日 读:Immutability 不是万能药,它是一种权衡 - 暗无天日 Conducty:给 Claude Code 加上项目记忆和并行执行能力 - 暗无天日 读 — GitHub Trending 里的 Claude Code 技能包 读 — Prompt Caching 省钱指南 TIL: Emacs 中那些跟鼠标配合的冷门快捷键 - 暗无天日 读:Anvil——把 Emacs 变成 AI 的工具服务器 读:Emacs 代码折叠终极指南 - 暗无天日 读:Clojure 搭车客指南 - 暗无天日 git推送失败后恢复仓库损坏的完整记录 - 暗无天日 多智能体系统的两个有效模式——以及对 Claude Code 用户的启示 - 暗无天日 用 Org Babel 写 Literate 博文:扩展执行 + 定制导出 proced:Emacs 内置的进程查看器 - 暗无天日 从 proced 定制中学到的 Elisp 模式 读:让 Emacs proced 在 macOS 上显示 CPU 和内存 异步编程的函数着色税 - 暗无天日 链式调用的代价:JavaScript 和 Clojure 的共同教训 - 暗无天日 hyperfine:命令行基准测试工具 - 暗无天日 管道中的变量去哪了?——子 shell 作用域陷阱 - 暗无天日 开源包装器的信任陷阱:四个危险信号 - 暗无天日
ERT 测试交互命令的三种方式 - 暗无天日
2026-04-23 · via 暗无天日

Emacs 31 新增的 ert-play-keys 填补了上面两个工具留下的空白。它的实现只有一行:

(defun ert-play-keys (keys)
  "Play the key sequence KEYS as if it was user input."
  (funcall (kmacro keys)))

它调用 kmacro 把按键序列当作键盘宏来执行。因为键盘宏走的是完整的命令循环路径——包括 keymap 查找、命令执行、hook 触发——所以它可以触发 keymap 绑定的命令,也能正确处理 called-interactively-p

使用时需要配合 ert-with-test-buffer:selected t 参数(或 ert-with-buffer-selected ),这会在临时窗口中选中 buffer,让按键序列能正确路由到目标 buffer:

(ert-deftest test-play-keys-triggers-keymap ()
  "ert-play-keys 可以触发 keymap 绑定的命令。"
  (ert-with-test-buffer (:selected t)
    (let (command-ran)
      (let* ((map (let ((map (make-sparse-keymap)))
                   (define-key map [?b]
                               (lambda ()
                                 (interactive)
                                 (setq command-ran t)
                                 (insert "ran")))
                   map))
            (minor-mode-map-alist (cons (cons t map) minor-mode-map-alist)))
        (ert-play-keys (vconcat [?b])))
      (should (eq command-ran t))
      (should (string= "ran" (buffer-substring (point-min) (point-max)))))))

ert-play-keys 还可以在一次调用中混合不同类型的输入——既有触发命令的按键,也有直接插入的文本:

(ert-deftest test-play-keys-mixed-input ()
  "ert-play-keys 可以混合按键命令和文本插入。"
  (ert-with-test-buffer (:selected t)
    (let* ((map (let ((map (make-sparse-keymap)))
                 (define-key map [?X]
                             (lambda ()
                               (interactive)
                               (insert "[pressed-X]")))
                 map))
          (minor-mode-map-alist (cons (cons t map) minor-mode-map-alist)))
            (ert-play-keys (vconcat [?X] "hello")))
    (should (string= "[pressed-X]hello"
                     (buffer-substring (point-min) (point-max))))))