1 ;; Author: Dmitry Gutov <dgutov@yandex.ru>
2 ;; URL: https://github.com/dgutov/diff-hl
4 ;; This file is not part of GNU Emacs.
6 ;; This file is free software: you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation, either version 3 of the License, or
9 ;; (at your option) any later version.
11 ;; This file is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21 ;; Toggle in the current buffer with `M-x diff-hl-amend-mode'.
22 ;; Toggle in all buffers with `M-x global-diff-hl-amend-mode'.
27 (define-minor-mode diff-hl-amend-mode
28 "Show changes against the second-last revision in `diff-hl-mode'.
29 Most useful with VCSes that support rewriting local commits, and
30 'amending' the most recent one in particular.
31 Currently only supports Git, Mercurial and Bazaar."
33 (if diff-hl-amend-mode
37 (add-hook 'find-file-hook 'diff-hl-amend-setup nil t))
38 (add-hook 'after-revert-hook 'diff-hl-amend-setup nil t))
39 (remove-hook 'find-file-hook 'diff-hl-amend-setup t)
40 (remove-hook 'after-revert-hook 'diff-hl-amend-setup t)
41 (setq-local diff-hl-reference-revision nil))
45 (defun diff-hl-amend-setup ()
46 (let ((backend (vc-backend buffer-file-name)))
48 (setq-local diff-hl-reference-revision
58 (define-globalized-minor-mode global-diff-hl-amend-mode diff-hl-amend-mode
59 turn-on-diff-hl-amend-mode)
61 (defun turn-on-diff-hl-amend-mode ()
62 "Turn on `diff-hl-amend-mode' in a buffer if appropriate."
63 (and buffer-file-name (diff-hl-amend-mode 1)))
65 (provide 'diff-hl-amend)
67 ;;; diff-hl-amend.el ends here