Mode-ify magit-mode and allow multiple status buffers to exist.
This commit is contained in:
parent
7a3e2bdf2c
commit
6801bef645
1 changed files with 79 additions and 60 deletions
139
magit.el
139
magit.el
|
@ -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,47 +256,57 @@
|
||||||
(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)
|
(let ((inhibit-read-only t))
|
||||||
(setq buffer-read-only t)
|
(erase-buffer)
|
||||||
(use-local-map magit-keymap)
|
(let* ((branch (magit-get-current-branch))
|
||||||
(let ((inhibit-read-only t))
|
(remote (and branch (magit-get "branch" branch "remote"))))
|
||||||
(erase-buffer)
|
(if remote
|
||||||
(let* ((branch (magit-get-current-branch))
|
(insert (format "Remote: %s %s\n"
|
||||||
(remote (and branch (magit-get "branch" branch "remote"))))
|
remote (magit-get "remote" remote "url"))))
|
||||||
(if remote
|
(insert (format "Local: %s %s\n"
|
||||||
(insert (format "Remote: %s %s\n"
|
(propertize (or branch "(detached)") 'face 'bold)
|
||||||
remote (magit-get "remote" remote "url"))))
|
(abbreviate-file-name default-directory)))
|
||||||
(insert (format "Local: %s %s\n"
|
(let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
|
||||||
(propertize (or branch "(detached)") 'face 'bold)
|
(if merge-heads
|
||||||
(abbreviate-file-name default-directory)))
|
(insert (format "Merging: %s\n"
|
||||||
(let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
|
(magit-concat-with-delim
|
||||||
(if merge-heads
|
", "
|
||||||
(insert (format "Merging: %s\n"
|
(mapcar 'magit-name-rev merge-heads))))))
|
||||||
(magit-concat-with-delim
|
(insert "\n")
|
||||||
", "
|
(magit-insert-output "Untracked files:" 'magit-wash-other-files
|
||||||
(mapcar 'magit-name-rev merge-heads))))))
|
"git" "ls-files" "--others" "--exclude-standard")
|
||||||
(insert "\n")
|
(magit-insert-output "Unstaged changes:" 'magit-wash-diff
|
||||||
(magit-insert-output "Untracked files:" 'magit-wash-other-files
|
"git" "diff")
|
||||||
"git" "ls-files" "--others" "--exclude-standard")
|
(magit-insert-output "Staged changes:" 'magit-wash-diff
|
||||||
(magit-insert-output "Unstaged changes:" 'magit-wash-diff
|
"git" "diff" "--cached")
|
||||||
"git" "diff")
|
(if remote
|
||||||
(magit-insert-output "Staged changes:" 'magit-wash-diff
|
(magit-insert-output "Unpushed changes:" 'nil
|
||||||
"git" "diff" "--cached")
|
"git" "diff" "--stat"
|
||||||
(if remote
|
(format "%s/%s..HEAD" remote branch)))))))
|
||||||
(magit-insert-output "Unpushed changes:" 'nil
|
|
||||||
"git" "diff" "--stat"
|
(defun magit-find-status-buffer (&optional dir)
|
||||||
(format "%s/%s..HEAD" remote branch))))))))
|
(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)
|
||||||
|
|
Loading…
Reference in a new issue