kacchi #405(2007/07/09 20:42 GMT) [ Emacs Lisp ] Rating0/0=0.00
EmacsLisp です :-) 毎秒、更新時刻を比較します。 (setq filename "hoge") などとして、M-x watch-modification で起動してください。 変数 filename がセットされてないなら、ファイル名を聞いてくるので指定してください。 キャンセルするには、M-x watch-modification-cancel です。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
(defvar watch-modification-repeat-sec 1.0) (defvar watch-modification-timer nil) (defvar watch-modification-stack nil) (defvar watch-modification-buffer "*watch*") (defun watch-modification () (interactive) (let ((file (or (and (boundp 'filename) filename) (read-file-name "File: ")))) (unless (string= file "") (watch-modification-cancel) (setq watch-modification-timer (run-with-timer 1 watch-modification-repeat-sec 'watch-modification-function file))))) (defun watch-modification-cancel () (interactive) (when watch-modification-timer (cancel-timer watch-modification-timer)) (setq watch-modification-timer nil watch-modification-stack nil)) (defun watch-modification-function (file) (let ((modified-time (nth 5 (file-attributes file)))) (if (null watch-modification-stack) (push modified-time watch-modification-stack) (unless (equal modified-time (car watch-modification-stack)) (push modified-time watch-modification-stack) (save-selected-window (pop-to-buffer (set-buffer (get-buffer-create watch-modification-buffer))) (insert "modified!\n"))))))
Rating0/0=0.00-0+
[ reply ]
kacchi
#405()
[
Emacs Lisp
]
Rating0/0=0.00
(defvar watch-modification-repeat-sec 1.0) (defvar watch-modification-timer nil) (defvar watch-modification-stack nil) (defvar watch-modification-buffer "*watch*") (defun watch-modification () (interactive) (let ((file (or (and (boundp 'filename) filename) (read-file-name "File: ")))) (unless (string= file "") (watch-modification-cancel) (setq watch-modification-timer (run-with-timer 1 watch-modification-repeat-sec 'watch-modification-function file))))) (defun watch-modification-cancel () (interactive) (when watch-modification-timer (cancel-timer watch-modification-timer)) (setq watch-modification-timer nil watch-modification-stack nil)) (defun watch-modification-function (file) (let ((modified-time (nth 5 (file-attributes file)))) (if (null watch-modification-stack) (push modified-time watch-modification-stack) (unless (equal modified-time (car watch-modification-stack)) (push modified-time watch-modification-stack) (save-selected-window (pop-to-buffer (set-buffer (get-buffer-create watch-modification-buffer))) (insert "modified!\n"))))))Rating0/0=0.00-0+
[ reply ]