如何检测 emacs 是否以“-Q”启动?

How can I detect if emacs was started with "-Q"?

我有一个 Emacs 包需要在退出 Emacs 时保存一些状态,但如果 Emacs 是 运行 和 -Q,我不想保存那个状态。有没有办法区分Emacs什么时候是运行和-Q

您可以测试 command-line-args (see lisp/startup.el 以获得更多信息):

(or (member "-Q" command-line-args)
    (member "-quick" command-line-args))

您可能更喜欢 "lower-level" 方法:与其检查特定的命令行参数,不如测试它的 效果 。 在你的情况下,像

(when init-file-user
  (save-my-state))

(请注意,这也会禁用 -q-no-init-file 上的状态保存)。