Commit
Closes #60 magit/magit#2491 magit/magit#2530
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -488,8 +488,8 @@ in the source file, or the last line of the hunk above it." | |
;; doesn't care about changed VC state. | ||
;; https://github.com/magit/magit/issues/603 | ||
(add-hook 'magit-revert-buffer-hook 'diff-hl-update nil t) | ||
;; Magit 2+ doesn't do the above and calls this instead, | ||
;; but only when it doesn't call `revert-buffer': | ||
;; Magit versions 2.0-2.3 don't do the above and call this | ||
;; instead, but only when they dosn't call `revert-buffer': | ||
(add-hook 'magit-not-reverted-hook 'diff-hl-update nil t) | ||
(add-hook 'auto-revert-mode-hook 'diff-hl-update nil t) | ||
(add-hook 'text-scale-mode-hook 'diff-hl-define-bitmaps nil t)) | ||
|
@@ -517,6 +517,32 @@ in the source file, or the last line of the hunk above it." | |
(scan diff-hl-command-map) | ||
(smartrep-define-key diff-hl-mode-map diff-hl-command-prefix smart-keys)))) | ||
|
||
(declare-function magit-toplevel "magit-git") | ||
(declare-function magit-unstaged-files "magit-git") | ||
|
||
(defun diff-hl-magit-post-refresh () | ||
(let* ((topdir (magit-toplevel)) | ||
(modified-files | ||
(mapcar (lambda (file) (expand-file-name file topdir)) | ||
(magit-unstaged-files t))) | ||
(unmodified-states '(up-to-date ignored unregistered))) | ||
(dolist (buf (buffer-list)) | ||
(when (and (buffer-local-value 'diff-hl-mode buf) | ||
(not (buffer-modified-p buf)) | ||
(file-in-directory-p (buffer-file-name buf) topdir)) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dgutov
Author
Owner
|
||
(with-current-buffer buf | ||
(let* ((file buffer-file-name) | ||
(backend (vc-backend file))) | ||
(when backend | ||
(cond | ||
((member file modified-files) | ||
(when (memq (vc-state file) unmodified-states) | ||
(vc-state-refresh file backend)) | ||
(diff-hl-update)) | ||
((not (memq (vc-state file backend) unmodified-states)) | ||
(vc-state-refresh file backend) | ||
(diff-hl-update)))))))))) | ||
|
||
(defun diff-hl-dir-update () | ||
(dolist (pair (if (vc-dir-marked-files) | ||
(vc-dir-marked-only-files-and-states) | ||
|
2 comments
on commit fdbf34a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 👍
I have run into cases where
(buffer-file-name buf)
returnednil
but the preceding conditions where non-nil. This happens in buffers created withmagit-find-file
. I am not sure wherediff-hl
gets turned on in those files and whether that is desirable or not.I'll investigate some other time but thought I would let you know. Meanwhile you might wanna add an additional condition
(buffer-file-name buf)
.