Merge pull request #3490 from ZyX-I/fix-3472

Fix local marks saving/restoring with ShaDa
This commit is contained in:
Justin M. Keyes 2015-10-23 10:11:59 -04:00
commit de4cb766ca
6 changed files with 65 additions and 13 deletions

View File

@ -797,7 +797,7 @@ g'{mark} g`{mark}
< <
:delm[arks]! Delete all marks for the current buffer, but not marks :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 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 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. for each opened file.
Only one position is remembered per buffer, not one Only one position is remembered per buffer, not one
for each window. As long as the buffer is visible in 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 '^ `^ To the position where the cursor was the last time

View File

@ -1169,6 +1169,8 @@ running) you have additional options:
cannot write ShaDa file!" check that no old temp files cannot write ShaDa file!" check that no old temp files
were left behind (e.g. ~/.nvim/shada/main.shada.tmp*). were left behind (e.g. ~/.nvim/shada/main.shada.tmp*).
Note: Executing :wshada will reset all |'quote| marks.
*:wv* *:wviminfo* *:wv* *:wviminfo*
:wv[iminfo][!] [file] Deprecated alias to |:wshada| command. :wv[iminfo][!] [file] Deprecated alias to |:wshada| command.

View File

@ -60,9 +60,22 @@ def mnormalize(o):
fname = sys.argv[1] 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)) 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: with open(fname, 'rb') as fp:
unpacker = msgpack.Unpacker(file_like=fp, read_size=1) unpacker = msgpack.Unpacker(file_like=fp, read_size=1)
max_type = max(typ.value for typ in EntryTypes) max_type = max(typ.value for typ in EntryTypes)
@ -82,5 +95,15 @@ with open(fname, 'rb') as fp:
else: else:
entry = unpacker.unpack() entry = unpacker.unpack()
typ = EntryTypes(typ) 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' % ( print('%*u %13s %s %5u %r' % (
poswidth, pos, typ.name, time.isoformat(), length, mnormalize(entry))) poswidth, pos, typ.name, time.isoformat(), length, mnormalize(entry)))

View File

@ -546,19 +546,26 @@ int check_mark(pos_T *pos)
return OK; return OK;
} }
/* /// Clear all marks and change list in the given buffer
* clrallmarks() - clear all marks in the buffer 'buf' ///
* /// Used mainly when trashing the entire buffer during ":e" type commands.
* Used mainly when trashing the entire buffer during ":e" type commands ///
*/ /// @param[out] buf Buffer to clear marks in.
void clrallmarks(buf_T *buf) void clrallmarks(buf_T *const buf)
FUNC_ATTR_NONNULL_ALL
{ {
memset(&(buf->b_namedm[0]), 0, sizeof(buf->b_namedm)); for (size_t i = 0; i < NMARKS; i++) {
buf->b_op_start.lnum = 0; /* start/end op mark cleared */ 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; buf->b_op_end.lnum = 0;
RESET_FMARK(&buf->b_last_cursor, ((pos_T) {1, 0, 0}), 0); // '" mark for (int i = 0; i < buf->b_changelistlen; i++) {
CLEAR_FMARK(&buf->b_last_insert); // '^ mark clear_fmark(&buf->b_changelist[i]);
CLEAR_FMARK(&buf->b_last_change); // '. mark }
buf->b_changelistlen = 0; buf->b_changelistlen = 0;
} }

View File

@ -2433,6 +2433,15 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
msgpack_packer *const packer = msgpack_packer_new(sd_writer, msgpack_packer *const packer = msgpack_packer_new(sd_writer,
&msgpack_sd_writer_write); &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) { FOR_ALL_BUFFERS(buf) {
if (buf->b_ffname != NULL && shada_removable((char *) buf->b_ffname)) { if (buf->b_ffname != NULL && shada_removable((char *) buf->b_ffname)) {
int kh_ret; int kh_ret;

View File

@ -90,6 +90,16 @@ describe('ShaDa support code', function()
eq(2, nvim_current_line()) eq(2, nvim_current_line())
end) 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() it('is able to populate v:oldfiles', function()
nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename)
local tf_full = curbufmeths.get_name() local tf_full = curbufmeths.get_name()