[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master eb553fa 09/57: Add support for different diff algorithms
From: |
Justin Burkett |
Subject: |
[elpa] master eb553fa 09/57: Add support for different diff algorithms |
Date: |
Tue, 3 Nov 2020 14:32:18 -0500 (EST) |
branch: master
commit eb553facd7b66cf3c108e68a3d96be4a5bcc0b83
Author: Justin Burkett <justin@burkett.cc>
Commit: Justin Burkett <justin@burkett.cc>
Add support for different diff algorithms
Replace vdiff-diff-{program,extra-args} with vdiff-diff-algorithm{s}, which
allows for selection of pre-specified commands that use different diff
algorithms.
Modify vdiff-diff3-command to comply with the expected format.
---
vdiff.el | 91 +++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 55 insertions(+), 36 deletions(-)
diff --git a/vdiff.el b/vdiff.el
index f9a9a19..0c4e4d3 100644
--- a/vdiff.el
+++ b/vdiff.el
@@ -72,23 +72,37 @@
`vdiff-mode'."
:type 'boolean)
-(defcustom vdiff-diff-program "diff"
- "diff program to use."
- :type 'string)
-
-(defcustom vdiff-diff3-program "diff3"
- "diff3 program to use."
- :type 'string)
-
-(defcustom vdiff-diff-extra-args "-u"
- "Extra arguments to pass to diff. If this is set wrong, you may
-break vdiff. It is \"-u\" by default."
- :type 'string)
-
-(defcustom vdiff-diff3-extra-args ""
- "Extra arguments to pass to diff. If this is set wrong, you may
-break vdiff. It is empty by default."
- :type 'string)
+(defcustom vdiff-diff-algorithms
+ '((diff-u . "diff -u")
+ (git-diff . "git --no-pager diff --no-index --no-color")
+ (git-diff-myers . "git --no-pager diff --myers --no-index --no-color")
+ (git-diff-minimal . "git --no-pager diff --minimal --no-index --no-color")
+ (git-diff-patience . "git --no-pager diff --patience --no-index
--no-color")
+ (git-diff-histogram . "git --no-pager diff --histogram --no-index
--no-color")
+ (custom . "diff -u"))
+ "An alist containing choices of diff algorithms to be selected
+by setting `vdiff-diff-algorithm'. If you want to use a custom
+command, set `vidff-diff-algorithm' to `custom' and customize the
+`custom' key in this alist."
+ :type '(alist :key-type symbol :value-type string))
+
+(defcustom vdiff-diff-algorithm 'diff-u
+ "Choice of algorithm for generating diffs. The choices are
+`diff-u', `git-diff',`git-diff-myers', `git-diff-minimal',
+`git-diff-patience', `git-diff-histogram' and `custom'. See
+`vdiff-diff-algorithms' for the associated commands."
+ :type '(choice (const :tag "diff -u" diff-u)
+ (const :tag "git diff" git-diff)
+ (const :tag "git diff --myers" git-diff-myers)
+ (const :tag "git diff --minimal" git-diff-minimal)
+ (const :tag "git diff --patience" git-diff-patience)
+ (const :tag "git diff --histogram" git-diff-histogram)
+ (const :tag "custom" custom)))
+
+(defcustom vdiff-diff3-command '("diff3")
+ "diff3 command to use. Specify as a list where the car is the command to use
+and the remaining elements are the arguments to the command."
+ :type '(repeat string))
(defcustom vdiff-disable-folding nil
"If non-nil, disable folding in vdiff buffers."
@@ -248,6 +262,12 @@ because those are handled differently.")
;; * Utilities
+(defsubst vdiff-diff-command ()
+ (let ((cmd-cons (assoc vdiff-diff-algorithm vdiff-diff-algorithms)))
+ (if (stringp (cdr-safe cmd-cons))
+ (split-string (cdr cmd-cons) " ")
+ '("diff" "-u"))))
+
(defun vdiff--maybe-int (str)
"Return an int>=0 from STR."
(let ((num (or (and (numberp str) str)
@@ -482,22 +502,17 @@ POST-REFRESH-FUNCTION is called when the process
finishes."
(tmp-b (make-temp-file "vdiff-b-"))
(tmp-c (when vdiff-3way-mode
(make-temp-file "vdiff-c-")))
- (prgm (if vdiff-3way-mode
- vdiff-diff3-program
- vdiff-diff-program))
- (extra-args (if vdiff-3way-mode
- vdiff-diff3-extra-args
- vdiff-diff-extra-args))
+ (base-cmd (if vdiff-3way-mode
+ vdiff-diff3-command
+ (vdiff-diff-command)))
(ses vdiff--session)
- (cmd (mapconcat
- #'identity
- (vdiff--non-nil-list
- prgm
- (vdiff-session-whitespace-args ses)
- (vdiff-session-case-args ses)
- extra-args
- tmp-a tmp-b tmp-c)
- " "))
+ (cmd (append
+ base-cmd
+ (vdiff-session-whitespace-args ses)
+ (vdiff-session-case-args ses)
+ (list "--" tmp-a tmp-b)
+ (when tmp-c
+ (list tmp-c))))
(buffers (vdiff-session-buffers ses))
(proc-buf (vdiff-session-process-buffer ses))
(proc (get-buffer-process proc-buf)))
@@ -513,9 +528,11 @@ POST-REFRESH-FUNCTION is called when the process finishes."
(kill-process proc))
(with-current-buffer (get-buffer-create proc-buf)
(erase-buffer))
- ;; (setq vdiff--last-command cmd)
(setq proc
- (start-process-shell-command proc-buf proc-buf cmd))
+ (make-process
+ :name "*vdiff*"
+ :buffer proc-buf
+ :command cmd))
(when vdiff-3way-mode
(process-put proc 'vdiff-3way t))
(process-put proc 'vdiff-session ses)
@@ -743,8 +760,10 @@ parsing the diff output and triggering the overlay
updates."
(write-region a-words nil tmp-file-a nil 'quietly)
(write-region b-words nil tmp-file-b nil 'quietly)
(with-current-buffer out-buffer (erase-buffer))
- (let ((exit-code (call-process
- vdiff-diff-program nil out-buffer nil tmp-file-a
tmp-file-b)))
+ (let ((exit-code (apply #'call-process
+ (car (vdiff-diff-command))
+ nil out-buffer nil tmp-file-a tmp-file-b
+ (cdr (vdiff-diff-command)))))
(delete-file tmp-file-a)
(delete-file tmp-file-b)
(when (= exit-code 1)
- [elpa] master c803bd6 17/57: Add warnings for obsolete variables, (continued)
- [elpa] master c803bd6 17/57: Add warnings for obsolete variables, Justin Burkett, 2020/11/03
- [elpa] master 5f7d3fd 22/57: Add Travis badge, Justin Burkett, 2020/11/03
- [elpa] master 348d1a7 27/57: Add after-quit arg to vdiff-test-with-buffers, Justin Burkett, 2020/11/03
- [elpa] master fd6ec8e 25/57: Test that both buffers are correct by default, Justin Burkett, 2020/11/03
- [elpa] master 45666cc 30/57: README: evil-collection adds vimdiff-like bindings, Justin Burkett, 2020/11/03
- [elpa] master 6878093 33/57: Add vdiff-toggle-fold and vdiff-toggle-all-folds, Justin Burkett, 2020/11/03
- [elpa] master ccc773b 39/57: Add optional to-buffer arg to vdiff--translate line, Justin Burkett, 2020/11/03
- [elpa] master 58d530b 53/57: Add vdiff-temp-files, Justin Burkett, 2020/11/03
- [elpa] master c732247 45/57: Reset truncate-lines on cleanup, Justin Burkett, 2020/11/03
- [elpa] master 61d29bb 54/57: Travis -> github workflow, Justin Burkett, 2020/11/03
- [elpa] master eb553fa 09/57: Add support for different diff algorithms,
Justin Burkett <=
- [elpa] master 8f3fa10 15/57: Fix Makefile typo, Justin Burkett, 2020/11/03
- [elpa] master 5667bc6 16/57: Ensure input files to diff end in newline, Justin Burkett, 2020/11/03
- [elpa] master 110d672 12/57: Cleanup diff parsing function, Justin Burkett, 2020/11/03
- [elpa] master bd8976e 26/57: Add movement and setup tests, Justin Burkett, 2020/11/03
- [elpa] master 40ffc92 29/57: Warn on bad initialization of vdiff session., Justin Burkett, 2020/11/03
- [elpa] master 0e10521 31/57: Merge pull request #20 from edkolev/patch-1, Justin Burkett, 2020/11/03
- [elpa] master f2a622f 34/57: Improve vdiff-toggle-fold, Justin Burkett, 2020/11/03
- [elpa] master 45f7019 19/57: Add basic send and receive tests, Justin Burkett, 2020/11/03
- [elpa] master 773e3eb 28/57: Fix compiler warnings, Justin Burkett, 2020/11/03
- [elpa] master 3bfb5de 32/57: Truncate long lines by default, Justin Burkett, 2020/11/03