|
| 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 | +--- |
0 commit comments