@matheusbsbs / matheus-bagliano / commits / 02f0559eba
Fork 0

git-blame.el: separate git-blame-mode to ease maintenance

git-blame-mode has been splitted into git-blame-mode-on and git-blame-mode-off; it now conditionnaly calls one of them depending of how we call it. Code is now easier to maintain and to understand. Fixed `git-reblame' function: interactive form was at the wrong place. String displayed on the mode line is now configurable through `git-blame-mode-line-string` (default to " blame"). Signed-off-by: Xavier Maillard <zedek@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Xavier Maillard committed Mar 26, 2007 at 23:00 UTC 02f0559ebafffac3af362ea1b1b0ee009090efa1
1 file changed +37 -18
contrib/emacs/git-blame.el
+37 -18
@@ -127,39 +127,58 @@
127
128 (defvar git-blame-mode nil)
129 (make-variable-buffer-local 'git-blame-mode)
130 -(unless (assq 'git-blame-mode minor-mode-alist)
131 - (setq minor-mode-alist
132 - (cons (list 'git-blame-mode " blame")
133 - minor-mode-alist)))
130 +
131 +(defvar git-blame-mode-line-string " blame"
132 + "String to display on the mode line when git-blame is active.")
133 +
134 +(or (assq 'git-blame-mode minor-mode-alist)
135 + (setq minor-mode-alist
136 + (cons '(git-blame-mode git-blame-mode-line-string) minor-mode-alist)))
137
138 ;;;###autoload
139 (defun git-blame-mode (&optional arg)
137 - "Minor mode for displaying Git blame"
140 + "Toggle minor mode for displaying Git blame
141 +
142 +With prefix ARG, turn the mode on if ARG is positive."
143 (interactive "P")
139 - (if arg
140 - (setq git-blame-mode (eq arg 1))
141 - (setq git-blame-mode (not git-blame-mode)))
144 + (cond
145 + ((null arg)
146 + (if git-blame-mode (git-blame-mode-off) (git-blame-mode-on)))
147 + ((> (prefix-numeric-value arg) 0) (git-blame-mode-on))
148 + (t (git-blame-mode-off))))
149 +
150 +(defun git-blame-mode-on ()
151 + "Turn on git-blame mode.
152 +
153 +See also function `git-blame-mode'."
154 (make-local-variable 'git-blame-colors)
155 (if git-blame-autoupdate
156 (add-hook 'after-change-functions 'git-blame-after-change nil t)
157 (remove-hook 'after-change-functions 'git-blame-after-change t))
158 (git-blame-cleanup)
147 - (if git-blame-mode
148 - (progn
149 - (let ((bgmode (cdr (assoc 'background-mode (frame-parameters)))))
150 - (if (eq bgmode 'dark)
151 - (setq git-blame-colors git-blame-dark-colors)
152 - (setq git-blame-colors git-blame-light-colors)))
153 - (setq git-blame-cache (make-hash-table :test 'equal))
154 - (git-blame-run))
155 - (cancel-timer git-blame-idle-timer)))
159 + (let ((bgmode (cdr (assoc 'background-mode (frame-parameters)))))
160 + (if (eq bgmode 'dark)
161 + (setq git-blame-colors git-blame-dark-colors)
162 + (setq git-blame-colors git-blame-light-colors)))
163 + (setq git-blame-cache (make-hash-table :test 'equal))
164 + (setq git-blame-mode t)
165 + (git-blame-run))
166 +
167 +(defun git-blame-mode-off ()
168 + "Turn off git-blame mode.
169 +
170 +See also function `git-blame-mode'."
171 + (git-blame-cleanup)
172 + (if git-blame-idle-timer (cancel-timer git-blame-idle-timer))
173 + (setq git-blame-mode nil))
174
175 ;;;###autoload
176 (defun git-reblame ()
177 "Recalculate all blame information in the current buffer"
178 + (interactive)
179 (unless git-blame-mode
180 (error "git-blame is not active"))
162 - (interactive)
181 +
182 (git-blame-cleanup)
183 (git-blame-run))
184