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

mso*_*orc 19 emacs

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

Tre*_*son 18

Emacs真的很想帮助你.阅读有关防止同时编辑的信息页面.

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

(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)
Run Code Online (Sandbox Code Playgroud)

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

我建议不要覆盖这两个例程,但是如果你想要它就在那里.


关闭机会 global-auto-revert-mode,您可以禁用它.将其添加到.emacs:

(global-auto-revert-mode -1)
Run Code Online (Sandbox Code Playgroud)

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

C-h v global-auto-revert-mode RET
Run Code Online (Sandbox Code Playgroud)

如果值为t,则模式打开,否则关闭.

  • 在VMWare中运行emacs并编辑/ mnt/hgfs中的文件(链接到主机文件夹)时会出现很多问题.VMWare的时钟与主机不同步 - 偶尔,您甚至可以看到时间系统调用的结果及时跳回.那么,...是否可以仅在编辑特定目录中的文件时禁用检查?(例如/ mnt/hgfs?) (6认同)

dou*_*lep 10

我有以下内容.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)
Run Code Online (Sandbox Code Playgroud)


Sin*_*ned 9

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

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

您还可以尝试(global-auto-revert-mode)自动将文件还原到磁盘上的文件.


Rad*_*ugh 5

就我而言,我想要:

(setq revert-without-query '(".*"))
Run Code Online (Sandbox Code Playgroud)

文档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.
Run Code Online (Sandbox Code Playgroud)

  • 这是一个很好的答案!比猴子修补好得多。 (2认同)