tools/magit: update vc on +magit/quit

Instead of magit-post-refresh-hook, which fires much more frequently.
Updating vc across all buffers is expensive, so let's only do it when we
quit magit.

Warning: this may make quitting magit expensive when you have many
buffers open. Still searching for a better solution.
This commit is contained in:
Henrik Lissner 2018-09-26 12:10:00 -04:00
parent d9a179d071
commit fcd1e913c5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 10 additions and 10 deletions

View file

@ -50,9 +50,16 @@
;;;###autoload
(defun +magit/quit (&optional _kill-buffer)
"Clean up magit buffers after quitting `magit-status'."
"Clean up magit buffers after quitting `magit-status' and refresh version
control in buffers."
(interactive)
(mapc #'+magit--kill-buffer (magit-mode-get-buffers)))
(mapc #'+magit--kill-buffer (magit-mode-get-buffers))
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (fboundp 'vc-refresh-state)
(vc-refresh-state))
(when (fboundp '+version-control|update-git-gutter)
(+version-control|update-git-gutter)))))
(defun +magit--kill-buffer (buf)
"TODO"

View file

@ -47,14 +47,7 @@ available.")
;; Don't replace the leader key
;; FIXME remove me when general.el is integrated
(define-key magit-diff-mode-map (kbd doom-leader-key) nil)
(defun +magit|update-vc ()
"Update vc in all verson-controlled buffers when magit refreshes."
(dolist (buf (buffer-list))
(with-current-buffer buf
(vc-refresh-state))))
(add-hook 'magit-post-refresh-hook #'+magit|update-vc))
(define-key magit-diff-mode-map (kbd doom-leader-key) nil))
(def-package! magit-todos