From a85163a5d2af9d147e74ef2e52b7b4ac95611ab3 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 18 Oct 2015 21:08:42 +0300 Subject: scripts: Add filter argument to shadacat.py --- scripts/shadacat.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/shadacat.py b/scripts/shadacat.py index 4ff493bfbc..2f2cf19f9d 100755 --- a/scripts/shadacat.py +++ b/scripts/shadacat.py @@ -60,9 +60,22 @@ def mnormalize(o): fname = sys.argv[1] +try: + filt = sys.argv[2] +except IndexError: + filt = lambda entry: True +else: + _filt = filt + filt = lambda entry: eval(_filt, globals(), {'entry': entry}) + poswidth = len(str(os.stat(fname).st_size or 1000)) +class FullEntry(dict): + def __init__(self, val): + self.__dict__.update(val) + + with open(fname, 'rb') as fp: unpacker = msgpack.Unpacker(file_like=fp, read_size=1) max_type = max(typ.value for typ in EntryTypes) @@ -82,5 +95,15 @@ with open(fname, 'rb') as fp: else: entry = unpacker.unpack() typ = EntryTypes(typ) + full_entry = FullEntry({ + 'value': entry, + 'timestamp': timestamp, + 'time': time, + 'length': length, + 'pos': pos, + 'type': typ, + }) + if not filt(full_entry): + continue print('%*u %13s %s %5u %r' % ( poswidth, pos, typ.name, time.isoformat(), length, mnormalize(entry))) -- cgit From ea2fe5255202b7fe169c5196a3a47138eaf947ba Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 23 Oct 2015 13:35:19 +0300 Subject: functests: Add test to check expected behaviour (failing) --- test/functional/shada/marks_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/functional/shada/marks_spec.lua b/test/functional/shada/marks_spec.lua index b03af39662..f03b330fb5 100644 --- a/test/functional/shada/marks_spec.lua +++ b/test/functional/shada/marks_spec.lua @@ -90,6 +90,16 @@ describe('ShaDa support code', function() eq(2, nvim_current_line()) end) + it('is able to dump and read back mark "', function() + nvim_command('edit ' .. testfilename) + nvim_command('2') + nvim_command('qall') + reset() + nvim_command('edit ' .. testfilename) + nvim_command('normal! `"') + eq(2, nvim_current_line()) + end) + it('is able to populate v:oldfiles', function() nvim_command('edit ' .. testfilename) local tf_full = curbufmeths.get_name() -- cgit From 7a1090eef54800c42086610b5ed9b373ce8af3ec Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 23 Oct 2015 13:58:02 +0300 Subject: shada: Run set_last_cursor before writing shada file --- runtime/doc/motion.txt | 3 ++- runtime/doc/starting.txt | 2 ++ src/nvim/shada.c | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt index 2e8f0801dc..3757a46fe2 100644 --- a/runtime/doc/motion.txt +++ b/runtime/doc/motion.txt @@ -877,7 +877,8 @@ was made yet in the current file. for each opened file. Only one position is remembered per buffer, not one for each window. As long as the buffer is visible in - a window the position won't be changed. + a window the position won't be changed. Mark is also + reset when |:wshada| is run. *'^* *`^* '^ `^ To the position where the cursor was the last time diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt index 84bd70db62..6ee95a94f4 100644 --- a/runtime/doc/starting.txt +++ b/runtime/doc/starting.txt @@ -1169,6 +1169,8 @@ running) you have additional options: cannot write ShaDa file!" check that no old temp files were left behind (e.g. ~/.nvim/shada/main.shada.tmp*). + Note: Executing :wshada will reset all |'quote| marks. + *:wv* *:wviminfo* :wv[iminfo][!] [file] Deprecated alias to |:wshada| command. diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 523f8db6f0..93a40fa736 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2433,6 +2433,15 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, msgpack_packer *const packer = msgpack_packer_new(sd_writer, &msgpack_sd_writer_write); + // Set b_last_cursor for all the buffers that have a window. + // + // It is needed to correctly save '"' mark on exit. Has a side effect of + // setting '"' mark in all windows on :wshada to the current cursor + // position (basically what :wviminfo used to do). + FOR_ALL_TAB_WINDOWS(tp, wp) { + set_last_cursor(wp); + } + FOR_ALL_BUFFERS(buf) { if (buf->b_ffname != NULL && shada_removable((char *) buf->b_ffname)) { int kh_ret; -- cgit From e96aa067f3a94e9633ffd577fce83575e7fd00a7 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 23 Oct 2015 14:42:35 +0300 Subject: mark: Make clrallmarks correctly free all marks, and set zero tstamps This and the previous commit together fix #3472. This one also fixes memory leak on :delmarks!. --- src/nvim/mark.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/nvim/mark.c b/src/nvim/mark.c index dd49b311d3..0432ec5cef 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -546,19 +546,26 @@ int check_mark(pos_T *pos) return OK; } -/* - * clrallmarks() - clear all marks in the buffer 'buf' - * - * Used mainly when trashing the entire buffer during ":e" type commands - */ -void clrallmarks(buf_T *buf) +/// Clear all marks and change list in the given buffer +/// +/// Used mainly when trashing the entire buffer during ":e" type commands. +/// +/// @param[out] buf Buffer to clear marks in. +void clrallmarks(buf_T *const buf) + FUNC_ATTR_NONNULL_ALL { - memset(&(buf->b_namedm[0]), 0, sizeof(buf->b_namedm)); - buf->b_op_start.lnum = 0; /* start/end op mark cleared */ + for (size_t i = 0; i < NMARKS; i++) { + clear_fmark(&buf->b_namedm[i]); + } + clear_fmark(&buf->b_last_cursor); + buf->b_last_cursor.mark.lnum = 1; + clear_fmark(&buf->b_last_insert); + clear_fmark(&buf->b_last_change); + buf->b_op_start.lnum = 0; // start/end op mark cleared buf->b_op_end.lnum = 0; - RESET_FMARK(&buf->b_last_cursor, ((pos_T) {1, 0, 0}), 0); // '" mark - CLEAR_FMARK(&buf->b_last_insert); // '^ mark - CLEAR_FMARK(&buf->b_last_change); // '. mark + for (int i = 0; i < buf->b_changelistlen; i++) { + clear_fmark(&buf->b_changelist[i]); + } buf->b_changelistlen = 0; } -- cgit From fc2bb200f75ab9650c1c35463bcc2be9008632c9 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 23 Oct 2015 14:46:18 +0300 Subject: documentation: Fix :delmarks! documentation :delmarks! clears the change list, but this fact is not mentioned. Also true for Vim. --- runtime/doc/motion.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt index 3757a46fe2..5e3fe715ab 100644 --- a/runtime/doc/motion.txt +++ b/runtime/doc/motion.txt @@ -797,7 +797,7 @@ g'{mark} g`{mark} < :delm[arks]! Delete all marks for the current buffer, but not marks - A-Z or 0-9. + A-Z or 0-9. Also clear the |changelist|. A mark is not visible in any way. It is just a position in the file that is remembered. Do not confuse marks with named registers, they are totally -- cgit