git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git.el: Diff only file at point by default

From
David Kågedal <davidk@lysator.liu.se>
Date
Aug 26, 2008, 22:22 UTC
Message-ID
<871w0bmn6w.fsf@lysator.liu.se>
In-Reply-To
<873aktnsbf.fsf@lysator.liu.se>
Use prefix (C-u) to diff all marked files.
Signed-off-by: David Kågedal <davidk@lysator.liu.se>
---
 contrib/emacs/git.el |   62 +++++++++++++++++++++++++++++---------------------
 1 files changed, 36 insertions(+), 26 deletions(-)

Here is an updated patch that udpate the stage diff commands as well. It doesn't touch git-diff-file-merge-head since that already uses prefix arguments. Don't know if there is a solution to that.

diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index c1cf1cb..de9d0f4 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -771,6 +771,11 @@ Return the list of files that haven't been handled."
               (setq file (pop files))
             (setq node (ewoc-next status node))))))))
 
+(defun git-current-file ()
+  "Return the file at point."
+  (unless git-status (error "Not in git-status buffer."))
+  (ewoc-data (ewoc-locate git-status)))
+
 (defun git-marked-files ()
   "Return a list of all marked files, or if none a list containing just the file at cursor position."
   (unless git-status (error "Not in git-status buffer."))
@@ -1137,10 +1142,11 @@ Return the list of files that haven't been handled."
   (when (eq (window-buffer) (current-buffer))
     (shrink-window-if-larger-than-buffer)))
 
-(defun git-diff-file ()
-  "Diff the marked file(s) against HEAD."
-  (interactive)
-  (let ((files (git-marked-files)))
+(defun git-diff-file (arg)
+  "Diff the current file against HEAD.
+With a prefix arg, diff the marked files instead."
+  (interactive "P")
+  (let ((files (if arg (git-marked-files) (list (git-current-file)))))
     (git-setup-diff-buffer
      (apply #'git-run-command-buffer "*git-diff*" "diff-index" "-p" "-M" "HEAD" "--" (git-get-filenames files)))))
 
@@ -1154,31 +1160,35 @@ Return the list of files that haven't been handled."
      (apply #'git-run-command-buffer "*git-diff*" "diff-index" "-p" "-M"
             (or (nth (1- arg) merge-heads) "HEAD") "--" (git-get-filenames files)))))
 
-(defun git-diff-unmerged-file (stage)
-  "Diff the marked unmerged file(s) against the specified stage."
-  (let ((files (git-marked-files)))
+(defun git-diff-unmerged-file (stage arg)
+  "Diff the files against the specified stage."
+  (let ((files (if arg (git-marked-files) (list (git-current-file)))))
     (git-setup-diff-buffer
      (apply #'git-run-command-buffer "*git-diff*" "diff-files" "-p" stage "--" (git-get-filenames files)))))
 
-(defun git-diff-file-base ()
-  "Diff the marked unmerged file(s) against the common base file."
-  (interactive)
-  (git-diff-unmerged-file "-1"))
-
-(defun git-diff-file-mine ()
-  "Diff the marked unmerged file(s) against my pre-merge version."
-  (interactive)
-  (git-diff-unmerged-file "-2"))
-
-(defun git-diff-file-other ()
-  "Diff the marked unmerged file(s) against the other's pre-merge version."
-  (interactive)
-  (git-diff-unmerged-file "-3"))
-
-(defun git-diff-file-combined ()
-  "Do a combined diff of the marked unmerged file(s)."
-  (interactive)
-  (git-diff-unmerged-file "-c"))
+(defun git-diff-file-base (arg)
+  "Diff the current file against the common base file.
+With a prefix arg, diff the marked files instead."
+  (interactive "P")
+  (git-diff-unmerged-file "-1" arg))
+
+(defun git-diff-file-mine (arg)
+  "Diff the current file against my pre-merge version.
+With a prefix arg, diff the marked files instead."
+  (interactive "P")
+  (git-diff-unmerged-file "-2" arg))
+
+(defun git-diff-file-other (arg)
+  "Diff the current file against the other's pre-merge version.
+With a prefix arg, diff the marked files instead."
+  (interactive "P")
+  (git-diff-unmerged-file "-3" arg))
+
+(defun git-diff-file-combined (arg)
+  "Do a combined diff of the marked unmerged file(s).
+With a prefix arg, diff the marked files instead."
+  (interactive "P")
+  (git-diff-unmerged-file "-c" arg))
 
 (defun git-diff-file-idiff ()
   "Perform an interactive diff on the current file."
-- 
1.6.0.rc2.7.gbf8a


-- 
David Kågedal
Previous: David KågedalNext: Junio C Hamano
Message 5 of 7 in “git.el: Diff only file at point by default”
  1. git.el: Diff only file at point by defaultDavid Kågedal, Aug 22, 2008
  2. Junio C HamanoAug 24, 2008
  3. Alexandre JulliardAug 25, 2008
  4. David KågedalAug 25, 2008
  5. git.el: Diff only file at point by defaultDavid Kågedal, Aug 26, 2008
  6. Junio C HamanoAug 27, 2008
  7. Alexandre JulliardAug 30, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.