Skip to content

Commit fffa7ed

Browse files
authored
Merge pull request #87 from ikappaki/issue/win-view-ediff-empty
Support MS-windows line edings in view_ediff
2 parents eb8b176 + 457cf0a commit fffa7ed

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
- name: Run tests
3636
run: |
3737
eask install-deps
38+
39+
eask test buttercup
40+
3841
eask package
3942
eask install
4043
eask compile

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
dist
44
.eask
55
*.elc
6+
*~

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
- Fix issue with `view_ediff` displaying empty buffers in ediff. #86

eca-diff.el

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ ROOTS may be passed for path relativization if desired.
5151
5252
This function tries to be Doom-compatible when Emacs runs Doom popup
5353
system (it ignores those popup rules for the generated ediff buffers)."
54-
(let* ((parsed (eca-diff-parse-unified-diff diff))
54+
(let* (;; ediff expects `\n` line endings.
55+
(diff (replace-regexp-in-string "\r\n" "\n" diff))
56+
(parsed (eca-diff-parse-unified-diff diff))
5557
(orig (plist-get parsed :original))
5658
(new (plist-get parsed :new))
5759
(buf-orig (generate-new-buffer (format "*eca-diff-orig:%s*" path)))

test/eca-diff-test.el

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
;;; -*- lexical-binding: t; -*-
2+
(require 'buttercup)
3+
(require 'eca-diff)
4+
5+
(defconst native-eol
6+
(if (eq system-type 'windows-nt)
7+
"\r\n"
8+
"\n")
9+
"Native end-of-line string for the current operating system.")
10+
11+
(describe "eca-diff-show-ediff"
12+
:var ((insert-orig (symbol-function 'insert))
13+
(contents '()))
14+
(before-each
15+
(spy-on 'insert
16+
:and-call-fake (lambda (&rest args)
17+
(apply insert-orig args)
18+
(push (list (buffer-name) (buffer-string)) contents )
19+
)))
20+
(it "can display unified diffs with native EOLs"
21+
(let* ((inhibit-message t)
22+
(path "/a/path")
23+
(diff (string-join '("@@ -1,3 +1,4 @@"
24+
"-Line 1"
25+
"-Line 2"
26+
"+Line 1 modified"
27+
"+Line 2"
28+
"+Line 3 added")
29+
native-eol)))
30+
31+
;; We expect this function to call `insert` twice.
32+
(eca-diff-show-ediff path diff)
33+
(expect (reverse contents)
34+
:to-equal
35+
`((,(format "*eca-diff-orig:%s*" path) "Line 1
36+
Line 2")
37+
(,(format "*eca-diff-new:%s*" path) "Line 1 modified
38+
Line 2
39+
Line 3 added"))))))

0 commit comments

Comments
 (0)