forked from emacsorphanage/git-gutter-fringe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-gutter-fringe.el
More file actions
162 lines (133 loc) · 4.84 KB
/
Copy pathgit-gutter-fringe.el
File metadata and controls
162 lines (133 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
;;; git-gutter-fringe.el --- Fringe version of git-gutter.el -*- lexical-binding: t; -*-
;; Copyright (C) 2014 by Syohei YOSHIDA
;; Author: Syohei YOSHIDA <syohex@gmail.com>
;; URL: https://github.com/syohex/emacs-git-gutter-fringe
;; Version: 0.21
;; Package-Requires: ((git-gutter "0.73") (fringe-helper "0.1.1") (cl-lib "0.5") (emacs "24"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Show git diff information in fringe. You can use this package
;; only GUI Emacs, not working no window emacs.
;; To use this package, add following code to your init.el or .emacs
;;
;; (require 'git-gutter-fringe)
;; (global-git-gutter-mode t)
;;
;; ; If you want to show git diff information at right fringe
;; (setq git-gutter-fr:side 'right-fringe)
;;
;;; Code:
(require 'cl-lib)
(defvar git-gutter-fringe nil)
(require 'git-gutter)
(require 'fringe-helper)
(defface git-gutter-fr:modified
'((t (:inherit git-gutter:modified)))
"Face of modified"
:group 'git-gutter)
(defface git-gutter-fr:added
'((t (:inherit git-gutter:added)))
"Face of added"
:group 'git-gutter)
(defface git-gutter-fr:deleted
'((t (:inherit git-gutter:deleted)))
"Face of deleted"
:group 'git-gutter)
(defcustom git-gutter-fr:side 'left-fringe
"Side of show diff information"
:type '(choice (const :tag "Right Fringe" right-fringe)
(const :tag "Left Fringe" left-fringe))
:group 'git-gutter)
(fringe-helper-define 'git-gutter-fr:added nil
"...XX..."
"...XX..."
"...XX..."
"XXXXXXXX"
"XXXXXXXX"
"...XX..."
"...XX..."
"...XX...")
(fringe-helper-define 'git-gutter-fr:deleted nil
"........"
"........"
"........"
"XXXXXXXX"
"XXXXXXXX"
"........"
"........"
"........")
(fringe-helper-define 'git-gutter-fr:modified nil
"........"
"..XXXX.."
"..XXXX.."
"..XXXX.."
"..XXXX.."
"..XXXX.."
"..XXXX.."
"........")
(defvar git-gutter-fr:bitmap-references nil)
(defsubst git-gutter-fr:select-sign (type)
(cl-case type
(modified 'git-gutter-fr:modified)
(added 'git-gutter-fr:added)
(deleted 'git-gutter-fr:deleted)))
(defsubst git-gutter-fr:select-face (type)
(cl-case type
(modified 'git-gutter-fr:modified)
(added 'git-gutter-fr:added)
(deleted 'git-gutter-fr:deleted)))
(defun git-gutter-fr:init ()
(make-local-variable 'git-gutter-fr:bitmap-references))
(defun git-gutter-fr:view-diff-infos (diffinfos)
(when git-gutter-fr:bitmap-references
(git-gutter:clear))
(save-excursion
(goto-char (point-min))
(cl-loop with curline = 1
for info in diffinfos
for start-line = (plist-get info :start-line)
for end-line = (plist-get info :end-line)
for type = (plist-get info :type)
do
(let (beg end)
(forward-line (- start-line curline))
(setq beg (point))
(if (eq type 'deleted)
(progn
(setq end beg))
(forward-line (- end-line start-line))
(setq end (point)))
(let* ((sign (git-gutter-fr:select-sign type))
(face (git-gutter-fr:select-face type))
(reference (fringe-helper-insert-region
beg end sign git-gutter-fr:side face)))
(overlay-put reference 'git-gutter t)
(dolist (ov (overlays-in beg (1+ end)))
(when (eq (overlay-get ov 'fringe-helper-parent) reference)
(overlay-put ov 'git-gutter t)))
(push reference git-gutter-fr:bitmap-references))
(setq curline end-line)))))
;; @@@ Somtimes `fringe-helper-remove' does not work for clearing overlays
;;(defun git-gutter-fr:clear-overlay (reference)
;; (fringe-helper-remove reference)
;; t)
(defun git-gutter-fr:clear ()
(dolist (ov (overlays-in (point-min) (point-max)))
(when (overlay-get ov 'git-gutter)
(delete-overlay ov)))
(setq git-gutter-fr:bitmap-references nil))
(setq git-gutter:init-function 'git-gutter-fr:init
git-gutter:view-diff-function 'git-gutter-fr:view-diff-infos
git-gutter:clear-function 'git-gutter-fr:clear
git-gutter:window-width -1)
(provide 'git-gutter-fringe)
;;; git-gutter-fringe.el ends here