mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #5079 from ZyX-I/shada-save-current-pos
shada: Save current cursor position before saving jumps
This commit is contained in:
commit
d2f16d534f
@ -2516,6 +2516,10 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):
|
|||||||
|
|
||||||
cast_line = re.sub(r'^# *define +\w+\([^)]*\)', '', line)
|
cast_line = re.sub(r'^# *define +\w+\([^)]*\)', '', line)
|
||||||
match = Search(r'(?<!\bkvec_t)'
|
match = Search(r'(?<!\bkvec_t)'
|
||||||
|
r'(?<!\bkvec_withinit_t)'
|
||||||
|
r'(?<!\bklist_t)'
|
||||||
|
r'(?<!\bkliter_t)'
|
||||||
|
r'(?<!\bkhash_t)'
|
||||||
r'\((?:const )?(?:struct )?[a-zA-Z_]\w*(?: *\*(?:const)?)*\)'
|
r'\((?:const )?(?:struct )?[a-zA-Z_]\w*(?: *\*(?:const)?)*\)'
|
||||||
r' +'
|
r' +'
|
||||||
r'-?(?:\*+|&)?(?:\w+|\+\+|--|\()', cast_line)
|
r'-?(?:\*+|&)?(?:\w+|\+\+|--|\()', cast_line)
|
||||||
|
107
src/nvim/shada.c
107
src/nvim/shada.c
@ -148,6 +148,9 @@ KHASH_SET_INIT_STR(strset)
|
|||||||
/// Common prefix for all ignorable “write” errors
|
/// Common prefix for all ignorable “write” errors
|
||||||
#define WERR "E574: "
|
#define WERR "E574: "
|
||||||
|
|
||||||
|
/// Callback function for add_search_pattern
|
||||||
|
typedef void (*SearchPatternGetter)(SearchPattern *);
|
||||||
|
|
||||||
/// Flags for shada_read_file and children
|
/// Flags for shada_read_file and children
|
||||||
typedef enum {
|
typedef enum {
|
||||||
kShaDaWantInfo = 1, ///< Load non-mark information
|
kShaDaWantInfo = 1, ///< Load non-mark information
|
||||||
@ -2323,8 +2326,9 @@ static inline ShaDaWriteResult shada_read_when_writing(
|
|||||||
/// @param[in] removable_bufs Buffers which are ignored
|
/// @param[in] removable_bufs Buffers which are ignored
|
||||||
///
|
///
|
||||||
/// @return ShadaEntry List of buffers to save, kSDItemBufferList entry.
|
/// @return ShadaEntry List of buffers to save, kSDItemBufferList entry.
|
||||||
static ShadaEntry shada_get_buflist(khash_t(bufset) *const removable_bufs)
|
static inline ShadaEntry shada_get_buflist(
|
||||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
|
khash_t(bufset) *const removable_bufs)
|
||||||
|
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
|
||||||
{
|
{
|
||||||
int max_bufs = get_shada_parameter('%');
|
int max_bufs = get_shada_parameter('%');
|
||||||
size_t buf_count = 0;
|
size_t buf_count = 0;
|
||||||
@ -2368,6 +2372,62 @@ static ShadaEntry shada_get_buflist(khash_t(bufset) *const removable_bufs)
|
|||||||
return buflist_entry;
|
return buflist_entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Save search pattern to PossiblyFreedShadaEntry
|
||||||
|
///
|
||||||
|
/// @param[out] ret_pse Location where result will be saved.
|
||||||
|
/// @param[in] get_pattern Function used to get pattern.
|
||||||
|
/// @param[in] is_substitute_pattern True if pattern in question is substitute
|
||||||
|
/// pattern. Also controls whether some
|
||||||
|
/// fields should be initialized to default
|
||||||
|
/// or values from get_pattern.
|
||||||
|
/// @param[in] search_last_used Result of search_was_last_used().
|
||||||
|
/// @param[in] search_highlighted True if search pattern was highlighted by
|
||||||
|
/// &hlsearch and this information should be
|
||||||
|
/// saved.
|
||||||
|
static inline void add_search_pattern(PossiblyFreedShadaEntry *const ret_pse,
|
||||||
|
const SearchPatternGetter get_pattern,
|
||||||
|
const bool is_substitute_pattern,
|
||||||
|
const bool search_last_used,
|
||||||
|
const bool search_highlighted)
|
||||||
|
FUNC_ATTR_ALWAYS_INLINE
|
||||||
|
{
|
||||||
|
const ShadaEntry defaults = sd_default_values[kSDItemSearchPattern];
|
||||||
|
SearchPattern pat;
|
||||||
|
get_pattern(&pat);
|
||||||
|
if (pat.pat != NULL) {
|
||||||
|
*ret_pse = (PossiblyFreedShadaEntry) {
|
||||||
|
.can_free_entry = false,
|
||||||
|
.data = {
|
||||||
|
.type = kSDItemSearchPattern,
|
||||||
|
.timestamp = pat.timestamp,
|
||||||
|
.data = {
|
||||||
|
.search_pattern = {
|
||||||
|
.magic = pat.magic,
|
||||||
|
.smartcase = !pat.no_scs,
|
||||||
|
.has_line_offset = (is_substitute_pattern
|
||||||
|
? defaults.data.search_pattern.has_line_offset
|
||||||
|
: pat.off.line),
|
||||||
|
.place_cursor_at_end = (
|
||||||
|
is_substitute_pattern
|
||||||
|
? defaults.data.search_pattern.place_cursor_at_end
|
||||||
|
: pat.off.end),
|
||||||
|
.offset = (is_substitute_pattern
|
||||||
|
? defaults.data.search_pattern.offset
|
||||||
|
: pat.off.off),
|
||||||
|
.is_last_used = (is_substitute_pattern ^ search_last_used),
|
||||||
|
.is_substitute_pattern = is_substitute_pattern,
|
||||||
|
.highlighted = ((is_substitute_pattern ^ search_last_used)
|
||||||
|
&& search_highlighted),
|
||||||
|
.pat = (char *)pat.pat,
|
||||||
|
.additional_data = pat.additional_data,
|
||||||
|
.search_backward = (!is_substitute_pattern && pat.off.dir == '?'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Write ShaDa file
|
/// Write ShaDa file
|
||||||
///
|
///
|
||||||
/// @param[in] sd_writer Structure containing file writer definition.
|
/// @param[in] sd_writer Structure containing file writer definition.
|
||||||
@ -2529,45 +2589,14 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
|
|||||||
const bool search_highlighted = !(no_hlsearch
|
const bool search_highlighted = !(no_hlsearch
|
||||||
|| find_shada_parameter('h') != NULL);
|
|| find_shada_parameter('h') != NULL);
|
||||||
const bool search_last_used = search_was_last_used();
|
const bool search_last_used = search_was_last_used();
|
||||||
#define ADD_SEARCH_PAT(func, wms_attr, hlo, pcae, o, is_sub) \
|
|
||||||
do { \
|
|
||||||
SearchPattern pat; \
|
|
||||||
func(&pat); \
|
|
||||||
if (pat.pat != NULL) { \
|
|
||||||
wms->wms_attr = (PossiblyFreedShadaEntry) { \
|
|
||||||
.can_free_entry = false, \
|
|
||||||
.data = { \
|
|
||||||
.type = kSDItemSearchPattern, \
|
|
||||||
.timestamp = pat.timestamp, \
|
|
||||||
.data = { \
|
|
||||||
.search_pattern = { \
|
|
||||||
.magic = pat.magic, \
|
|
||||||
.smartcase = !pat.no_scs, \
|
|
||||||
.has_line_offset = hlo, \
|
|
||||||
.place_cursor_at_end = pcae, \
|
|
||||||
.offset = o, \
|
|
||||||
.is_last_used = (is_sub ^ search_last_used), \
|
|
||||||
.is_substitute_pattern = is_sub, \
|
|
||||||
.highlighted = ((is_sub ^ search_last_used) \
|
|
||||||
&& search_highlighted), \
|
|
||||||
.pat = (char *) pat.pat, \
|
|
||||||
.additional_data = pat.additional_data, \
|
|
||||||
.search_backward = (!is_sub && pat.off.dir == '?'), \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
} \
|
|
||||||
}; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
// Initialize search pattern
|
// Initialize search pattern
|
||||||
ADD_SEARCH_PAT(get_search_pattern, search_pattern, pat.off.line, \
|
add_search_pattern(&wms->search_pattern, &get_search_pattern, false,
|
||||||
pat.off.end, pat.off.off, false);
|
search_last_used, search_highlighted);
|
||||||
|
|
||||||
// Initialize substitute search pattern
|
// Initialize substitute search pattern
|
||||||
ADD_SEARCH_PAT(get_substitute_pattern, sub_search_pattern, false, false, 0,
|
add_search_pattern(&wms->sub_search_pattern, &get_substitute_pattern, true,
|
||||||
true);
|
search_last_used, search_highlighted);
|
||||||
#undef ADD_SEARCH_PAT
|
|
||||||
|
|
||||||
// Initialize substitute replacement string
|
// Initialize substitute replacement string
|
||||||
{
|
{
|
||||||
@ -2590,10 +2619,12 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer,
|
|||||||
|
|
||||||
// Initialize jump list
|
// Initialize jump list
|
||||||
const void *jump_iter = NULL;
|
const void *jump_iter = NULL;
|
||||||
|
setpcmark();
|
||||||
|
cleanup_jumplist();
|
||||||
do {
|
do {
|
||||||
xfmark_T fm;
|
xfmark_T fm;
|
||||||
cleanup_jumplist();
|
|
||||||
jump_iter = mark_jumplist_iter(jump_iter, curwin, &fm);
|
jump_iter = mark_jumplist_iter(jump_iter, curwin, &fm);
|
||||||
|
|
||||||
const buf_T *const buf = (fm.fmark.fnum == 0
|
const buf_T *const buf = (fm.fmark.fnum == 0
|
||||||
? NULL
|
? NULL
|
||||||
: buflist_findnr(fm.fmark.fnum));
|
: buflist_findnr(fm.fmark.fnum));
|
||||||
|
@ -153,6 +153,19 @@ describe('ShaDa support code', function()
|
|||||||
eq(saved, redir_exec('jumps'))
|
eq(saved, redir_exec('jumps'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('when dumping jump list also dumps current position', function()
|
||||||
|
nvim_command('edit ' .. testfilename)
|
||||||
|
nvim_command('normal! G')
|
||||||
|
nvim_command('split ' .. testfilename_2)
|
||||||
|
nvim_command('normal! G')
|
||||||
|
nvim_command('wshada')
|
||||||
|
nvim_command('quit')
|
||||||
|
nvim_command('rshada')
|
||||||
|
nvim_command('normal! \15') -- <C-o>
|
||||||
|
eq(testfilename_2, funcs.bufname('%'))
|
||||||
|
eq({2, 0}, curwinmeths.get_cursor())
|
||||||
|
end)
|
||||||
|
|
||||||
it('is able to dump and restore jump list with different times (slow!)',
|
it('is able to dump and restore jump list with different times (slow!)',
|
||||||
function()
|
function()
|
||||||
nvim_command('edit ' .. testfilename_2)
|
nvim_command('edit ' .. testfilename_2)
|
||||||
|
Loading…
Reference in New Issue
Block a user