From 81ef9f55aebb9572adac14779369b37a4569a59c Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 17 Jul 2016 15:28:14 +0300 Subject: shada: Save current cursor position before saving jumps --- src/nvim/shada.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 867c697a9a..0c710b3903 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2591,9 +2591,12 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, // Initialize jump list const void *jump_iter = NULL; do { - xfmark_T fm; + setpcmark(); cleanup_jumplist(); + + xfmark_T fm; jump_iter = mark_jumplist_iter(jump_iter, curwin, &fm); + const buf_T *const buf = (fm.fmark.fnum == 0 ? NULL : buflist_findnr(fm.fmark.fnum)); -- cgit From 40cedfd0f5fd7f2523118c932f6b1cae9ef7e14e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 17 Jul 2016 19:57:14 +0300 Subject: shada: Silence linter --- src/nvim/shada.c | 100 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 64 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 0c710b3903..e9a2167635 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -148,6 +148,9 @@ KHASH_SET_INIT_STR(strset) /// Common prefix for all ignorable “write” errors #define WERR "E574: " +/// Callback function for add_search_pattern +typedef void (*SearchPatternGetter)(SearchPattern *); + /// Flags for shada_read_file and children typedef enum { kShaDaWantInfo = 1, ///< Load non-mark information @@ -2324,7 +2327,7 @@ static inline ShaDaWriteResult shada_read_when_writing( /// /// @return ShadaEntry List of buffers to save, kSDItemBufferList entry. static ShadaEntry shada_get_buflist(khash_t(bufset) *const removable_bufs) - FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE { int max_bufs = get_shada_parameter('%'); size_t buf_count = 0; @@ -2368,6 +2371,62 @@ static ShadaEntry shada_get_buflist(khash_t(bufset) *const removable_bufs) 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 + ? pat.off.off + : defaults.data.search_pattern.offset), + .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 /// /// @param[in] sd_writer Structure containing file writer definition. @@ -2529,45 +2588,14 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, const bool search_highlighted = !(no_hlsearch || find_shada_parameter('h') != NULL); 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 - ADD_SEARCH_PAT(get_search_pattern, search_pattern, pat.off.line, \ - pat.off.end, pat.off.off, false); + add_search_pattern(&wms->search_pattern, &get_search_pattern, false, + search_last_used, search_highlighted); // Initialize substitute search pattern - ADD_SEARCH_PAT(get_substitute_pattern, sub_search_pattern, false, false, 0, - true); -#undef ADD_SEARCH_PAT + add_search_pattern(&wms->sub_search_pattern, &get_substitute_pattern, true, + search_last_used, search_highlighted); // Initialize substitute replacement string { -- cgit From ec975a74ad71993d8163fa39f0120ae693d2d3ee Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 4 Jan 2017 16:42:43 +0300 Subject: shada: Fix offset saving --- src/nvim/shada.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index e9a2167635..8d9e8a679f 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2411,8 +2411,8 @@ static inline void add_search_pattern(PossiblyFreedShadaEntry *const ret_pse, ? defaults.data.search_pattern.place_cursor_at_end : pat.off.end), .offset = (is_substitute_pattern - ? pat.off.off - : defaults.data.search_pattern.offset), + ? 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) -- cgit From ac50971f8779c5a86c31e69aa84bb42e149c3fdc Mon Sep 17 00:00:00 2001 From: ZyX Date: Wed, 4 Jan 2017 16:55:28 +0300 Subject: shada: Move setpcmark()/cleanup_jumplist() out of the cycle --- src/nvim/shada.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 8d9e8a679f..f83a3bdad9 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2618,10 +2618,9 @@ static ShaDaWriteResult shada_write(ShaDaWriteDef *const sd_writer, // Initialize jump list const void *jump_iter = NULL; + setpcmark(); + cleanup_jumplist(); do { - setpcmark(); - cleanup_jumplist(); - xfmark_T fm; jump_iter = mark_jumplist_iter(jump_iter, curwin, &fm); -- cgit From 10d9c6d813d51750e6f77b3ef58ac4d4fef08e86 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 6 Jan 2017 01:47:07 +0300 Subject: shada: Mark ALWAYS_INLINE function as `inline` --- src/nvim/shada.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/shada.c b/src/nvim/shada.c index f83a3bdad9..64610ae8f8 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -2326,7 +2326,8 @@ static inline ShaDaWriteResult shada_read_when_writing( /// @param[in] removable_bufs Buffers which are ignored /// /// @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( + 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('%'); -- cgit From a1cce83d3c7a0b3b9f63db837db521e0b4e6a31f Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 6 Jan 2017 01:52:36 +0300 Subject: clint: Add more exceptions to “space after a cast” rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Python does not allow branching here, complaining that look-behind is not fixed-width. --- src/clint.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/clint.py b/src/clint.py index efc5f18378..0470f824fa 100755 --- a/src/clint.py +++ b/src/clint.py @@ -2516,6 +2516,10 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error): cast_line = re.sub(r'^# *define +\w+\([^)]*\)', '', line) match = Search(r'(?