minmo : minmo--file-exists-cache
This commit is contained in:
parent
31056f946a
commit
b5f6f080e1
1 changed files with 30 additions and 5 deletions
|
|
@ -187,7 +187,7 @@ Optional FORCE means ignore the minmo--git-directory-table."
|
||||||
(add-hook 'after-save-hook #'minmo--update-git-cache)
|
(add-hook 'after-save-hook #'minmo--update-git-cache)
|
||||||
|
|
||||||
;; NOTE: but normal cache update when window state changes:
|
;; NOTE: but normal cache update when window state changes:
|
||||||
(defun minmo--update-git-cache-window-status (frame-or-window)
|
(defun minmo--update-git-cache-window (frame-or-window)
|
||||||
(let ((win (if (framep frame-or-window)
|
(let ((win (if (framep frame-or-window)
|
||||||
(frame-selected-window frame-or-window)
|
(frame-selected-window frame-or-window)
|
||||||
frame-or-window)))
|
frame-or-window)))
|
||||||
|
|
@ -196,9 +196,9 @@ Optional FORCE means ignore the minmo--git-directory-table."
|
||||||
|
|
||||||
;; NOTE: window-state-change-functions includes size changes, which would be spammy.
|
;; NOTE: window-state-change-functions includes size changes, which would be spammy.
|
||||||
;; this does selection changes, eg other-window:
|
;; this does selection changes, eg other-window:
|
||||||
(add-hook 'window-selection-change-functions #'minmo--update-git-cache-window-status)
|
(add-hook 'window-selection-change-functions #'minmo--update-git-cache-window)
|
||||||
;; this does buffer changes, eg switch-to-buffer:
|
;; this does buffer changes, eg switch-to-buffer:
|
||||||
(add-hook 'window-buffer-change-functions #'minmo--update-git-cache-window-status)
|
(add-hook 'window-buffer-change-functions #'minmo--update-git-cache-window)
|
||||||
|
|
||||||
;; this is set by vc-hooks.el, which is loaded with `vc'
|
;; this is set by vc-hooks.el, which is loaded with `vc'
|
||||||
;; TODO: remove?
|
;; TODO: remove?
|
||||||
|
|
@ -245,6 +245,30 @@ Optional FORCE means ignore the minmo--git-directory-table."
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;;; disk
|
;;;; disk
|
||||||
|
|
||||||
|
(defvar-local minmo--file-exists-cache nil
|
||||||
|
"Cached boolean indicating if the file exists on disk.")
|
||||||
|
|
||||||
|
(defun minmo--update-file-exists-cache ()
|
||||||
|
(when buffer-file-name
|
||||||
|
(setq minmo--file-exists-cache
|
||||||
|
;; skip the check for remote files and assume they exist:
|
||||||
|
(if (file-remote-p (buffer-file-name)) t
|
||||||
|
(file-exists-p buffer-file-name)))))
|
||||||
|
|
||||||
|
(defun minmo--update-file-exists-cache-window (frame-or-window)
|
||||||
|
(let ((win (if (framep frame-or-window)
|
||||||
|
(frame-selected-window frame-or-window)
|
||||||
|
frame-or-window)))
|
||||||
|
(with-current-buffer (window-buffer win)
|
||||||
|
(minmo--update-file-exists-cache))))
|
||||||
|
|
||||||
|
(add-hook 'find-file-hook #'minmo--update-file-exists-cache)
|
||||||
|
;; NOTE: before hook, because revert will refuse when it's gone:
|
||||||
|
(add-hook 'before-revert-hook #'minmo--update-file-exists-cache)
|
||||||
|
(add-hook 'after-save-hook #'minmo--update-file-exists-cache)
|
||||||
|
(add-hook 'window-selection-change-functions #'minmo--update-file-exists-cache-window)
|
||||||
|
(add-hook 'window-buffer-change-functions #'minmo--update-file-exists-cache-window)
|
||||||
|
|
||||||
(defun minmo-disk-status ()
|
(defun minmo-disk-status ()
|
||||||
(cond
|
(cond
|
||||||
;; readonly:
|
;; readonly:
|
||||||
|
|
@ -253,9 +277,10 @@ Optional FORCE means ignore the minmo--git-directory-table."
|
||||||
;; no file but modified:
|
;; no file but modified:
|
||||||
((and (not buffer-file-name) (buffer-modified-p))
|
((and (not buffer-file-name) (buffer-modified-p))
|
||||||
(minmo--status 'nofile/untracked 'disk))
|
(minmo--status 'nofile/untracked 'disk))
|
||||||
;; has a path but was never visited: new unsaved file
|
;; has a path but was never visited or no longer exists.
|
||||||
;; NOTE: visited-file-modtime involves no disk read:
|
;; NOTE: visited-file-modtime involves no disk read:
|
||||||
((and buffer-file-name (eq -1 (visited-file-modtime)))
|
((and buffer-file-name (or (eq -1 (visited-file-modtime))
|
||||||
|
(not minmo--file-exists-cache)))
|
||||||
(minmo--status 'staged 'disk))
|
(minmo--status 'staged 'disk))
|
||||||
;; normally modified:
|
;; normally modified:
|
||||||
((and buffer-file-name (buffer-modified-p))
|
((and buffer-file-name (buffer-modified-p))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue