Mode-ify magit-mode and allow multiple status buffers to exist.

This commit is contained in:
Marius Vollmer 2008-08-07 01:49:35 +03:00
parent 7a3e2bdf2c
commit 6801bef645

View file

@ -160,36 +160,45 @@
(t (t
(message "Git is weird."))) (message "Git is weird.")))
(magit-revert-files) (magit-revert-files)
(magit-update-status)) (magit-update-status (magit-find-status-buffer)))
(defun magit-display-process () (defun magit-display-process ()
(interactive) (interactive)
(display-buffer "*git-process*")) (display-buffer "*git-process*"))
;;; Keymap ;;; Mode
(defvar magit-keymap nil) (defvar magit-mode-map nil)
(when (not magit-keymap) (when (not magit-mode-map)
(setq magit-keymap (make-keymap)) (setq magit-mode-map (make-keymap))
(suppress-keymap magit-keymap) (suppress-keymap magit-mode-map)
(define-key magit-keymap (kbd "g") 'magit-status) (define-key magit-mode-map (kbd "g") 'magit-status)
(define-key magit-keymap (kbd "A") 'magit-stage-all) (define-key magit-mode-map (kbd "A") 'magit-stage-all)
(define-key magit-keymap (kbd "a") 'magit-stage-thing-at-point) (define-key magit-mode-map (kbd "a") 'magit-stage-thing-at-point)
(define-key magit-keymap (kbd "u") 'magit-unstage-thing-at-point) (define-key magit-mode-map (kbd "u") 'magit-unstage-thing-at-point)
(define-key magit-keymap (kbd "i") 'magit-ignore-thing-at-point) (define-key magit-mode-map (kbd "i") 'magit-ignore-thing-at-point)
(define-key magit-keymap (kbd "?") 'magit-describe-thing-at-point) (define-key magit-mode-map (kbd "?") 'magit-describe-thing-at-point)
(define-key magit-keymap (kbd "x") 'magit-reset-soft) (define-key magit-mode-map (kbd "x") 'magit-reset-soft)
(define-key magit-keymap (kbd "X") 'magit-reset-hard) (define-key magit-mode-map (kbd "X") 'magit-reset-hard)
(define-key magit-keymap (kbd "RET") 'magit-visit-thing-at-point) (define-key magit-mode-map (kbd "RET") 'magit-visit-thing-at-point)
(define-key magit-keymap (kbd "b") 'magit-switch-branch) (define-key magit-mode-map (kbd "b") 'magit-switch-branch)
(define-key magit-keymap (kbd "B") 'magit-create-branch) (define-key magit-mode-map (kbd "B") 'magit-create-branch)
(define-key magit-keymap (kbd "m") 'magit-manual-merge) (define-key magit-mode-map (kbd "m") 'magit-manual-merge)
(define-key magit-keymap (kbd "M") 'magit-automatic-merge) (define-key magit-mode-map (kbd "M") 'magit-automatic-merge)
(define-key magit-keymap (kbd "U") 'magit-pull) (define-key magit-mode-map (kbd "U") 'magit-pull)
(define-key magit-keymap (kbd "P") 'magit-push) (define-key magit-mode-map (kbd "P") 'magit-push)
(define-key magit-keymap (kbd "c") 'magit-log-edit) (define-key magit-mode-map (kbd "c") 'magit-log-edit)
(define-key magit-keymap (kbd "p") 'magit-display-process)) (define-key magit-mode-map (kbd "p") 'magit-display-process))
(defun magit-mode ()
"Review the status of a git repository and act on it.
\\{magit-mode-map}"
(kill-all-local-variables)
(setq buffer-read-only t)
(setq major-mode 'magit-mode
mode-name "Magit")
(use-local-map magit-mode-map))
;;; Status ;;; Status
@ -247,12 +256,9 @@
(magit-wash-diff-propertize-diff head-beg head-end) (magit-wash-diff-propertize-diff head-beg head-end)
(magit-wash-diff-propertize-hunk head-beg head-end hunk-beg))) (magit-wash-diff-propertize-hunk head-beg head-end hunk-beg)))
(defun magit-update-status () (defun magit-update-status (buf)
(let ((buf (get-buffer "*git-status*")))
(save-excursion (save-excursion
(set-buffer buf) (set-buffer buf)
(setq buffer-read-only t)
(use-local-map magit-keymap)
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(erase-buffer) (erase-buffer)
(let* ((branch (magit-get-current-branch)) (let* ((branch (magit-get-current-branch))
@ -279,15 +285,28 @@
(if remote (if remote
(magit-insert-output "Unpushed changes:" 'nil (magit-insert-output "Unpushed changes:" 'nil
"git" "diff" "--stat" "git" "diff" "--stat"
(format "%s/%s..HEAD" remote branch)))))))) (format "%s/%s..HEAD" remote branch)))))))
(defun magit-find-status-buffer (&optional dir)
(let ((topdir (magit-get-top-dir (or dir default-directory))))
(dolist (buf (buffer-list))
(if (save-excursion
(set-buffer buf)
(and (equal default-directory topdir)
(eq major-mode 'magit-mode)))
(return buf)))))
(defun magit-status (dir) (defun magit-status (dir)
(interactive (list (magit-read-top-dir current-prefix-arg))) (interactive (list (magit-read-top-dir current-prefix-arg)))
(save-some-buffers) (save-some-buffers)
(let ((buf (get-buffer-create "*git-status*"))) (let* ((topdir (magit-get-top-dir dir))
(buf (or (magit-find-status-buffer topdir)
(create-file-buffer (file-name-nondirectory
(directory-file-name topdir))))))
(switch-to-buffer buf) (switch-to-buffer buf)
(setq default-directory dir) (setq default-directory topdir)
(magit-update-status))) (magit-mode)
(magit-update-status buf)))
;;; Staging ;;; Staging
@ -471,7 +490,7 @@
(case (car info) (case (car info)
((other-file) ((other-file)
(append-to-file (concat (cadr info) "\n") nil ".gitignore") (append-to-file (concat (cadr info) "\n") nil ".gitignore")
(magit-update-status)))))) (magit-update-status (magit-find-status-buffer)))))))
(defun magit-visit-thing-at-point () (defun magit-visit-thing-at-point ()
(interactive) (interactive)