代码之家  ›  专栏  ›  技术社区  ›  prosseek

在外部修改文件时,为什么在emacs中重新加载通知速度慢?

  •  3
  • prosseek  · 技术社区  · 14 年前

    • 有什么办法可以让通知立即生效吗?

    补充

    (custom-set-variables
     '(auto-revert-interval 1))
    (global-auto-revert-mode 1)
    

    它为恢复间隔设置了1秒,而且似乎工作得很好。

    2 回复  |  直到 11 年前
        1
  •  3
  •   offby1    14 年前

    您应该查看“自动恢复模式”。顾名思义,如果基础文件发生更改,它将自动恢复缓冲区。

    请注意,您仍然无法获得 瞬间 通知;相反,Emacs实际上每隔一段时间就“轮询”一次文件(可通过“自动恢复间隔”进行配置;我认为我对大多数内容使用5秒钟,对我正在仔细监视的日志文件使用1秒钟)。

    我把所有的东西都打开了,像这样:

    (defvar running-on-windows
       (memq system-type '(windows-nt cygwin32 cygwin))
       "True if and only if we're running on Windows.  Both Win32 and
    Cygwin count.")
    
    (when (fboundp 'global-auto-revert-mode)
    
      ;; All the "reverting buffer foo" messages are _really_ distracting.
      (setq auto-revert-verbose nil)
    
      (global-auto-revert-mode 1)
    
      ;; just as the docs warn, this can really make Emacs sluggish.
      (if running-on-windows
          (if (fboundp 'lwarn)
              (lwarn
               'global-auto-revert-mode
               :warning
               "I just turned on global-auto-revert-mode.  It's nifty,
    but it's REALLY SLOW when you have buffers that are visiting
    remote files.  And despite its documentation, it does NOT ignore
    those files, if you're using windows, and the file name begins
    with a drive letter and a colon."))
        (setq global-auto-revert-non-file-buffers t)))
    
        2
  •  0
  •   Gilles 'SO- stop being evil'    14 年前

    从磁盘上的副本重新加载内容缓冲区称为 还原

    如果您从Emacs执行版本控制,它应该负责在更新时恢复。


    下面是我在外部修改文件时使用的函数。

    (defun revert-files (&rest files)
      "Reload all specified files from disk.
    Only files that are currently visited in some buffer are reverted.
    Do not ask confirmation unless the buffer is modified."
      (save-excursion
        (let ((revert-without-query '("")))
          (dolist (file-name files)
            (message "Considering whether to revert file %s" file-name)
            (let ((buf (find-buffer-visiting file-name)))
              (when buf
                (message "Reverting file in buffer %s" (buffer-name buf))
                (set-buffer buf)
                (revert-buffer t nil t)))))))
    

    #!/bin/sh
    files=
    for x; do
      files="$files \"`printf '%s' "$x" | sed 's/[\\\\\\\"]/\\\\&/g'`\""
    done
    emacsclient -e "(revert-files$files)"