Skip to content

Commit a772fbd

Browse files
committed
fix(auto-revert): fix immediate auto-reverting when the file is deleted
1 parent c0d41ed commit a772fbd

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/me-builtin.el

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ Typing these will trigger reindentation of the current line.")
10411041
;; modification time of the file on save and on buffer switch.
10421042
(defvar-local +auto-revert-buffer-time nil)
10431043
(defun +file-mtime (file)
1044-
(when-let* ((file-attr (and file (file-attributes file))))
1044+
(when-let* ((file-attr (and file (file-exists-p file) (file-attributes file))))
10451045
(file-attribute-modification-time file-attr)))
10461046

10471047
(defun +auto-revert--save-file-mtime (&rest _args)
@@ -1054,9 +1054,10 @@ Typing these will trigger reindentation of the current line.")
10541054
(defun +auto-revert--on-buffer-switch-h (_frame)
10551055
(unless +auto-revert-buffer-time
10561056
(setq +auto-revert-buffer-time (+file-mtime buffer-file-name)))
1057-
(unless (equal +auto-revert-buffer-time (+file-mtime buffer-file-name))
1058-
(+log! "File %S modified externally, reverting immediately!" buffer-file-name)
1059-
(revert-buffer t t)))
1057+
(when-let* ((mtime (+file-mtime buffer-file-name)))
1058+
(unless (equal mtime +auto-revert-buffer-time)
1059+
(+log! "File %S modified externally, reverting immediately!" buffer-file-name)
1060+
(revert-buffer t t))))
10601061

10611062
(add-hook 'window-buffer-change-functions #'+auto-revert--on-buffer-switch-h))
10621063

0 commit comments

Comments
 (0)