]> code.delx.au - gnu-emacs-elpa/blob - diff-hl-amend.el
Add the footer
[gnu-emacs-elpa] / diff-hl-amend.el
1 ;; Author: Dmitry Gutov <dgutov@yandex.ru>
2 ;; URL: https://github.com/dgutov/diff-hl
3
4 ;; This file is not part of GNU Emacs.
5
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.
10
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.
15
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/>.
18
19 ;;; Commentary:
20
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'.
23
24 ;;; Code:
25
26 ;;;###autoload
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."
32 :lighter " Amend"
33 (if diff-hl-amend-mode
34 (progn
35 (if vc-mode
36 (diff-hl-amend-set)
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))
42 (when diff-hl-mode
43 (diff-hl-update)))
44
45 (defun diff-hl-amend-setup ()
46 (let ((backend (vc-backend buffer-file-name)))
47 (when backend
48 (setq-local diff-hl-reference-revision
49 (cl-case backend
50 (Git
51 "HEAD^")
52 (Hg
53 "-2")
54 (Bzr
55 "revno:-2"))))))
56
57 ;;;###autoload
58 (define-globalized-minor-mode global-diff-hl-amend-mode diff-hl-amend-mode
59 turn-on-diff-hl-amend-mode)
60
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)))
64
65 (provide 'diff-hl-amend)
66
67 ;;; diff-hl-amend.el ends here