git.el: Try to reuse an existing buffer when running git-status.
By default, running git-status again will now reuse an existing buffer that displays the same directory. The old behavior of always creating a new buffer can be obtained by customizing the git-reuse-status-buffer option. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Alexandre Julliard committed
Jul 22, 2006 at 15:39 UTC
73389f12bf0ef39820685a322527fab549676f33
1 file changed
+23
-1
contrib/emacs/git.el
+23
-1
@@ -83,6 +83,12 @@ then to `add-log-mailing-address' and then to `user-mail-address'."
83
:group 'git
84
:type 'boolean)
85
86
+(defcustom git-reuse-status-buffer t
87
+ "Whether `git-status' should try to reuse an existing buffer
88
+if there is already one that displays the same directory."
89
+ :group 'git
90
+ :type 'boolean)
91
+
92
(defcustom git-per-dir-ignore-file ".gitignore"
93
"Name of the per-directory ignore file."
94
:group 'git
@@ -1003,12 +1009,28 @@ Commands:
1009
(set (make-local-variable 'list-buffers-directory) default-directory)
1010
(run-hooks 'git-status-mode-hook)))
1011
1012
+(defun git-find-status-buffer (dir)
1013
+ "Find the git status buffer handling a specified directory."
1014
+ (let ((list (buffer-list))
1015
+ (fulldir (expand-file-name dir))
1016
+ found)
1017
+ (while (and list (not found))
1018
+ (let ((buffer (car list)))
1019
+ (with-current-buffer buffer
1020
+ (when (and list-buffers-directory
1021
+ (string-equal fulldir (expand-file-name list-buffers-directory))
1022
+ (string-match "\\*git-status\\*$" (buffer-name buffer)))
1023
+ (setq found buffer))))
1024
+ (setq list (cdr list)))
1025
+ found))
1026
+
1027
(defun git-status (dir)
1028
"Entry point into git-status mode."
1029
(interactive "DSelect directory: ")
1030
(setq dir (git-get-top-dir dir))
1031
(if (file-directory-p (concat (file-name-as-directory dir) ".git"))
1011
- (let ((buffer (create-file-buffer (expand-file-name "*git-status*" dir))))
1032
+ (let ((buffer (or (and git-reuse-status-buffer (git-find-status-buffer dir))
1033
+ (create-file-buffer (expand-file-name "*git-status*" dir)))))
1034
(switch-to-buffer buffer)
1035
(cd dir)
1036
(git-status-mode)