When the (vers开发者_开发问答ion controlled) file is updated, emacs doesn't show the status instantly. With TextMate, if something changes with the file that I'm editing, it notifies me right away.
- Is there any way to make the notification instant?
- M-x load-file is the only way to check if something is changed?
ADDED
(custom-set-variables
'(auto-revert-interval 1))
(global-auto-revert-mode 1)
It sets 1 seconds for revert interval, and it seems to work pretty well.
You should look into "auto-revert-mode". As the name implies, it'll automatically revert buffers if the underlying file has changed.
Note that you still won't get instant notifications; instead, Emacs will in effect "poll" the files every so often (configurable via "auto-revert-interval"; I think I use five seconds for most stuff, and one second for log files that I'm carefully monitoring).
I have it turned on for everything, like this:
(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)))
Reloading the contents buffer from the copy on disk is called reverting in Emacs, and you may be interested in the “Reverting” section in the manual.
If you do your version control from Emacs, it should take care of reverting on an update.
By default, Emacs checks for a file update when you make the first change after saving.
Here's a function I use when I've modified a file externally.
(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)))))))
Here's a script to invoke it from a shell command (it could be invoked from a wrapper script for version control operations).
#!/bin/sh
files=
for x; do
files="$files \"`printf '%s' "$x" | sed 's/[\\\\\\\"]/\\\\&/g'`\""
done
emacsclient -e "(revert-files$files)"
Warning: I've removed some cruft from the code as I copied it, so there may be typos.
精彩评论