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>
This commit is contained in:
parent
d8b6a1a10b
commit
02f0559eba
@ -127,39 +127,58 @@
|
|||||||
|
|
||||||
(defvar git-blame-mode nil)
|
(defvar git-blame-mode nil)
|
||||||
(make-variable-buffer-local 'git-blame-mode)
|
(make-variable-buffer-local 'git-blame-mode)
|
||||||
(unless (assq 'git-blame-mode minor-mode-alist)
|
|
||||||
(setq minor-mode-alist
|
(defvar git-blame-mode-line-string " blame"
|
||||||
(cons (list 'git-blame-mode " blame")
|
"String to display on the mode line when git-blame is active.")
|
||||||
minor-mode-alist)))
|
|
||||||
|
(or (assq 'git-blame-mode minor-mode-alist)
|
||||||
|
(setq minor-mode-alist
|
||||||
|
(cons '(git-blame-mode git-blame-mode-line-string) minor-mode-alist)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun git-blame-mode (&optional arg)
|
(defun git-blame-mode (&optional arg)
|
||||||
"Minor mode for displaying Git blame"
|
"Toggle minor mode for displaying Git blame
|
||||||
|
|
||||||
|
With prefix ARG, turn the mode on if ARG is positive."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(if arg
|
(cond
|
||||||
(setq git-blame-mode (eq arg 1))
|
((null arg)
|
||||||
(setq git-blame-mode (not git-blame-mode)))
|
(if git-blame-mode (git-blame-mode-off) (git-blame-mode-on)))
|
||||||
|
((> (prefix-numeric-value arg) 0) (git-blame-mode-on))
|
||||||
|
(t (git-blame-mode-off))))
|
||||||
|
|
||||||
|
(defun git-blame-mode-on ()
|
||||||
|
"Turn on git-blame mode.
|
||||||
|
|
||||||
|
See also function `git-blame-mode'."
|
||||||
(make-local-variable 'git-blame-colors)
|
(make-local-variable 'git-blame-colors)
|
||||||
(if git-blame-autoupdate
|
(if git-blame-autoupdate
|
||||||
(add-hook 'after-change-functions 'git-blame-after-change nil t)
|
(add-hook 'after-change-functions 'git-blame-after-change nil t)
|
||||||
(remove-hook 'after-change-functions 'git-blame-after-change t))
|
(remove-hook 'after-change-functions 'git-blame-after-change t))
|
||||||
(git-blame-cleanup)
|
(git-blame-cleanup)
|
||||||
(if git-blame-mode
|
(let ((bgmode (cdr (assoc 'background-mode (frame-parameters)))))
|
||||||
(progn
|
(if (eq bgmode 'dark)
|
||||||
(let ((bgmode (cdr (assoc 'background-mode (frame-parameters)))))
|
(setq git-blame-colors git-blame-dark-colors)
|
||||||
(if (eq bgmode 'dark)
|
(setq git-blame-colors git-blame-light-colors)))
|
||||||
(setq git-blame-colors git-blame-dark-colors)
|
(setq git-blame-cache (make-hash-table :test 'equal))
|
||||||
(setq git-blame-colors git-blame-light-colors)))
|
(setq git-blame-mode t)
|
||||||
(setq git-blame-cache (make-hash-table :test 'equal))
|
(git-blame-run))
|
||||||
(git-blame-run))
|
|
||||||
(cancel-timer git-blame-idle-timer)))
|
(defun git-blame-mode-off ()
|
||||||
|
"Turn off git-blame mode.
|
||||||
|
|
||||||
|
See also function `git-blame-mode'."
|
||||||
|
(git-blame-cleanup)
|
||||||
|
(if git-blame-idle-timer (cancel-timer git-blame-idle-timer))
|
||||||
|
(setq git-blame-mode nil))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun git-reblame ()
|
(defun git-reblame ()
|
||||||
"Recalculate all blame information in the current buffer"
|
"Recalculate all blame information in the current buffer"
|
||||||
|
(interactive)
|
||||||
(unless git-blame-mode
|
(unless git-blame-mode
|
||||||
(error "git-blame is not active"))
|
(error "git-blame is not active"))
|
||||||
(interactive)
|
|
||||||
(git-blame-cleanup)
|
(git-blame-cleanup)
|
||||||
(git-blame-run))
|
(git-blame-run))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user