Data Structures | Macros | Functions
diff.c File Reference
#include <inttypes.h>
#include <stdbool.h>
#include "nvim/vim.h"
#include "xdiff/xdiff.h"
#include "nvim/ascii.h"
#include "nvim/diff.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/memory.h"
#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/path.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/undo.h"
#include "nvim/window.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"

Data Structures

struct  diffin_T
 
struct  diffout_T
 
struct  diffio_T
 

Macros

#define DIFF_FILLER   0x001
 
#define DIFF_IBLANK   0x002
 
#define DIFF_ICASE   0x004
 
#define DIFF_IWHITE   0x008
 
#define DIFF_IWHITEALL   0x010
 
#define DIFF_IWHITEEOL   0x020
 
#define DIFF_HORIZONTAL   0x040
 
#define DIFF_VERTICAL   0x080
 
#define DIFF_HIDDEN_OFF   0x100
 
#define DIFF_INTERNAL   0x200
 
#define ALL_WHITE_DIFF   (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL)
 
#define LBUFLEN   50
 

Functions

void diff_buf_delete (buf_T *buf)
 
void diff_buf_adjust (win_T *win)
 
void diff_buf_add (buf_T *buf)
 
void diff_invalidate (buf_T *buf)
 
void diff_mark_adjust (linenr_T line1, linenr_T line2, long amount, long amount_after)
 
int diff_internal (void)
 
void ex_diffupdate (exarg_T *eap)
 
void ex_diffpatch (exarg_T *eap)
 
void ex_diffsplit (exarg_T *eap)
 
void ex_diffthis (exarg_T *eap)
 
void diff_win_options (win_T *wp, int addbuf)
 
void ex_diffoff (exarg_T *eap)
 
void diff_clear (tabpage_T *tp)
 
int diff_check (win_T *wp, linenr_T lnum)
 
int diff_check_fill (win_T *wp, linenr_T lnum)
 
void diff_set_topline (win_T *fromwin, win_T *towin)
 
int diffopt_changed (void)
 
bool diffopt_horizontal (void)
 Check that "diffopt" contains "horizontal". More...
 
bool diffopt_hiddenoff (void)
 
bool diff_find_change (win_T *wp, linenr_T lnum, int *startp, int *endp) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
 
bool diff_infold (win_T *wp, linenr_T lnum) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
 
void nv_diffgetput (bool put, size_t count)
 "dp" and "do" commands. More...
 
void ex_diffgetput (exarg_T *eap)
 
bool diff_mode_buf (buf_T *buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
 
int diff_move_to (int dir, long count)
 
linenr_T diff_get_corresponding_line (buf_T *buf1, linenr_T lnum1)
 
linenr_T diff_lnum_win (linenr_T lnum, win_T *wp)
 

Detailed Description

Code for diff'ing two, three or four buffers.

There are three ways to diff:

Macro Definition Documentation

#define ALL_WHITE_DIFF   (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL)
#define DIFF_FILLER   0x001
#define DIFF_HIDDEN_OFF   0x100
#define DIFF_HORIZONTAL   0x040
#define DIFF_IBLANK   0x002
#define DIFF_ICASE   0x004
#define DIFF_INTERNAL   0x200
#define DIFF_IWHITE   0x008
#define DIFF_IWHITEALL   0x010
#define DIFF_IWHITEEOL   0x020
#define DIFF_VERTICAL   0x080
#define LBUFLEN   50

Function Documentation

void diff_buf_add ( buf_T buf)

Add a buffer to make diffs for.

Call this when a new buffer is being edited in the current window where 'diff' is set. Marks the current buffer as being part of the diff and requiring updating. This must be done before any autocmd, because a command may use info about the screen contents.

Parameters
bufThe buffer to add.
void diff_buf_adjust ( win_T win)

Check if the current buffer should be added to or removed from the list of diff buffers.

Parameters
win
void diff_buf_delete ( buf_T buf)

Called when deleting or unloading a buffer: No longer make a diff with it.

Parameters
buf
int diff_check ( win_T wp,
linenr_T  lnum 
)

Check diff status for line "lnum" in buffer "buf":

Returns 0 for nothing special Returns -1 for a line that should be highlighted as changed. Returns -2 for a line that should be highlighted as added/deleted. Returns > 0 for inserting that many filler lines above it (never happens when 'diffopt' doesn't contain "filler"). This should only be used for windows where 'diff' is set.

Parameters
wp
lnum
Returns
diff status.
int diff_check_fill ( win_T wp,
linenr_T  lnum 
)

Return the number of filler lines above "lnum".

Parameters
wp
lnum
Returns
Number of filler lines above lnum
void diff_clear ( tabpage_T tp)

Clear the list of diffblocks for tab page "tp".

Parameters
tp
bool diff_find_change ( win_T wp,
linenr_T  lnum,
int *  startp,
int *  endp 
)

Find the difference within a changed line.

Parameters
wpwindow whose current buffer to check
lnumline number to check within the buffer
startpfirst char of the change
endplast char of the change
Returns
true if the line was added, no other buffer has it.
linenr_T diff_get_corresponding_line ( buf_T buf1,
linenr_T  lnum1 
)

Finds the corresponding line in a diff.

Parameters
buf1
lnum1
Returns
The corresponding line.
bool diff_infold ( win_T wp,
linenr_T  lnum 
)

Check that line "lnum" is not close to a diff block, this line should be in a fold.

Parameters
wpwindow containing the buffer to check
lnumline number to check within the buffer
Returns
false if there are no diff blocks at all in this window.
int diff_internal ( void  )

Return true if the options are set to use the internal diff library. Note that if the internal diff failed for one of the buffers, the external diff will be used anyway.

void diff_invalidate ( buf_T buf)

Mark the diff info involving buffer "buf" as invalid, it will be updated when info is requested.

Parameters
buf
linenr_T diff_lnum_win ( linenr_T  lnum,
win_T wp 
)

For line "lnum" in the current window find the equivalent lnum in window "wp", compensating for inserted/deleted lines.

void diff_mark_adjust ( linenr_T  line1,
linenr_T  line2,
long  amount,
long  amount_after 
)

Called by mark_adjust(): update line numbers in "curbuf".

Parameters
line1
line2
amount
amount_after
bool diff_mode_buf ( buf_T buf)

Checks that the buffer is in diff-mode.

Parameters
bufbuffer to check.
int diff_move_to ( int  dir,
long  count 
)

Move "count" times in direction "dir" to the next diff block.

Parameters
dir
count
Returns
FAIL if there isn't such a diff block.
void diff_set_topline ( win_T fromwin,
win_T towin 
)

Set the topline of "towin" to match the position in "fromwin", so that they show the same diff'ed lines.

Parameters
fromwin
towin
void diff_win_options ( win_T wp,
int  addbuf 
)

Set options in window "wp" for diff mode.

Parameters
addbufAdd buffer to diff.
int diffopt_changed ( void  )

This is called when 'diffopt' is changed.

Returns
bool diffopt_hiddenoff ( void  )
bool diffopt_horizontal ( void  )

Check that "diffopt" contains "horizontal".

void ex_diffgetput ( exarg_T eap)

":diffget" and ":diffput"

Parameters
eap
void ex_diffoff ( exarg_T eap)

Set options not to show diffs. For the current window or all windows. Only in the current tab page.

Parameters
eap
void ex_diffpatch ( exarg_T eap)

Create a new version of a file from the current buffer and a diff file.

The buffer is written to a file, also for unmodified buffers (the file could have been produced by autocommands, e.g. the netrw plugin).

Parameters
eap
void ex_diffsplit ( exarg_T eap)

Split the window and edit another file, setting options to show the diffs.

Parameters
eap
void ex_diffthis ( exarg_T eap)
void ex_diffupdate ( exarg_T eap)

Completely update the diffs for the buffers involved.

When using the external "diff" command the buffers are written to a file, also for unmodified buffers (the file could have been produced by autocommands, e.g. the netrw plugin).

Parameters
eapcan be NULL
void nv_diffgetput ( bool  put,
size_t  count 
)

"dp" and "do" commands.