Skip to content

Commit 6bdd448

Browse files
committed
Initial commit into new repository.
Previous history has not been preserved.
0 parents  commit 6bdd448

File tree

6 files changed

+959
-0
lines changed

6 files changed

+959
-0
lines changed

.github/workflows/release.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: release
2+
on:
3+
push:
4+
branch: default
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
container: ghcr.io/orbitalquark/textadept-build:v1.0
10+
steps:
11+
- name: Checkout textadept
12+
uses: actions/checkout@v2
13+
with:
14+
repository: orbitalquark/textadept
15+
path: textadept
16+
- name: Checkout textadept-build dependencies
17+
uses: actions/checkout@v2
18+
with:
19+
repository: orbitalquark/textadept-build
20+
path: textadept-build
21+
- name: Checkout textadept-file-diff module
22+
uses: actions/checkout@v2
23+
with:
24+
path: textadept/modules/file_diff
25+
- name: Build
26+
shell: bash
27+
run: |
28+
mv textadept-build/* textadept/src && make -C textadept/src lua
29+
cd textadept/modules/file_diff
30+
make deps && make -j
31+
cd .. && zip -r ../../file_diff.zip file_diff -x "*.zip" "*.h" "*.o" \
32+
"*.def" "*.la" file_diff/.github
33+
- name: Upload artifacts
34+
uses: actions/upload-artifact@v2
35+
with:
36+
name: artifacts
37+
path: file_diff.zip
38+
release:
39+
runs-on: ubuntu-latest
40+
needs: build
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v2
44+
- name: Tag
45+
run: |
46+
git tag latest
47+
git push -f origin latest
48+
- name: Download artifacts
49+
uses: actions/download-artifact@v2
50+
with:
51+
name: artifacts
52+
- name: Create release
53+
uses: ncipollo/release-action@v1
54+
with:
55+
name: latest
56+
tag: latest
57+
allowUpdates: true
58+
body: Latest automated build (ignore github-actions' release date)
59+
artifacts: file_diff.zip
60+
token: ${{ secrets.GITHUB_TOKEN }}
61+
cleanup:
62+
runs-on: ubuntu-latest
63+
needs: [build, release]
64+
steps:
65+
- name: Remove older build artifacts
66+
uses: c-hive/gha-remove-artifacts@v1
67+
with:
68+
age: '1 minute'

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2015-2020 Mitchell
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Makefile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2017-2020 Mitchell. See LICENSE.
2+
3+
ta = ../..
4+
ta_src = $(ta)/src
5+
ta_lua = $(ta_src)/lua/src
6+
7+
CXX = g++
8+
CXXFLAGS = -std=c++11 -pedantic -fPIC -Wall
9+
LDFLAGS = -Wl,--retain-symbols-file -Wl,$(ta_src)/lua.sym
10+
11+
all: diff.so diff.dll diff-curses.dll diffosx.so
12+
clean: ; rm -f *.o *.so *.dll
13+
14+
# Platform objects.
15+
16+
CROSS_WIN = i686-w64-mingw32-
17+
CROSS_OSX = x86_64-apple-darwin17-c++
18+
19+
diff.so: diff.o ; $(CXX) -shared $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
20+
diff.dll: diff-win.o lua.la
21+
$(CROSS_WIN)$(CXX) -shared -static-libgcc -static-libstdc++ $(CXXFLAGS) -o \
22+
$@ $^ $(LDFLAGS)
23+
diff-curses.dll: diff-win.o lua-curses.la
24+
$(CROSS_WIN)$(CXX) -shared -static-libgcc -static-libstdc++ $(CXXFLAGS) -o \
25+
$@ $^ $(LDFLAGS)
26+
diffosx.so: diff-osx.o
27+
$(CROSS_OSX) -shared $(CXXFLAGS_OSX) -undefined dynamic_lookup -o $@ $^
28+
29+
diff.o: diff.cxx ; $(CXX) -c $(CXXFLAGS) -I$(ta_lua) -o $@ $^
30+
diff-win.o: diff.cxx
31+
$(CROSS_WIN)$(CXX) -c $(CXXFLAGS) -DLUA_BUILD_AS_DLL -DLUA_LIB -I$(ta_lua) \
32+
-o $@ $^
33+
diff-osx.o: diff.cxx ; $(CROSS_OSX) -c $(CXXFLAGS_OSX) -I$(ta_lua) -o $@ $^
34+
35+
lua.def:
36+
echo LIBRARY \"textadept.exe\" > $@ && echo EXPORTS >> $@
37+
grep -v "^#" $(ta_src)/lua.sym >> $@
38+
lua.la: lua.def ; $(CROSS_WIN)dlltool -d $< -l $@
39+
lua-curses.def:
40+
echo LIBRARY \"textadept-curses.exe\" > $@ && echo EXPORTS >> $@
41+
grep -v "^#" $(ta_src)/lua.sym >> $@
42+
lua-curses.la: lua-curses.def ; $(CROSS_WIN)dlltool -d $< -l $@
43+
44+
# Documentation.
45+
46+
cwd = $(shell pwd)
47+
docs: luadoc README.md
48+
README.md: init.lua
49+
cd $(ta)/scripts && luadoc --doclet markdowndoc $(cwd)/$< > $(cwd)/$@
50+
sed -i -e '1,+4d' -e '6c# File Diff' -e '7d' -e 's/^##/#/;' $@
51+
luadoc: init.lua
52+
cd $(ta)/modules && luadoc -d $(cwd) --doclet lua/tadoc $(cwd)/$< \
53+
--ta-home=$(shell readlink -f $(ta))
54+
sed -i 's/_HOME.\+\?_HOME/_HOME/;' tags
55+
56+
# External diff_match_patch dependency.
57+
58+
deps: diff_match_patch.h
59+
60+
diff_match_patch_zip = 7f95b37e554453262e2bcda830724fc362614103.zip
61+
$(diff_match_patch_zip):
62+
wget https://github.com/leutloff/diff-match-patch-cpp-stl/archive/$@
63+
diff_match_patch.h: | $(diff_match_patch_zip) ; unzip -j $| "*/$@"

README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# File Diff
2+
3+
Two-way file comparison for Textadept.
4+
5+
Install this module by copying it into your *~/.textadept/modules/* directory
6+
or Textadept's *modules/* directory, and then putting the following in your
7+
*~/.textadept/init.lua*:
8+
9+
require('file_diff')
10+
11+
## Usage
12+
13+
A sample workflow is this:
14+
15+
1. Start comparing two files via the "Compare Files" submenu in the "Tools"
16+
menu.
17+
2. The caret is initially placed in the file on the left.
18+
3. Go to the next change via menu or key binding.
19+
4. Merge the change from the other buffer into the current one (right to
20+
left) via menu or key binding.
21+
5. Go to the next change via menu or key binding.
22+
6. Merge the change from the current buffer into the other one (left to
23+
right) via menu or key binding.
24+
7. Repeat as necessary.
25+
26+
Note: merging can be performed wherever the caret is placed when jumping
27+
between changes, even if one buffer has a change and the other does not
28+
(additions or deletions).
29+
30+
## Key Bindings
31+
32+
Windows, Linux, BSD|macOS|Terminal|Command
33+
-------------------|-----|--------|-------
34+
**Tools** | | |
35+
F6 |F6 |F6 |Compare files...
36+
Shift+F6 |⇧F6 |S-F6 |Compare the buffers in two split views
37+
Alt+Down |⌥⇣ |M-Down |Goto next difference
38+
Alt+Up |⌥⇡ |M-Up |Goto previous difference
39+
Alt+Left |⌥⇠ |M-Left |Merge left
40+
Alt+Right |⌥⇢ |M-Right |Merge right
41+
42+
43+
## Fields defined by `file_diff`
44+
45+
<a id="file_diff.INDIC_ADDITION"></a>
46+
### `file_diff.INDIC_ADDITION` (number)
47+
48+
The indicator number for text added within lines.
49+
50+
<a id="file_diff.INDIC_DELETION"></a>
51+
### `file_diff.INDIC_DELETION` (number)
52+
53+
The indicator number for text deleted within lines.
54+
55+
<a id="file_diff.MARK_ADDITION"></a>
56+
### `file_diff.MARK_ADDITION` (number)
57+
58+
The marker for line additions.
59+
60+
<a id="file_diff.MARK_DELETION"></a>
61+
### `file_diff.MARK_DELETION` (number)
62+
63+
The marker for line deletions.
64+
65+
<a id="file_diff.MARK_MODIFICATION"></a>
66+
### `file_diff.MARK_MODIFICATION` (number)
67+
68+
The marker for line modifications.
69+
70+
<a id="file_diff.theme"></a>
71+
### `file_diff.theme` (string)
72+
73+
The theme to use, either 'dark' or 'light'.
74+
This is not the theme used with Textadept.
75+
Depending on this setting, additions will be colored 'dark_green' or
76+
'light_green', deletions will be colored 'dark_red' or 'light_red', and so
77+
on.
78+
The default value is auto-detected.
79+
80+
81+
## Functions defined by `file_diff`
82+
83+
<a id="_G.diff"></a>
84+
### `_G.diff`(*text1, text2*)
85+
86+
Returns a list that represents the differences between strings *text1* and
87+
*text2*.
88+
Each consecutive pair of elements in the returned list represents a "diff".
89+
The first element is an integer: 0 for a deletion, 1 for an insertion, and 2
90+
for equality. The second element is the associated diff text.
91+
92+
Parameters:
93+
94+
* *`text1`*: String to compare against.
95+
* *`text2`*: String to compare.
96+
97+
Usage:
98+
99+
* `diffs = diff(text1, text2)
100+
for i = 1, #diffs, 2 do print(diffs[i], diffs[i + 1]) end`
101+
102+
Return:
103+
104+
* list of differences
105+
106+
<a id="file_diff.goto_change"></a>
107+
### `file_diff.goto_change`(*next*)
108+
109+
Jumps to the next or previous difference between the two files depending on
110+
boolean *next*.
111+
[`file_diff.start()`](#file_diff.start) must have been called previously.
112+
113+
Parameters:
114+
115+
* *`next`*: Whether to go to the next or previous difference relative to the
116+
current line.
117+
118+
<a id="file_diff.merge"></a>
119+
### `file_diff.merge`(*left*)
120+
121+
Merges a change from one buffer to another, depending on the change under
122+
the caret and the merge direction.
123+
124+
Parameters:
125+
126+
* *`left`*: Whether to merge from right to left or left to right.
127+
128+
<a id="file_diff.start"></a>
129+
### `file_diff.start`(*file1, file2, horizontal*)
130+
131+
Highlight differences between files *file1* and *file2*, or the user-selected
132+
files.
133+
134+
Parameters:
135+
136+
* *`file1`*: Optional name of the older file. If `-`, uses the current
137+
buffer. If `nil`, the user is prompted for a file.
138+
* *`file2`*: Optional name of the newer file. If `-`, uses the current
139+
buffer. If `nil`, the user is prompted for a file.
140+
* *`horizontal`*: Optional flag specifying whether or not to split the view
141+
horizontally. The default value is `false`, comparing the two files
142+
side-by-side.
143+
144+
145+
---

diff.cxx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2017-2020 Mitchell. See LICENSE.
2+
3+
#include "diff_match_patch.h"
4+
5+
extern "C" {
6+
#include "lua.h"
7+
#include "lualib.h"
8+
#include "lauxlib.h"
9+
}
10+
11+
/** diff() Lua function. */
12+
static int diff(lua_State *L) {
13+
diff_match_patch<std::string> dmp;
14+
auto diffs = dmp.diff_main(
15+
luaL_checkstring(L, 1), luaL_checkstring(L, 2), false);
16+
dmp.diff_cleanupSemantic(diffs);
17+
lua_createtable(L, diffs.size() * 2, 0);
18+
int len = 1;
19+
for(auto& diff : diffs) {
20+
lua_pushnumber(L, diff.operation), lua_rawseti(L, -2, len++);
21+
lua_pushstring(L, diff.text.c_str()), lua_rawseti(L, -2, len++);
22+
}
23+
return 1;
24+
}
25+
26+
extern "C" {
27+
int luaopen_diff(lua_State *L) {
28+
return (lua_pushcfunction(L, diff), 1);
29+
}
30+
31+
// Platform-specific Lua library entry points.
32+
LUALIB_API int luaopen_file_diff_diff(lua_State *L) {
33+
return luaopen_diff(L);
34+
}
35+
LUALIB_API int luaopen_file_diff_diffosx(lua_State *L) {
36+
return luaopen_diff(L);
37+
}
38+
}

0 commit comments

Comments
 (0)