Macros | Functions | Variables
undo.c File Reference
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include "auto/config.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/change.h"
#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/extmark.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/lib/kvec.h"
#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/pos.h"
#include "nvim/sha256.h"
#include "nvim/state.h"
#include "nvim/strings.h"
#include "nvim/types.h"
#include "nvim/undo.h"


#define UH_MAGIC   0x18dade
#define UE_MAGIC   0xabc123
#define UF_START_MAGIC   "Vim\237UnDo\345"
#define UF_START_MAGIC_LEN   9
#define UF_HEADER_MAGIC   0x5fd0
#define UF_HEADER_END_MAGIC   0xe7aa
#define UF_ENTRY_MAGIC   0xf518
#define UF_ENTRY_END_MAGIC   0x3581
#define UF_VERSION   3
#define UF_LAST_SAVE_NR   1
#define UHP_SAVE_NR   1
#define SET_FLAG(j)


int u_save_cursor (void)
int u_save (linenr_T top, linenr_T bot)
int u_savesub (linenr_T lnum)
int u_inssub (linenr_T lnum)
int u_savedel (linenr_T lnum, long nlines)
bool undo_allowed (buf_T *buf)
int u_savecommon (buf_T *buf, linenr_T top, linenr_T bot, linenr_T newbot, int reload)
void u_compute_hash (buf_T *buf, char_u *hash)
char * u_get_undo_file_name (const char *const buf_ffname, const bool reading) FUNC_ATTR_WARN_UNUSED_RESULT
void u_write_undo (const char *const name, const bool forceit, buf_T *const buf, char_u *const hash) FUNC_ATTR_NONNULL_ARG(3
 if (name==NULL)
 if (buf->b_ffname !=NULL)
 if (os_path_exists((char_u *) file_name))
 if (buf->b_u_numhead==0 &&buf->b_u_line_ptr==NULL)
 if (fd< 0)
void os_setperm (file_name, perm)
 if (p_verbose > 0)
 if (fp==NULL)
 u_sync (true)
 if (!serialize_header(&bi, hash))
 while (uhp !=NULL)
 if (undo_write_bytes(&bi,(uintmax_t) UF_HEADER_END_MAGIC, 2))
 if (!write_ok)
void u_read_undo (char *name, const char_u *hash, const char_u *orig_name FUNC_ATTR_UNUSED) FUNC_ATTR_NONNULL_ARG(2)
void u_undo (int count)
void u_redo (int count)
bool u_undo_and_forget (int count)
void undo_time (long step, bool sec, bool file, bool absolute)
void undo_fmt_time (char_u *buf, size_t buflen, time_t tt)
 Put the timestamp of an undo header in "buf[buflen]" in a nice format. More...
void u_sync (bool force)
void ex_undolist (exarg_T *eap)
void ex_undojoin (exarg_T *eap)
void u_unchanged (buf_T *buf)
void u_find_first_changed (void)
void u_update_save_nr (buf_T *buf)
void u_clearall (buf_T *buf)
void u_saveline (linenr_T lnum)
void u_clearline (void)
void u_undoline (void)
void u_blockfree (buf_T *buf)
bool anyBufIsChanged (void)
bool curbufIsChanged (void)
list_Tu_eval_tree (const u_header_T *const first_uhp) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
u_header_Tu_force_get_undo_header (buf_T *buf)


void char * file_name
int mark = ++lastmark
int fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm)
FILE * fp = NULL
int perm = 0600
bool write_ok = false
bufinfo_T bi
bi bi_buf = buf
bi bi_fp = fp
 uhp = buf->b_u_oldhead
write_error __pad0__
theend __pad1__

Macro Definition Documentation


#define SET_FLAG (   j)


#define UE_MAGIC   0xabc123


#define UF_ENTRY_END_MAGIC   0x3581


#define UF_ENTRY_MAGIC   0xf518


#define UF_HEADER_END_MAGIC   0xe7aa


#define UF_HEADER_MAGIC   0x5fd0


#define UF_LAST_SAVE_NR   1


#define UF_START_MAGIC   "Vim\237UnDo\345"


#define UF_START_MAGIC_LEN   9


#define UF_VERSION   3


#define UH_MAGIC   0x18dade


#define UHP_SAVE_NR   1

Function Documentation

◆ anyBufIsChanged()

bool anyBufIsChanged ( void  )

◆ bufIsChanged()

bool bufIsChanged ( buf_T buf)

Check if the 'modified' flag is set, or 'ff' has changed (only need to check the first character, because it can only be "dos", "unix" or "mac"). "nofile" and "scratch" type buffers are considered to always be unchanged.

bufThe buffer to check
true if the buffer has changed

◆ curbufIsChanged()

bool curbufIsChanged ( void  )
See also
true if the current buffer has changed

◆ ex_undojoin()

void ex_undojoin ( exarg_T eap)

◆ ex_undolist()

void ex_undolist ( exarg_T eap)

◆ if() [1/10]

if ( !serialize_header &,  hash)

◆ if() [2/10]

if ( write_ok)

◆ if() [3/10]

if ( buf->b_ffname !  = NULL)

◆ if() [4/10]

if ( buf->  b_u_numhead = = 0 && buf->b_u_line_ptr == NULL)

◆ if() [5/10]

if ( )

◆ if() [6/10]

if ( fp  = NULL)

◆ if() [7/10]

if ( name  = NULL)

◆ if() [8/10]

◆ if() [9/10]

if ( p_verbose  ,

◆ if() [10/10]

if ( undo_write_bytes(&,  uintmax_tUF_HEADER_END_MAGIC,

◆ os_setperm()

void os_setperm ( file_name  ,

◆ u_blockfree()

void u_blockfree ( buf_T buf)

◆ u_clearall()

void u_clearall ( buf_T buf)

◆ u_clearline()

void u_clearline ( void  )

◆ u_compute_hash()

void u_compute_hash ( buf_T buf,
char_u hash 

Compute the hash for a buffer text into hash[UNDO_HASH_SIZE].

[in]bufThe buffer used to compute the hash
[in]hashArray of size UNDO_HASH_SIZE in which to store the value of the hash

◆ u_eval_tree()

list_T* u_eval_tree ( const u_header_T *const  first_uhp)

Append the list of undo blocks to a newly allocated list

For use in undotree(). Recursive.

[in]first_uhpUndo blocks list to start with.
[allocated] List with a representation of undo blocks.

◆ u_find_first_changed()

void u_find_first_changed ( void  )

◆ u_force_get_undo_header()

u_header_T* u_force_get_undo_header ( buf_T buf)

◆ u_get_undo_file_name()

char* u_get_undo_file_name ( const char *const  buf_ffname,
const bool  reading 

Return an allocated string of the full path of the target undofile.

[in]buf_ffnameFull file name for which undo file location should be found.
[in]readingIf true, find the file to read by traversing all of the directories in &undodir. If false use the first existing directory. If none of the directories in &undodir option exist then last directory in the list will be automatically created.
[allocated] File name to read from/write to or NULL.

◆ u_inssub()

int u_inssub ( linenr_T  lnum)

◆ u_read_undo()

void u_read_undo ( char *  name,
const char_u hash,
const char_u *orig_name  FUNC_ATTR_UNUSED 

Loads the undo tree from an undo file. If "name" is not NULL use it as the undo file name. This also means being a bit more verbose. Otherwise use curbuf->b_ffname to generate the undo file name. "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text.

◆ u_redo()

void u_redo ( int  count)

◆ u_save()

int u_save ( linenr_T  top,
linenr_T  bot 

◆ u_save_cursor()

int u_save_cursor ( void  )

◆ u_savecommon()

int u_savecommon ( buf_T buf,
linenr_T  top,
linenr_T  bot,
linenr_T  newbot,
int  reload 

◆ u_savedel()

int u_savedel ( linenr_T  lnum,
long  nlines 

◆ u_saveline()

void u_saveline ( linenr_T  lnum)

◆ u_savesub()

int u_savesub ( linenr_T  lnum)

◆ u_sync() [1/2]

void u_sync ( bool  force)

u_sync: stop adding to the current entry list

forceif true, also sync when no_u_sync is set.

◆ u_sync() [2/2]

u_sync ( true  )

◆ u_unchanged()

void u_unchanged ( buf_T buf)

◆ u_undo()

void u_undo ( int  count)

◆ u_undo_and_forget()

bool u_undo_and_forget ( int  count)

Undo and remove the branch from the undo tree. Also moves the cursor (as a "normal" undo would).

◆ u_undoline()

void u_undoline ( void  )

◆ u_update_save_nr()

void u_update_save_nr ( buf_T buf)

◆ u_write_undo()

void u_write_undo ( const char *const  name,
const bool  forceit,
buf_T *const  buf,
char_u *const  hash 

Write the undo tree in an undo file.

[in]nameName of the undo file or NULL if this function needs to generate the undo file name based on buf->b_ffname.
[in]forceitTrue for :wundo!, false otherwise.
[in]bufBuffer for which undo file is written.
[in]hashHash value of the buffer text. Must have UNDO_HASH_SIZE size.

◆ undo_allowed()

bool undo_allowed ( buf_T buf)

Return true when undo is allowed. Otherwise print an error message and return false.

true if undo is allowed.

◆ undo_fmt_time()

void undo_fmt_time ( char_u buf,
size_t  buflen,
time_t  tt 

Put the timestamp of an undo header in "buf[buflen]" in a nice format.

◆ undo_time()

void undo_time ( long  step,
bool  sec,
bool  file,
bool  absolute 

◆ while()

while ( uhp = NULL)

Variable Documentation

◆ __pad0__

write_error __pad0__

◆ __pad1__

theend __pad1__

◆ bi

◆ bi_buf

bi bi_buf = buf

◆ bi_fp

bi bi_fp = fp

◆ else

Initial value:
file_name = (char *)name

◆ fd

fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm)

◆ file_name

void char* file_name
Initial value:

◆ fp

fp = NULL

◆ mark

mark = ++lastmark

◆ perm

perm = 0600

◆ uhp

uhp = buf->b_u_oldhead

◆ write_ok

bool write_ok = false
void char * file_name
Definition: undo.c:1176
Definition: undo.c:1327
Definition: undo_defs.h:35
char_u * name
Definition: userfunc.c:817