#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <msgpack.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <uv.h>
#include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/buffer_defs.h"
#include "nvim/eval/decode.h"
#include "nvim/eval/encode.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/fileio.h"
#include "nvim/garray.h"
#include "nvim/globals.h"
#include "nvim/lib/khash.h"
#include "nvim/lib/kvec.h"
#include "nvim/macros.h"
#include "nvim/mark.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/msgpack_rpc/helpers.h"
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/os/fileio.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/path.h"
#include "nvim/pos.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/search.h"
#include "nvim/shada.h"
#include "nvim/strings.h"
#include "nvim/version.h"
#include "nvim/vim.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 | 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 | 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_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 | BIN_CONVERTED(b) (xmemdupz((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... | |
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) |
void | shada_encode_regs (msgpack_sbuffer *const sbuf) FUNC_ATTR_NONNULL_ALL |
void | shada_encode_jumps (msgpack_sbuffer *const sbuf) FUNC_ATTR_NONNULL_ALL |
void | shada_encode_buflist (msgpack_sbuffer *const sbuf) FUNC_ATTR_NONNULL_ALL |
void | shada_encode_gvars (msgpack_sbuffer *const sbuf) FUNC_ATTR_NONNULL_ALL |
void | shada_read_sbuf (msgpack_sbuffer *const sbuf, const int flags) FUNC_ATTR_NONNULL_ALL |
#define ADDITIONAL_KEY | ( | un | ) |
#define ADJUST_IDX | ( | i | ) |
#define AFTERFREE | ( | entry | ) | (entry).data.filemark.fname = NULL |
#define AFTERFREE_DUMMY | ( | entry | ) |
#define BOOLEAN_KEY | ( | un, | |
entry_name, | |||
name, | |||
tgt | |||
) | TYPED_KEY(un, entry_name, name, "a boolean", tgt, BOOLEAN, boolean, ID) |
#define CHECK_DEFAULT | ( | entry, | |
attr | |||
) | (sd_default_values[entry.type].data.attr == entry.data.attr) |
#define CHECK_KEY | ( | key, | |
expected | |||
) |
#define CHECK_KEY_IS_STR | ( | un, | |
entry_name | |||
) |
#define CHECKED_ENTRY | ( | condition, | |
error_desc, | |||
entry_name, | |||
obj, | |||
tgt, | |||
attr, | |||
proc | |||
) |
#define CHECKED_KEY | ( | un, | |
entry_name, | |||
name, | |||
error_desc, | |||
tgt, | |||
condition, | |||
attr, | |||
proc | |||
) |
#define CLEAR_GA_AND_ERROR_OUT | ( | ga | ) |
#define COMPARE_WITH_ENTRY | ( | wms_entry_, | |
entry | |||
) |
#define CONVERTED_STRING_KEY | ( | un, | |
entry_name, | |||
name, | |||
tgt | |||
) |
#define DEF_SDE | ( | name, | |
attr, | |||
... | |||
) |
#define DEFAULT_POS { 1, 0, 0 } |
#define DUMMY_AFTERFREE | ( | entry | ) |
#define DUMMY_IDX_ADJ | ( | i | ) |
#define DUMMY_IDX_ADJ | ( | i | ) |
#define FORMAT_MARK_ENTRY | ( | entry_name, | |
name_fmt, | |||
name_fmt_arg | |||
) |
#define FREE_POSSIBLY_FREED_SHADA_ENTRY | ( | entry | ) |
#define HMLL_FORALL | ( | hmll, | |
cur_entry, | |||
code | |||
) |
Iterate over HMLList in forward direction
hmll | Pointer to the list. |
cur_entry | Name of the variable to iterate over. |
code | Code to execute on each iteration. |
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
[in] | hms_p | Merger structure to iterate over. |
[out] | cur_entry | Name of the iterator variable. |
code | Code to execute on each iteration. |
HMS_ITER(hms_p, cur_entry) {body}
. #define INT_KEY | ( | un, | |
entry_name, | |||
name, | |||
tgt, | |||
proc | |||
) |
#define KEY_COL "c" |
#define KEY_FILE "f" |
#define KEY_LNUM "l" |
#define KEY_NAME_CHAR "n" |
#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 PACK_BIN | ( | s | ) |
#define PACK_BOOL | ( | entry, | |
name, | |||
attr | |||
) |
#define PACK_STATIC_STR | ( | s | ) |
#define PACK_WMS_ARRAY | ( | wms_array | ) |
#define PACK_WMS_ENTRY | ( | wms_entry | ) |
#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 | |||
) |
#define REG_KEY_CONTENTS "rc" |
#define REG_KEY_TYPE "rt" |
#define REG_KEY_UNNAMED "ru" |
#define REG_KEY_WIDTH "rw" |
#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 | |||
) |
#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 TYPED_KEY | ( | un, | |
entry_name, | |||
name, | |||
type_name, | |||
tgt, | |||
objtype, | |||
attr, | |||
proc | |||
) |
#define WERR "E574: " |
Common prefix for all ignorable “write” errors.
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.
enum ShadaEntryType |
Possible ShaDa entry types
All values that are not in enum are ignored.
enum ShaDaReadResult |
Possible results when reading ShaDa file.
Enumerator | |
---|---|
kSDReadStatusSuccess | Reading was successful. |
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. |
enum ShaDaWriteResult |
Possible results of shada_write function.
enum SRNIFlags |
Flags for shada_read_next_item.
void shada_encode_buflist | ( | msgpack_sbuffer *const | sbuf | ) |
Write buffer list ShaDa entry in given msgpack_sbuffer.
[in] | sbuf | target msgpack_sbuffer to write to. |
void shada_encode_gvars | ( | msgpack_sbuffer *const | sbuf | ) |
Write global variables ShaDa entries in given msgpack_sbuffer.
[in] | sbuf | target msgpack_sbuffer to write to. |
void shada_encode_jumps | ( | msgpack_sbuffer *const | sbuf | ) |
Write jumplist ShaDa entries in given msgpack_sbuffer.
[in] | sbuf | target msgpack_sbuffer to write to. |
void shada_encode_regs | ( | msgpack_sbuffer *const | sbuf | ) |
Write registers ShaDa entries in given msgpack_sbuffer.
[in] | sbuf | target msgpack_sbuffer to write to. |
Read all information from ShaDa file
[in] | fname | File to write to. If it is NULL or empty then default |
[in] | forceit | If true, use forced reading (prioritize file contents over current Neovim state). |
[in] | missing_ok | If true, do not error out when file is missing. |
int shada_read_marks | ( | void | ) |
Read marks information from ShaDa file
void shada_read_sbuf | ( | msgpack_sbuffer *const | sbuf, |
const int | flags | ||
) |
Read ShaDa from msgpack_sbuffer.
[in] | file | msgpack_sbuffer to read from. |
[in] | flags | Flags, see ShaDaReadFileFlags enum. |
int shada_write_file | ( | const char *const | file, |
bool | nomerge | ||
) |
Write ShaDa file to a given location
[in] | fname | File to write to. If it is NULL or empty then default location is used. |
[in] | nomerge | If true then old file is ignored. |