Emacs:如何禁用'磁盘上的文件更改'检查?

时间:2010-02-17 21:57:06

标签: emacs

如何禁止Emacs检查缓冲区文件是否在编辑器外部更改了?

4 个答案:

答案 0 :(得分:18)

Emacs真的很想帮助你。阅读Protection against Simultaneous Editing上的信息页。

但是,如果您仍想避免该消息/提示,则可以重新定义正在执行提示的功能:

(defun ask-user-about-supersession-threat (fn)
  "blatantly ignore files that changed on disk"
  )
(defun ask-user-about-lock (file opponent)
  "always grab lock"
   t)

第二个功能是当两个人使用Emacs编辑同一个文件时,会提供类似的提示(但不是你似乎在问题中引用的提示)。

我建议不要覆盖这两个例程,但是如果你愿意的话,它就在那里。

<小时/> 如果关闭机会global-auto-revert-mode,您可以禁用它。将其添加到.emacs:

(global-auto-revert-mode -1)

您可以通过查看同名变量来判断模式是否已启用:

C-h v global-auto-revert-mode RET

如果值为t,则模式开启,否则关闭。

答案 1 :(得分:9)

我对此感到烦恼,因为每次我在git中切换分支时,emacs都认为我的所有文件都已更改。

Revbuffs可以帮助您应对这种症状。它允许您重新加载所有缓冲区。

您还可以尝试(global-auto-revert-mode),它会自动将您的文件还原为磁盘上的文件。

答案 2 :(得分:9)

我的.emacs中有以下内容。它使Emacs只询问真正改变的文件。如果文件按字节保持不变,只更新其时间戳,就像在VCS中切换分支时经常发生的那样,Emacs会忽略此“更改”。

;; Ignore modification-time-only changes in files, i.e. ones that
;; don't really change the contents.  This happens often with
;; switching between different VC buffers.

(defun update-buffer-modtime-if-byte-identical ()
  (let* ((size      (buffer-size))
         (byte-size (position-bytes size))
         (filename  buffer-file-name))
    (when (and byte-size (<= size 1000000))
      (let* ((attributes (file-attributes filename))
             (file-size  (nth 7 attributes)))
        (when (and file-size
                   (= file-size byte-size)
                   (string= (buffer-substring-no-properties 1 (1+ size))
                            (with-temp-buffer
                              (insert-file-contents filename)
                              (buffer-string))))
          (set-visited-file-modtime (nth 5 attributes))
          t)))))

(defun verify-visited-file-modtime--ignore-byte-identical (original &optional buffer)
  (or (funcall original buffer)
      (with-current-buffer buffer
        (update-buffer-modtime-if-byte-identical))))
(advice-add 'verify-visited-file-modtime :around #'verify-visited-file-modtime--ignore-byte-identical)

(defun ask-user-about-supersession-threat--ignore-byte-identical (original &rest arguments)
  (unless (update-buffer-modtime-if-byte-identical)
    (apply original arguments)))
(advice-add 'ask-user-about-supersession-threat :around #'ask-user-about-supersession-threat--ignore-byte-identical)

答案 3 :(得分:4)

就我而言,我想:

(setq revert-without-query '(".*"))

revert-without-query的文档:

Specify which files should be reverted without query.
The value is a list of regular expressions.
If the file name matches one of these regular expressions,
then ‘revert-buffer’ reverts the file without querying
if the file has changed on disk and you have not edited the buffer.
相关问题