[PATCH/RFC] git.el: show/refresh diff buffer from commit buffer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds Emacs Lisp plumbing:
  run-hooks 'git-log-edit-commit-hook to git-commit-file
  run-hooks 'git-diff-setup-hook to git-setup-diff-buffer
  a commit buffer reference to the diff buffer

This allows diff buffer refreshing:

The hooks git-log-edit-commit-hook and git-diff-setup-hook are given
sample hooks that add keybindings "\C-c\C-d" and "g" to the
*git-commit* and *git-diff* buffer, respectively. These keybindings
allow refreshing the diff information shown in the *git-diff* buffer.

Signed-off-by: Clifford Caoile <piyo@xxxxxxxxxxxxxxxxxxxxx>
---
 contrib/emacs/git.el |   53 ++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index 4fa853f..6b23145 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -179,6 +179,32 @@ if there is already one that displays the same directory."
     (,(concat "^\\(" (regexp-quote git-log-msg-separator) "\\)$")
      (1 font-lock-comment-face))))

+;
+
+(defvar git-log-edit-commit-hook nil
+  "Run after the log edit buffer created `git-commit-file' is setup.")
+
+(defvar git-diff-setup-hook nil
+  "Run after the diff buffer created by `git-diff-setup-buffer' is setup.")
+
+(defun git-log-edit-diff-cmd ()
+  "The interactive version of `git-log-edit-diff', designed to be
+called from define-key calls inside of `git-log-edit-commit-hook'
+and `git-diff-setup-hook'."
+  (interactive)
+  (git-log-edit-diff))
+
+(add-hook 'git-log-edit-commit-hook 'git-log-commit-sample-hook)
+(add-hook 'git-diff-setup-hook      'git-diff-setup-sample-hook)
+
+(defun git-log-commit-sample-hook ()
+  (define-key (current-local-map) "\C-c\C-d" 'git-log-edit-diff-cmd))
+
+(defun git-diff-setup-sample-hook ()
+  (define-key (current-local-map) "g"  'git-log-edit-diff-cmd))
+
+;
+
 (defun git-get-env-strings (env)
   "Build a list of NAME=VALUE strings from a list of environment strings."
   (mapcar (lambda (entry) (concat (car entry) "=" (cdr entry))) env))
@@ -1124,25 +1150,34 @@ Return the list of files that haven't been handled."
       (git-refresh-ewoc-hf git-status)
       t)))

-(defun git-setup-diff-buffer (buffer)
+(defun git-setup-diff-buffer (buffer &optional parent-buffer)
   "Setup a buffer for displaying a diff."
   (let ((dir default-directory))
     (with-current-buffer buffer
       (diff-mode)
       (goto-char (point-min))
       (setq default-directory dir)
-      (setq buffer-read-only t)))
+      (setq buffer-read-only t)
+      ;; when called by (git-diff-file) via the git's log-edit buffer,
+      ;; parent-buffer will be non-nil
+      (when parent-buffer
+        (set (make-local-variable 'log-edit-parent-buffer) parent-buffer))
+      (run-hooks 'git-diff-setup-hook)))
   (display-buffer buffer)
   ; shrink window only if it displays the status buffer
   (when (eq (window-buffer) (current-buffer))
     (shrink-window-if-larger-than-buffer)))

-(defun git-diff-file ()
-  "Diff the marked file(s) against HEAD."
+(defun git-diff-file (&optional parent-buffer)
+  "Diff the marked file(s) against HEAD.
+
+PARENT-BUFFER is usually passed by `git-log-edit-diff' to be able
+to revert the diff buffer."
   (interactive)
   (let ((files (git-marked-files)))
     (git-setup-diff-buffer
-     (apply #'git-run-command-buffer "*git-diff*" "diff-index" "-p"
"-M" "HEAD" "--" (git-get-filenames files)))))
+     (apply #'git-run-command-buffer "*git-diff*" "diff-index" "-p"
"-M" "HEAD" "--" (git-get-filenames files))
+     parent-buffer)))

 (defun git-diff-file-merge-head (arg)
   "Diff the marked file(s) against the first merge head (or the nth
one with a numeric prefix)."
@@ -1210,8 +1245,9 @@ Return the list of files that haven't been handled."

 (defun git-log-edit-diff ()
   "Run a diff of the current files being committed from a log-edit buffer."
-  (with-current-buffer log-edit-parent-buffer
-    (git-diff-file)))
+  (let ((original-buffer log-edit-parent-buffer))
+    (with-current-buffer log-edit-parent-buffer
+      (git-diff-file original-buffer))))

 (defun git-append-sign-off (name email)
   "Append a Signed-off-by entry to the current buffer, avoiding duplicates."
@@ -1292,7 +1328,8 @@ Return the list of files that haven't been handled."
 	(log-edit 'git-do-commit nil 'git-log-edit-files buffer))
       (setq font-lock-keywords (font-lock-compile-keywords
git-log-edit-font-lock-keywords))
       (setq buffer-file-coding-system coding-system)
-      (re-search-forward (regexp-quote (concat git-log-msg-separator
"\n")) nil t))))
+      (re-search-forward (regexp-quote (concat git-log-msg-separator
"\n")) nil t)
+      (run-hooks 'git-log-edit-commit-hook))))

 (defun git-setup-commit-buffer (commit)
   "Setup the commit buffer with the contents of COMMIT."
-- 
1.5.5.1015.g9d258
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux