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

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

[elpa] master 7e8c4e9 6/6: Merge commit 'f4edea201bc4c38d082ec3143ceec87


From: Dmitry Gutov
Subject: [elpa] master 7e8c4e9 6/6: Merge commit 'f4edea201bc4c38d082ec3143ceec87d2dcadb37' from diff-hl
Date: Wed, 03 Feb 2016 23:03:37 +0000

branch: master
commit 7e8c4e9591151043ecbc8ad78163861d3348106d
Merge: d33fb54 f4edea2
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Merge commit 'f4edea201bc4c38d082ec3143ceec87d2dcadb37' from diff-hl
---
 packages/diff-hl/README.md        |   10 +++++++-
 packages/diff-hl/diff-hl-dired.el |   13 ++++++++++-
 packages/diff-hl/diff-hl.el       |   40 ++++++++++++++++++++++++++++++++++--
 3 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/packages/diff-hl/README.md b/packages/diff-hl/README.md
index ab8c9d8..b8bbe3a 100644
--- a/packages/diff-hl/README.md
+++ b/packages/diff-hl/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)
+```
diff --git a/packages/diff-hl/diff-hl-dired.el 
b/packages/diff-hl/diff-hl-dired.el
index 663d293..895341b 100644
--- a/packages/diff-hl/diff-hl-dired.el
+++ b/packages/diff-hl/diff-hl-dired.el
@@ -33,6 +33,7 @@
 
 (require 'diff-hl)
 (require 'dired)
+(require 'vc-hooks)
 
 (defvar diff-hl-dired-process-buffer nil)
 
@@ -62,9 +63,17 @@
 
 (defcustom diff-hl-dired-extra-indicators t
   "Non-nil to indicate ignored files."
-  :group 'diff-hl
   :type 'boolean)
 
+(defcustom diff-hl-dired-ignored-backends '(RCS)
+  "VC backends to ignore.
+The directories registered to one of these backends won't have
+status indicators."
+  :type `(repeat (choice ,@(mapcar
+                            (lambda (name)
+                              `(const :tag ,(symbol-name name) ,name))
+                            vc-handled-backends))))
+
 ;;;###autoload
 (define-minor-mode diff-hl-dired-mode
   "Toggle VC diff highlighting on the side of a Dired window."
@@ -83,7 +92,7 @@
         (def-dir default-directory)
         (buffer (current-buffer))
         dirs-alist files-alist)
-    (when backend
+    (when (and backend (not (memq backend diff-hl-dired-ignored-backends)))
       (diff-hl-dired-clear)
       (if (buffer-live-p diff-hl-dired-process-buffer)
           (let ((proc (get-buffer-process diff-hl-dired-process-buffer)))
diff --git a/packages/diff-hl/diff-hl.el b/packages/diff-hl/diff-hl.el
index b840788..2aaabd4 100644
--- a/packages/diff-hl/diff-hl.el
+++ b/packages/diff-hl/diff-hl.el
@@ -5,7 +5,7 @@
 ;; Author:   Dmitry Gutov <address@hidden>
 ;; URL:      https://github.com/dgutov/diff-hl
 ;; Keywords: vc, diff
-;; Version:  1.8.2
+;; Version:  1.8.3
 ;; Package-Requires: ((cl-lib "0.2"))
 
 ;; This file is part of GNU Emacs.
@@ -445,6 +445,14 @@ in the source file, or the last line of the hunk above it."
   (interactive)
   (diff-hl-next-hunk t))
 
+(defun diff-hl-mark-hunk ()
+  (interactive)
+  (let ((hunk (diff-hl-hunk-overlay-at (point))))
+    (unless hunk
+      (error "No hunk at point"))
+    (goto-char (overlay-start hunk))
+    (push-mark (overlay-end hunk) nil t)))
+
 (defvar diff-hl-command-map
   (let ((map (make-sparse-keymap)))
     (define-key map "n" 'diff-hl-revert-hunk)
@@ -480,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))
@@ -509,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]