From 244dbe3a77bf548f73d8781da7327f30e818b08a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 25 Apr 2015 18:47:31 +0300 Subject: 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). --- src/nvim/buffer.c | 94 +++++-------------------------------------------------- 1 file changed, 7 insertions(+), 87 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index b212e75283..5ebeec1b70 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -73,6 +73,7 @@ #include "nvim/undo.h" #include "nvim/version.h" #include "nvim/window.h" +#include "nvim/shada.h" #include "nvim/os/os.h" #include "nvim/os/time.h" #include "nvim/os/input.h" @@ -555,6 +556,12 @@ static void free_buffer(buf_T *buf) free_buffer_stuff(buf, TRUE); unref_var_dict(buf->b_vars); aubuflocal_remove(buf); + free_fmark(buf->b_last_cursor); + free_fmark(buf->b_last_insert); + free_fmark(buf->b_last_change); + for (size_t i = 0; i < NMARKS; i++) { + free_fmark(buf->b_namedm[i]); + } if (autocmd_busy) { // Do not free the buffer structure while autocommands are executing, // it's still needed. Free it when autocmd_busy is reset. @@ -4164,93 +4171,6 @@ chk_modeline ( return retval; } -int read_viminfo_bufferlist(vir_T *virp, int writing) -{ - char_u *tab; - linenr_T lnum; - colnr_T col; - buf_T *buf; - char_u *sfname; - char_u *xline; - - /* Handle long line and escaped characters. */ - xline = viminfo_readstring(virp, 1, FALSE); - - /* don't read in if there are files on the command-line or if writing: */ - if (xline != NULL && !writing && ARGCOUNT == 0 - && find_viminfo_parameter('%') != NULL) { - /* Format is: Tab Tab . - * Watch out for a Tab in the file name, work from the end. */ - lnum = 0; - col = 0; - tab = vim_strrchr(xline, '\t'); - if (tab != NULL) { - *tab++ = '\0'; - col = (colnr_T)atoi((char *)tab); - tab = vim_strrchr(xline, '\t'); - if (tab != NULL) { - *tab++ = '\0'; - lnum = atol((char *)tab); - } - } - - /* Expand "~/" in the file name at "line + 1" to a full path. - * Then try shortening it by comparing with the current directory */ - expand_env(xline, NameBuff, MAXPATHL); - sfname = path_shorten_fname_if_possible(NameBuff); - - buf = buflist_new(NameBuff, sfname, (linenr_T)0, BLN_LISTED); - if (buf != NULL) { /* just in case... */ - buf->b_last_cursor.lnum = lnum; - buf->b_last_cursor.col = col; - buflist_setfpos(buf, curwin, lnum, col, FALSE); - } - } - xfree(xline); - - return viminfo_readline(virp); -} - -void write_viminfo_bufferlist(FILE *fp) -{ - char_u *line; - int max_buffers; - - if (find_viminfo_parameter('%') == NULL) - return; - - /* Without a number -1 is returned: do all buffers. */ - max_buffers = get_viminfo_parameter('%'); - - /* Allocate room for the file name, lnum and col. */ -#define LINE_BUF_LEN (MAXPATHL + 40) - line = xmalloc(LINE_BUF_LEN); - - FOR_ALL_TAB_WINDOWS(tp, win) { - set_last_cursor(win); - } - - fputs(_("\n# Buffer list:\n"), fp); - FOR_ALL_BUFFERS(buf) { - if (buf->b_fname == NULL - || !buf->b_p_bl - || bt_quickfix(buf) - || removable(buf->b_ffname)) - continue; - - if (max_buffers-- == 0) - break; - putc('%', fp); - home_replace(NULL, buf->b_ffname, line, MAXPATHL, TRUE); - vim_snprintf_add((char *)line, LINE_BUF_LEN, "\t%" PRId64 "\t%d", - (int64_t)buf->b_last_cursor.lnum, - buf->b_last_cursor.col); - viminfo_writestring(fp, line); - } - xfree(line); -} - - /* * Return special buffer name. * Returns NULL when the buffer has a normal file name. -- cgit From 200e62efebe8e87fc612218b675b74def57519f1 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 28 Jun 2015 08:06:16 +0300 Subject: shada: Add support for dumping/restoring bufs changes and win jumps --- src/nvim/buffer.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 5ebeec1b70..5f7120e47c 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -562,6 +562,9 @@ static void free_buffer(buf_T *buf) for (size_t i = 0; i < NMARKS; i++) { free_fmark(buf->b_namedm[i]); } + for (int i = 0; i < buf->b_changelistlen; i++) { + free_fmark(buf->b_changelist[i]); + } if (autocmd_busy) { // Do not free the buffer structure while autocommands are executing, // it's still needed. Free it when autocmd_busy is reset. -- cgit From 8c93877e1c3205f6b42b3e4c94d9be6262557dfb Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 4 Jul 2015 22:36:06 +0300 Subject: shada: Add support for dumping and restoring buffer list --- src/nvim/buffer.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 5f7120e47c..53612977ee 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -30,6 +30,7 @@ #include #include "nvim/api/private/handle.h" +#include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/vim.h" #include "nvim/buffer.h" @@ -556,6 +557,10 @@ static void free_buffer(buf_T *buf) free_buffer_stuff(buf, TRUE); unref_var_dict(buf->b_vars); aubuflocal_remove(buf); + if (buf->additional_data != NULL) { + api_free_dictionary(*buf->additional_data); + xfree(buf->additional_data); + } free_fmark(buf->b_last_cursor); free_fmark(buf->b_last_insert); free_fmark(buf->b_last_change); @@ -1988,12 +1993,18 @@ buflist_nr2name ( fullname ? buf->b_ffname : buf->b_fname); } -/* - * Set the "lnum" and "col" for the buffer "buf" and the current window. - * When "copy_options" is TRUE save the local window option values. - * When "lnum" is 0 only do the options. - */ -static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options) +/// Set the line and column numbers for the given buffer and window +/// +/// @param[in,out] buf Buffer for which line and column are set. +/// @param[in,out] win Window for which line and column are set. +/// @param[in] lnum Line number to be set. If it is zero then only +/// options are touched. +/// @param[in] col Column number to be set. +/// @param[in] copy_options If true save the local window option values. +void buflist_setfpos(buf_T *const buf, win_T *const win, + linenr_T lnum, colnr_T col, + bool copy_options) + FUNC_ATTR_NONNULL_ALL { wininfo_T *wip; -- cgit From 07d9ab26c6526c0d9af0435f1adeb614a1b88743 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 3 Aug 2015 23:06:06 +0300 Subject: *: Make ShaDa code use VimL values for additional_\* data --- src/nvim/buffer.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 53612977ee..a25a51c6ce 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -30,7 +30,6 @@ #include #include "nvim/api/private/handle.h" -#include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/vim.h" #include "nvim/buffer.h" @@ -557,10 +556,7 @@ static void free_buffer(buf_T *buf) free_buffer_stuff(buf, TRUE); unref_var_dict(buf->b_vars); aubuflocal_remove(buf); - if (buf->additional_data != NULL) { - api_free_dictionary(*buf->additional_data); - xfree(buf->additional_data); - } + dict_unref(buf->additional_data); free_fmark(buf->b_last_cursor); free_fmark(buf->b_last_insert); free_fmark(buf->b_last_change); -- cgit From 22906265a2647aadcbc3ab9ab8a590bffd95002c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 16 Aug 2015 18:54:41 +0300 Subject: mark: Clear marks in some cases, but do not do useless job in free_\* --- src/nvim/buffer.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index a25a51c6ce..d0fad0e002 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -557,9 +557,9 @@ static void free_buffer(buf_T *buf) unref_var_dict(buf->b_vars); aubuflocal_remove(buf); dict_unref(buf->additional_data); - free_fmark(buf->b_last_cursor); - free_fmark(buf->b_last_insert); - free_fmark(buf->b_last_change); + clear_fmark(&buf->b_last_cursor); + clear_fmark(&buf->b_last_insert); + clear_fmark(&buf->b_last_change); for (size_t i = 0; i < NMARKS; i++) { free_fmark(buf->b_namedm[i]); } @@ -569,6 +569,8 @@ static void free_buffer(buf_T *buf) if (autocmd_busy) { // Do not free the buffer structure while autocommands are executing, // it's still needed. Free it when autocmd_busy is reset. + memset(&buf->b_namedm[0], 0, sizeof(buf->b_namedm)); + memset(&buf->b_changelist[0], 0, sizeof(buf->b_changelist)); buf->b_next = au_pending_free_buf; au_pending_free_buf = buf; } else { -- cgit From ad7b7716bb00ad19c013956861b437ee0ccf0876 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 23 Aug 2015 13:53:47 +0300 Subject: *: Fix lint errors found in new code in previously ignored files --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d0fad0e002..b3eba4f5f6 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1995,7 +1995,7 @@ buflist_nr2name ( /// /// @param[in,out] buf Buffer for which line and column are set. /// @param[in,out] win Window for which line and column are set. -/// @param[in] lnum Line number to be set. If it is zero then only +/// @param[in] lnum Line number to be set. If it is zero then only /// options are touched. /// @param[in] col Column number to be set. /// @param[in] copy_options If true save the local window option values. -- cgit