vim-patch:8.2.0877: cannot get the search statistics

Problem:    Cannot get the search statistics.
Solution:   Add the searchcount() function. (Fujiwara Takuya, closes vim/vim#4446)
e8f5ec0d30

Additional changes:
- Tests weren't passing because the test ran assuming the cursor was at
  start of buffer but append() left the cursor at end of buffer .
  So cursor is moved to start of buffer after append.
- searchcount() added to list of builtin functions.
This commit is contained in:
shadmansaleh
2021-04-20 12:31:03 +06:00
parent f8173df4d7
commit e498f265f4
6 changed files with 493 additions and 128 deletions

View File

@@ -6,6 +6,7 @@
#include "nvim/vim.h"
#include "nvim/buffer_defs.h"
#include "nvim/eval/funcs.h"
#include "nvim/eval/typval.h"
#include "nvim/normal.h"
#include "nvim/os/time.h"
@@ -49,6 +50,11 @@
#define RE_BOTH 2 /* save pat in both patterns */
#define RE_LAST 2 /* use last used pattern if "pat" is NULL */
// Values for searchcount()
#define SEARCH_STAT_DEF_TIMEOUT 20L
#define SEARCH_STAT_DEF_MAX_COUNT 99
#define SEARCH_STAT_BUF_LEN 12
/// Structure containing offset definition for the last search pattern
///
/// @note Only offset for the last search pattern is used, not for the last
@@ -78,6 +84,16 @@ typedef struct {
int sa_wrapped; ///< search wrapped around
} searchit_arg_T;
typedef struct searchstat
{
int cur; // current position of found words
int cnt; // total count of found words
int exact_match; // TRUE if matched exactly on specified position
int incomplete; // 0: search was fully completed
// 1: recomputing was timed out
// 2: max count exceeded
int last_maxcount; // the max count of the last search
} searchstat_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "search.h.generated.h"