mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #3490 from ZyX-I/fix-3472
Fix local marks saving/restoring with ShaDa
This commit is contained in:
commit
de4cb766ca
@ -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
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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)))
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user