]> code.delx.au - gnu-emacs-elpa/blob - diff-hl-amend.el
Bump the version
[gnu-emacs-elpa] / diff-hl-amend.el
1 ;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
2
3 ;; Author: Dmitry Gutov <dgutov@yandex.ru>
4 ;; URL: https://github.com/dgutov/diff-hl
5
6 ;; This file is part of GNU Emacs.
7
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; Toggle in the current buffer with `M-x diff-hl-amend-mode'.
24 ;; Toggle in all buffers with `M-x global-diff-hl-amend-mode'.
25
26 ;;; Code:
27
28 (require 'diff-hl)
29
30 ;;;###autoload
31 (define-minor-mode diff-hl-amend-mode
32 "Show changes against the second-last revision in `diff-hl-mode'.
33 Most useful with backends that support rewriting local commits,
34 and most importantly, 'amending' the most recent one.
35 Currently only supports Git, Mercurial and Bazaar."
36 :lighter " Amend"
37 (if diff-hl-amend-mode
38 (progn
39 (diff-hl-amend-setup)
40 (add-hook 'after-revert-hook 'diff-hl-amend-setup nil t))
41 (remove-hook 'after-revert-hook 'diff-hl-amend-setup t)
42 (setq-local diff-hl-reference-revision nil))
43 (when diff-hl-mode
44 (diff-hl-update)))
45
46 (defun diff-hl-amend-setup ()
47 (let ((backend (vc-backend buffer-file-name)))
48 (when backend
49 (setq-local diff-hl-reference-revision
50 (cl-case backend
51 (Git
52 "HEAD^")
53 (Hg
54 "-2")
55 (Bzr
56 "revno:-2"))))))
57
58 ;;;###autoload
59 (define-globalized-minor-mode global-diff-hl-amend-mode diff-hl-amend-mode
60 turn-on-diff-hl-amend-mode)
61
62 (defun turn-on-diff-hl-amend-mode ()
63 "Turn on `diff-hl-amend-mode' in a buffer if appropriate."
64 (and buffer-file-name (diff-hl-amend-mode 1)))
65
66 (provide 'diff-hl-amend)
67
68 ;;; diff-hl-amend.el ends here