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

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

[elpa] externals/diff-hl 89aeb2f 4/4: Merge pull request #146 from AmaiK


From: ELPA Syncer
Subject: [elpa] externals/diff-hl 89aeb2f 4/4: Merge pull request #146 from AmaiKinono/generalize-amend-mode
Date: Wed, 6 Jan 2021 21:57:09 -0500 (EST)

branch: externals/diff-hl
commit 89aeb2fc8b24b6c4de4394f85041c5dd5fa60dad
Merge: a0028d9 ecd3a3e
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: GitHub <noreply@github.com>

    Merge pull request #146 from AmaiKinono/generalize-amend-mode
    
    Set reference rev in change log buffer
---
 README.md        |  4 +++-
 diff-hl-amend.el |  2 +-
 diff-hl.el       | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 9bc4576..b64d228 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,9 @@ The package also contains auxiliary modes:
 * `diff-hl-dired-mode` provides similar functionality in Dired.
 * `diff-hl-margin-mode` changes the highlighting function to
   use the margin instead of the fringe.
-* `diff-hl-amend-mode` shifts the reference revision back by one.
+* `diff-hl-amend-mode` sets the reference revision to the one before
+  recent one. Also, you could use `diff-hl-set-reference-rev` to set
+  it to any revision, see its docstring for details.
 * `diff-hl-flydiff-mode` implements highlighting changes on the fly.
   It requires Emacs 24.4 or newer.
 
diff --git a/diff-hl-amend.el b/diff-hl-amend.el
index b0470ae..c58a2bd 100644
--- a/diff-hl-amend.el
+++ b/diff-hl-amend.el
@@ -39,7 +39,7 @@ Currently only supports Git, Mercurial and Bazaar."
         (diff-hl-amend-setup)
         (add-hook 'after-revert-hook 'diff-hl-amend-setup nil t))
     (remove-hook 'after-revert-hook 'diff-hl-amend-setup t)
-    (setq-local diff-hl-reference-revision nil))
+    (kill-local-variable 'diff-hl-reference-revision))
   (when diff-hl-mode
     (diff-hl-update)))
 
diff --git a/diff-hl.el b/diff-hl.el
index 0b7adc3..bf82254 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -35,6 +35,8 @@
 ;; `diff-hl-revert-hunk'     C-x v n
 ;; `diff-hl-previous-hunk'   C-x v [
 ;; `diff-hl-next-hunk'       C-x v ]
+;; `diff-hl-set-reference-rev'
+;; `diff-hl-reset-reference-rev'
 ;;
 ;; The mode takes advantage of `smartrep' if it is installed.
 
@@ -55,6 +57,8 @@
 (require 'diff-mode)
 (require 'vc)
 (require 'vc-dir)
+(require 'log-view)
+
 (eval-when-compile
   (require 'cl-lib)
   (require 'vc-git)
@@ -698,6 +702,51 @@ The value of this variable is a mode line template as in
     (turn-on-diff-hl-mode)))
 
 ;;;###autoload
+(defun diff-hl-set-reference-rev (&optional rev)
+  "Set the reference revision globally to REV.
+When called interactively, REV is get from contexts:
+
+- In a log view buffer, it uses the revision of current entry.
+Call `vc-print-log' or `vc-print-root-log' first to open a log
+view buffer.
+- In a VC annotate buffer, it uses the revision of current line.
+- In other situations, get the revision name at point.
+
+Notice that this sets the reference revision globally, so in
+files from other repositories, `diff-hl-mode' will not highlight
+changes correctly, until you run `diff-hl-reset-reference-rev'.
+
+Also notice that this will disable `diff-hl-amend-mode' in
+buffers that enables it, since `diff-hl-amend-mode' overrides its
+effect."
+  (interactive)
+  (let* ((rev (or rev
+                  (and (equal major-mode 'vc-annotate-mode)
+                       (car (vc-annotate-extract-revision-at-line)))
+                  (log-view-current-tag)
+                  (thing-at-point 'symbol t))))
+    (if rev
+        (message "Set reference rev to %s" rev)
+      (user-error "Can't find a revision around point"))
+    (setq diff-hl-reference-revision rev))
+  (dolist (buf (buffer-list))
+    (with-current-buffer buf
+      (when diff-hl-mode
+        (when diff-hl-amend-mode
+          (diff-hl-amend-mode -1))
+        (diff-hl-update)))))
+
+;;;###autoload
+(defun diff-hl-reset-reference-rev ()
+  "Reset the reference revision globally to the most recent one."
+  (interactive)
+  (setq diff-hl-reference-revision nil)
+  (dolist (buf (buffer-list))
+    (with-current-buffer buf
+      (when diff-hl-mode
+        (diff-hl-update)))))
+
+;;;###autoload
 (define-globalized-minor-mode global-diff-hl-mode diff-hl-mode
   diff-hl--global-turn-on :after-hook (diff-hl-global-mode-change))
 



reply via email to

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