Data Structures | Macros | Typedefs | Enumerations | Functions
shada.c File Reference
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
#include <assert.h>
#include <msgpack.h>
#include <uv.h>
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/vim.h"
#include "nvim/pos.h"
#include "nvim/ascii.h"
#include "nvim/shada.h"
#include "nvim/message.h"
#include "nvim/globals.h"
#include "nvim/memory.h"
#include "nvim/mark.h"
#include "nvim/macros.h"
#include "nvim/ops.h"
#include "nvim/garray.h"
#include "nvim/option.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/buffer.h"
#include "nvim/buffer_defs.h"
#include "nvim/ex_getln.h"
#include "nvim/search.h"
#include "nvim/regexp.h"
#include "nvim/eval/typval.h"
#include "nvim/version.h"
#include "nvim/path.h"
#include "nvim/fileio.h"
#include "nvim/os/fileio.h"
#include "nvim/strings.h"
#include "nvim/quickfix.h"
#include "nvim/eval/encode.h"
#include "nvim/eval/decode.h"
#include "nvim/lib/khash.h"
#include "nvim/lib/kvec.h"

Data Structures

struct  ShadaEntry
 Structure defining a single ShaDa file entry. More...
 
struct  hm_llist_entry
 One entry in sized linked list. More...
 
struct  HMLList
 Sized linked list structure for history merger. More...
 
struct  HistoryMergerState
 
struct  PossiblyFreedShadaEntry
 ShadaEntry structure that knows whether it should be freed. More...
 
struct  FileMarks
 Structure that holds one file marks. More...
 
struct  WriteMergerState
 
struct  sd_read_def
 Structure containing necessary pointers for reading ShaDa files. More...
 
struct  sd_write_def
 Structure containing necessary pointers for writing ShaDa files. More...
 

Macros

#define copy_option_part(src, dest, ...)   ((char *) copy_option_part((char_u **) src, (char_u *) dest, __VA_ARGS__))
 
#define find_shada_parameter(...)   ((const char *) find_shada_parameter(__VA_ARGS__))
 
#define home_replace_save(a, b)   ((char *)home_replace_save(a, (char_u *)b))
 
#define home_replace(a, b, c, d, e)   home_replace(a, (char_u *)b, (char_u *)c, d, e)
 
#define vim_rename(a, b)   (vim_rename((char_u *)a, (char_u *)b))
 
#define mb_strnicmp(a, b, c)   (mb_strnicmp((char_u *)a, (char_u *)b, c))
 
#define path_try_shorten_fname(b)   ((char *)path_try_shorten_fname((char_u *)b))
 
#define buflist_new(ffname, sfname, ...)   (buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
 
#define os_isdir(f)   (os_isdir((char_u *) f))
 
#define regtilde(s, m)   ((char *) regtilde((char_u *) s, m))
 
#define path_tail_with_sep(f)   ((char *) path_tail_with_sep((char_u *)f))
 
#define SEARCH_KEY_MAGIC   "sm"
 
#define SEARCH_KEY_SMARTCASE   "sc"
 
#define SEARCH_KEY_HAS_LINE_OFFSET   "sl"
 
#define SEARCH_KEY_PLACE_CURSOR_AT_END   "se"
 
#define SEARCH_KEY_IS_LAST_USED   "su"
 
#define SEARCH_KEY_IS_SUBSTITUTE_PATTERN   "ss"
 
#define SEARCH_KEY_HIGHLIGHTED   "sh"
 
#define SEARCH_KEY_OFFSET   "so"
 
#define SEARCH_KEY_PAT   "sp"
 
#define SEARCH_KEY_BACKWARD   "sb"
 
#define REG_KEY_TYPE   "rt"
 
#define REG_KEY_WIDTH   "rw"
 
#define REG_KEY_CONTENTS   "rc"
 
#define REG_KEY_UNNAMED   "ru"
 
#define KEY_LNUM   "l"
 
#define KEY_COL   "c"
 
#define KEY_FILE   "f"
 
#define KEY_NAME_CHAR   "n"
 
#define RERR   "E575: "
 
#define RCERR   "E576: "
 
#define SERR   "E886: "
 Common prefix for all “system” errors. More...
 
#define RNERR   "E136: "
 Common prefix for all “rename” errors. More...
 
#define WERR   "E574: "
 Common prefix for all ignorable “write” errors. More...
 
#define SHADA_LAST_ENTRY   ((uint64_t) kSDItemChange)
 
#define DEF_SDE(name, attr, ...)
 
#define DEFAULT_POS   { 1, 0, 0 }
 
#define HMLL_FORALL(hmll, cur_entry, code)
 
#define HMLL_ITER_BACK(hmll, cur_entry, code)
 
#define HMS_ITER(hms_p, cur_entry, code)   HMLL_FORALL(&((hms_p)->hmll), cur_entry, code)
 
#define MERGE_JUMPS(jumps_size, jumps, jumps_type, timestamp_attr, mark_attr, entry, fname_cond, free_func, fin_func, idxadj_func, afterfree_func)
 
#define SDE_TO_XFMARK(entry)   fm
 
#define ADJUST_IDX(i)
 
#define DUMMY_AFTERFREE(entry)
 
#define SDE_TO_FMARK(entry)   fm
 
#define AFTERFREE(entry)   (entry).data.filemark.fname = NULL
 
#define DUMMY_IDX_ADJ(i)
 
#define PACK_STATIC_STR(s)
 
#define PACK_STRING(s)
 
#define PACK_BIN(s)
 
#define DUMP_ADDITIONAL_ELEMENTS(src, what)
 
#define DUMP_ADDITIONAL_DATA(src, what)
 
#define CHECK_DEFAULT(entry, attr)   (sd_default_values[entry.type].data.attr == entry.data.attr)
 
#define ONE_IF_NOT_DEFAULT(entry, attr)   ((size_t) (!CHECK_DEFAULT(entry, attr)))
 
#define PACK_BOOL(entry, name, attr)
 
#define FORMAT_MARK_ENTRY(entry_name, name_fmt, name_fmt_arg)
 
#define COMPARE_WITH_ENTRY(wms_entry_, entry)
 
#define FREE_POSSIBLY_FREED_SHADA_ENTRY(entry)
 
#define SDE_TO_PFSDE(entry)   ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = entry })
 
#define AFTERFREE_DUMMY(entry)
 
#define DUMMY_IDX_ADJ(i)
 
#define PACK_WMS_ARRAY(wms_array)
 
#define PACK_WMS_ENTRY(wms_entry)
 
#define READERR(entry_name, error_desc)
 
#define CHECK_KEY(key, expected)
 
#define CLEAR_GA_AND_ERROR_OUT(ga)
 
#define ID(s)   s
 
#define BINDUP(b)   xmemdupz(b.ptr, b.size)
 
#define TOINT(s)   ((int) (s))
 
#define TOLONG(s)   ((long) (s))
 
#define TOCHAR(s)   ((char) (s))
 
#define TOU8(s)   ((uint8_t) (s))
 
#define TOSIZE(s)   ((size_t) (s))
 
#define CHECKED_ENTRY(condition, error_desc, entry_name, obj, tgt, attr, proc)
 
#define CHECK_KEY_IS_STR(un, entry_name)
 
#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, proc)
 
#define TYPED_KEY(un, entry_name, name, type_name, tgt, objtype, attr, proc)
 
#define BOOLEAN_KEY(un, entry_name, name, tgt)   TYPED_KEY(un, entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID)
 
#define STRING_KEY(un, entry_name, name, tgt)   TYPED_KEY(un, entry_name, name, "a binary", tgt, BIN, bin, BINDUP)
 
#define CONVERTED_STRING_KEY(un, entry_name, name, tgt)
 
#define INT_KEY(un, entry_name, name, tgt, proc)
 
#define INTEGER_KEY(un, entry_name, name, tgt)   INT_KEY(un, entry_name, name, tgt, TOINT)
 
#define LONG_KEY(un, entry_name, name, tgt)   INT_KEY(un, entry_name, name, tgt, TOLONG)
 
#define ADDITIONAL_KEY(un)
 
#define CONVERTED(str, len)   (xmemdupz((str), (len)))
 
#define BIN_CONVERTED(b)   CONVERTED(b.ptr, b.size)
 
#define SET_ADDITIONAL_DATA(tgt, name)
 
#define SET_ADDITIONAL_ELEMENTS(src, src_maxsize, tgt, name)
 

Typedefs

typedef void(* SearchPatternGetter) (SearchPattern *)
 Callback function for add_search_pattern. More...
 
typedef struct hm_llist_entry HMLListEntry
 One entry in sized linked list. More...
 
typedef void(* ShaDaReadCloser) (struct sd_read_def *const sd_reader) REAL_FATTR_NONNULL_ALL
 Function used to close files defined by ShaDaReadDef. More...
 
typedef ptrdiff_t(* ShaDaFileReader) (struct sd_read_def *const sd_reader, void *const dest, const size_t size) REAL_FATTR_NONNULL_ALL REAL_FATTR_WARN_UNUSED_RESULT
 Function used to read ShaDa files. More...
 
typedef int(* ShaDaFileSkipper) (struct sd_read_def *const sd_reader, const size_t offset) REAL_FATTR_NONNULL_ALL REAL_FATTR_WARN_UNUSED_RESULT
 Function used to skip in ShaDa files. More...
 
typedef struct sd_read_def ShaDaReadDef
 Structure containing necessary pointers for reading ShaDa files. More...
 
typedef void(* ShaDaWriteCloser) (struct sd_write_def *const sd_writer) REAL_FATTR_NONNULL_ALL
 Function used to close files defined by ShaDaWriteDef. More...
 
typedef ptrdiff_t(* ShaDaFileWriter) (struct sd_write_def *const sd_writer, const void *const src, const size_t size) REAL_FATTR_NONNULL_ALL REAL_FATTR_WARN_UNUSED_RESULT
 Function used to write ShaDa files. More...
 
typedef struct sd_write_def ShaDaWriteDef
 Structure containing necessary pointers for writing ShaDa files. More...
 

Enumerations

enum  ShaDaReadFileFlags {
  kShaDaWantInfo = 1, kShaDaWantMarks = 2, kShaDaForceit = 4, kShaDaGetOldfiles = 8,
  kShaDaMissingError = 16
}
 Flags for shada_read_file and children. More...
 
enum  ShadaEntryType {
  kSDItemUnknown = -1, kSDItemMissing = 0, kSDItemHeader = 1, kSDItemSearchPattern = 2,
  kSDItemSubString = 3, kSDItemHistoryEntry = 4, kSDItemRegister = 5, kSDItemVariable = 6,
  kSDItemGlobalMark = 7, kSDItemJump = 8, kSDItemBufferList = 9, kSDItemLocalMark = 10,
  kSDItemChange = 11
}
 
enum  ShaDaReadResult {
  kSDReadStatusSuccess, kSDReadStatusFinished, kSDReadStatusReadError, kSDReadStatusNotShaDa,
  kSDReadStatusMalformed
}
 Possible results when reading ShaDa file. More...
 
enum  ShaDaWriteResult { kSDWriteSuccessfull, kSDWriteReadNotShada, kSDWriteFailed, kSDWriteIgnError }
 Possible results of shada_write function. More...
 
enum  SRNIFlags {
  kSDReadHeader = (1 << kSDItemHeader), kSDReadUndisableableData, kSDReadRegisters = (1 << kSDItemRegister), kSDReadHistory = (1 << kSDItemHistoryEntry),
  kSDReadVariables = (1 << kSDItemVariable), kSDReadBufferList = (1 << kSDItemBufferList), kSDReadUnknown = (1 << (SHADA_LAST_ENTRY + 1)), kSDReadGlobalMarks = (1 << kSDItemGlobalMark),
  kSDReadLocalMarks = (1 << kSDItemLocalMark), kSDReadChanges = (1 << kSDItemChange)
}
 Flags for shada_read_next_item. More...
 

Functions

int shada_write_file (const char *const file, bool nomerge)
 
int shada_read_marks (void)
 
int shada_read_everything (const char *const fname, const bool forceit, const bool missing_ok)
 

Macro Definition Documentation

#define ADDITIONAL_KEY (   un)
Value:
else { /* NOLINT(readability/braces) */ \
ga_grow(&ad_ga, 1); \
memcpy(((char *)ad_ga.ga_data) + ((size_t)ad_ga.ga_len \
* sizeof(*un.data.via.map.ptr)), \
un.data.via.map.ptr + i, \
sizeof(*un.data.via.map.ptr)); \
ad_ga.ga_len++; \
}
void ga_grow(garray_T *gap, int n)
Definition: garray.c:77
int i
Definition: typval.c:868
#define ADJUST_IDX (   i)
Value:
}
EXTERN win_T * curwin
Definition: globals.h:448
int i
Definition: typval.c:868
int w_jumplistlen
Definition: buffer_defs.h:1242
int w_jumplistidx
Definition: buffer_defs.h:1243
#define AFTERFREE (   entry)    (entry).data.filemark.fname = NULL
#define AFTERFREE_DUMMY (   entry)
#define BIN_CONVERTED (   b)    CONVERTED(b.ptr, b.size)
#define BINDUP (   b)    xmemdupz(b.ptr, b.size)
#define BOOLEAN_KEY (   un,
  entry_name,
  name,
  tgt 
)    TYPED_KEY(un, entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID)
#define buflist_new (   ffname,
  sfname,
  ... 
)    (buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
#define CHECK_DEFAULT (   entry,
  attr 
)    (sd_default_values[entry.type].data.attr == entry.data.attr)
#define CHECK_KEY (   key,
  expected 
)
Value:
( \
key.via.str.size == sizeof(expected) - 1 \
&& STRNCMP(key.via.str.ptr, expected, sizeof(expected) - 1) == 0)
#define STRNCMP(d, s, n)
Definition: vim.h:219
#define CHECK_KEY_IS_STR (   un,
  entry_name 
)
Value:
if (un.data.via.map.ptr[i].key.type != MSGPACK_OBJECT_STR) { \
emsgf(_(READERR(entry_name, "has key which is not a string")), \
initial_fpos); \
} else if (un.data.via.map.ptr[i].key.via.str.size == 0) { \
emsgf(_(READERR(entry_name, "has empty key")), initial_fpos); \
}
#define _(x)
Definition: gettext.h:20
bool emsgf(const char *const fmt,...)
Print an error message with unknown number of arguments.
int i
Definition: typval.c:868
#define READERR(entry_name, error_desc)
Definition: shada.c:3451
#define CLEAR_GA_AND_ERROR_OUT(ga)
Definition: shada.c:3458
#define CHECKED_ENTRY (   condition,
  error_desc,
  entry_name,
  obj,
  tgt,
  attr,
  proc 
)
Value:
do { \
if (!(condition)) { \
emsgf(_(READERR(entry_name, error_desc)), initial_fpos); \
} \
tgt = proc(obj.via.attr); \
} while (0)
#define _(x)
Definition: gettext.h:20
if(len)
Definition: encode.c:222
bool emsgf(const char *const fmt,...)
Print an error message with unknown number of arguments.
#define READERR(entry_name, error_desc)
Definition: shada.c:3451
#define CLEAR_GA_AND_ERROR_OUT(ga)
Definition: shada.c:3458
#define CHECKED_KEY (   un,
  entry_name,
  name,
  error_desc,
  tgt,
  condition,
  attr,
  proc 
)
Value:
else if (CHECK_KEY( /* NOLINT(readability/braces) */ \
un.data.via.map.ptr[i].key, name)) { \
condition, "has " name " key value " error_desc, \
entry_name, un.data.via.map.ptr[i].val, \
tgt, attr, proc); \
}
#define CHECK_KEY(key, expected)
Definition: shada.c:3455
char * name
Definition: eval.c:1851
int i
Definition: typval.c:868
#define CHECKED_ENTRY(condition, error_desc, entry_name, obj, tgt, attr, proc)
Definition: shada.c:3470
#define CLEAR_GA_AND_ERROR_OUT (   ga)
Value:
do { \
ga_clear(&ga); \
goto shada_read_next_item_error; \
} while (0)
void ga_clear(garray_T *gap)
Clear an allocated growing array.
Definition: garray.c:27
#define COMPARE_WITH_ENTRY (   wms_entry_,
  entry 
)
Value:
do { \
PossiblyFreedShadaEntry *const wms_entry = (wms_entry_); \
if (wms_entry->data.type != kSDItemMissing) { \
if (wms_entry->data.timestamp >= (entry).timestamp) { \
shada_free_shada_entry(&(entry)); \
break; \
} \
if (wms_entry->can_free_entry) { \
shada_free_shada_entry(&wms_entry->data); \
} \
} \
*wms_entry = pfs_entry; \
} while (0)
if(len)
Definition: encode.c:222
Missing value. Should never appear in a file.
Definition: shada.c:170
#define CONVERTED (   str,
  len 
)    (xmemdupz((str), (len)))
#define CONVERTED_STRING_KEY (   un,
  entry_name,
  name,
  tgt 
)
Value:
TYPED_KEY(un, entry_name, name, "a binary", tgt, BIN, bin, \
#define TYPED_KEY(un, entry_name, name, type_name, tgt, objtype, attr, proc)
Definition: shada.c:3497
#define BIN_CONVERTED(b)
Definition: shada.c:3531
char * name
Definition: eval.c:1851
#define copy_option_part (   src,
  dest,
  ... 
)    ((char *) copy_option_part((char_u **) src, (char_u *) dest, __VA_ARGS__))
#define DEF_SDE (   name,
  attr,
  ... 
)
Value:
[kSDItem##name] = { \
.timestamp = 0, \
.type = kSDItem##name, \
.data = { \
.attr = { __VA_ARGS__ } \
} \
}
char * name
Definition: eval.c:1851
#define DEFAULT_POS   { 1, 0, 0 }
#define DUMMY_AFTERFREE (   entry)
#define DUMMY_IDX_ADJ (   i)
#define DUMMY_IDX_ADJ (   i)
#define DUMP_ADDITIONAL_DATA (   src,
  what 
)
Value:
do { \
dict_T *const d = (src); \
if (d != NULL) { \
size_t todo = d->dv_hashtab.ht_used; \
for (const hashitem_T *hi= d->dv_hashtab.ht_array; todo; hi++) { \
if (!HASHITEM_EMPTY(hi)) { \
todo--; \
dictitem_T *const di = TV_DICT_HI2DI(hi); \
const size_t key_len = strlen((const char *)hi->hi_key); \
msgpack_pack_str(spacker, key_len); \
msgpack_pack_str_body(spacker, (const char *)hi->hi_key, key_len); \
if (encode_vim_to_msgpack(spacker, &di->di_tv, \
_("additional data of ShaDa " what)) \
== FAIL) { \
goto shada_pack_entry_error; \
} \
} \
} \
} \
} while (0)
#define _(x)
Definition: gettext.h:20
#define HASHITEM_EMPTY(hi)
Definition: hashtab.h:19
tv_copy & TV_DICT_HI2DI(hi) ->di_tv, rettv
if(len)
Definition: encode.c:222
dict_T * d
Definition: eval.c:14725
return NULL
Definition: eval.c:22229
int encode_vim_to_msgpack(msgpack_packer *const packer, typval_T *const tv, const char *const objname)
for(size_t i=1;i< ARRAY_SIZE(argv);i++)
Definition: typval.c:1215
#define FAIL
Definition: vim.h:93
dictitem_T *const di
Definition: typval.c:1528
struct dictvar_S dict_T
Definition: typval.h:67
Definition: hashtab.h:38
#define DUMP_ADDITIONAL_ELEMENTS (   src,
  what 
)
Value:
do { \
if ((src) != NULL) { \
TV_LIST_ITER((src), li, { \
_("additional elements of ShaDa " what)) \
== FAIL) { \
goto shada_pack_entry_error; \
} \
}); \
} \
} while (0)
#define _(x)
Definition: gettext.h:20
if(len)
Definition: encode.c:222
#define TV_LIST_ITEM_TV(li)
Definition: typval.h:728
return NULL
Definition: eval.c:22229
int encode_vim_to_msgpack(msgpack_packer *const packer, typval_T *const tv, const char *const objname)
TV_LIST_ITER(l, li,{ptrs[i].item=li;ptrs[i].idx=i;i++;})
#define FAIL
Definition: vim.h:93
#define find_shada_parameter (   ...)    ((const char *) find_shada_parameter(__VA_ARGS__))
#define FORMAT_MARK_ENTRY (   entry_name,
  name_fmt,
  name_fmt_arg 
)
Value:
do { \
typval_T ad_tv = { \
.v_type = VAR_DICT, \
.vval.v_dict = entry.data.filemark.additional_data \
}; \
size_t ad_len; \
char *const ad = encode_tv2string(&ad_tv, &ad_len); \
S_LEN(ret), \
entry_name " {" name_fmt " file=[%zu]\"%.512s\", " \
"pos={l=%" PRIdLINENR ",c=%" PRIdCOLNR ",a=%" PRIdCOLNR "}, " \
"ad={%p:[%zu]%.64s} }", \
name_fmt_arg, \
strlen(entry.data.filemark.fname), \
entry.data.filemark.fname, \
entry.data.filemark.mark.lnum, \
entry.data.filemark.mark.col, \
entry.data.filemark.mark.coladd, \
(void *)entry.data.filemark.additional_data, \
ad_len, \
ad); \
} while (0)
int int ret
Definition: eval.c:19501
#define S_LEN(s)
Definition: macros.h:29
#define PRIdCOLNR
Format used to print values which have colnr_T type.
Definition: pos.h:11
char * encode_tv2string(typval_T *tv, size_t *len) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_MALLOC
Definition: encode.c:798
#define PRIdLINENR
Format used to print values which have linenr_T type.
Definition: pos.h:6
int vim_snprintf_add(char *str, size_t str_m, char *fmt,...) FUNC_ATTR_PRINTF(3
Dictionary, .v_dict is used.
Definition: typval.h:117
#define FREE_POSSIBLY_FREED_SHADA_ENTRY (   entry)
Value:
do { \
if (entry.can_free_entry) { \
shada_free_shada_entry(&entry.data); \
} \
} while (0)
if(len)
Definition: encode.c:222
#define HMLL_FORALL (   hmll,
  cur_entry,
  code 
)
Value:
for (HMLListEntry *cur_entry = (hmll)->first; cur_entry != NULL; \
cur_entry = cur_entry->next) { \
code \
} \
return NULL
Definition: eval.c:22229
One entry in sized linked list.
Definition: shada.c:323

Iterate over HMLList in forward direction

Parameters
hmllPointer to the list.
cur_entryName of the variable to iterate over.
codeCode to execute on each iteration.
Returns
for cycle header (use HMLL_FORALL(hmll, cur_entry) {body}).
#define HMLL_ITER_BACK (   hmll,
  cur_entry,
  code 
)
Value:
for (cur_entry = (hmll)->last; cur_entry != NULL; \
cur_entry = cur_entry->prev) { \
code \
}
return NULL
Definition: eval.c:22229

Iterate over HMLList in backward direction

Parameters
hmllPointer to the list.
cur_entryName of the variable to iterate over, must be already defined.
codeCode to execute on each iteration.
Returns
for cycle header (use HMLL_FORALL(hmll, cur_entry) {body}).
#define HMS_ITER (   hms_p,
  cur_entry,
  code 
)    HMLL_FORALL(&((hms_p)->hmll), cur_entry, code)

Iterate over all history entries in history merger, in order

Parameters
[in]hms_pMerger structure to iterate over.
[out]cur_entryName of the iterator variable.
codeCode to execute on each iteration.
Returns
for cycle header. Use HMS_ITER(hms_p, cur_entry) {body}.
#define home_replace (   a,
  b,
  c,
  d,
 
)    home_replace(a, (char_u *)b, (char_u *)c, d, e)
#define home_replace_save (   a,
 
)    ((char *)home_replace_save(a, (char_u *)b))
#define ID (   s)    s
#define INT_KEY (   un,
  entry_name,
  name,
  tgt,
  proc 
)
Value:
un, entry_name, name, "which is not an integer", tgt, \
((un.data.via.map.ptr[i].val.type \
== MSGPACK_OBJECT_POSITIVE_INTEGER) \
|| (un.data.via.map.ptr[i].val.type \
== MSGPACK_OBJECT_NEGATIVE_INTEGER)), \
i64, proc)
#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, proc)
Definition: shada.c:3488
char * name
Definition: eval.c:1851
int i
Definition: typval.c:868
#define INTEGER_KEY (   un,
  entry_name,
  name,
  tgt 
)    INT_KEY(un, entry_name, name, tgt, TOINT)
#define KEY_COL   "c"
#define KEY_FILE   "f"
#define KEY_LNUM   "l"
#define KEY_NAME_CHAR   "n"
#define LONG_KEY (   un,
  entry_name,
  name,
  tgt 
)    INT_KEY(un, entry_name, name, tgt, TOLONG)
#define mb_strnicmp (   a,
  b,
 
)    (mb_strnicmp((char_u *)a, (char_u *)b, c))
#define MERGE_JUMPS (   jumps_size,
  jumps,
  jumps_type,
  timestamp_attr,
  mark_attr,
  entry,
  fname_cond,
  free_func,
  fin_func,
  idxadj_func,
  afterfree_func 
)
#define ONE_IF_NOT_DEFAULT (   entry,
  attr 
)    ((size_t) (!CHECK_DEFAULT(entry, attr)))
#define os_isdir (   f)    (os_isdir((char_u *) f))
#define PACK_BIN (   s)
Value:
do { \
const String s_ = (s); \
msgpack_pack_bin(spacker, s_.size); \
if (s_.size > 0) { \
msgpack_pack_bin_body(spacker, s_.data, s_.size); \
} \
} while (0)
if(len)
Definition: encode.c:222
Definition: defs.h:77
char * s
Definition: message.c:732
#define PACK_BOOL (   entry,
  name,
  attr 
)
Value:
do { \
if (!CHECK_DEFAULT(entry, search_pattern.attr)) { \
if (sd_default_values[entry.type].data.search_pattern.attr) { \
msgpack_pack_false(spacker); \
} else { \
msgpack_pack_true(spacker); \
} \
} \
} while (0)
if(len)
Definition: encode.c:222
#define PACK_STATIC_STR(s)
Definition: shada.c:1563
#define CHECK_DEFAULT(entry, attr)
char * name
Definition: eval.c:1851
#define PACK_STATIC_STR (   s)
Value:
do { \
msgpack_pack_str(spacker, sizeof(s) - 1); \
msgpack_pack_str_body(spacker, s, sizeof(s) - 1); \
} while (0)
char * s
Definition: message.c:732
#define PACK_STRING (   s)
Value:
do { \
const String s_ = (s); \
msgpack_pack_str(spacker, s_.size); \
if (s_.size) { \
msgpack_pack_str_body(spacker, s_.data, s_.size); \
} \
} while (0)
if(len)
Definition: encode.c:222
Definition: defs.h:77
char * s
Definition: message.c:732
#define PACK_WMS_ARRAY (   wms_array)
Value:
do { \
for (size_t i_ = 0; i_ < ARRAY_SIZE(wms_array); i_++) { \
if (wms_array[i_].data.type != kSDItemMissing) { \
if (shada_pack_pfreed_entry(packer, wms_array[i_], max_kbyte) \
goto shada_write_exit; \
} \
} \
} \
} while (0)
if(len)
Definition: encode.c:222
int int ret
Definition: eval.c:19501
for(size_t i=1;i< ARRAY_SIZE(argv);i++)
Definition: typval.c:1215
Definition: shada.c:202
Missing value. Should never appear in a file.
Definition: shada.c:170
#define ARRAY_SIZE(arr)
Definition: macros.h:140
#define PACK_WMS_ENTRY (   wms_entry)
Value:
do { \
if (wms_entry.data.type != kSDItemMissing) { \
if (shada_pack_pfreed_entry(packer, wms_entry, max_kbyte) \
goto shada_write_exit; \
} \
} \
} while (0)
if(len)
Definition: encode.c:222
int int ret
Definition: eval.c:19501
Definition: shada.c:202
Missing value. Should never appear in a file.
Definition: shada.c:170
#define path_tail_with_sep (   f)    ((char *) path_tail_with_sep((char_u *)f))
#define path_try_shorten_fname (   b)    ((char *)path_try_shorten_fname((char_u *)b))
#define RCERR   "E576: "

Common prefix for critical read errors

I.e. errors that make shada_read_next_item return kSDReadStatusNotShaDa.

#define READERR (   entry_name,
  error_desc 
)
Value:
RERR "Error while reading ShaDa file: " \
entry_name " entry at position %" PRIu64 " " \
error_desc
#define RERR
Definition: shada.c:135
#define REG_KEY_CONTENTS   "rc"
#define REG_KEY_TYPE   "rt"
#define REG_KEY_UNNAMED   "ru"
#define REG_KEY_WIDTH   "rw"
#define regtilde (   s,
 
)    ((char *) regtilde((char_u *) s, m))
#define RERR   "E575: "

Common prefix for all errors inside ShaDa file

I.e. errors occurred while parsing, but not system errors occurred while reading.

#define RNERR   "E136: "

Common prefix for all “rename” errors.

#define SDE_TO_FMARK (   entry)    fm
#define SDE_TO_PFSDE (   entry)    ((PossiblyFreedShadaEntry) { .can_free_entry = true, .data = entry })
#define SDE_TO_XFMARK (   entry)    fm
#define SEARCH_KEY_BACKWARD   "sb"
#define SEARCH_KEY_HAS_LINE_OFFSET   "sl"
#define SEARCH_KEY_HIGHLIGHTED   "sh"
#define SEARCH_KEY_IS_LAST_USED   "su"
#define SEARCH_KEY_IS_SUBSTITUTE_PATTERN   "ss"
#define SEARCH_KEY_MAGIC   "sm"
#define SEARCH_KEY_OFFSET   "so"
#define SEARCH_KEY_PAT   "sp"
#define SEARCH_KEY_PLACE_CURSOR_AT_END   "se"
#define SEARCH_KEY_SMARTCASE   "sc"
#define SERR   "E886: "

Common prefix for all “system” errors.

#define SET_ADDITIONAL_DATA (   tgt,
  name 
)
Value:
do { \
if (ad_ga.ga_len) { \
msgpack_object obj = { \
.type = MSGPACK_OBJECT_MAP, \
.via = { \
.map = { \
.size = (uint32_t) ad_ga.ga_len, \
.ptr = ad_ga.ga_data, \
} \
} \
}; \
typval_T adtv; \
if (msgpack_to_vim(obj, &adtv) == FAIL \
|| adtv.v_type != VAR_DICT) { \
"cannot be converted to a VimL dictionary")), \
initial_fpos); \
ga_clear(&ad_ga); \
tv_clear(&adtv); \
goto shada_read_next_item_error; \
} \
tgt = adtv.vval.v_dict; \
} \
ga_clear(&ad_ga); \
} while (0)
#define _(x)
Definition: gettext.h:20
void ga_clear(garray_T *gap)
Clear an allocated growing array.
Definition: garray.c:27
if(len)
Definition: encode.c:222
void tv_clear(typval_T *const tv)
Definition: typval.c:2176
bool emsgf(const char *const fmt,...)
Print an error message with unknown number of arguments.
#define FAIL
Definition: vim.h:93
char * name
Definition: eval.c:1851
#define READERR(entry_name, error_desc)
Definition: shada.c:3451
Dictionary, .v_dict is used.
Definition: typval.h:117
int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
Convert msgpack object to a VimL one.
Definition: decode.c:943
#define SET_ADDITIONAL_ELEMENTS (   src,
  src_maxsize,
  tgt,
  name 
)
Value:
do { \
if ((src).size > (size_t) (src_maxsize)) { \
msgpack_object obj = { \
.type = MSGPACK_OBJECT_ARRAY, \
.via = { \
.array = { \
.size = ((src).size - (uint32_t) (src_maxsize)), \
.ptr = (src).ptr + (src_maxsize), \
} \
} \
}; \
typval_T aetv; \
if (msgpack_to_vim(obj, &aetv) == FAIL) { \
emsgf(_(READERR(name, "cannot be converted to a VimL list")), \
initial_fpos); \
tv_clear(&aetv); \
goto shada_read_next_item_error; \
} \
assert(aetv.v_type == VAR_LIST); \
(tgt) = aetv.vval.v_list; \
} \
} while (0)
#define _(x)
Definition: gettext.h:20
if(len)
Definition: encode.c:222
void tv_clear(typval_T *const tv)
Definition: typval.c:2176
assert(len >=0)
bool emsgf(const char *const fmt,...)
Print an error message with unknown number of arguments.
#define FAIL
Definition: vim.h:93
List, .v_list is used.
Definition: typval.h:116
char * name
Definition: eval.c:1851
#define READERR(entry_name, error_desc)
Definition: shada.c:3451
int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
Convert msgpack object to a VimL one.
Definition: decode.c:943
#define SHADA_LAST_ENTRY   ((uint64_t) kSDItemChange)
#define STRING_KEY (   un,
  entry_name,
  name,
  tgt 
)    TYPED_KEY(un, entry_name, name, "a binary", tgt, BIN, bin, BINDUP)
#define TOCHAR (   s)    ((char) (s))
#define TOINT (   s)    ((int) (s))
#define TOLONG (   s)    ((long) (s))
#define TOSIZE (   s)    ((size_t) (s))
#define TOU8 (   s)    ((uint8_t) (s))
#define TYPED_KEY (   un,
  entry_name,
  name,
  type_name,
  tgt,
  objtype,
  attr,
  proc 
)
Value:
un, entry_name, name, "which is not " type_name, tgt, \
un.data.via.map.ptr[i].val.type == MSGPACK_OBJECT_##objtype, \
attr, proc)
#define CHECKED_KEY(un, entry_name, name, error_desc, tgt, condition, attr, proc)
Definition: shada.c:3488
char * name
Definition: eval.c:1851
int i
Definition: typval.c:868
#define vim_rename (   a,
 
)    (vim_rename((char_u *)a, (char_u *)b))
#define WERR   "E574: "

Common prefix for all ignorable “write” errors.

Typedef Documentation

typedef struct hm_llist_entry HMLListEntry

One entry in sized linked list.

typedef void(* SearchPatternGetter) (SearchPattern *)

Callback function for add_search_pattern.

typedef ptrdiff_t(* ShaDaFileReader) (struct sd_read_def *const sd_reader, void *const dest, const size_t size) REAL_FATTR_NONNULL_ALL REAL_FATTR_WARN_UNUSED_RESULT

Function used to read ShaDa files.

typedef int(* ShaDaFileSkipper) (struct sd_read_def *const sd_reader, const size_t offset) REAL_FATTR_NONNULL_ALL REAL_FATTR_WARN_UNUSED_RESULT

Function used to skip in ShaDa files.

typedef ptrdiff_t(* ShaDaFileWriter) (struct sd_write_def *const sd_writer, const void *const src, const size_t size) REAL_FATTR_NONNULL_ALL REAL_FATTR_WARN_UNUSED_RESULT

Function used to write ShaDa files.

typedef void(* ShaDaReadCloser) (struct sd_read_def *const sd_reader) REAL_FATTR_NONNULL_ALL

Function used to close files defined by ShaDaReadDef.

typedef struct sd_read_def ShaDaReadDef

Structure containing necessary pointers for reading ShaDa files.

typedef void(* ShaDaWriteCloser) (struct sd_write_def *const sd_writer) REAL_FATTR_NONNULL_ALL

Function used to close files defined by ShaDaWriteDef.

typedef struct sd_write_def ShaDaWriteDef

Structure containing necessary pointers for writing ShaDa files.

Enumeration Type Documentation

Possible ShaDa entry types

Warning
Enum values are part of the API and must not be altered.

All values that are not in enum are ignored.

Enumerator
kSDItemUnknown 

Unknown item.

kSDItemMissing 

Missing value. Should never appear in a file.

kSDItemHeader 

Header. Present for debugging purposes.

kSDItemSearchPattern 

Last search pattern (not history item). Comes from user searches (e.g. when typing "/pat") or :substitute command calls.

kSDItemSubString 

Last substitute replacement string.

kSDItemHistoryEntry 

History item.

kSDItemRegister 

Register.

kSDItemVariable 

Global variable.

kSDItemGlobalMark 

Global mark definition.

kSDItemJump 

Item from jump list.

kSDItemBufferList 

Buffer list.

kSDItemLocalMark 

Buffer-local mark.

kSDItemChange 

Item from buffer change list.

Flags for shada_read_file and children.

Enumerator
kShaDaWantInfo 

Load non-mark information.

kShaDaWantMarks 

Load local file marks and change list.

kShaDaForceit 

Overwrite info already read.

kShaDaGetOldfiles 

Load v:oldfiles.

kShaDaMissingError 

Error out when os_open returns -ENOENT.

Possible results when reading ShaDa file.

Enumerator
kSDReadStatusSuccess 

Reading was successfull.

kSDReadStatusFinished 

Nothing more to read.

kSDReadStatusReadError 

Failed to read from file.

kSDReadStatusNotShaDa 

Input is most likely not a ShaDa file.

kSDReadStatusMalformed 

Error in the currently read item.

Possible results of shada_write function.

Enumerator
kSDWriteSuccessfull 

Writing was successfull.

kSDWriteReadNotShada 

Writing was successfull, but when reading it attempted to read file that did not look like a ShaDa file.

kSDWriteFailed 

Writing was not successfull (e.g. because there was no space left on device).

kSDWriteIgnError 

Writing resulted in a error which can be ignored (e.g. when trying to dump a function reference or self-referencing container in a variable).

enum SRNIFlags

Flags for shada_read_next_item.

Enumerator
kSDReadHeader 

Determines whether header should be read (it is usually ignored).

kSDReadUndisableableData 

Data reading which cannot be disabled by &shada or other options except for disabling reading ShaDa as a whole.

kSDReadRegisters 

Determines whether registers should be read (may only be disabled when writing, but not when reading).

kSDReadHistory 

Determines whether history should be read (can only be disabled by &history).

kSDReadVariables 

Determines whether variables should be read (disabled by removing ! from &shada).

kSDReadBufferList 

Determines whether buffer list should be read (disabled by removing % entry from &shada).

kSDReadUnknown 

Determines whether unknown items should be read (usually disabled).

kSDReadGlobalMarks 

Determines whether global marks should be read. Can only be disabled by having f0 in &shada when writing.

kSDReadLocalMarks 

Determines whether local marks should be read. Can only be disabled by disabling &shada or putting '0 there. Is also used for v:oldfiles.

kSDReadChanges 

Determines whether change list should be read. Can only be disabled by disabling &shada or putting '0 there.

Function Documentation

int shada_read_everything ( const char *const  fname,
const bool  forceit,
const bool  missing_ok 
)

Read all information from ShaDa file

Parameters
[in]fnameFile to write to. If it is NULL or empty then default
[in]forceitIf true, use forced reading (prioritize file contents over current Neovim state).
[in]missing_okIf true, do not error out when file is missing.
Returns
OK in case of success, FAIL otherwise.
int shada_read_marks ( void  )

Read marks information from ShaDa file

Returns
OK in case of success, FAIL otherwise.
int shada_write_file ( const char *const  file,
bool  nomerge 
)

Write ShaDa file to a given location

Parameters
[in]fnameFile to write to. If it is NULL or empty then default location is used.
[in]nomergeIf true then old file is ignored.
Returns
OK if writing was successfull, FAIL otherwise.