Skip to content

Commit 7b8393f

Browse files
committed
Updated API documentation.
1 parent e6d565d commit 7b8393f

File tree

3 files changed

+81
-82
lines changed

3 files changed

+81
-82
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ endif()
6262
get_filename_component(ta_dir ${src}/../../ ABSOLUTE)
6363
add_custom_target(docs DEPENDS README.md)
6464
add_custom_command(OUTPUT ${src}/README.md
65-
COMMAND ldoc --filter markdowndoc.ldoc ${src}/init.lua > ${src}/README.md
66-
COMMAND sed -i -e "1,+4d" -e "6c# File Diff" -e "7d" -e "s/^##/#/;" ${src}/README.md
65+
COMMAND ldoc --filter markdowndoc.ldoc ${src}/init.lua -- --title="File Diff" --single
66+
> ${src}/README.md
6767
DEPENDS init.lua
6868
WORKING_DIRECTORY ${ta_dir}/scripts
6969
VERBATIM)

README.md

+55-58
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ Two-way file comparison for Textadept.
55
Install this module by copying it into your *~/.textadept/modules/* directory or Textadept's
66
*modules/* directory, and then putting the following in your *~/.textadept/init.lua*:
77

8-
require('file_diff')
8+
```lua
9+
local file_diff = require('file_diff')
10+
```
911

1012
## Compiling
1113

1214
Releases include binaries, so building this modules should not be necessary. If you want
1315
to build manually, use CMake. For example:
1416

15-
cmake -S . -B build_dir
16-
cmake --build build_dir --target diff
17-
cmake --install build_dir
17+
```bash
18+
cmake -S . -B build_dir
19+
cmake --build build_dir --target diff
20+
cmake --install build_dir
21+
```
1822

1923
## Usage
2024

2125
A sample workflow is this:
22-
2326
1. Start comparing two files via the "Compare Files" submenu in the "Tools" menu.
2427
2. The caret is initially placed in the file on the left.
2528
3. Go to the next change via menu or key binding.
@@ -46,113 +49,107 @@ Ctrl+Alt+, | ^⌘, | None | Goto previous difference
4649
Ctrl+Alt+< | ^⌘< | None | Merge left
4750
Ctrl+Alt+> | ^⌘> | None | Merge right
4851

49-
## Fields defined by `file_diff`
50-
5152
<a id="file_diff.INDIC_ADDITION"></a>
52-
### `file_diff.INDIC_ADDITION`
53+
## `file_diff.INDIC_ADDITION`
5354

5455
The indicator number for text added within lines.
5556

5657
<a id="file_diff.INDIC_DELETION"></a>
57-
### `file_diff.INDIC_DELETION`
58+
## `file_diff.INDIC_DELETION`
5859

5960
The indicator number for text deleted within lines.
6061

6162
<a id="file_diff.MARK_ADDITION"></a>
62-
### `file_diff.MARK_ADDITION`
63+
## `file_diff.MARK_ADDITION`
6364

6465
The marker for line additions.
6566

6667
<a id="file_diff.MARK_DELETION"></a>
67-
### `file_diff.MARK_DELETION`
68+
## `file_diff.MARK_DELETION`
6869

6970
The marker for line deletions.
7071

7172
<a id="file_diff.MARK_MODIFICATION"></a>
72-
### `file_diff.MARK_MODIFICATION`
73+
## `file_diff.MARK_MODIFICATION`
7374

7475
The marker for line modifications.
7576

76-
<a id="file_diff.addition_color_name"></a>
77-
### `file_diff.addition_color_name`
78-
79-
The name of the theme color used to mark additions.
80-
The default value is 'green'. If your theme does not define that color, set this field to
81-
your theme's equivalent.
82-
83-
<a id="file_diff.deletion_color_name"></a>
84-
### `file_diff.deletion_color_name`
85-
86-
The name of the theme color used to mark deletions.
87-
The default value is 'red'. If your theme does not define that color, set this field to your
88-
theme's equivalent.
89-
90-
<a id="file_diff.modification_color_name"></a>
91-
### `file_diff.modification_color_name`
92-
93-
The name of the theme color used to mark modifications.
94-
The default value is 'yellow'. If your theme does not define that color, set this field to
95-
your theme's equivalent.
96-
97-
98-
## Functions defined by `file_diff`
99-
10077
<a id="_G.diff"></a>
101-
### `_G.diff`(*text1*, *text2*)
78+
## `_G.diff`(*text1*, *text2*)
79+
80+
Returns a list of the differences between strings.
10281

103-
Returns a list that represents the differences between strings *text1* and *text2*.
10482
Each consecutive pair of elements in the returned list represents a "diff". The first element
10583
is an integer: 0 for a deletion, 1 for an insertion, and 2 for equality. The second element
10684
is the associated diff text.
10785

10886
Parameters:
109-
11087
- *text1*: String to compare against.
11188
- *text2*: String to compare.
11289

11390
Usage:
11491

115-
- `diffs = diff(text1, text2)
92+
```lua
93+
diffs = diff(text1, text2)
11694
for i = 1, #diffs, 2 do print(diffs[i], diffs[i + 1]) end
117-
`
95+
```
96+
97+
<a id="file_diff.addition_color_name"></a>
98+
## `file_diff.addition_color_name`
99+
100+
The name of the theme color used to mark additions.
101+
102+
The default value is 'green'. If your theme does not define that color, set this field to
103+
your theme's equivalent.
104+
105+
<a id="file_diff.deletion_color_name"></a>
106+
## `file_diff.deletion_color_name`
118107

119-
Return:
108+
The name of the theme color used to mark deletions.
120109

121-
- list of differences
110+
The default value is 'red'. If your theme does not define that color, set this field to your
111+
theme's equivalent.
122112

123113
<a id="file_diff.goto_change"></a>
124-
### `file_diff.goto_change`(*next*)
114+
## `file_diff.goto_change`([*next*=false])
115+
116+
Jumps to the next or previous difference between the two files.
125117

126-
Jumps to the next or previous difference between the two files depending on boolean *next*.
127118
[`file_diff.start()`](#file_diff.start) must have been called previously.
128119

129120
Parameters:
130-
131-
- *next*: Whether to go to the next or previous difference relative to the current line.
121+
- *next*: Go to the next previous difference relative to the current line,
122+
as opposed to the previous one.
132123

133124
<a id="file_diff.merge"></a>
134-
### `file_diff.merge`(*left*)
125+
## `file_diff.merge`([*left*=false])
135126

136127
Merges a change from one buffer to another, depending on the change under the caret and the
137128
merge direction.
138129

139130
Parameters:
131+
- *left*: Merge from right to left as opposed to left to right.
140132

141-
- *left*: Whether to merge from right to left or left to right.
133+
<a id="file_diff.modification_color_name"></a>
134+
## `file_diff.modification_color_name`
135+
136+
The name of the theme color used to mark modifications.
137+
138+
The default value is 'yellow'. If your theme does not define that color, set this field to
139+
your theme's equivalent.
142140

143141
<a id="file_diff.start"></a>
144-
### `file_diff.start`(*file1*, *file2*, *horizontal*)
142+
## `file_diff.start`([*file1*[, *file2*[, *horizontal*=false]]])
145143

146-
Highlight differences between files *file1* and *file2*, or the user-selected files.
144+
Highlight differences between files.
147145

148146
Parameters:
147+
- *file1*: String older filename. If `-`, uses the current buffer. If `nil`, the user
148+
is prompted for a file.
149+
- *file2*: String newer filename. If `-`, uses the current buffer. If `nil`, the user
150+
is prompted for a file.
151+
- *horizontal*: Split the view horizontally instead of vertically. The
152+
default is to compare files side-by-side.
149153

150-
- *file1*: Optional name of the older file. If `-`, uses the current buffer. If `nil`,
151-
the user is prompted for a file.
152-
- *file2*: Optional name of the newer file. If `-`, uses the current buffer. If `nil`,
153-
the user is prompted for a file.
154-
- *horizontal*: Optional flag specifying whether or not to split the view horizontally. The
155-
default value is `false`, comparing the two files side-by-side.
156154

157155

158-
---

init.lua

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
-- Copyright 2015-2025 Mitchell. See LICENSE.
22

33
--- Two-way file comparison for Textadept.
4-
--
54
-- Install this module by copying it into your *~/.textadept/modules/* directory or Textadept's
65
-- *modules/* directory, and then putting the following in your *~/.textadept/init.lua*:
76
--
8-
-- require('file_diff')
7+
-- ```lua
8+
-- local file_diff = require('file_diff')
9+
-- ```
910
--
10-
-- ### Compiling
11+
-- ## Compiling
1112
--
1213
-- Releases include binaries, so building this modules should not be necessary. If you want
1314
-- to build manually, use CMake. For example:
1415
--
15-
-- cmake -S . -B build_dir
16-
-- cmake --build build_dir --target diff
17-
-- cmake --install build_dir
16+
-- ```bash
17+
-- cmake -S . -B build_dir
18+
-- cmake --build build_dir --target diff
19+
-- cmake --install build_dir
20+
-- ```
1821
--
19-
-- ### Usage
22+
-- ## Usage
2023
--
2124
-- A sample workflow is this:
22-
--
2325
-- 1. Start comparing two files via the "Compare Files" submenu in the "Tools" menu.
2426
-- 2. The caret is initially placed in the file on the left.
2527
-- 3. Go to the next change via menu or key binding.
@@ -33,7 +35,7 @@
3335
-- Note: merging can be performed wherever the caret is placed when jumping between changes,
3436
-- even if one buffer has a change and the other does not (additions or deletions).
3537
--
36-
-- ### Key Bindings
38+
-- ## Key Bindings
3739
--
3840
-- Windows and Linux | macOS | Terminal | Command
3941
-- -|-|-|-
@@ -289,13 +291,13 @@ end
289291

290292
local starting_diff = false
291293

292-
--- Highlight differences between files *file1* and *file2*, or the user-selected files.
293-
-- @param file1 Optional name of the older file. If `-`, uses the current buffer. If `nil`,
294-
-- the user is prompted for a file.
295-
-- @param file2 Optional name of the newer file. If `-`, uses the current buffer. If `nil`,
296-
-- the user is prompted for a file.
297-
-- @param horizontal Optional flag specifying whether or not to split the view horizontally. The
298-
-- default value is `false`, comparing the two files side-by-side.
294+
--- Highlight differences between files.
295+
-- @param[opt] file1 String older filename. If `-`, uses the current buffer. If `nil`, the user
296+
-- is prompted for a file.
297+
-- @param[optchain] file2 String newer filename. If `-`, uses the current buffer. If `nil`, the user
298+
-- is prompted for a file.
299+
-- @param[optchain=false] horizontal Split the view horizontally instead of vertically. The
300+
-- default is to compare files side-by-side.
299301
function M.start(file1, file2, horizontal)
300302
file1 = file1 or ui.dialogs.open{
301303
title = _L['Select the first file to compare'],
@@ -337,7 +339,7 @@ end
337339
events.connect(events.BUFFER_BEFORE_SWITCH, function() if not starting_diff then stop() end end)
338340
events.connect(events.BUFFER_DELETED, stop)
339341

340-
--- Retrieves the equivalent of line number *line* in the other buffer.
342+
--- Retrieves a line number's equivalent in the other buffer.
341343
-- @param line Line to get the synchronized equivalent of in the other buffer.
342344
-- @return line
343345
local function get_synchronized_line(line)
@@ -350,9 +352,10 @@ local function get_synchronized_line(line)
350352
return line
351353
end
352354

353-
--- Jumps to the next or previous difference between the two files depending on boolean *next*.
355+
--- Jumps to the next or previous difference between the two files.
354356
-- `file_diff.start()` must have been called previously.
355-
-- @param next Whether to go to the next or previous difference relative to the current line.
357+
-- @param[opt=false] next Go to the next previous difference relative to the current line,
358+
-- as opposed to the previous one.
356359
function M.goto_change(next)
357360
if not _VIEWS[view1] or not _VIEWS[view2] then return end
358361
-- Determine the line to start on, keeping in mind the synchronized line numbers may be different.
@@ -422,7 +425,7 @@ end
422425

423426
--- Merges a change from one buffer to another, depending on the change under the caret and the
424427
-- merge direction.
425-
-- @param left Whether to merge from right to left or left to right.
428+
-- @param[opt=false] left Merge from right to left as opposed to left to right.
426429
function M.merge(left)
427430
if not _VIEWS[view1] or not _VIEWS[view2] then return end
428431
local buffer1, buffer2 = view1.buffer, view2.buffer
@@ -574,13 +577,12 @@ return M
574577

575578
-- The function below is a Lua C function.
576579

577-
--- Returns a list that represents the differences between strings *text1* and *text2*.
580+
--- Returns a list of the differences between strings.
578581
-- Each consecutive pair of elements in the returned list represents a "diff". The first element
579582
-- is an integer: 0 for a deletion, 1 for an insertion, and 2 for equality. The second element
580583
-- is the associated diff text.
581584
-- @param text1 String to compare against.
582585
-- @param text2 String to compare.
583-
-- @return list of differences
584586
-- @usage diffs = diff(text1, text2)
585587
-- for i = 1, #diffs, 2 do print(diffs[i], diffs[i + 1]) end
586588
-- @function _G.diff

0 commit comments

Comments
 (0)