emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master fdbf34a 3/6: Implement integration with Magit 2.4


From: Dmitry Gutov
Subject: [elpa] master fdbf34a 3/6: Implement integration with Magit 2.4
Date: Wed, 03 Feb 2016 23:03:37 +0000

branch: master
commit fdbf34a93d6b249ba20d9e7501dfa026aa88ac04
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Implement integration with Magit 2.4
    
    Closes #60
    
    https://github.com/magit/magit/issues/2491
    https://github.com/magit/magit/pull/2530
---
 README.md  |   10 ++++++++--
 diff-hl.el |   30 ++++++++++++++++++++++++++++--
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index ab8c9d8..8de2bf0 100644
--- a/README.md
+++ b/README.md
@@ -90,5 +90,11 @@ psvn
 Magit
 -----
 
-If you have a recent enough version installed, it defines
-`magit-revert-buffer-hook` (or `magit-not-reverted-hook`), which we use.
+If you're using a version before 2.4.0, it defines `magit-revert-buffer-hook`
+(or `magit-not-reverted-hook`), which we use.
+
+When using Magit 2.4 or newer, add this to your init script:
+
+```lisp
+(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh t)
+```
diff --git a/diff-hl.el b/diff-hl.el
index 63c2cde..9c6f877 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -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))
+        (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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]