5

我在守护程序模式下使用 emacs,并且我还initial-buffer-choice 设置了一个变量。有时,当我编辑用于initial-buffer-choice. 在这种情况下,当我使用 --daemon 启动 emacs 时,它会挂起以下消息:

"todo.org has auto save data; consider M-x recover-this-file"

由于我主要从初始化脚本启动守护程序,我无法确认或拒绝此对话框,因此守护程序永远挂起。在这种情况下如何绕过自动保存数据的通知?如有必要,我不介意丢失自动保存数据。

这是我的尝试:

(defadvice command-line
  (around my-command-line-advice)
  "Be non-interactive while starting a daemon."
  (if (and (daemonp)
           (not server-process))
      (let ((noninteractive t))
        ad-do-it)
    ad-do-it))
 (ad-activate 'command-line)

但是,这不起作用。我仍然得到相同的悬挂行为。事实上,在通知中放置一个“消息”调用表明该通知根本没有被调用。

类似的问题:emacs-daemon startup freezes if file has auto-save data。但是,此解决方案不适用于initial-buffer-choice. 接受的答案似乎是从以前的版本编辑的,该版本可能已经成功地定义了command-line我试图做的建议,但不幸的是,这个版本现在已经消失,取而代之的是特定于 desktop.el 的版本。

4

3 回答 3

1

一种可能性是将其放入您的 .emacs 中:

(setq auto-save-default nil)

另一个(可能更好的解决方案)是通过使用它来查找文件来抑制警告消息:

(find-file-noselect FILENAME &optional NOWARN RAWFILE WILDCARDS)

正如您在此处看到的,您可以使用可选的 NOWARN 参数抑制警告消息(因为这是导致问题的原因)。

来源:这个 EmacsWiki 页面

如果我要自己解决这个问题,您可以进行以下更改。在 .emacs 设置中定义:

(defun find-file (filename &optional wildcards)
  (interactive
   (find-file-read-args "Find file: "
                        (confirm-nonexistent-file-or-buffer)))

  ; the "t" here is normally set to "nil", this should solve the problem
  (let ((value (find-file-noselect filename t nil wildcards)))  
    (if (listp value)
    (mapcar 'switch-to-buffer (nreverse value))
      (switch-to-buffer value))))

编辑:到目前为止,这对任何人都没有帮助,但为了完整起见,它可能会有所帮助。

提问者确认的当前方式是使用and 与andemacs-startup-hook结合。(kill-buffer "*scratch*")(find-file "~/.../todo.org")

于 2013-03-23T20:03:56.930 回答
1

根据原始发布者在问题中报告的行为描述,似乎当 Emacs 被激活时--daemoninitial-buffer-choice(即,到find-file-noselect "~/.../todo.org"[see ])在默认值之前... lisp/startup.el的启动顺序中被激活可以使用 禁用自动保存设置。如果更改顺序没有效果[即,在初始化文件中将优先级放在更高的位置,使其在] 之前,那么下一步是采取肯定的措施以确保在打开文件之前禁用自动保存(例如, )。这可以通过在或中放置和来实现(setq auto-save-default nil)(setq auto-save-default nil)initial-buffer-choicetodo.org(setq initial-buffer-choice t)(setq auto-save-default nil)init.el.emacs文件(不带钩子)——然后,为了确保所有其他设置都已首先加载,使用emacs-startup-hookto(kill-buffer "*scratch*")(find-file "~/.../todo.org")——这确保在调用之前 find-file禁用自动保存(使用find-file-noselect[see ... lisp/files.el])。

于 2013-10-25T22:47:02.660 回答
0

由于“ ...具有自动保存数据;考虑 Mx recover-this-file ”只是一条消息,我不确定问题是否真的与自动保存文件有关。但是,如果是这种情况,您可以directory-files在您的服务器初始化文件中构建一个测试 emacs 的自动保存目录是否为空 ( )。如果自动保存目录不为空,请将所有文件移动到另一个位置并继续(rename-file)。

我真的很好奇这是否能解决问题。

真正的问题是:如何在 emacs 中调试服务器问题。Debug 和 edebug 在服务器模式下非常无意义。最好将所有内容都跟踪到文件(例如日志记录)。

于 2013-10-24T07:03:01.533 回答