git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Clifford Caoile" <piyo@users.sourceforge.net>
To: "Git Mailing List" <git@vger.kernel.org>
Subject: [PATCH/RFC] git.el: show/refresh diff buffer from commit buffer
Date: Sat, 19 Apr 2008 15:53:21 +0900	[thread overview]
Message-ID: <1f748ec60804182353q45237c8esc8d05cb49a132676@mail.gmail.com> (raw)

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@users.sourceforge.net>
---
 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

                 reply	other threads:[~2008-04-19  6:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1f748ec60804182353q45237c8esc8d05cb49a132676@mail.gmail.com \
    --to=piyo@users.sourceforge.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).