Added minor mode for the different magit buffer.

Signed-off-by: Rémi Vanicat <vanicat@debian.org>
This commit is contained in:
Rémi Vanicat 2010-04-09 13:22:08 +02:00 committed by Phil Jackson
parent 8175d6dfad
commit 9105c3e557

104
magit.el
View file

@ -1420,6 +1420,34 @@ FUNC should leave point at the end of the modified region"
(define-key map (kbd "q") 'quit-window) (define-key map (kbd "q") 'quit-window)
map)) map))
(defvar magit-commit-mode-map
(let ((map (make-sparse-keymap)))
map))
(defvar magit-status-mode-map
(let ((map (make-sparse-keymap)))
map))
(defvar magit-stash-mode-map
(let ((map (make-sparse-keymap)))
map))
(defvar magit-log-mode-map
(let ((map (make-sparse-keymap)))
map))
(defvar magit-reflog-mode-map
(let ((map (make-sparse-keymap)))
map))
(defvar magit-diff-mode-map
(let ((map (make-sparse-keymap)))
map))
(defvar magit-wazzup-mode-map
(let ((map (make-sparse-keymap)))
map))
(easy-menu-define magit-mode-menu magit-mode-map (easy-menu-define magit-mode-menu magit-mode-map
"Magit menu" "Magit menu"
'("Magit" '("Magit"
@ -2105,6 +2133,13 @@ must return a string which will represent the log line.")
"--pretty=medium" "--pretty=medium"
"--cc" "-p" commit))) "--cc" "-p" commit)))
(define-minor-mode magit-commit-mode
"Minor mode to view git commit"
:group magit
:init-value ()
:lighter ()
:keymap magit-commit-mode-map)
(defun magit-show-commit (commit &optional scroll) (defun magit-show-commit (commit &optional scroll)
(when (magit-section-p commit) (when (magit-section-p commit)
(setq commit (magit-section-info commit))) (setq commit (magit-section-info commit)))
@ -2127,7 +2162,8 @@ must return a string which will represent the log line.")
(set-buffer buf) (set-buffer buf)
(goto-char (point-min)) (goto-char (point-min))
(magit-mode-init dir 'commit (magit-mode-init dir 'commit
#'magit-refresh-commit-buffer commit)))))) #'magit-refresh-commit-buffer commit)
(magit-commit-mode t))))))
(defvar magit-marked-commit nil) (defvar magit-marked-commit nil)
@ -2269,6 +2305,13 @@ must return a string which will represent the log line.")
(let ((default-directory dir)) (let ((default-directory dir))
(magit-run* (list "git" "init")))))) (magit-run* (list "git" "init"))))))
(define-minor-mode magit-status-mode
"Minor mode for looking at git status"
:group magit
:init-value ()
:lighter ()
:keymap magit-status-mode-map)
;;;###autoload ;;;###autoload
(defun magit-status (dir) (defun magit-status (dir)
(interactive (list (or (and (not current-prefix-arg) (interactive (list (or (and (not current-prefix-arg)
@ -2291,7 +2334,8 @@ must return a string which will represent the log line.")
(file-name-nondirectory (file-name-nondirectory
(directory-file-name topdir)) "*")))))) (directory-file-name topdir)) "*"))))))
(switch-to-buffer buf) (switch-to-buffer buf)
(magit-mode-init topdir 'status #'magit-refresh-status))))) (magit-mode-init topdir 'status #'magit-refresh-status)
(magit-status-mode t)))))
;;; Staging and Unstaging ;;; Staging and Unstaging
@ -3065,6 +3109,13 @@ Prefix arg means justify as well."
(defvar magit-currently-shown-stash nil) (defvar magit-currently-shown-stash nil)
(define-minor-mode magit-stash-mode
"Minor mode for looking at git status"
:group magit
:init-value ()
:lighter ()
:keymap magit-stash-mode-map)
(defun magit-show-stash (stash &optional scroll) (defun magit-show-stash (stash &optional scroll)
(when (magit-section-p stash) (when (magit-section-p stash)
(setq stash (magit-section-info stash))) (setq stash (magit-section-info stash)))
@ -3089,7 +3140,8 @@ Prefix arg means justify as well."
(let* ((range (cons (concat stash "^2^") stash)) (let* ((range (cons (concat stash "^2^") stash))
(args (magit-rev-range-to-git range))) (args (magit-rev-range-to-git range)))
(magit-mode-init dir 'diff #'magit-refresh-diff-buffer (magit-mode-init dir 'diff #'magit-refresh-diff-buffer
range args))))))) range args)
(magit-stash-mode t)))))))
;;; Topic branches (using topgit) ;;; Topic branches (using topgit)
@ -3225,6 +3277,13 @@ Prefix arg means justify as well."
,@args ,@args
"--")))) "--"))))
(define-minor-mode magit-log-mode
"Minor mode for looking at git status"
:group magit
:init-value ()
:lighter ()
:keymap magit-log-mode-map)
(defun magit-log (&optional arg) (defun magit-log (&optional arg)
(interactive "P") (interactive "P")
(let* ((range (if arg (let* ((range (if arg
@ -3234,7 +3293,8 @@ Prefix arg means justify as well."
(args (list (magit-rev-range-to-git range)))) (args (list (magit-rev-range-to-git range))))
(switch-to-buffer "*magit-log*") (switch-to-buffer "*magit-log*")
(magit-mode-init topdir 'log #'magit-refresh-log-buffer range (magit-mode-init topdir 'log #'magit-refresh-log-buffer range
"--pretty=oneline" args))) "--pretty=oneline" args)
(magit-log-mode t)))
(defun magit-log-grep (str) (defun magit-log-grep (str)
"Search for regexp specified by STR in the commit log." "Search for regexp specified by STR in the commit log."
@ -3244,7 +3304,8 @@ Prefix arg means justify as well."
(magit-mode-init topdir 'log #'magit-refresh-log-buffer "HEAD" (magit-mode-init topdir 'log #'magit-refresh-log-buffer "HEAD"
"--pretty=oneline" "--pretty=oneline"
(list "-E" (list "-E"
(format "--grep=%s" (shell-quote-argument str)))))) (format "--grep=%s" (shell-quote-argument str))))
(magit-log-mode t)))
(defun magit-log-long (&optional arg) (defun magit-log-long (&optional arg)
(interactive "P") (interactive "P")
@ -3255,7 +3316,8 @@ Prefix arg means justify as well."
(args (list (magit-rev-range-to-git range)))) (args (list (magit-rev-range-to-git range))))
(switch-to-buffer "*magit-log*") (switch-to-buffer "*magit-log*")
(magit-mode-init topdir 'log #'magit-refresh-log-buffer range (magit-mode-init topdir 'log #'magit-refresh-log-buffer range
"--stat" args))) "--stat" args)
(magit-log-mode t)))
;;; Reflog ;;; Reflog
@ -3269,6 +3331,13 @@ Prefix arg means justify as well."
"--pretty=format:* %H %s" "--pretty=format:* %H %s"
args))) args)))
(define-minor-mode magit-reflog-mode
"Minor mode for looking at git status"
:group magit
:init-value ()
:lighter ()
:keymap magit-reflog-mode-map)
(defun magit-reflog (head) (defun magit-reflog (head)
(interactive (list (magit-read-rev "Reflog of" "HEAD"))) (interactive (list (magit-read-rev "Reflog of" "HEAD")))
(if head (if head
@ -3276,7 +3345,8 @@ Prefix arg means justify as well."
(args (magit-rev-to-git head))) (args (magit-rev-to-git head)))
(switch-to-buffer "*magit-reflog*") (switch-to-buffer "*magit-reflog*")
(magit-mode-init topdir 'reflog (magit-mode-init topdir 'reflog
#'magit-refresh-reflog-buffer head args)))) #'magit-refresh-reflog-buffer head args)
(magit-reflog-mode t))))
(defun magit-reflog-head () (defun magit-reflog-head ()
(interactive) (interactive)
@ -3291,6 +3361,13 @@ Prefix arg means justify as well."
'magit-wash-diffs 'magit-wash-diffs
"diff" (magit-diff-U-arg) args))) "diff" (magit-diff-U-arg) args)))
(define-minor-mode magit-diff-mode
"Minor mode for looking at git status"
:group magit
:init-value ()
:lighter ()
:keymap magit-diff-mode-map)
(defun magit-diff (range) (defun magit-diff (range)
(interactive (list (magit-read-rev-range "Diff"))) (interactive (list (magit-read-rev-range "Diff")))
(if range (if range
@ -3300,7 +3377,8 @@ Prefix arg means justify as well."
(display-buffer buf) (display-buffer buf)
(save-excursion (save-excursion
(set-buffer buf) (set-buffer buf)
(magit-mode-init dir 'diff #'magit-refresh-diff-buffer range args))))) (magit-mode-init dir 'diff #'magit-refresh-diff-buffer range args)
(magit-diff-mode t)))))
(defun magit-diff-working-tree (rev) (defun magit-diff-working-tree (rev)
(interactive (list (magit-read-rev "Diff with (default HEAD)"))) (interactive (list (magit-read-rev "Diff with (default HEAD)")))
@ -3369,6 +3447,13 @@ Prefix arg means justify as well."
"--")))) "--"))))
(magit-set-section-info ref section)))))))))) (magit-set-section-info ref section))))))))))
(define-minor-mode magit-wazzup-mode
"Minor mode for looking at git status"
:group magit
:init-value ()
:lighter ()
:keymap magit-wazzup-mode-map)
(defun magit-wazzup (&optional all) (defun magit-wazzup (&optional all)
(interactive "P") (interactive "P")
(let ((topdir (magit-get-top-dir default-directory)) (let ((topdir (magit-get-top-dir default-directory))
@ -3376,7 +3461,8 @@ Prefix arg means justify as well."
(switch-to-buffer "*magit-wazzup*") (switch-to-buffer "*magit-wazzup*")
(magit-mode-init topdir 'wazzup (magit-mode-init topdir 'wazzup
#'magit-refresh-wazzup-buffer #'magit-refresh-wazzup-buffer
current-branch all))) current-branch all)
(magit-wazzup-mode t)))
;;; Miscellaneous ;;; Miscellaneous