]> code.delx.au - gnu-emacs-elpa/blob - diff-hl-amend.el
diff-hl-amend-mode: Don't defer via find-file-hook
[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 (require 'diff-hl)
27
28 ;;;###autoload
29 (define-minor-mode diff-hl-amend-mode
30 "Show changes against the second-last revision in `diff-hl-mode'.
31 Most useful with backends that support rewriting local commits,
32 and most importantly, 'amending' the most recent one.
33 Currently only supports Git, Mercurial and Bazaar."
34 :lighter " Amend"
35 (if diff-hl-amend-mode
36 (progn
37 (diff-hl-amend-setup)
38 (add-hook 'after-revert-hook 'diff-hl-amend-setup nil t))
39 (remove-hook 'after-revert-hook 'diff-hl-amend-setup t)
40 (setq-local diff-hl-reference-revision nil))
41 (when diff-hl-mode
42 (diff-hl-update)))
43
44 (defun diff-hl-amend-setup ()
45 (let ((backend (vc-backend buffer-file-name)))
46 (when backend
47 (setq-local diff-hl-reference-revision
48 (cl-case backend
49 (Git
50 "HEAD^")
51 (Hg
52 "-2")
53 (Bzr
54 "revno:-2"))))))
55
56 ;;;###autoload
57 (define-globalized-minor-mode global-diff-hl-amend-mode diff-hl-amend-mode
58 turn-on-diff-hl-amend-mode)
59
60 (defun turn-on-diff-hl-amend-mode ()
61 "Turn on `diff-hl-amend-mode' in a buffer if appropriate."
62 (and buffer-file-name (diff-hl-amend-mode 1)))
63
64 (provide 'diff-hl-amend)
65
66 ;;; diff-hl-amend.el ends here