mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
viminfo: First version of ShaDa file dumping
What works: 1. ShaDa file dumping: header, registers, jump list, history, search patterns, substitute strings, variables. 2. ShaDa file reading: registers, global marks, variables. Most was not tested. TODO: 1. Merging. 2. Reading history, local marks, jump and buffer lists. 3. Documentation update. 4. Converting some data from &encoding. 5. Safer variant of dumping viminfo (dump to temporary file then rename). 6. Removing old viminfo code (currently masked with `#if 0` in a ShaDa file for reference).
This commit is contained in:
@@ -111,6 +111,7 @@
|
||||
#include "nvim/types.h"
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/os/time.h"
|
||||
#include "nvim/api/private/helpers.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "undo.c.generated.h"
|
||||
@@ -325,6 +326,17 @@ static long get_undolevel(void)
|
||||
return curbuf->b_p_ul;
|
||||
}
|
||||
|
||||
static inline void zero_fmark_additional_data(fmark_T *fmarks)
|
||||
{
|
||||
for (size_t i = 0; i < NMARKS; i++) {
|
||||
if (fmarks[i].additional_data != NULL) {
|
||||
api_free_dictionary(*fmarks[i].additional_data);
|
||||
free(fmarks[i].additional_data);
|
||||
fmarks[i].additional_data = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Common code for various ways to save text before a change.
|
||||
* "top" is the line above the first changed line.
|
||||
@@ -467,7 +479,9 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload)
|
||||
((curbuf->b_ml.ml_flags & ML_EMPTY) ? UH_EMPTYBUF : 0);
|
||||
|
||||
/* save named marks and Visual marks for undo */
|
||||
memmove(uhp->uh_namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS);
|
||||
zero_fmark_additional_data(curbuf->b_namedm);
|
||||
memmove(uhp->uh_namedm, curbuf->b_namedm,
|
||||
sizeof(curbuf->b_namedm[0]) * NMARKS);
|
||||
uhp->uh_visual = curbuf->b_visual;
|
||||
|
||||
curbuf->b_u_newhead = uhp;
|
||||
@@ -785,7 +799,7 @@ static bool serialize_uhp(bufinfo_T *bi, u_header_T *uhp)
|
||||
undo_write_bytes(bi, (uintmax_t)uhp->uh_flags, 2);
|
||||
// Assume NMARKS will stay the same.
|
||||
for (size_t i = 0; i < (size_t)NMARKS; i++) {
|
||||
serialize_pos(bi, uhp->uh_namedm[i]);
|
||||
serialize_pos(bi, uhp->uh_namedm[i].mark);
|
||||
}
|
||||
serialize_visualinfo(bi, &uhp->uh_visual);
|
||||
uint8_t time_buf[8];
|
||||
@@ -832,7 +846,9 @@ static u_header_T *unserialize_uhp(bufinfo_T *bi, char_u *file_name)
|
||||
uhp->uh_cursor_vcol = undo_read_4c(bi);
|
||||
uhp->uh_flags = undo_read_2c(bi);
|
||||
for (size_t i = 0; i < (size_t)NMARKS; i++) {
|
||||
unserialize_pos(bi, &uhp->uh_namedm[i]);
|
||||
unserialize_pos(bi, &uhp->uh_namedm[i].mark);
|
||||
uhp->uh_namedm[i].timestamp = 0;
|
||||
uhp->uh_namedm[i].fnum = 0;
|
||||
}
|
||||
unserialize_visualinfo(bi, &uhp->uh_visual);
|
||||
uhp->uh_time = undo_read_time(bi);
|
||||
@@ -2009,7 +2025,7 @@ static void u_undoredo(int undo)
|
||||
u_entry_T *newlist = NULL;
|
||||
int old_flags;
|
||||
int new_flags;
|
||||
pos_T namedm[NMARKS];
|
||||
fmark_T namedm[NMARKS];
|
||||
visualinfo_T visualinfo;
|
||||
int empty_buffer; /* buffer became empty */
|
||||
u_header_T *curhead = curbuf->b_u_curhead;
|
||||
@@ -2029,7 +2045,8 @@ static void u_undoredo(int undo)
|
||||
/*
|
||||
* save marks before undo/redo
|
||||
*/
|
||||
memmove(namedm, curbuf->b_namedm, sizeof(pos_T) * NMARKS);
|
||||
zero_fmark_additional_data(curbuf->b_namedm);
|
||||
memmove(namedm, curbuf->b_namedm, sizeof(curbuf->b_namedm[0]) * NMARKS);
|
||||
visualinfo = curbuf->b_visual;
|
||||
curbuf->b_op_start.lnum = curbuf->b_ml.ml_line_count;
|
||||
curbuf->b_op_start.col = 0;
|
||||
@@ -2158,7 +2175,8 @@ static void u_undoredo(int undo)
|
||||
* restore marks from before undo/redo
|
||||
*/
|
||||
for (i = 0; i < NMARKS; ++i)
|
||||
if (curhead->uh_namedm[i].lnum != 0) {
|
||||
if (curhead->uh_namedm[i].mark.lnum != 0) {
|
||||
free_fmark(curbuf->b_namedm[i]);
|
||||
curbuf->b_namedm[i] = curhead->uh_namedm[i];
|
||||
curhead->uh_namedm[i] = namedm[i];
|
||||
}
|
||||
|
Reference in New Issue
Block a user