diff options
author | Tomas Abrahamsson <tab@lysator.liu.se> | 2008-08-09 18:30:58 +0200 |
---|---|---|
committer | Tomas Abrahamsson <tab@lysator.liu.se> | 2008-08-09 19:21:31 +0200 |
commit | e2f112f220db2b511471c02095e3a28f40d419fd (patch) | |
tree | fdb5e01f730995bcb06ab9201a41f313a6904def | |
parent | b95c77d61f9ff85205d4a815b8b8d68990494dae (diff) | |
download | gitsum-master.tar.gz gitsum-master.tar.xz gitsum-master.zip |
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.
-rw-r--r-- | gitsum.el | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/gitsum.el b/gitsum.el index 0815309..1ae5858 100644 --- a/gitsum.el +++ b/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." (interactive) - (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" |