禁用“自动保存…完成”消息


14

我希望自动保存我的文档,但我不想每隔几分钟被“自动保存...完成”消息打断。

有什么方法可以只禁用此消息,而不能禁用自动保存功能?

我尝试了以下失败的尝试:https : //stackoverflow.com/questions/22511847/how-to-disable-auto-save-message


12
尽管该函数do-auto-save允许t忽略该消息的参数,keyboard.c但是在调用该函数时,该参数被硬编码为nil。我建议您打开一个错误报告,以便可以自定义参数。
安格斯

Answers:


2

您可以do-auto-save通过建议该函数来确保使用正确的参数调用来抑制消息:

(defun my-auto-save-wrapper (save-fn &rest args)
  (apply save-fn '(t)))

(advice-add 'do-auto-save :around #'my-auto-save-wrapper)

这不起作用(至少在Emacs 24.4.1上)。正如@angus所提到的,do-auto-save没有考虑到它收到的参数。
Scaramouche 2015年

@scaramouche:奇怪,因为我在emacs-24分支的HEAD上对其进行了测试,并且工作正常。虽然我打电话给Mx做自动保存。
2015年

1

有什么方法可以只禁用此消息,而不能禁用自动保存功能?

是的,Emacs 27将引入用户选项auto-save-no-message

auto-save-no-message is a variable defined in ‘keyboard.c’.
Its value is nil

  You can customize this variable.


This variable was introduced, or its default value was changed, in
version 27.1 of Emacs.

Documentation:
Non-nil means do not print any message when auto-saving.

Quoth (emacs) Auto Save

18.6 Auto-Saving: Protection Against Disasters
==============================================

From time to time, Emacs automatically saves each visited file in a
separate file, without altering the file you actually use.  This is
called “auto-saving”.  It prevents you from losing more than a limited
amount of work if the system crashes.

   When Emacs determines that it is time for auto-saving, it considers
each buffer, and each is auto-saved if auto-saving is enabled for it and
it has been changed since the last time it was auto-saved.  When the
‘auto-save-no-message’ variable is set to ‘nil’ (the default), the
message ‘Auto-saving...’ is displayed in the echo area during
auto-saving, if any files are actually auto-saved; to disable these
messages, customize the variable to a non-‘nil’ value.  Errors occurring
during auto-saving are caught so that they do not interfere with the
execution of commands you have been typing.

要自定义变量,您可以M-xcustomize-variableRETauto-save-no-messageRET或者简单地:

(setq-default auto-save-no-message t)

0

因为这里do-auto-save是通过c代码调用的,所以这里advice是不可能的。

我们可以使用一个空闲计时器。以下代码经过测试。

(setq auto-save-list-file-prefix nil)
(setq auto-save-visited-file-name t)
(setq auto-save-timeout 0)
(setq auto-save-interval 0)

(defun my-auto-save-silent ()
  (do-auto-save t))

(run-with-idle-timer 1 t #'my-auto-save-silent)

也,参见。http://tinyurl.com/ydeyn4ks


我想知道为什么这个答案得分为0。空闲计时器是完成这项工作的错误工具吗?

0

自动保存auto-save-hook在保存之前运行,因此您可以使用它来临时禁用消息(它们仍然记录到*Messages*缓冲区中):

(add-hook 'auto-save-hook 'auto-save-silence+)

(defun auto-save-silence+ ()
  (setq inhibit-message t)
  (run-at-time 0 nil
               (lambda ()
                 (setq inhibit-message nil))))
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.