aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/motion.txt5
-rw-r--r--runtime/doc/starting.txt2
-rwxr-xr-xscripts/shadacat.py23
-rw-r--r--src/nvim/mark.c29
-rw-r--r--src/nvim/shada.c9
-rw-r--r--test/functional/shada/marks_spec.lua10
6 files changed, 65 insertions, 13 deletions
diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt
index 2e8f0801dc..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
@@ -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/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)))
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;
}
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;
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()