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


#define UH_MAGIC   0x18dade /* value for uh_magic when in use */
#define UE_MAGIC   0xabc123 /* value for ue_magic when in use */
#define UF_START_MAGIC   "Vim\237UnDo\345" /* magic at start of undofile */
#define UF_START_MAGIC_LEN   9
#define UF_HEADER_MAGIC   0x5fd0 /* magic at start of header */
#define UF_HEADER_END_MAGIC   0xe7aa /* magic after last header */
#define UF_ENTRY_MAGIC   0xf518 /* magic at start of entry */
#define UF_ENTRY_END_MAGIC   0x3581 /* magic after last entry */
#define UF_VERSION   2 /* 2-byte undofile version number */
#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 (void)
int u_savecommon (linenr_T top, linenr_T bot, linenr_T newbot, int reload)
void u_compute_hash (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))
void u_sync (int 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__
if(!write_ok) EMSG2(_("E829 s u_oldcount< 0 ? (int64_t)-u_oldcount : (int64_t)u_oldcount, _(msgstr), did_undo ? _("before") : _("after"), uhp == NULL ? (int64_t)0L : (int64_t)uhp-> uh_seq
if(!write_ok) EMSG2(_("E829 s u_oldcount< 0 ? (int64_t)-u_oldcount : (int64_t)u_oldcount, _(msgstr), did_undo ? _("before") : _("after"), uhp == NULL ? (int64_t)0L : (int64_t)uhp-> msgbuf

Macro Definition Documentation

#define SET_FLAG (   j)
#define UE_MAGIC   0xabc123 /* value for ue_magic when in use */
#define UF_ENTRY_END_MAGIC   0x3581 /* magic after last entry */
#define UF_ENTRY_MAGIC   0xf518 /* magic at start of entry */
#define UF_HEADER_END_MAGIC   0xe7aa /* magic after last header */
#define UF_HEADER_MAGIC   0x5fd0 /* magic at start of header */
#define UF_LAST_SAVE_NR   1
#define UF_START_MAGIC   "Vim\237UnDo\345" /* magic at start of undofile */
#define UF_START_MAGIC_LEN   9
#define UF_VERSION   2 /* 2-byte undofile version number */
#define UH_MAGIC   0x18dade /* value for uh_magic when in use */
#define UHP_SAVE_NR   1

Function Documentation

bool anyBufIsChanged ( void  )
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
bool curbufIsChanged ( void  )
See also
true if the current buffer has changed
void ex_undojoin ( exarg_T eap)
void ex_undolist ( exarg_T eap)
if ( name  = NULL)
if ( buf->b_ffname!  = NULL)
if ( buf->  b_u_numhead = = 0 && buf->b_u_line_ptr == NULL)
if ( )
if ( p_verbose  ,
if ( fp  = NULL)
if ( !serialize_header &,  hash)
if ( undo_write_bytes(&,  uintmax_tUF_HEADER_END_MAGIC,
void os_setperm ( file_name  ,
void u_blockfree ( buf_T buf)
void u_clearall ( buf_T buf)
void u_clearline ( void  )
void u_compute_hash ( char_u hash)
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.
void u_find_first_changed ( void  )
u_header_T* u_force_get_undo_header ( buf_T buf)
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.
int u_inssub ( linenr_T  lnum)
int u_save ( linenr_T  top,
linenr_T  bot 
int u_save_cursor ( void  )
int u_savecommon ( linenr_T  top,
linenr_T  bot,
linenr_T  newbot,
int  reload 
int u_savedel ( linenr_T  lnum,
long  nlines 
void u_saveline ( linenr_T  lnum)
int u_savesub ( linenr_T  lnum)
u_sync ( TRUE  )
void u_sync ( int  force)
void u_unchanged ( buf_T buf)
void u_undoline ( void  )
void u_update_save_nr ( buf_T buf)
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.
bool undo_allowed ( void  )

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

true if undo is allowed.
while ( uhp!  = NULL)

Variable Documentation

write_error __pad0__
bi bi_buf = buf
bi bi_fp = fp
Initial value:
file_name = (char *) name
void char * file_name
Definition: undo.c:1042
char_u * name
Definition: userfunc.c:772
fd = os_open(file_name, O_CREAT|O_WRONLY|O_EXCL|O_NOFOLLOW, perm)
void char* file_name
Initial value:
Definition: undo_defs.h:35
Definition: undo.c:1189
fp = NULL
mark = ++lastmark
if (!write_ok) EMSG2(_("E829 s u_oldcount< 0 ? (int64_t)-u_oldcount : (int64_t)u_oldcount, _(msgstr), did_undo ? _("before") : _("after"), uhp == NULL ? (int64_t)0L : (int64_t)uhp-> msgbuf
perm = 0600
if (!write_ok) EMSG2(_("E829 s u_oldcount< 0 ? (int64_t)-u_oldcount : (int64_t)u_oldcount, _(msgstr), did_undo ? _("before") : _("after"), uhp == NULL ? (int64_t)0L : (int64_t)uhp-> uh_seq
uhp = buf->b_u_oldhead
bool write_ok = false