我希望自动保存我的文档,但我不想每隔几分钟被“自动保存...完成”消息打断。
有什么方法可以只禁用此消息,而不能禁用自动保存功能?
我尝试了以下失败的尝试:https : //stackoverflow.com/questions/22511847/how-to-disable-auto-save-message
我希望自动保存我的文档,但我不想每隔几分钟被“自动保存...完成”消息打断。
有什么方法可以只禁用此消息,而不能禁用自动保存功能?
我尝试了以下失败的尝试:https : //stackoverflow.com/questions/22511847/how-to-disable-auto-save-message
Answers:
您可以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)
do-auto-save
没有考虑到它收到的参数。
有什么方法可以只禁用此消息,而不能禁用自动保存功能?
是的,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-variable
RETauto-save-no-message
RET或者简单地:
(setq-default auto-save-no-message t)
因为这里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)
do-auto-save
允许t
忽略该消息的参数,keyboard.c
但是在调用该函数时,该参数被硬编码为nil
。我建议您打开一个错误报告,以便可以自定义参数。