From bba2d3125969b1cb7c3490fac9e6cd354949cf99 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Thu, 10 Apr 2008 21:39:53 +0200 Subject: Make "s" in git-status acknowledge the currently marked files --- gitsum.el | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gitsum.el b/gitsum.el index 299f5fa..f7578f6 100644 --- a/gitsum.el +++ b/gitsum.el @@ -38,7 +38,7 @@ This mode is meant to be activated by `M-x gitsum' or pressing `s' in git-status ;; When git.el is loaded, hack into keymap. (when (boundp 'git-status-mode-map) - (define-key git-status-mode-map "s" 'gitsum)) + (define-key git-status-mode-map "s" 'gitsum-switch-from-git-status)) ;; Undo doesn't work in read-only buffers else. (defun gitsum-undo () @@ -50,7 +50,7 @@ A numeric argument serves as a repeat count." (let ((inhibit-read-only t)) (undo))) -(defun gitsum-refresh () +(defun gitsum-refresh (&optional arguments) "Regenerate the patch based on the current state of the index." (interactive) (let ((inhibit-read-only t)) @@ -58,7 +58,7 @@ A numeric argument serves as a repeat count." (insert "# Directory: " default-directory "\n") (insert "# Use n and p to navigate and k to kill a hunk. u is undo, g will refresh.\n") (insert "# Edit the patch as you please and press 'c' to commit.\n\n") - (let ((diff (shell-command-to-string "git diff"))) + (let ((diff (shell-command-to-string (concat "git diff " arguments)))) (if (zerop (length diff)) (insert "## No changes. ##") (insert diff) @@ -156,6 +156,16 @@ A numeric argument serves as a repeat count." (interactive) (git-status default-directory)) +(defun gitsum-switch-from-git-status () + "Switch to gitsum, resticting diff to marked files if any." + (interactive) + (let ((marked (git-get-filenames + (ewoc-collect git-status + (lambda (info) (git-fileinfo->marked info)))))) + (gitsum) + (when marked + (gitsum-refresh (mapconcat 'identity marked " "))))) + (defun gitsum () "Entry point into gitsum-diff-mode." (interactive) -- cgit 1.4.1