GithubHelp home page GithubHelp logo

orbitalquark / textadept-file-diff Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 1.0 106 KB

Two-way file comparison module for Textadept.

License: MIT License

C++ 3.29% Lua 87.71% CMake 9.00%
textadept textadept-module file-compare file-diff file-comparison

textadept-file-diff's Introduction

File Diff

Two-way file comparison for Textadept.

Install this module by copying it into your ~/.textadept/modules/ directory or Textadept's modules/ directory, and then putting the following in your ~/.textadept/init.lua:

require('file_diff')

Compiling

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

cmake -S . -B build_dir
cmake --build build_dir --target diff
cmake --install build_dir

Usage

A sample workflow is this:

  1. Start comparing two files via the "Compare Files" submenu in the "Tools" menu.
  2. The caret is initially placed in the file on the left.
  3. Go to the next change via menu or key binding.
  4. Merge the change from the other buffer into the current one (right to left) via menu or key binding.
  5. Go to the next change via menu or key binding.
  6. Merge the change from the current buffer into the other one (left to right) via menu or key binding.
  7. Repeat as necessary.

Note: merging can be performed wherever the caret is placed when jumping between changes, even if one buffer has a change and the other does not (additions or deletions).

Key Bindings

Windows and Linux macOS Terminal Command
Tools
F6 F6 None Compare files...
Shift+F6 ⇧F6 None Compare the buffers in two split views
Ctrl+F6 ⌘F6 None Stop comparing
Ctrl+Alt+. ^⌘. None Goto next difference
Ctrl+Alt+, ^⌘, None Goto previous difference
Ctrl+Alt+< ^⌘< None Merge left
Ctrl+Alt+> ^⌘> None Merge right

Fields defined by file_diff

file_diff.INDIC_ADDITION

The indicator number for text added within lines.

file_diff.INDIC_DELETION

The indicator number for text deleted within lines.

file_diff.MARK_ADDITION

The marker for line additions.

file_diff.MARK_DELETION

The marker for line deletions.

file_diff.MARK_MODIFICATION

The marker for line modifications.

file_diff.addition_color_name

The name of the theme color used to mark additions. The default value is 'green'. If your theme does not define that color, set this field to your theme's equivalent.

file_diff.deletion_color_name

The name of the theme color used to mark deletions. The default value is 'red'. If your theme does not define that color, set this field to your theme's equivalent.

file_diff.modification_color_name

The name of the theme color used to mark modifications. The default value is 'yellow'. If your theme does not define that color, set this field to your theme's equivalent.

Functions defined by file_diff

_G.diff(text1, text2)

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

Parameters:

  • text1: String to compare against.
  • text2: String to compare.

Usage:

  • diffs = diff(text1, text2) for i = 1, #diffs, 2 do print(diffs[i], diffs[i + 1]) end

Return:

  • list of differences

file_diff.goto_change(next)

Jumps to the next or previous difference between the two files depending on boolean next. file_diff.start() must have been called previously.

Parameters:

  • next: Whether to go to the next or previous difference relative to the current line.

file_diff.merge(left)

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

Parameters:

  • left: Whether to merge from right to left or left to right.

file_diff.start(file1, file2, horizontal)

Highlight differences between files file1 and file2, or the user-selected files.

Parameters:

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

textadept-file-diff's People

Contributors

orbitalquark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

paaguti

textadept-file-diff's Issues

Errors trying to install/require this neat-sounding module...

So I thought I'd go for this:

cd ~/.textadept/modules
git clone [email protected]:orbitalquark/textadept-file-diff.git
mv textadept-file-diff file_diff

Then require('file_diff') in init.lua but this produces:

lua: /home/_/.textadept/modules/file_diff/init.lua:102: module 'file_diff.diff' not found:
	no field package.preload['file_diff.diff']
	no file '/home/_/.textadept/modules/file_diff/diff.lua'
	no file '/home/_/.textadept/modules/file_diff/diff/init.lua'
	no file '/home/_/a/textadept/modules/file_diff/diff.lua'
	no file '/home/_/a/textadept/modules/file_diff/diff/init.lua'
	no file '/home/_/a/textadept/core/file_diff/diff.lua'
	no file '/usr/share/lua/5.4/file_diff/diff.lua'
	no file '/usr/share/lua/5.4/file_diff/diff/init.lua'
	no file '/usr/lib/lua/5.4/file_diff/diff.lua'
	no file '/usr/lib/lua/5.4/file_diff/diff/init.lua'
	no file ''
	no file '/home/_/.textadept/modules/file_diff/diff.so'
	no file '/home/_/a/textadept/modules/file_diff/diff.so'
	no file '/usr/lib/lua/5.4/file_diff/diff.so'
	no file '/usr/lib/lua/5.4/loadall.so'
	no file ''
	no file '/home/_/.textadept/modules/file_diff.so'
	no file '/home/_/a/textadept/modules/file_diff.so'
	no file '/usr/lib/lua/5.4/file_diff.so'
	no file '/usr/lib/lua/5.4/loadall.so'
	no file ''

(Of course there is diff.cxx but that's not pertinent I guess.) So since there's a makefile I do a make clean and make all but this yields:

g++ -c -std=c++11 -pedantic -fPIC -Wall -I../../src/lua/src -o diff.o diff.cxx
diff.cxx:3:10: fatal error: diff_match_patch.h: No such file or directory
    3 | #include "diff_match_patch.h"
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:27: diff.o] Error 1

which must related to this wild net fetch from L55+:

diff_match_patch_zip = 7f95b37e554453262e2bcda830724fc362614103.zip
$(diff_match_patch_zip): ; wget https://github.com/leutloff/diff-match-patch-cpp-stl/archive/$@
diff_match_patch.h: | $(diff_match_patch_zip) ; unzip -j $| "*/$@"

So leutloff has no more archive dir in that repo so now I'm out of ideas 😁 guess to resolve, would have to dig in that repo's history to find the latest .h that did exist under his ...../archive/ and bring it here into the repo? Or you might have a better idea since you actually what all this stuff is for and why...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.