Skip to content

Commit

Permalink
Make "s" in git-status acknowledge the currently marked files
Browse files Browse the repository at this point in the history
  • Loading branch information
leahneukirchen committed Apr 10, 2008
1 parent 1cbc163 commit bba2d31
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions gitsum.el
Expand Up @@ -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 ()
Expand All @@ -50,15 +50,15 @@ 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))
(erase-buffer)
(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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit bba2d31

Please sign in to comment.