From 86181a7ae9bc2e8b2b06398e0a3f2d2a96b04acd Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Wed, 6 Mar 2024 14:03:54 +0300 Subject: [PATCH 1/4] Add difftastic-dired --- README.md | 1 + difftastic.el | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index efe1425..4a06f32 100644 --- a/README.md +++ b/README.md @@ -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` - 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` 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` (n), `difftastic-next-file` (N) - move point to a next logical chunk or a next file respectively. diff --git a/difftastic.el b/difftastic.el index 35f84b5..2e7b545 100644 --- a/difftastic.el +++ b/difftastic.el @@ -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' - 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' @@ -105,6 +108,7 @@ (require 'ansi-color) (require 'cl-lib) +(require 'dired) (require 'ediff) (require 'font-lock) (require 'magit) @@ -1040,6 +1044,17 @@ running difftastic." (cons file-B nil) lang-override)) +;;;###autoload +(defun difftastic-dired () + "Compare file at point with FILE using difftastic. + +The behavior is the same as `dired-diff'." + (interactive) + (cl-letf (((symbol-function 'diff) + (lambda (current file _switches) + (difftastic-files current file)))) + (call-interactively #'dired-diff))) + (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 From 5f46338dc4e28d6cb0d43881082bdb0594f3dc7a Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Wed, 6 Mar 2024 21:44:42 +0300 Subject: [PATCH 2/4] Improve difftastic-dired --- difftastic.el | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/difftastic.el b/difftastic.el index 2e7b545..6f72e5f 100644 --- a/difftastic.el +++ b/difftastic.el @@ -1045,15 +1045,23 @@ running difftastic." lang-override)) ;;;###autoload -(defun difftastic-dired () +(defun difftastic-dired-diff (file &optional lang-override) "Compare file at point with FILE using difftastic. -The behavior is the same as `dired-diff'." - (interactive) +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)))) - (call-interactively #'dired-diff))) + (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. From 42006f5fc98dbd3e1a02c637d07126b86a0c6232 Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Wed, 6 Mar 2024 23:10:42 +0300 Subject: [PATCH 3/4] Update documentation to reflect difftastic-dired-diff --- README.md | 2 +- difftastic.el | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4a06f32..c73a2eb 100644 --- a/README.md +++ b/README.md @@ -64,7 +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` - same as `dired-diff`, but with `difftastic-files` instead of the built-in `diff`. +- `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` 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` (n), `difftastic-next-file` (N) - move point to a next logical chunk or a next file respectively. diff --git a/difftastic.el b/difftastic.el index 6f72e5f..299cb47 100644 --- a/difftastic.el +++ b/difftastic.el @@ -84,8 +84,8 @@ ;; Language is guessed based on buffers modes. When called with prefix ;; argument it will ask for language to use. ;; -;; - `difftastic-dired' - same as `dired-diff', but with `difftastic-files' -;; instead of the built-in `diff'. +;; - `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 From cb923b6d9a2b79dbcfa8e09e23a572403c0845ef Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Thu, 7 Mar 2024 01:48:38 +0300 Subject: [PATCH 4/4] Fix: quoting in docstring --- difftastic.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/difftastic.el b/difftastic.el index 299cb47..2057b80 100644 --- a/difftastic.el +++ b/difftastic.el @@ -1049,8 +1049,8 @@ running difftastic." "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." +makes the function prompt for LANG-OVERRIDE. See \\='difft +--list-languages\\=' for language list." (interactive (list 'interactive (when current-prefix-arg