#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <wctype.h>
#include <stddef.h>
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/change.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/fileio.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
#include "nvim/input.h"
#include "nvim/mark.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/normal.h"
#include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/search.h"
#include "nvim/spell.h"
#include "nvim/spellfile.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/ui.h"
#include "nvim/undo.h"
Data Structures | |
struct | wordcount_S |
struct | suginfo_S |
struct | suggest_T |
struct | matchinf_S |
struct | spelload_S |
struct | syl_item_S |
struct | sftword_T |
struct | limitscore_T |
Macros | |
#define | RESCORE(word_score, sound_score) ((3 * (word_score) + (sound_score)) / 4) |
#define | MAXSCORE(word_score, sound_score) ((4 * (word_score) - (sound_score)) / 3) |
#define | WF_MIXCAP 0x20 |
#define | WF_CAPMASK (WF_ONECAP | WF_ALLCAP | WF_KEEPCAP | WF_FIXCAP) |
#define | SP_BANNED (-1) |
#define | SP_RARE 0 |
#define | SP_OK 1 |
#define | SP_LOCAL 2 |
#define | SP_BAD 3 |
#define | WC_KEY_OFF offsetof(wordcount_T, wc_word) |
#define | HI2WC(hi) ((wordcount_T *)((hi)->hi_key - WC_KEY_OFF)) |
#define | MAXWORDCOUNT 0xffff |
#define | SUG(ga, i) (((suggest_T *)(ga).ga_data)[i]) |
#define | WAS_BANNED(su, word) (!HASHITEM_EMPTY(hash_find(&(su)->su_banned, word))) |
#define | SUG_CLEAN_COUNT(su) |
#define | SUG_MAX_COUNT(su) (SUG_CLEAN_COUNT(su) + 50) |
#define | SCORE_SPLIT 149 |
#define | SCORE_SPLIT_NO 249 |
#define | SCORE_ICASE 52 |
#define | SCORE_REGION 200 |
#define | SCORE_RARE 180 |
#define | SCORE_SWAP 75 |
#define | SCORE_SWAP3 110 |
#define | SCORE_REP 65 |
#define | SCORE_SUBST 93 |
#define | SCORE_SIMILAR 33 |
#define | SCORE_SUBCOMP 33 |
#define | SCORE_DEL 94 |
#define | SCORE_DELDUP 66 |
#define | SCORE_DELCOMP 28 |
#define | SCORE_INS 96 |
#define | SCORE_INSDUP 67 |
#define | SCORE_INSCOMP 30 |
#define | SCORE_NONWORD 103 |
#define | SCORE_FILE 30 |
#define | SCORE_MAXINIT 350 |
#define | SCORE_COMMON1 30 |
#define | SCORE_COMMON2 40 |
#define | SCORE_COMMON3 50 |
#define | SCORE_THRES2 10 |
#define | SCORE_THRES3 100 |
#define | SCORE_SFMAX1 200 |
#define | SCORE_SFMAX2 300 |
#define | SCORE_SFMAX3 400 |
#define | SCORE_BIG (SCORE_INS * 3) |
#define | SCORE_MAXMAX 999999 |
#define | SCORE_LIMITMAX 350 |
#define | SCORE_EDIT_MIN SCORE_SIMILAR |
#define | SY_MAXLEN 30 |
#define | DIFF_NONE 0 |
#define | DIFF_YES 1 |
#define | DIFF_INSERT 2 |
#define | TSF_PREFIXOK 1 |
#define | TSF_DIDSPLIT 2 |
#define | TSF_DIDDEL 4 |
#define | PFD_NOPREFIX 0xff |
#define | PFD_PREFIXTREE 0xfe |
#define | PFD_NOTSPECIAL 0xfd |
#define | FIND_FOLDWORD 0 |
#define | FIND_KEEPWORD 1 |
#define | FIND_PREFIX 2 |
#define | FIND_COMPOUND 3 |
#define | FIND_KEEPCOMPOUND 4 |
#define | SPS_BEST 1 |
#define | SPS_FAST 2 |
#define | SPS_DOUBLE 4 |
#define | FREE_SUG_WORD(sug) xfree(sug->st_word) |
#define | PROF_STORE(state) |
#define | TRY_DEEPER(su, stack, depth, add) ((depth) < MAXWLEN - 1 && (stack)[depth].ts_score + (add) < (su)->su_maxscore) |
#define | HIKEY2SFT(p) ((sftword_T *)((p) - (dumsft.sft_word - (char_u *)&dumsft))) |
#define | HI2SFT(hi) HIKEY2SFT((hi)->hi_key) |
#define | CNT(a, b) cnt[(a) + (b) * (badlen + 1)] |
#define | DUMPFLAG_KEEPCASE 1 |
#define | DUMPFLAG_COUNT 2 |
#define | DUMPFLAG_ICASE 4 |
#define | DUMPFLAG_ONECAP 8 |
#define | DUMPFLAG_ALLCAP 16 |
Typedefs | |
typedef struct wordcount_S | wordcount_T |
typedef struct suginfo_S | suginfo_T |
typedef struct matchinf_S | matchinf_T |
typedef struct spelload_S | spelload_T |
typedef struct syl_item_S | syl_item_T |
Variables | |
slang_T * | first_lang = NULL |
char_u * | int_wordlist = NULL |
spelltab_T | spelltab |
int | did_set_spelltab |
char * | e_format = N_("E759: Format error in spell file") |
#define CNT | ( | a, | |
b | |||
) | cnt[(a) + (b) * (badlen + 1)] |
#define DIFF_INSERT 2 |
#define DIFF_NONE 0 |
#define DIFF_YES 1 |
#define DUMPFLAG_ALLCAP 16 |
#define DUMPFLAG_COUNT 2 |
#define DUMPFLAG_ICASE 4 |
#define DUMPFLAG_KEEPCASE 1 |
#define DUMPFLAG_ONECAP 8 |
#define FIND_COMPOUND 3 |
#define FIND_FOLDWORD 0 |
#define FIND_KEEPCOMPOUND 4 |
#define FIND_KEEPWORD 1 |
#define FIND_PREFIX 2 |
#define FREE_SUG_WORD | ( | sug | ) | xfree(sug->st_word) |
#define HI2SFT | ( | hi | ) | HIKEY2SFT((hi)->hi_key) |
#define HI2WC | ( | hi | ) | ((wordcount_T *)((hi)->hi_key - WC_KEY_OFF)) |
#define MAXSCORE | ( | word_score, | |
sound_score | |||
) | ((4 * (word_score) - (sound_score)) / 3) |
#define MAXWORDCOUNT 0xffff |
#define PFD_NOPREFIX 0xff |
#define PFD_NOTSPECIAL 0xfd |
#define PFD_PREFIXTREE 0xfe |
#define PROF_STORE | ( | state | ) |
#define RESCORE | ( | word_score, | |
sound_score | |||
) | ((3 * (word_score) + (sound_score)) / 4) |
#define SCORE_BIG (SCORE_INS * 3) |
#define SCORE_COMMON1 30 |
#define SCORE_COMMON2 40 |
#define SCORE_COMMON3 50 |
#define SCORE_DEL 94 |
#define SCORE_DELCOMP 28 |
#define SCORE_DELDUP 66 |
#define SCORE_EDIT_MIN SCORE_SIMILAR |
#define SCORE_FILE 30 |
#define SCORE_ICASE 52 |
#define SCORE_INS 96 |
#define SCORE_INSCOMP 30 |
#define SCORE_INSDUP 67 |
#define SCORE_LIMITMAX 350 |
#define SCORE_MAXINIT 350 |
#define SCORE_MAXMAX 999999 |
#define SCORE_NONWORD 103 |
#define SCORE_RARE 180 |
#define SCORE_REGION 200 |
#define SCORE_REP 65 |
#define SCORE_SFMAX1 200 |
#define SCORE_SFMAX2 300 |
#define SCORE_SFMAX3 400 |
#define SCORE_SIMILAR 33 |
#define SCORE_SPLIT 149 |
#define SCORE_SPLIT_NO 249 |
#define SCORE_SUBCOMP 33 |
#define SCORE_SUBST 93 |
#define SCORE_SWAP 75 |
#define SCORE_SWAP3 110 |
#define SCORE_THRES2 10 |
#define SCORE_THRES3 100 |
#define SP_BAD 3 |
#define SP_BANNED (-1) |
#define SP_LOCAL 2 |
#define SP_OK 1 |
#define SP_RARE 0 |
#define SPS_BEST 1 |
#define SPS_DOUBLE 4 |
#define SPS_FAST 2 |
#define SUG_CLEAN_COUNT | ( | su | ) |
#define SUG_MAX_COUNT | ( | su | ) | (SUG_CLEAN_COUNT(su) + 50) |
#define SY_MAXLEN 30 |
#define TRY_DEEPER | ( | su, | |
stack, | |||
depth, | |||
add | |||
) | ((depth) < MAXWLEN - 1 && (stack)[depth].ts_score + (add) < (su)->su_maxscore) |
#define TSF_DIDDEL 4 |
#define TSF_DIDSPLIT 2 |
#define TSF_PREFIXOK 1 |
#define WAS_BANNED | ( | su, | |
word | |||
) | (!HASHITEM_EMPTY(hash_find(&(su)->su_banned, word))) |
#define WC_KEY_OFF offsetof(wordcount_T, wc_word) |
#define WF_CAPMASK (WF_ONECAP | WF_ALLCAP | WF_KEEPCAP | WF_FIXCAP) |
#define WF_MIXCAP 0x20 |
typedef struct matchinf_S matchinf_T |
typedef struct spelload_S spelload_T |
typedef struct syl_item_S syl_item_T |
typedef struct wordcount_S wordcount_T |
Return case type of word: w word 0 Word WF_ONECAP W WORD WF_ALLCAP WoRd wOrd WF_KEEPCAP
[in] | word | |
[in] | end | End of word or NULL for NUL delimited string |
void clear_spell_chartab | ( | spelltab_T * | sp | ) |
Add a word to the hashtable of common words. If it's already there then the counter is increased.
[in] | lp | |
[in] | word | added to common words hashtable |
[in] | len | length of word or -1 for NUL terminated |
[in] | count | 1 to count once, 10 to init |
char* did_set_spelllang | ( | win_T * | wp | ) |
char* eval_soundfold | ( | const char *const | word | ) |
Soundfold a string, for soundfold()
[in] | word | Word to soundfold. |
int init_syl_tab | ( | slang_T * | slang | ) |
Make a copy of "word", with the first letter upper or lower cased, to "wcopy[MAXWLEN]". "word" must not be empty. The result is NUL terminated.
[in] | word | source string to copy |
[in,out] | wcopy | copied string, with case of first letter changed |
[in] | upper | True to upper case, otherwise lower case |
Main spell-checking function. "ptr" points to a character that could be the start of a word. "*attrp" is set to the highlight index for a badly spelled word. For a non-word or when it's OK it remains unchanged. This must only be called when 'spelllang' is not empty.
"capcol" is used to check for a Capitalised word after the end of a sentence. If it's zero then perform the check. Return the column where to check next, or -1 when no sentence end was found. If it's NULL then don't worry.
wp | current window |
capcol | column to check for Capital |
docount | count good words |
int spell_check_sps | ( | void | ) |
Go through all possible words and:
pat | leading part of the word |
ic | ignore case |
dir | direction for adding matches |
dumpflags_arg | DUMPFLAG_* |
Moves to the next spell error. "curline" is false for "[s", "]s", "[S" and "]S". "curline" is true to find word under/after cursor in the same line. For Insert mode completion "dir" is BACKWARD and "curline" is true: move to after badly spelled word before the cursor.
dir | FORWARD or BACKWARD |
allwords | true for "[s"/"]s", false for "[S"/"]S" |
attrp | return: attributes of bad word or NULL (only when "dir" is FORWARD) |
Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]".
There are many ways to turn a word into a sound-a-like representation. The oldest is Soundex (1918!). A nice overview can be found in "Approximate swedish name matching - survey and test of different algorithms" by Klas Erikson.
We support two methods:
[in] | slang | |
[in] | inword | word to soundfold |
[in] | folded | whether inword is already case-folded |
[in,out] | res | destination for soundfolded word |
void spell_suggest | ( | int | count | ) |
void spell_suggest_list | ( | garray_T * | gap, |
char_u * | word, | ||
int | maxcount, | ||
bool | need_cap, | ||
bool | interactive | ||
) |
Find spell suggestions for "word". Return them in the growarray "*gap" as a list of allocated strings.
maxcount | maximum nr of suggestions |
need_cap | 'spellcapcheck' matched |
int spell_word_start | ( | int | startcol | ) |
int did_set_spelltab |
char* e_format = N_("E759: Format error in spell file") |
spelltab_T spelltab |