Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add difftastic-dired-diff #6

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The following commands are meant to help to interact with `difftastic`. Commands
- `difftastic-magit-show` - show the result of `git show ARG` with `difftastic`. It tries to guess `ARG`, and ask for it when can't. When called with prefix argument it will ask for `ARG`.
- `difftastic-files` - show the result of `difft FILE-A FILE-B`. When called with prefix argument it will ask for language to use, instead of relaying on `difftastic`'s detection mechanism.
- `difftastic-buffers` - show the result of `difft BUFFER-A BUFFER-B`. Language is guessed based on buffers modes. When called with prefix argument it will ask for language to use.
- `difftastic-dired-diff` - same as `dired-diff`, but with `difftastic-files` instead of the built-in `diff`.
- `difftastic-rerun` (<kbd>g</kbd>) - rerun difftastic for the current buffer. It runs difftastic again in the current buffer, but respects the window configuration.
It uses `difftastic-rerun-requested-window-width-function` which, by default, returns current window width (instead of `difftastic-requested-window-width-function`). It will also reuse current buffer and will not call `difftastic-display-buffer-function`. When called with prefix argument it will ask for language to use.
- `difftastic-next-chunk` (<kbd>n</kbd>), `difftastic-next-file` (<kbd>N</kbd>) - move point to a next logical chunk or a next file respectively.
Expand Down
23 changes: 23 additions & 0 deletions difftastic.el
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
;; Language is guessed based on buffers modes. When called with prefix
;; argument it will ask for language to use.
;;
;; - `difftastic-dired-diff' - same as `dired-diff', but with
;; `difftastic-files' instead of the built-in `diff'.
;;
;; - `difftastic-rerun' ('g') - rerun difftastic for the current buffer. It
;; runs difftastic again in the current buffer, but respects the window
;; configuration. It uses `difftastic-rerun-requested-window-width-function'
Expand All @@ -105,6 +108,7 @@

(require 'ansi-color)
(require 'cl-lib)
(require 'dired)
(require 'ediff)
(require 'font-lock)
(require 'magit)
Expand Down Expand Up @@ -1040,6 +1044,25 @@ running difftastic."
(cons file-B nil)
lang-override))

;;;###autoload
(defun difftastic-dired-diff (file &optional lang-override)
"Compare file at point with FILE using difftastic.

The behavior is the same as `dired-diff', except for the prefix argument, which
makes the function prompt for LANG-OVERRIDE. See \\='difft
--list-languages\\=' for language list."
(interactive
(list 'interactive
(when current-prefix-arg
(completing-read "Language: " (difftastic--languages) nil t))))
(cl-letf (((symbol-function 'diff)
(lambda (current file _switches)
(difftastic-files current file lang-override)))
(current-prefix-arg nil))
(if (eq file 'interactive)
(call-interactively #'dired-diff))
(funcall #'dired-diff file)))

(defun difftastic--rerun-file-buf (prefix file-buf rerun-alist)
"Create a new temporary file for the FILE-BUF with PREFIX if needed.
The new FILE-BUF is additionally set in RERUN-ALIST. The FILE-BUF
Expand Down