Skip to content
Browse files

Can now reuse an existing buffer displaying the same directory

Imported and adapted from `git.el', gitsum can now reuse an existing
buffer if there is one showing the same directory. This is useful if
you forget to quit/kill the gitsum buffer and then run gitsum again.
  • Loading branch information...
1 parent b95c77d commit e2f112f220db2b511471c02095e3a28f40d419fd @tomas-abrahamsson tomas-abrahamsson committed Aug 9, 2008
Showing with 29 additions and 4 deletions.
  1. +29 −4 gitsum.el
33 gitsum.el
@@ -11,6 +11,12 @@
(eval-when-compile (require 'cl))
+(defcustom gitsum-reuse-buffer t
+ "Whether `gitsum' should try to reuse an existing buffer
+if there is already one that displays the same directory."
+ :group 'git
+ :type 'boolean)
(easy-mmode-defmap gitsum-diff-mode-shared-map
'(("A" . gitsum-amend)
("c" . gitsum-commit)
@@ -167,13 +173,32 @@ A numeric argument serves as a repeat count."
(when marked
(gitsum-refresh (mapconcat 'identity marked " ")))))
+(defun gitsum-find-buffer (dir)
+ "Find the gitsum buffer handling a specified directory."
+ (let ((list (buffer-list))
+ (fulldir (expand-file-name dir))
+ found)
+ (while (and list (not found))
+ (let ((buffer (car list)))
+ (with-current-buffer buffer
+ (when (and list-buffers-directory
+ (string-equal fulldir
+ (expand-file-name list-buffers-directory))
+ (eq major-mode 'gitsum-diff-mode))
+ (setq found buffer))))
+ (setq list (cdr list)))
+ found))
(defun gitsum ()
"Entry point into gitsum-diff-mode."
- (switch-to-buffer (generate-new-buffer "*gitsum*"))
- (gitsum-diff-mode)
- (set (make-local-variable 'list-buffers-directory) default-directory)
- (gitsum-refresh))
+ (let* ((dir default-directory)
+ (buffer (or (and gitsum-reuse-buffer (gitsum-find-buffer dir))
+ (generate-new-buffer "*gitsum*"))))
+ (switch-to-buffer buffer)
+ (gitsum-diff-mode)
+ (set (make-local-variable 'list-buffers-directory) dir)
+ (gitsum-refresh)))
;; viper compatible
(eval-after-load "viper"

0 comments on commit e2f112f

Please sign in to comment.
Something went wrong with that request. Please try again.