help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Magit and seeing the whole diff


From: Thien-Thi Nguyen
Subject: Re: Magit and seeing the whole diff
Date: Tue, 21 Dec 2010 10:31:36 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

() Andrea Crotti <andrea.crotti.0@gmail.com>
() Mon, 20 Dec 2010 14:06:44 +0100

   I don't quite get what you mean...
   How does this integrates with magit/emacs?

Sorry, i sent the mail out before completing it.  That shell
script in fact doesn't integrate with anything, because i haven't
found any Emacs Lisp wrapping that lets me play (fully) with all
the git diff variants and options.

   You keep a buffer with the diff and you
   revert it sometimes?

Yes.  The shell script (aka $0 aka .ttn.diff) rewrites its tail on
every invocation (it requires a sed that supports ‘-i’, like GNU
sed).  Typically, i futz the command line to taste then move point
after the close-paren and type ‘C-x C-e’.  This invokes the script
and reverts the buffer; btw, here is ‘revert-buffer-t-t’:

  (defun revert-buffer-t-t ()
    (interactive)
    (revert-buffer t t))

The file is automatically placed into Diff mode because of its
name.  I usually immediately type ‘C-x C-q’ to toggle read-only,
which enables ‘n’ and ‘p’ bindings to for fast cruising, etc.

I suppose all of this can be translated into an Emacs Lisp
command.  Here's a lightly-tested sketch that does more or less
(it moves point, annoyingly) the same thing:

(defun update-diff ()
  "Update the current buffer using its \"git diff\" command.
The command should be near the beginning of the file at bol,
and start with \"git diff\" (so \"git diff-index\", etc, is ok).
It should be followed at some point by #### on a line by itself.
For example:

   #git diff-index [...]           ;; unused
   #git diff a q                   ;; unused
   git diff -p --stat q r/hack
   #git diff -p --stat q r/fix     ;; unused
   ####

The updated buffer has a time stamp and the output of the
git diff command.  It is in Diff mode, read-only."
  (interactive)
  (let ((me (buffer-file-name))
        (cmd (progn (goto-char (point-min))
                    (re-search-forward "^git diff")
                    (buffer-substring (match-beginning 0)
                                      (line-end-position)))))
    (re-search-forward "^####.*\n")
    (let ((inhibit-read-only t))
      (delete-region (point) (point-max))
      (save-excursion
        (insert (format-time-string "\n\t\t\t\t\t\t%F %T\n\n")
                (shell-command-to-string cmd))))
    (diff-mode)
    (toggle-read-only 1)))

Now that i've written it, probably i'll stop using the shell
script.  So, thanks for prompting this pleasant interlude!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]