July 26, 2007

diredでgを押さずにbufferを更新

若干誇張しすぎてる気もするけど、とりあえずgを押せと言われるシチュエーションに於いてgを押さずに勝手に更新してもらう方法。

(defadvice dired-noselect (after my-dired-noselect (dir-or-list &optional switches) activate)
(if (dired-directory-changed-p dir-or-list)
(with-current-buffer ad-return-value
(let ((pos (point))
(current-file (dired-get-filename)))
(revert-buffer)
(unless (dired-goto-file current-file)
(goto-char pos))
(message "Dired buffer `%s' has been updated." dir-or-list)))))

No comments: