Mercurial > vim
annotate src/spell.c @ 30771:cf77f7a19ab6 v9.0.0720
patch 9.0.0720: MS-Windows GUI may have pixel dust from antialiasing
Commit: https://github.com/vim/vim/commit/0c502d2e7031611788c301c7da0896f0fd9515fd
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Oct 11 12:48:44 2022 +0100
patch 9.0.0720: MS-Windows GUI may have pixel dust from antialiasing
Problem: MS-Windows GUI may have pixel dust from antialiasing.
Solution: When a character changes also redraw the next one. (issue https://github.com/vim/vim/issues/8532)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 11 Oct 2022 14:00:07 +0200 |
parents | 8e73ecbee60d |
children | c7983f593fa7 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
223 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * spell.c: code for spell checking | |
226 | 12 * |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
13 * See spellfile.c for the Vim spell file format. |
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
14 * |
300 | 15 * The spell checking mechanism uses a tree (aka trie). Each node in the tree |
16 * has a list of bytes that can appear (siblings). For each byte there is a | |
17 * pointer to the node with the byte that follows in the word (child). | |
324 | 18 * |
19 * A NUL byte is used where the word may end. The bytes are sorted, so that | |
20 * binary searching can be used and the NUL bytes are at the start. The | |
21 * number of possible bytes is stored before the list of bytes. | |
22 * | |
23 * The tree uses two arrays: "byts" stores the characters, "idxs" stores | |
24 * either the next index or flags. The tree starts at index 0. For example, | |
25 * to lookup "vi" this sequence is followed: | |
26 * i = 0 | |
27 * len = byts[i] | |
28 * n = where "v" appears in byts[i + 1] to byts[i + len] | |
29 * i = idxs[n] | |
30 * len = byts[i] | |
31 * n = where "i" appears in byts[i + 1] to byts[i + len] | |
32 * i = idxs[n] | |
33 * len = byts[i] | |
34 * find that byts[i + 1] is 0, idxs[i + 1] has flags for "vi". | |
300 | 35 * |
339 | 36 * There are two word trees: one with case-folded words and one with words in |
300 | 37 * original case. The second one is only used for keep-case words and is |
38 * usually small. | |
39 * | |
481 | 40 * There is one additional tree for when not all prefixes are applied when |
339 | 41 * generating the .spl file. This tree stores all the possible prefixes, as |
42 * if they were words. At each word (prefix) end the prefix nr is stored, the | |
43 * following word must support this prefix nr. And the condition nr is | |
44 * stored, used to lookup the condition that the word must match with. | |
45 * | |
300 | 46 * Thanks to Olaf Seibert for providing an example implementation of this tree |
47 * and the compression mechanism. | |
625 | 48 * LZ trie ideas: |
49 * http://www.irb.hr/hr/home/ristov/papers/RistovLZtrieRevision1.pdf | |
50 * More papers: http://www-igm.univ-mlv.fr/~laporte/publi_en.html | |
243 | 51 * |
52 * Matching involves checking the caps type: Onecap ALLCAP KeepCap. | |
53 * | |
236 | 54 * Why doesn't Vim use aspell/ispell/myspell/etc.? |
55 * See ":help develop-spell". | |
56 */ | |
57 | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
58 #define IN_SPELL_C |
223 | 59 #include "vim.h" |
60 | |
737 | 61 #if defined(FEAT_SPELL) || defined(PROTO) |
223 | 62 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
63 #ifndef UNIX // it's in os_unix.h for Unix |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
64 # include <time.h> // for time_t |
625 | 65 #endif |
66 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
67 #define REGION_ALL 0xff // word valid in all regions |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
68 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
69 // Result values. Lower number is accepted over higher one. |
27752
c1d1639b52dd
patch 8.2.4402: missing parenthesis may cause unexpected problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
70 #define SP_BANNED (-1) |
236 | 71 #define SP_OK 0 |
307 | 72 #define SP_RARE 1 |
73 #define SP_LOCAL 2 | |
74 #define SP_BAD 3 | |
236 | 75 |
323 | 76 /* |
236 | 77 * Structure to store info for word matching. |
78 */ | |
79 typedef struct matchinf_S | |
80 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
81 langp_T *mi_lp; // info for language and region |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
82 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
83 // pointers to original text to be checked |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
84 char_u *mi_word; // start of word being checked |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
85 char_u *mi_end; // end of matching word so far |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
86 char_u *mi_fend; // next char to be added to mi_fword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
87 char_u *mi_cend; // char after what was used for |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
88 // mi_capflags |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
89 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
90 // case-folded text |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
91 char_u mi_fword[MAXWLEN + 1]; // mi_word case-folded |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
92 int mi_fwordlen; // nr of valid bytes in mi_fword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
93 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
94 // for when checking word after a prefix |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
95 int mi_prefarridx; // index in sl_pidxs with list of |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
96 // affixID/condition |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
97 int mi_prefcnt; // number of entries at mi_prefarridx |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
98 int mi_prefixlen; // byte length of prefix |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
99 int mi_cprefixlen; // byte length of prefix in original |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
100 // case |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
101 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
102 // for when checking a compound word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
103 int mi_compoff; // start of following word offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
104 char_u mi_compflags[MAXWLEN]; // flags for compound words used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
105 int mi_complen; // nr of compound words used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
106 int mi_compextra; // nr of COMPOUNDROOT words |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
107 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
108 // others |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
109 int mi_result; // result so far: SP_BAD, SP_OK, etc. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
110 int mi_capflags; // WF_ONECAP WF_ALLCAP WF_KEEPCAP |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
111 win_T *mi_win; // buffer being checked |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
112 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
113 // for NOBREAK |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
114 int mi_result2; // "mi_resul" without following word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
115 char_u *mi_end2; // "mi_end" without following word |
236 | 116 } matchinf_T; |
117 | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
118 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
119 static int spell_mb_isword_class(int cl, win_T *wp); |
307 | 120 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
121 // mode values for find_word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
122 #define FIND_FOLDWORD 0 // find word case-folded |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
123 #define FIND_KEEPWORD 1 // find keep-case word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
124 #define FIND_PREFIX 2 // find word after prefix |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
125 #define FIND_COMPOUND 3 // find case-folded compound word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
126 #define FIND_KEEPCOMPOUND 4 // find keep-case compound word |
339 | 127 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
128 static void find_word(matchinf_T *mip, int mode); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
129 static void find_prefix(matchinf_T *mip, int mode); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
130 static int fold_more(matchinf_T *mip); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
131 static void spell_load_cb(char_u *fname, void *cookie); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
132 static int count_syllables(slang_T *slang, char_u *word); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
133 static void clear_midword(win_T *buf); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
134 static void use_midword(slang_T *lp, win_T *buf); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
135 static int find_region(char_u *rp, char_u *region); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
136 static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
137 static void spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
138 static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
139 static void dump_word(slang_T *slang, char_u *word, char_u *pat, int *dir, int round, int flags, linenr_T lnum); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
140 static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, int *dir, int round, int flags, linenr_T startlnum); |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
141 |
236 | 142 /* |
143 * Main spell-checking function. | |
300 | 144 * "ptr" points to a character that could be the start of a word. |
534 | 145 * "*attrp" is set to the highlight index for a badly spelled word. For a |
146 * non-word or when it's OK it remains unchanged. | |
236 | 147 * This must only be called when 'spelllang' is not empty. |
323 | 148 * |
385 | 149 * "capcol" is used to check for a Capitalised word after the end of a |
150 * sentence. If it's zero then perform the check. Return the column where to | |
151 * check next, or -1 when no sentence end was found. If it's NULL then don't | |
152 * worry. | |
323 | 153 * |
236 | 154 * Returns the length of the word in bytes, also when it's OK, so that the |
155 * caller can skip over the word. | |
156 */ | |
157 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
158 spell_check( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
159 win_T *wp, // current window |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
160 char_u *ptr, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
161 hlf_T *attrp, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
162 int *capcol, // column to check for Capital |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
163 int docount) // count good words |
236 | 164 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
165 matchinf_T mi; // Most things are put in "mi" so that it can |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
166 // be passed to functions quickly. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
167 int nrlen = 0; // found a number first |
385 | 168 int c; |
483 | 169 int wrongcaplen = 0; |
500 | 170 int lpi; |
625 | 171 int count_word = docount; |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
172 int use_camel_case = *wp->w_s->b_p_spo != NUL; |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
173 int camel_case = 0; |
236 | 174 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
175 // A word never starts at a space or a control character. Return quickly |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
176 // then, skipping over the character. |
307 | 177 if (*ptr <= ' ') |
178 return 1; | |
690 | 179 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
180 // Return here when loading language files failed. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
181 if (wp->w_s->b_langp.ga_len == 0) |
690 | 182 return 1; |
183 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
184 CLEAR_FIELD(mi); |
236 | 185 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
186 // A number is always OK. Also skip hexadecimal numbers 0xFF99 and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
187 // 0X99FF. But always do check spelling to find "3GPP" and "11 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
188 // julifeest". |
300 | 189 if (*ptr >= '0' && *ptr <= '9') |
190 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
191 if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
192 mi.mi_end = skipbin(ptr + 2); |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
193 else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) |
316 | 194 mi.mi_end = skiphex(ptr + 2); |
300 | 195 else |
344 | 196 mi.mi_end = skipdigits(ptr); |
835 | 197 nrlen = (int)(mi.mi_end - ptr); |
584 | 198 } |
346 | 199 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
200 // Find the normal end of the word (until the next non-word character). |
344 | 201 mi.mi_word = ptr; |
584 | 202 mi.mi_fend = ptr; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
203 if (spell_iswordp(mi.mi_fend, wp)) |
344 | 204 { |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
205 int prev_upper; |
20810
f9245f58c134
patch 8.2.0957: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20808
diff
changeset
|
206 int this_upper = FALSE; // init for gcc |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
207 |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
208 if (use_camel_case) |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
209 { |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
210 c = PTR2CHAR(mi.mi_fend); |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
211 this_upper = SPELL_ISUPPER(c); |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
212 } |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
213 |
344 | 214 do |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
215 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
216 MB_PTR_ADV(mi.mi_fend); |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
217 if (use_camel_case) |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
218 { |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
219 prev_upper = this_upper; |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
220 c = PTR2CHAR(mi.mi_fend); |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
221 this_upper = SPELL_ISUPPER(c); |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
222 camel_case = !prev_upper && this_upper; |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
223 } |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
224 } while (*mi.mi_fend != NUL && spell_iswordp(mi.mi_fend, wp) |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
225 && !camel_case); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
226 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
227 if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) |
385 | 228 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
229 // Check word starting with capital letter. |
455 | 230 c = PTR2CHAR(ptr); |
385 | 231 if (!SPELL_ISUPPER(c)) |
483 | 232 wrongcaplen = (int)(mi.mi_fend - ptr); |
385 | 233 } |
234 } | |
235 if (capcol != NULL) | |
236 *capcol = -1; | |
344 | 237 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
238 // We always use the characters up to the next non-word character, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
239 // also for bad words. |
344 | 240 mi.mi_end = mi.mi_fend; |
241 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
242 // Check caps type later. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
243 mi.mi_capflags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
244 mi.mi_cend = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
245 mi.mi_win = wp; |
344 | 246 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
247 // case-fold the word with one non-word character, so that we can check |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
248 // for the word end. |
344 | 249 if (*mi.mi_fend != NUL) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
250 MB_PTR_ADV(mi.mi_fend); |
344 | 251 |
24872
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
252 (void)spell_casefold(wp, ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, |
344 | 253 MAXWLEN + 1); |
835 | 254 mi.mi_fwordlen = (int)STRLEN(mi.mi_fword); |
344 | 255 |
28925
46fa2d54e389
patch 8.2.4985: PVS warns for possible array underrun
Bram Moolenaar <Bram@vim.org>
parents:
28848
diff
changeset
|
256 if (camel_case && mi.mi_fwordlen > 0) |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
257 // Introduce a fake word end space into the folded word. |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
258 mi.mi_fword[mi.mi_fwordlen - 1] = ' '; |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
259 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
260 // The word is bad unless we recognize it. |
344 | 261 mi.mi_result = SP_BAD; |
492 | 262 mi.mi_result2 = SP_BAD; |
344 | 263 |
264 /* | |
265 * Loop over the languages specified in 'spelllang'. | |
625 | 266 * We check them all, because a word may be matched longer in another |
267 * language. | |
344 | 268 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
269 for (lpi = 0; lpi < wp->w_s->b_langp.ga_len; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
270 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
271 mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, lpi); |
500 | 272 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
273 // If reloading fails the language is still in the list but everything |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
274 // has been cleared. |
500 | 275 if (mi.mi_lp->lp_slang->sl_fidxs == NULL) |
276 continue; | |
277 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
278 // Check for a matching word in case-folded words. |
344 | 279 find_word(&mi, FIND_FOLDWORD); |
280 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
281 // Check for a matching word in keep-case words. |
344 | 282 find_word(&mi, FIND_KEEPWORD); |
283 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
284 // Check for matching prefixes. |
485 | 285 find_prefix(&mi, FIND_FOLDWORD); |
492 | 286 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
287 // For a NOBREAK language, may want to use a word without a following |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
288 // word as a backup. |
492 | 289 if (mi.mi_lp->lp_slang->sl_nobreak && mi.mi_result == SP_BAD |
290 && mi.mi_result2 != SP_BAD) | |
291 { | |
292 mi.mi_result = mi.mi_result2; | |
293 mi.mi_end = mi.mi_end2; | |
294 } | |
625 | 295 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
296 // Count the word in the first language where it's found to be OK. |
625 | 297 if (count_word && mi.mi_result == SP_OK) |
298 { | |
299 count_common_word(mi.mi_lp->lp_slang, ptr, | |
300 (int)(mi.mi_end - ptr), 1); | |
301 count_word = FALSE; | |
302 } | |
344 | 303 } |
304 | |
305 if (mi.mi_result != SP_OK) | |
306 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
307 // If we found a number skip over it. Allows for "42nd". Do flag |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
308 // rare and local words, e.g., "3GPP". |
344 | 309 if (nrlen > 0) |
346 | 310 { |
311 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) | |
312 return nrlen; | |
313 } | |
344 | 314 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
315 // When we are at a non-word character there is no error, just |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
316 // skip over the character (try looking for a word after it). |
5477 | 317 else if (!spell_iswordp_nmw(ptr, wp)) |
243 | 318 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
319 if (capcol != NULL && wp->w_s->b_cap_prog != NULL) |
385 | 320 { |
321 regmatch_T regmatch; | |
6375 | 322 int r; |
385 | 323 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
324 // Check for end of sentence. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
325 regmatch.regprog = wp->w_s->b_cap_prog; |
385 | 326 regmatch.rm_ic = FALSE; |
6375 | 327 r = vim_regexec(®match, ptr, 0); |
328 wp->w_s->b_cap_prog = regmatch.regprog; | |
329 if (r) | |
385 | 330 *capcol = (int)(regmatch.endp[0] - ptr); |
331 } | |
332 | |
344 | 333 if (has_mbyte) |
474 | 334 return (*mb_ptr2len)(ptr); |
344 | 335 return 1; |
300 | 336 } |
483 | 337 else if (mi.mi_end == ptr) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
338 // Always include at least one character. Required for when there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
339 // is a mixup in "midword". |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
340 MB_PTR_ADV(mi.mi_end); |
492 | 341 else if (mi.mi_result == SP_BAD |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
342 && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) |
492 | 343 { |
344 char_u *p, *fp; | |
345 int save_result = mi.mi_result; | |
346 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
347 // First language in 'spelllang' is NOBREAK. Find first position |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
348 // at which any word would be valid. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
349 mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, 0); |
500 | 350 if (mi.mi_lp->lp_slang->sl_fidxs != NULL) |
351 { | |
352 p = mi.mi_word; | |
353 fp = mi.mi_fword; | |
354 for (;;) | |
355 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
356 MB_PTR_ADV(p); |
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
357 MB_PTR_ADV(fp); |
500 | 358 if (p >= mi.mi_end) |
359 break; | |
835 | 360 mi.mi_compoff = (int)(fp - mi.mi_fword); |
500 | 361 find_word(&mi, FIND_COMPOUND); |
362 if (mi.mi_result != SP_BAD) | |
363 { | |
364 mi.mi_end = p; | |
365 break; | |
366 } | |
367 } | |
368 mi.mi_result = save_result; | |
369 } | |
492 | 370 } |
243 | 371 |
344 | 372 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) |
534 | 373 *attrp = HLF_SPB; |
344 | 374 else if (mi.mi_result == SP_RARE) |
534 | 375 *attrp = HLF_SPR; |
344 | 376 else |
534 | 377 *attrp = HLF_SPL; |
243 | 378 } |
379 | |
483 | 380 if (wrongcaplen > 0 && (mi.mi_result == SP_OK || mi.mi_result == SP_RARE)) |
381 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
382 // Report SpellCap only when the word isn't badly spelled. |
534 | 383 *attrp = HLF_SPC; |
483 | 384 return wrongcaplen; |
385 } | |
386 | |
300 | 387 return (int)(mi.mi_end - ptr); |
236 | 388 } |
389 | |
390 /* | |
300 | 391 * Check if the word at "mip->mi_word" is in the tree. |
339 | 392 * When "mode" is FIND_FOLDWORD check in fold-case word tree. |
393 * When "mode" is FIND_KEEPWORD check in keep-case word tree. | |
394 * When "mode" is FIND_PREFIX check for word after prefix in fold-case word | |
395 * tree. | |
300 | 396 * |
397 * For a match mip->mi_result is updated. | |
243 | 398 */ |
399 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
400 find_word(matchinf_T *mip, int mode) |
243 | 401 { |
324 | 402 idx_T arridx = 0; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
403 int endlen[MAXWLEN]; // length at possible word endings |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
404 idx_T endidx[MAXWLEN]; // possible word endings |
300 | 405 int endidxcnt = 0; |
406 int len; | |
407 int wlen = 0; | |
408 int flen; | |
409 int c; | |
410 char_u *ptr; | |
324 | 411 idx_T lo, hi, m; |
300 | 412 char_u *s; |
339 | 413 char_u *p; |
307 | 414 int res = SP_BAD; |
300 | 415 slang_T *slang = mip->mi_lp->lp_slang; |
416 unsigned flags; | |
417 char_u *byts; | |
324 | 418 idx_T *idxs; |
481 | 419 int word_ends; |
485 | 420 int prefix_found; |
492 | 421 int nobreak_result; |
481 | 422 |
423 if (mode == FIND_KEEPWORD || mode == FIND_KEEPCOMPOUND) | |
236 | 424 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
425 // Check for word with matching case in keep-case tree. |
300 | 426 ptr = mip->mi_word; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
427 flen = 9999; // no case folding, always enough bytes |
300 | 428 byts = slang->sl_kbyts; |
429 idxs = slang->sl_kidxs; | |
481 | 430 |
431 if (mode == FIND_KEEPCOMPOUND) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
432 // Skip over the previously found word(s). |
481 | 433 wlen += mip->mi_compoff; |
236 | 434 } |
435 else | |
436 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
437 // Check for case-folded in case-folded tree. |
300 | 438 ptr = mip->mi_fword; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
439 flen = mip->mi_fwordlen; // available case-folded bytes |
300 | 440 byts = slang->sl_fbyts; |
441 idxs = slang->sl_fidxs; | |
339 | 442 |
443 if (mode == FIND_PREFIX) | |
444 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
445 // Skip over the prefix. |
339 | 446 wlen = mip->mi_prefixlen; |
447 flen -= mip->mi_prefixlen; | |
448 } | |
481 | 449 else if (mode == FIND_COMPOUND) |
450 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
451 // Skip over the previously found word(s). |
481 | 452 wlen = mip->mi_compoff; |
453 flen -= mip->mi_compoff; | |
454 } | |
455 | |
243 | 456 } |
457 | |
300 | 458 if (byts == NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
459 return; // array is empty |
236 | 460 |
461 /* | |
307 | 462 * Repeat advancing in the tree until: |
463 * - there is a byte that doesn't match, | |
464 * - we reach the end of the tree, | |
465 * - or we reach the end of the line. | |
236 | 466 */ |
300 | 467 for (;;) |
236 | 468 { |
346 | 469 if (flen <= 0 && *mip->mi_fend != NUL) |
339 | 470 flen = fold_more(mip); |
300 | 471 |
472 len = byts[arridx++]; | |
473 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
474 // If the first possible byte is a zero the word could end here. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
475 // Remember this index, we first check for the longest word. |
300 | 476 if (byts[arridx] == 0) |
477 { | |
307 | 478 if (endidxcnt == MAXWLEN) |
479 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
480 // Must be a corrupted spell file. |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
481 emsg(_(e_format_error_in_spell_file)); |
307 | 482 return; |
483 } | |
300 | 484 endlen[endidxcnt] = wlen; |
485 endidx[endidxcnt++] = arridx++; | |
486 --len; | |
487 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
488 // Skip over the zeros, there can be several flag/region |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
489 // combinations. |
300 | 490 while (len > 0 && byts[arridx] == 0) |
491 { | |
492 ++arridx; | |
493 --len; | |
494 } | |
495 if (len == 0) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
496 break; // no children, word must end here |
300 | 497 } |
498 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
499 // Stop looking at end of the line. |
300 | 500 if (ptr[wlen] == NUL) |
501 break; | |
502 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
503 // Perform a binary search in the list of accepted bytes. |
300 | 504 c = ptr[wlen]; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
505 if (c == TAB) // <Tab> is handled like <Space> |
346 | 506 c = ' '; |
300 | 507 lo = arridx; |
508 hi = arridx + len - 1; | |
509 while (lo < hi) | |
510 { | |
511 m = (lo + hi) / 2; | |
512 if (byts[m] > c) | |
513 hi = m - 1; | |
514 else if (byts[m] < c) | |
515 lo = m + 1; | |
516 else | |
517 { | |
518 lo = hi = m; | |
519 break; | |
236 | 520 } |
521 } | |
300 | 522 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
523 // Stop if there is no matching byte. |
300 | 524 if (hi < lo || byts[lo] != c) |
525 break; | |
526 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
527 // Continue at the child (if there is one). |
300 | 528 arridx = idxs[lo]; |
529 ++wlen; | |
530 --flen; | |
346 | 531 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
532 // One space in the good word may stand for several spaces in the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
533 // checked word. |
346 | 534 if (c == ' ') |
535 { | |
536 for (;;) | |
537 { | |
538 if (flen <= 0 && *mip->mi_fend != NUL) | |
539 flen = fold_more(mip); | |
540 if (ptr[wlen] != ' ' && ptr[wlen] != TAB) | |
541 break; | |
542 ++wlen; | |
543 --flen; | |
544 } | |
545 } | |
236 | 546 } |
547 | |
300 | 548 /* |
549 * Verify that one of the possible endings is valid. Try the longest | |
550 * first. | |
551 */ | |
552 while (endidxcnt > 0) | |
553 { | |
554 --endidxcnt; | |
555 arridx = endidx[endidxcnt]; | |
556 wlen = endlen[endidxcnt]; | |
236 | 557 |
300 | 558 if ((*mb_head_off)(ptr, ptr + wlen) > 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
559 continue; // not at first byte of character |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
560 if (spell_iswordp(ptr + wlen, mip->mi_win)) |
481 | 561 { |
492 | 562 if (slang->sl_compprog == NULL && !slang->sl_nobreak) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
563 continue; // next char is a word character |
481 | 564 word_ends = FALSE; |
565 } | |
566 else | |
567 word_ends = TRUE; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
568 // The prefix flag is before compound flags. Once a valid prefix flag |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
569 // has been found we try compound flags. |
485 | 570 prefix_found = FALSE; |
300 | 571 |
339 | 572 if (mode != FIND_KEEPWORD && has_mbyte) |
300 | 573 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
574 // Compute byte length in original word, length may change |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
575 // when folding case. This can be slow, take a shortcut when the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
576 // case-folded word is equal to the keep-case word. |
300 | 577 p = mip->mi_word; |
339 | 578 if (STRNCMP(ptr, p, wlen) != 0) |
579 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
580 for (s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) |
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
581 MB_PTR_ADV(p); |
835 | 582 wlen = (int)(p - mip->mi_word); |
339 | 583 } |
300 | 584 } |
236 | 585 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
586 // Check flags and region. For FIND_PREFIX check the condition and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
587 // prefix ID. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
588 // Repeat this if there are more flags/region alternatives until there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
589 // is a match. |
339 | 590 res = SP_BAD; |
591 for (len = byts[arridx - 1]; len > 0 && byts[arridx] == 0; | |
592 --len, ++arridx) | |
300 | 593 { |
594 flags = idxs[arridx]; | |
324 | 595 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
596 // For the fold-case tree check that the case of the checked word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
597 // matches with what the word in the tree requires. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
598 // For keep-case tree the case is always right. For prefixes we |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
599 // don't bother to check. |
339 | 600 if (mode == FIND_FOLDWORD) |
300 | 601 { |
602 if (mip->mi_cend != mip->mi_word + wlen) | |
603 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
604 // mi_capflags was set for a different word length, need |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
605 // to do it again. |
300 | 606 mip->mi_cend = mip->mi_word + wlen; |
323 | 607 mip->mi_capflags = captype(mip->mi_word, mip->mi_cend); |
300 | 608 } |
609 | |
346 | 610 if (mip->mi_capflags == WF_KEEPCAP |
611 || !spell_valid_case(mip->mi_capflags, flags)) | |
339 | 612 continue; |
300 | 613 } |
236 | 614 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
615 // When mode is FIND_PREFIX the word must support the prefix: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
616 // check the prefix ID and the condition. Do that for the list at |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
617 // mip->mi_prefarridx that find_prefix() filled. |
485 | 618 else if (mode == FIND_PREFIX && !prefix_found) |
481 | 619 { |
366 | 620 c = valid_word_prefix(mip->mi_prefcnt, mip->mi_prefarridx, |
390 | 621 flags, |
455 | 622 mip->mi_word + mip->mi_cprefixlen, slang, |
623 FALSE); | |
366 | 624 if (c == 0) |
339 | 625 continue; |
366 | 626 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
627 // Use the WF_RARE flag for a rare prefix. |
366 | 628 if (c & WF_RAREPFX) |
629 flags |= WF_RARE; | |
485 | 630 prefix_found = TRUE; |
339 | 631 } |
632 | |
492 | 633 if (slang->sl_nobreak) |
634 { | |
635 if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND) | |
636 && (flags & WF_BANNED) == 0) | |
637 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
638 // NOBREAK: found a valid following word. That's all we |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
639 // need to know, so return. |
492 | 640 mip->mi_result = SP_OK; |
641 break; | |
642 } | |
643 } | |
644 | |
645 else if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND | |
646 || !word_ends)) | |
481 | 647 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
648 // If there is no compound flag or the word is shorter than |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
649 // COMPOUNDMIN reject it quickly. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
650 // Makes you wonder why someone puts a compound flag on a word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
651 // that's too short... Myspell compatibility requires this |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
652 // anyway. |
490 | 653 if (((unsigned)flags >> 24) == 0 |
654 || wlen - mip->mi_compoff < slang->sl_compminlen) | |
483 | 655 continue; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
656 // For multi-byte chars check character length against |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
657 // COMPOUNDMIN. |
500 | 658 if (has_mbyte |
501 | 659 && slang->sl_compminlen > 0 |
500 | 660 && mb_charlen_len(mip->mi_word + mip->mi_compoff, |
661 wlen - mip->mi_compoff) < slang->sl_compminlen) | |
662 continue; | |
483 | 663 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
664 // Limit the number of compound words to COMPOUNDWORDMAX if no |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
665 // maximum for syllables is specified. |
809 | 666 if (!word_ends && mip->mi_complen + mip->mi_compextra + 2 |
667 > slang->sl_compmax | |
490 | 668 && slang->sl_compsylmax == MAXWLEN) |
483 | 669 continue; |
670 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
671 // Don't allow compounding on a side where an affix was added, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
672 // unless COMPOUNDPERMITFLAG was used. |
819 | 673 if (mip->mi_complen > 0 && (flags & WF_NOCOMPBEF)) |
674 continue; | |
675 if (!word_ends && (flags & WF_NOCOMPAFT)) | |
676 continue; | |
677 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
678 // Quickly check if compounding is possible with this flag. |
495 | 679 if (!byte_in_str(mip->mi_complen == 0 |
485 | 680 ? slang->sl_compstartflags |
681 : slang->sl_compallflags, | |
495 | 682 ((unsigned)flags >> 24))) |
481 | 683 continue; |
684 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
685 // If there is a match with a CHECKCOMPOUNDPATTERN rule |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
686 // discard the compound word. |
1762 | 687 if (match_checkcompoundpattern(ptr, wlen, &slang->sl_comppat)) |
688 continue; | |
689 | |
490 | 690 if (mode == FIND_COMPOUND) |
691 { | |
692 int capflags; | |
693 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
694 // Need to check the caps type of the appended compound |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
695 // word. |
490 | 696 if (has_mbyte && STRNCMP(ptr, mip->mi_word, |
697 mip->mi_compoff) != 0) | |
698 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
699 // case folding may have changed the length |
490 | 700 p = mip->mi_word; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
701 for (s = ptr; s < ptr + mip->mi_compoff; MB_PTR_ADV(s)) |
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
702 MB_PTR_ADV(p); |
490 | 703 } |
704 else | |
705 p = mip->mi_word + mip->mi_compoff; | |
706 capflags = captype(p, mip->mi_word + wlen); | |
707 if (capflags == WF_KEEPCAP || (capflags == WF_ALLCAP | |
708 && (flags & WF_FIXCAP) != 0)) | |
709 continue; | |
710 | |
711 if (capflags != WF_ALLCAP) | |
712 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
713 // When the character before the word is a word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
714 // character we do not accept a Onecap word. We do |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
715 // accept a no-caps word, even when the dictionary |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
716 // word specifies ONECAP. |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
717 MB_PTR_BACK(mip->mi_word, p); |
5477 | 718 if (spell_iswordp_nmw(p, mip->mi_win) |
490 | 719 ? capflags == WF_ONECAP |
720 : (flags & WF_ONECAP) != 0 | |
721 && capflags != WF_ONECAP) | |
722 continue; | |
723 } | |
724 } | |
725 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
726 // If the word ends the sequence of compound flags of the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
727 // words must match with one of the COMPOUNDRULE items and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
728 // the number of syllables must not be too large. |
483 | 729 mip->mi_compflags[mip->mi_complen] = ((unsigned)flags >> 24); |
730 mip->mi_compflags[mip->mi_complen + 1] = NUL; | |
731 if (word_ends) | |
732 { | |
733 char_u fword[MAXWLEN]; | |
734 | |
735 if (slang->sl_compsylmax < MAXWLEN) | |
736 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
737 // "fword" is only needed for checking syllables. |
483 | 738 if (ptr == mip->mi_word) |
24872
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
739 (void)spell_casefold(mip->mi_win, |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
740 ptr, wlen, fword, MAXWLEN); |
483 | 741 else |
742 vim_strncpy(fword, ptr, endlen[endidxcnt]); | |
743 } | |
744 if (!can_compound(slang, fword, mip->mi_compflags)) | |
745 continue; | |
746 } | |
1762 | 747 else if (slang->sl_comprules != NULL |
748 && !match_compoundrule(slang, mip->mi_compflags)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
749 // The compound flags collected so far do not match any |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
750 // COMPOUNDRULE, discard the compounded word. |
1762 | 751 continue; |
481 | 752 } |
753 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
754 // Check NEEDCOMPOUND: can't use word without compounding. |
500 | 755 else if (flags & WF_NEEDCOMP) |
756 continue; | |
757 | |
492 | 758 nobreak_result = SP_OK; |
759 | |
481 | 760 if (!word_ends) |
761 { | |
492 | 762 int save_result = mip->mi_result; |
763 char_u *save_end = mip->mi_end; | |
501 | 764 langp_T *save_lp = mip->mi_lp; |
765 int lpi; | |
492 | 766 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
767 // Check that a valid word follows. If there is one and we |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
768 // are compounding, it will set "mi_result", thus we are |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
769 // always finished here. For NOBREAK we only check that a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
770 // valid word follows. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
771 // Recursive! |
492 | 772 if (slang->sl_nobreak) |
773 mip->mi_result = SP_BAD; | |
481 | 774 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
775 // Find following word in case-folded tree. |
481 | 776 mip->mi_compoff = endlen[endidxcnt]; |
777 if (has_mbyte && mode == FIND_KEEPWORD) | |
778 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
779 // Compute byte length in case-folded word from "wlen": |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
780 // byte length in keep-case word. Length may change when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
781 // folding case. This can be slow, take a shortcut when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
782 // the case-folded word is equal to the keep-case word. |
481 | 783 p = mip->mi_fword; |
784 if (STRNCMP(ptr, p, wlen) != 0) | |
785 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
786 for (s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) |
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
787 MB_PTR_ADV(p); |
835 | 788 mip->mi_compoff = (int)(p - mip->mi_fword); |
481 | 789 } |
790 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
791 #if 0 // Disabled, see below |
485 | 792 c = mip->mi_compoff; |
8956
d9e671c5afe6
commit https://github.com/vim/vim/commit/ba53435144f46eaaa53c63a62e748b3feee9742c
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
793 #endif |
483 | 794 ++mip->mi_complen; |
809 | 795 if (flags & WF_COMPROOT) |
796 ++mip->mi_compextra; | |
501 | 797 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
798 // For NOBREAK we need to try all NOBREAK languages, at least |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
799 // to find the ".add" file(s). |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
800 for (lpi = 0; lpi < mip->mi_win->w_s->b_langp.ga_len; ++lpi) |
501 | 801 { |
802 if (slang->sl_nobreak) | |
803 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
804 mip->mi_lp = LANGP_ENTRY(mip->mi_win->w_s->b_langp, lpi); |
501 | 805 if (mip->mi_lp->lp_slang->sl_fidxs == NULL |
806 || !mip->mi_lp->lp_slang->sl_nobreak) | |
807 continue; | |
808 } | |
809 | |
810 find_word(mip, FIND_COMPOUND); | |
811 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
812 // When NOBREAK any word that matches is OK. Otherwise we |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
813 // need to find the longest match, thus try with keep-case |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
814 // and prefix too. |
492 | 815 if (!slang->sl_nobreak || mip->mi_result == SP_BAD) |
816 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
817 // Find following word in keep-case tree. |
501 | 818 mip->mi_compoff = wlen; |
819 find_word(mip, FIND_KEEPCOMPOUND); | |
820 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
821 #if 0 // Disabled, a prefix must not appear halfway a compound word, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
822 // unless the COMPOUNDPERMITFLAG is used and then it can't be a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
823 // postponed prefix. |
501 | 824 if (!slang->sl_nobreak || mip->mi_result == SP_BAD) |
825 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
826 // Check for following word with prefix. |
501 | 827 mip->mi_compoff = c; |
828 find_prefix(mip, FIND_COMPOUND); | |
829 } | |
819 | 830 #endif |
492 | 831 } |
501 | 832 |
833 if (!slang->sl_nobreak) | |
834 break; | |
492 | 835 } |
483 | 836 --mip->mi_complen; |
809 | 837 if (flags & WF_COMPROOT) |
838 --mip->mi_compextra; | |
501 | 839 mip->mi_lp = save_lp; |
485 | 840 |
492 | 841 if (slang->sl_nobreak) |
842 { | |
843 nobreak_result = mip->mi_result; | |
844 mip->mi_result = save_result; | |
845 mip->mi_end = save_end; | |
846 } | |
847 else | |
848 { | |
849 if (mip->mi_result == SP_OK) | |
850 break; | |
851 continue; | |
852 } | |
481 | 853 } |
854 | |
339 | 855 if (flags & WF_BANNED) |
856 res = SP_BANNED; | |
857 else if (flags & WF_REGION) | |
858 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
859 // Check region. |
390 | 860 if ((mip->mi_lp->lp_region & (flags >> 16)) != 0) |
300 | 861 res = SP_OK; |
339 | 862 else |
863 res = SP_LOCAL; | |
300 | 864 } |
339 | 865 else if (flags & WF_RARE) |
866 res = SP_RARE; | |
307 | 867 else |
339 | 868 res = SP_OK; |
869 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
870 // Always use the longest match and the best result. For NOBREAK |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
871 // we separately keep the longest match without a following good |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
872 // word as a fall-back. |
492 | 873 if (nobreak_result == SP_BAD) |
874 { | |
875 if (mip->mi_result2 > res) | |
876 { | |
877 mip->mi_result2 = res; | |
878 mip->mi_end2 = mip->mi_word + wlen; | |
879 } | |
880 else if (mip->mi_result2 == res | |
881 && mip->mi_end2 < mip->mi_word + wlen) | |
882 mip->mi_end2 = mip->mi_word + wlen; | |
883 } | |
884 else if (mip->mi_result > res) | |
339 | 885 { |
886 mip->mi_result = res; | |
887 mip->mi_end = mip->mi_word + wlen; | |
888 } | |
351 | 889 else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen) |
339 | 890 mip->mi_end = mip->mi_word + wlen; |
891 | |
492 | 892 if (mip->mi_result == SP_OK) |
339 | 893 break; |
300 | 894 } |
895 | |
492 | 896 if (mip->mi_result == SP_OK) |
300 | 897 break; |
898 } | |
236 | 899 } |
900 | |
323 | 901 /* |
1762 | 902 * Return TRUE if there is a match between the word ptr[wlen] and |
903 * CHECKCOMPOUNDPATTERN rules, assuming that we will concatenate with another | |
904 * word. | |
905 * A match means that the first part of CHECKCOMPOUNDPATTERN matches at the | |
906 * end of ptr[wlen] and the second part matches after it. | |
907 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
908 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
909 match_checkcompoundpattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
910 char_u *ptr, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
911 int wlen, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
912 garray_T *gap) // &sl_comppat |
1762 | 913 { |
914 int i; | |
915 char_u *p; | |
916 int len; | |
917 | |
918 for (i = 0; i + 1 < gap->ga_len; i += 2) | |
919 { | |
920 p = ((char_u **)gap->ga_data)[i + 1]; | |
921 if (STRNCMP(ptr + wlen, p, STRLEN(p)) == 0) | |
922 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
923 // Second part matches at start of following compound word, now |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
924 // check if first part matches at end of previous word. |
1762 | 925 p = ((char_u **)gap->ga_data)[i]; |
1771 | 926 len = (int)STRLEN(p); |
1762 | 927 if (len <= wlen && STRNCMP(ptr + wlen - len, p, len) == 0) |
928 return TRUE; | |
929 } | |
930 } | |
931 return FALSE; | |
932 } | |
933 | |
934 /* | |
626 | 935 * Return TRUE if "flags" is a valid sequence of compound flags and "word" |
936 * does not have too many syllables. | |
482 | 937 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
938 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
939 can_compound(slang_T *slang, char_u *word, char_u *flags) |
483 | 940 { |
495 | 941 char_u uflags[MAXWLEN * 2]; |
942 int i; | |
943 char_u *p; | |
483 | 944 |
945 if (slang->sl_compprog == NULL) | |
946 return FALSE; | |
495 | 947 if (enc_utf8) |
948 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
949 // Need to convert the single byte flags to utf8 characters. |
495 | 950 p = uflags; |
951 for (i = 0; flags[i] != NUL; ++i) | |
11269
121d29004998
patch 8.0.0520: using a function pointer while the function is known
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
952 p += utf_char2bytes(flags[i], p); |
495 | 953 *p = NUL; |
954 p = uflags; | |
955 } | |
956 else | |
957 p = flags; | |
6375 | 958 if (!vim_regexec_prog(&slang->sl_compprog, FALSE, p, 0)) |
483 | 959 return FALSE; |
960 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
961 // Count the number of syllables. This may be slow, do it last. If there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
962 // are too many syllables AND the number of compound words is above |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
963 // COMPOUNDWORDMAX then compounding is not allowed. |
483 | 964 if (slang->sl_compsylmax < MAXWLEN |
965 && count_syllables(slang, word) > slang->sl_compsylmax) | |
495 | 966 return (int)STRLEN(flags) < slang->sl_compmax; |
483 | 967 return TRUE; |
482 | 968 } |
969 | |
970 /* | |
1762 | 971 * Return TRUE if the compound flags in compflags[] match the start of any |
972 * compound rule. This is used to stop trying a compound if the flags | |
973 * collected so far can't possibly match any compound rule. | |
974 * Caller must check that slang->sl_comprules is not NULL. | |
975 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
976 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
977 match_compoundrule(slang_T *slang, char_u *compflags) |
1762 | 978 { |
979 char_u *p; | |
980 int i; | |
981 int c; | |
982 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
983 // loop over all the COMPOUNDRULE entries |
1762 | 984 for (p = slang->sl_comprules; *p != NUL; ++p) |
985 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
986 // loop over the flags in the compound word we have made, match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
987 // them against the current rule entry |
1762 | 988 for (i = 0; ; ++i) |
989 { | |
990 c = compflags[i]; | |
991 if (c == NUL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
992 // found a rule that matches for the flags we have so far |
1762 | 993 return TRUE; |
994 if (*p == '/' || *p == NUL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
995 break; // end of rule, it's too short |
1762 | 996 if (*p == '[') |
997 { | |
998 int match = FALSE; | |
999 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1000 // compare against all the flags in [] |
1762 | 1001 ++p; |
1002 while (*p != ']' && *p != NUL) | |
1003 if (*p++ == c) | |
1004 match = TRUE; | |
1005 if (!match) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1006 break; // none matches |
1762 | 1007 } |
1008 else if (*p != c) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1009 break; // flag of word doesn't match flag in pattern |
1762 | 1010 ++p; |
1011 } | |
1012 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1013 // Skip to the next "/", where the next pattern starts. |
1762 | 1014 p = vim_strchr(p, '/'); |
1015 if (p == NULL) | |
1016 break; | |
1017 } | |
1018 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1019 // Checked all the rules and none of them match the flags, so there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1020 // can't possibly be a compound starting with these flags. |
1762 | 1021 return FALSE; |
1022 } | |
1023 | |
1024 /* | |
390 | 1025 * Return non-zero if the prefix indicated by "arridx" matches with the prefix |
1026 * ID in "flags" for the word "word". | |
366 | 1027 * The WF_RAREPFX flag is included in the return value for a rare prefix. |
351 | 1028 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1029 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1030 valid_word_prefix( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1031 int totprefcnt, // nr of prefix IDs |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1032 int arridx, // idx in sl_pidxs[] |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1033 int flags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1034 char_u *word, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1035 slang_T *slang, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1036 int cond_req) // only use prefixes with a condition |
351 | 1037 { |
1038 int prefcnt; | |
1039 int pidx; | |
6375 | 1040 regprog_T **rp; |
390 | 1041 int prefid; |
1042 | |
1043 prefid = (unsigned)flags >> 24; | |
351 | 1044 for (prefcnt = totprefcnt - 1; prefcnt >= 0; --prefcnt) |
1045 { | |
1046 pidx = slang->sl_pidxs[arridx + prefcnt]; | |
1047 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1048 // Check the prefix ID. |
351 | 1049 if (prefid != (pidx & 0xff)) |
1050 continue; | |
1051 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1052 // Check if the prefix doesn't combine and the word already has a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1053 // suffix. |
390 | 1054 if ((flags & WF_HAS_AFF) && (pidx & WF_PFX_NC)) |
1055 continue; | |
1056 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1057 // Check the condition, if there is one. The condition index is |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1058 // stored in the two bytes above the prefix ID byte. |
6375 | 1059 rp = &slang->sl_prefprog[((unsigned)pidx >> 8) & 0xffff]; |
1060 if (*rp != NULL) | |
1061 { | |
1062 if (!vim_regexec_prog(rp, FALSE, word, 0)) | |
351 | 1063 continue; |
1064 } | |
455 | 1065 else if (cond_req) |
1066 continue; | |
1067 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1068 // It's a match! Return the WF_ flags. |
366 | 1069 return pidx; |
1070 } | |
1071 return 0; | |
351 | 1072 } |
1073 | |
1074 /* | |
339 | 1075 * Check if the word at "mip->mi_word" has a matching prefix. |
1076 * If it does, then check the following word. | |
1077 * | |
485 | 1078 * If "mode" is "FIND_COMPOUND" then do the same after another word, find a |
1079 * prefix in a compound word. | |
1080 * | |
339 | 1081 * For a match mip->mi_result is updated. |
1082 */ | |
1083 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1084 find_prefix(matchinf_T *mip, int mode) |
339 | 1085 { |
1086 idx_T arridx = 0; | |
1087 int len; | |
1088 int wlen = 0; | |
1089 int flen; | |
1090 int c; | |
1091 char_u *ptr; | |
1092 idx_T lo, hi, m; | |
1093 slang_T *slang = mip->mi_lp->lp_slang; | |
1094 char_u *byts; | |
1095 idx_T *idxs; | |
1096 | |
375 | 1097 byts = slang->sl_pbyts; |
1098 if (byts == NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1099 return; // array is empty |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1100 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1101 // We use the case-folded word here, since prefixes are always |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1102 // case-folded. |
339 | 1103 ptr = mip->mi_fword; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1104 flen = mip->mi_fwordlen; // available case-folded bytes |
485 | 1105 if (mode == FIND_COMPOUND) |
1106 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1107 // Skip over the previously found word(s). |
485 | 1108 ptr += mip->mi_compoff; |
1109 flen -= mip->mi_compoff; | |
1110 } | |
339 | 1111 idxs = slang->sl_pidxs; |
1112 | |
1113 /* | |
1114 * Repeat advancing in the tree until: | |
1115 * - there is a byte that doesn't match, | |
1116 * - we reach the end of the tree, | |
1117 * - or we reach the end of the line. | |
1118 */ | |
1119 for (;;) | |
1120 { | |
1121 if (flen == 0 && *mip->mi_fend != NUL) | |
1122 flen = fold_more(mip); | |
1123 | |
1124 len = byts[arridx++]; | |
1125 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1126 // If the first possible byte is a zero the prefix could end here. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1127 // Check if the following word matches and supports the prefix. |
339 | 1128 if (byts[arridx] == 0) |
1129 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1130 // There can be several prefixes with different conditions. We |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1131 // try them all, since we don't know which one will give the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1132 // longest match. The word is the same each time, pass the list |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1133 // of possible prefixes to find_word(). |
339 | 1134 mip->mi_prefarridx = arridx; |
1135 mip->mi_prefcnt = len; | |
1136 while (len > 0 && byts[arridx] == 0) | |
1137 { | |
1138 ++arridx; | |
1139 --len; | |
1140 } | |
1141 mip->mi_prefcnt -= len; | |
1142 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1143 // Find the word that comes after the prefix. |
339 | 1144 mip->mi_prefixlen = wlen; |
485 | 1145 if (mode == FIND_COMPOUND) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1146 // Skip over the previously found word(s). |
485 | 1147 mip->mi_prefixlen += mip->mi_compoff; |
1148 | |
455 | 1149 if (has_mbyte) |
1150 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1151 // Case-folded length may differ from original length. |
485 | 1152 mip->mi_cprefixlen = nofold_len(mip->mi_fword, |
1153 mip->mi_prefixlen, mip->mi_word); | |
455 | 1154 } |
1155 else | |
485 | 1156 mip->mi_cprefixlen = mip->mi_prefixlen; |
339 | 1157 find_word(mip, FIND_PREFIX); |
1158 | |
1159 | |
1160 if (len == 0) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1161 break; // no children, word must end here |
339 | 1162 } |
1163 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1164 // Stop looking at end of the line. |
339 | 1165 if (ptr[wlen] == NUL) |
1166 break; | |
1167 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1168 // Perform a binary search in the list of accepted bytes. |
339 | 1169 c = ptr[wlen]; |
1170 lo = arridx; | |
1171 hi = arridx + len - 1; | |
1172 while (lo < hi) | |
1173 { | |
1174 m = (lo + hi) / 2; | |
1175 if (byts[m] > c) | |
1176 hi = m - 1; | |
1177 else if (byts[m] < c) | |
1178 lo = m + 1; | |
1179 else | |
1180 { | |
1181 lo = hi = m; | |
1182 break; | |
1183 } | |
1184 } | |
1185 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1186 // Stop if there is no matching byte. |
339 | 1187 if (hi < lo || byts[lo] != c) |
1188 break; | |
1189 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1190 // Continue at the child (if there is one). |
339 | 1191 arridx = idxs[lo]; |
1192 ++wlen; | |
1193 --flen; | |
1194 } | |
1195 } | |
1196 | |
1197 /* | |
1198 * Need to fold at least one more character. Do until next non-word character | |
626 | 1199 * for efficiency. Include the non-word character too. |
339 | 1200 * Return the length of the folded chars in bytes. |
1201 */ | |
1202 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1203 fold_more(matchinf_T *mip) |
339 | 1204 { |
1205 int flen; | |
1206 char_u *p; | |
1207 | |
1208 p = mip->mi_fend; | |
1209 do | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1210 MB_PTR_ADV(mip->mi_fend); |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
16142
diff
changeset
|
1211 while (*mip->mi_fend != NUL && spell_iswordp(mip->mi_fend, mip->mi_win)); |
339 | 1212 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1213 // Include the non-word character so that we can check for the word end. |
339 | 1214 if (*mip->mi_fend != NUL) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1215 MB_PTR_ADV(mip->mi_fend); |
339 | 1216 |
24872
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
1217 (void)spell_casefold(mip->mi_win, p, (int)(mip->mi_fend - p), |
339 | 1218 mip->mi_fword + mip->mi_fwordlen, |
1219 MAXWLEN - mip->mi_fwordlen); | |
835 | 1220 flen = (int)STRLEN(mip->mi_fword + mip->mi_fwordlen); |
339 | 1221 mip->mi_fwordlen += flen; |
1222 return flen; | |
1223 } | |
1224 | |
1225 /* | |
323 | 1226 * Check case flags for a word. Return TRUE if the word has the requested |
1227 * case. | |
1228 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1229 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1230 spell_valid_case( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1231 int wordflags, // flags for the checked word. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1232 int treeflags) // flags for the word in the spell tree |
323 | 1233 { |
389 | 1234 return ((wordflags == WF_ALLCAP && (treeflags & WF_FIXCAP) == 0) |
323 | 1235 || ((treeflags & (WF_ALLCAP | WF_KEEPCAP)) == 0 |
474 | 1236 && ((treeflags & WF_ONECAP) == 0 |
1237 || (wordflags & WF_ONECAP) != 0))); | |
323 | 1238 } |
1239 | |
351 | 1240 /* |
30509
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1241 * Return TRUE if spell checking is enabled for "wp". |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1242 */ |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1243 int |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1244 spell_check_window(win_T *wp) |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1245 { |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1246 return wp->w_p_spell |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1247 && *wp->w_s->b_p_spl != NUL |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1248 && wp->w_s->b_langp.ga_len > 0 |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1249 && *(char **)(wp->w_s->b_langp.ga_data) != NULL; |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1250 } |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1251 |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1252 /* |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1253 * Return TRUE and give an error if spell checking is not enabled. |
351 | 1254 */ |
25567
0082503ff2ff
patch 8.2.3320: some local functions are not static
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1255 static int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1256 no_spell_checking(win_T *wp) |
498 | 1257 { |
30509
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1258 if (spell_check_window(wp)) |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1259 return FALSE; |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1260 emsg(_(e_spell_checking_is_not_possible)); |
087c42245022
patch 9.0.0590: after exiting Insert mode spelling not checked in next line
Bram Moolenaar <Bram@vim.org>
parents:
29732
diff
changeset
|
1261 return TRUE; |
351 | 1262 } |
300 | 1263 |
236 | 1264 /* |
1265 * Move to next spell error. | |
500 | 1266 * "curline" is FALSE for "[s", "]s", "[S" and "]S". |
1267 * "curline" is TRUE to find word under/after cursor in the same line. | |
483 | 1268 * For Insert mode completion "dir" is BACKWARD and "curline" is TRUE: move |
1269 * to after badly spelled word before the cursor. | |
495 | 1270 * Return 0 if not found, length of the badly spelled word otherwise. |
236 | 1271 */ |
1272 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1273 spell_move_to( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1274 win_T *wp, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1275 int dir, // FORWARD or BACKWARD |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1276 int allwords, // TRUE for "[s"/"]s", FALSE for "[S"/"]S" |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1277 int curline, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1278 hlf_T *attrp) // return: attributes of bad word or NULL |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1279 // (only when "dir" is FORWARD) |
236 | 1280 { |
249 | 1281 linenr_T lnum; |
1282 pos_T found_pos; | |
495 | 1283 int found_len = 0; |
236 | 1284 char_u *line; |
1285 char_u *p; | |
346 | 1286 char_u *endp; |
29102
fd9006d6ddcf
patch 8.2.5072: using uninitialized value and freed memory in spell command
Bram Moolenaar <Bram@vim.org>
parents:
28925
diff
changeset
|
1287 hlf_T attr = 0; |
236 | 1288 int len; |
5519 | 1289 #ifdef FEAT_SYN_HL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1290 int has_syntax = syntax_present(wp); |
5519 | 1291 #endif |
249 | 1292 int col; |
1293 int can_spell; | |
346 | 1294 char_u *buf = NULL; |
1295 int buflen = 0; | |
1296 int skip = 0; | |
385 | 1297 int capcol = -1; |
500 | 1298 int found_one = FALSE; |
1299 int wrapped = FALSE; | |
236 | 1300 |
498 | 1301 if (no_spell_checking(wp)) |
495 | 1302 return 0; |
236 | 1303 |
249 | 1304 /* |
1305 * Start looking for bad word at the start of the line, because we can't | |
817 | 1306 * start halfway a word, we don't know where it starts or ends. |
249 | 1307 * |
1308 * When searching backwards, we continue in the line to find the last | |
1309 * bad word (in the cursor line: before the cursor). | |
346 | 1310 * |
1311 * We concatenate the start of the next line, so that wrapped words work | |
1312 * (e.g. "et<line-break>cetera"). Doesn't work when searching backwards | |
1313 * though... | |
249 | 1314 */ |
498 | 1315 lnum = wp->w_cursor.lnum; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10950
diff
changeset
|
1316 CLEAR_POS(&found_pos); |
236 | 1317 |
1318 while (!got_int) | |
1319 { | |
29102
fd9006d6ddcf
patch 8.2.5072: using uninitialized value and freed memory in spell command
Bram Moolenaar <Bram@vim.org>
parents:
28925
diff
changeset
|
1320 int empty_line; |
fd9006d6ddcf
patch 8.2.5072: using uninitialized value and freed memory in spell command
Bram Moolenaar <Bram@vim.org>
parents:
28925
diff
changeset
|
1321 |
498 | 1322 line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
346 | 1323 |
835 | 1324 len = (int)STRLEN(line); |
346 | 1325 if (buflen < len + MAXWLEN + 2) |
1326 { | |
1327 vim_free(buf); | |
1328 buflen = len + MAXWLEN + 2; | |
1329 buf = alloc(buflen); | |
1330 if (buf == NULL) | |
1331 break; | |
1332 } | |
1333 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1334 // In first line check first word for Capital. |
385 | 1335 if (lnum == 1) |
1336 capcol = 0; | |
1337 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1338 // For checking first word with a capital skip white space. |
385 | 1339 if (capcol == 0) |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1340 capcol = getwhitecols(line); |
835 | 1341 else if (curline && wp == curwin) |
1342 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1343 // For spellbadword(): check if first word needs a capital. |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1344 col = getwhitecols(line); |
835 | 1345 if (check_need_cap(lnum, col)) |
1346 capcol = col; | |
1347 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1348 // Need to get the line again, may have looked at the previous |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1349 // one. |
835 | 1350 line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
1351 } | |
385 | 1352 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1353 // Copy the line into "buf" and append the start of the next line if |
29102
fd9006d6ddcf
patch 8.2.5072: using uninitialized value and freed memory in spell command
Bram Moolenaar <Bram@vim.org>
parents:
28925
diff
changeset
|
1354 // possible. Note: this ml_get_buf() may make "line" invalid, check |
fd9006d6ddcf
patch 8.2.5072: using uninitialized value and freed memory in spell command
Bram Moolenaar <Bram@vim.org>
parents:
28925
diff
changeset
|
1355 // for empty line first. |
fd9006d6ddcf
patch 8.2.5072: using uninitialized value and freed memory in spell command
Bram Moolenaar <Bram@vim.org>
parents:
28925
diff
changeset
|
1356 empty_line = *skipwhite(line) == NUL; |
346 | 1357 STRCPY(buf, line); |
498 | 1358 if (lnum < wp->w_buffer->b_ml.ml_line_count) |
883 | 1359 spell_cat_line(buf + STRLEN(buf), |
1360 ml_get_buf(wp->w_buffer, lnum + 1, FALSE), MAXWLEN); | |
346 | 1361 |
1362 p = buf + skip; | |
1363 endp = buf + len; | |
1364 while (p < endp) | |
236 | 1365 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1366 // When searching backward don't search after the cursor. Unless |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1367 // we wrapped around the end of the buffer. |
300 | 1368 if (dir == BACKWARD |
498 | 1369 && lnum == wp->w_cursor.lnum |
500 | 1370 && !wrapped |
498 | 1371 && (colnr_T)(p - buf) >= wp->w_cursor.col) |
300 | 1372 break; |
249 | 1373 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1374 // start of word |
534 | 1375 attr = HLF_COUNT; |
625 | 1376 len = spell_check(wp, p, &attr, &capcol, FALSE); |
249 | 1377 |
534 | 1378 if (attr != HLF_COUNT) |
300 | 1379 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1380 // We found a bad word. Check the attribute. |
534 | 1381 if (allwords || attr == HLF_SPB) |
236 | 1382 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1383 // When searching forward only accept a bad word after |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1384 // the cursor. |
300 | 1385 if (dir == BACKWARD |
500 | 1386 || lnum != wp->w_cursor.lnum |
28169
bef82285dda0
patch 8.2.4610: some conditions are always true
Bram Moolenaar <Bram@vim.org>
parents:
27752
diff
changeset
|
1387 || (wrapped |
bef82285dda0
patch 8.2.4610: some conditions are always true
Bram Moolenaar <Bram@vim.org>
parents:
27752
diff
changeset
|
1388 || (colnr_T)(curline ? p - buf + len |
346 | 1389 : p - buf) |
28169
bef82285dda0
patch 8.2.4610: some conditions are always true
Bram Moolenaar <Bram@vim.org>
parents:
27752
diff
changeset
|
1390 > wp->w_cursor.col)) |
236 | 1391 { |
5519 | 1392 #ifdef FEAT_SYN_HL |
300 | 1393 if (has_syntax) |
249 | 1394 { |
835 | 1395 col = (int)(p - buf); |
498 | 1396 (void)syn_get_id(wp, lnum, (colnr_T)col, |
1504 | 1397 FALSE, &can_spell, FALSE); |
857 | 1398 if (!can_spell) |
1399 attr = HLF_COUNT; | |
300 | 1400 } |
1401 else | |
737 | 1402 #endif |
300 | 1403 can_spell = TRUE; |
249 | 1404 |
300 | 1405 if (can_spell) |
1406 { | |
857 | 1407 found_one = TRUE; |
300 | 1408 found_pos.lnum = lnum; |
835 | 1409 found_pos.col = (int)(p - buf); |
300 | 1410 found_pos.coladd = 0; |
1411 if (dir == FORWARD) | |
1412 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1413 // No need to search further. |
498 | 1414 wp->w_cursor = found_pos; |
346 | 1415 vim_free(buf); |
498 | 1416 if (attrp != NULL) |
1417 *attrp = attr; | |
495 | 1418 return len; |
249 | 1419 } |
483 | 1420 else if (curline) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1421 // Insert mode completion: put cursor after |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1422 // the bad word. |
483 | 1423 found_pos.col += len; |
495 | 1424 found_len = len; |
249 | 1425 } |
236 | 1426 } |
857 | 1427 else |
1428 found_one = TRUE; | |
236 | 1429 } |
1430 } | |
1431 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1432 // advance to character after the word |
300 | 1433 p += len; |
385 | 1434 capcol -= len; |
236 | 1435 } |
1436 | |
483 | 1437 if (dir == BACKWARD && found_pos.lnum != 0) |
1438 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1439 // Use the last match in the line (before the cursor). |
498 | 1440 wp->w_cursor = found_pos; |
483 | 1441 vim_free(buf); |
495 | 1442 return found_len; |
483 | 1443 } |
1444 | |
323 | 1445 if (curline) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1446 break; // only check cursor line |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1447 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1448 // If we are back at the starting line and searched it again there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1449 // is no match, give up. |
10950
2297aae8e127
patch 8.0.0364: ]s does not move cursor with two spell errors in one line
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1450 if (lnum == wp->w_cursor.lnum && wrapped) |
2297aae8e127
patch 8.0.0364: ]s does not move cursor with two spell errors in one line
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1451 break; |
2297aae8e127
patch 8.0.0364: ]s does not move cursor with two spell errors in one line
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1452 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1453 // Advance to next line. |
249 | 1454 if (dir == BACKWARD) |
1455 { | |
500 | 1456 if (lnum > 1) |
1457 --lnum; | |
1458 else if (!p_ws) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1459 break; // at first line and 'nowrapscan' |
500 | 1460 else |
1461 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1462 // Wrap around to the end of the buffer. May search the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1463 // starting line again and accept the last match. |
500 | 1464 lnum = wp->w_buffer->b_ml.ml_line_count; |
1465 wrapped = TRUE; | |
503 | 1466 if (!shortmess(SHM_SEARCH)) |
1467 give_warning((char_u *)_(top_bot_msg), TRUE); | |
500 | 1468 } |
385 | 1469 capcol = -1; |
249 | 1470 } |
1471 else | |
1472 { | |
500 | 1473 if (lnum < wp->w_buffer->b_ml.ml_line_count) |
1474 ++lnum; | |
1475 else if (!p_ws) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1476 break; // at first line and 'nowrapscan' |
500 | 1477 else |
1478 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1479 // Wrap around to the start of the buffer. May search the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1480 // starting line again and accept the first match. |
500 | 1481 lnum = 1; |
1482 wrapped = TRUE; | |
503 | 1483 if (!shortmess(SHM_SEARCH)) |
1484 give_warning((char_u *)_(bot_top_msg), TRUE); | |
500 | 1485 } |
1486 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1487 // If we are back at the starting line and there is no match then |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1488 // give up. |
10950
2297aae8e127
patch 8.0.0364: ]s does not move cursor with two spell errors in one line
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1489 if (lnum == wp->w_cursor.lnum && !found_one) |
346 | 1490 break; |
1491 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1492 // Skip the characters at the start of the next line that were |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1493 // included in a match crossing line boundaries. |
534 | 1494 if (attr == HLF_COUNT) |
835 | 1495 skip = (int)(p - endp); |
346 | 1496 else |
1497 skip = 0; | |
385 | 1498 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1499 // Capcol skips over the inserted space. |
385 | 1500 --capcol; |
1501 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1502 // But after empty line check first word in next line |
29102
fd9006d6ddcf
patch 8.2.5072: using uninitialized value and freed memory in spell command
Bram Moolenaar <Bram@vim.org>
parents:
28925
diff
changeset
|
1503 if (empty_line) |
385 | 1504 capcol = 0; |
249 | 1505 } |
236 | 1506 |
1507 line_breakcheck(); | |
1508 } | |
1509 | |
346 | 1510 vim_free(buf); |
495 | 1511 return 0; |
346 | 1512 } |
1513 | |
1514 /* | |
1515 * For spell checking: concatenate the start of the following line "line" into | |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
1516 * "buf", blanking-out special characters. Copy less than "maxlen" bytes. |
1577 | 1517 * Keep the blanks at the start of the next line, this is used in win_line() |
1518 * to skip those bytes if the word was OK. | |
346 | 1519 */ |
1520 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1521 spell_cat_line(char_u *buf, char_u *line, int maxlen) |
346 | 1522 { |
1523 char_u *p; | |
1524 int n; | |
1525 | |
1526 p = skipwhite(line); | |
1527 while (vim_strchr((char_u *)"*#/\"\t", *p) != NULL) | |
1528 p = skipwhite(p + 1); | |
1529 | |
1530 if (*p != NUL) | |
1531 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1532 // Only worth concatenating if there is something else than spaces to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1533 // concatenate. |
1577 | 1534 n = (int)(p - line) + 1; |
1535 if (n < maxlen - 1) | |
1536 { | |
1537 vim_memset(buf, ' ', n); | |
1538 vim_strncpy(buf + n, p, maxlen - 1 - n); | |
1539 } | |
346 | 1540 } |
236 | 1541 } |
1542 | |
626 | 1543 /* |
1544 * Structure used for the cookie argument of do_in_runtimepath(). | |
1545 */ | |
501 | 1546 typedef struct spelload_S |
1547 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1548 char_u sl_lang[MAXWLEN + 1]; // language name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1549 slang_T *sl_slang; // resulting slang_T struct |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1550 int sl_nobreak; // NOBREAK language found |
501 | 1551 } spelload_T; |
1552 | |
236 | 1553 /* |
307 | 1554 * Load word list(s) for "lang" from Vim spell file(s). |
310 | 1555 * "lang" must be the language without the region: e.g., "en". |
236 | 1556 */ |
307 | 1557 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1558 spell_load_lang(char_u *lang) |
236 | 1559 { |
310 | 1560 char_u fname_enc[85]; |
236 | 1561 int r; |
501 | 1562 spelload_T sl; |
649 | 1563 int round; |
307 | 1564 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1565 // Copy the language name to pass it to spell_load_cb() as a cookie. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1566 // It's truncated when an error is detected. |
501 | 1567 STRCPY(sl.sl_lang, lang); |
1568 sl.sl_slang = NULL; | |
1569 sl.sl_nobreak = FALSE; | |
307 | 1570 |
30558
8e73ecbee60d
patch 9.0.0614: SpellFileMissing autocmd may delete buffer
Bram Moolenaar <Bram@vim.org>
parents:
30509
diff
changeset
|
1571 // Disallow deleting the current buffer. Autocommands can do weird things |
8e73ecbee60d
patch 9.0.0614: SpellFileMissing autocmd may delete buffer
Bram Moolenaar <Bram@vim.org>
parents:
30509
diff
changeset
|
1572 // and cause "lang" to be freed. |
8e73ecbee60d
patch 9.0.0614: SpellFileMissing autocmd may delete buffer
Bram Moolenaar <Bram@vim.org>
parents:
30509
diff
changeset
|
1573 ++curbuf->b_locked; |
8e73ecbee60d
patch 9.0.0614: SpellFileMissing autocmd may delete buffer
Bram Moolenaar <Bram@vim.org>
parents:
30509
diff
changeset
|
1574 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1575 // We may retry when no spell file is found for the language, an |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1576 // autocommand may load it then. |
649 | 1577 for (round = 1; round <= 2; ++round) |
1578 { | |
1579 /* | |
1580 * Find the first spell file for "lang" in 'runtimepath' and load it. | |
1581 */ | |
1582 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, | |
2660 | 1583 #ifdef VMS |
1584 "spell/%s_%s.spl", | |
1585 #else | |
1586 "spell/%s.%s.spl", | |
1587 #endif | |
1588 lang, spell_enc()); | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
1589 r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); |
649 | 1590 |
1591 if (r == FAIL && *sl.sl_lang != NUL) | |
1592 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1593 // Try loading the ASCII version. |
649 | 1594 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, |
2660 | 1595 #ifdef VMS |
1596 "spell/%s_ascii.spl", | |
1597 #else | |
1598 "spell/%s.ascii.spl", | |
1599 #endif | |
1600 lang); | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
1601 r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); |
649 | 1602 |
1603 if (r == FAIL && *sl.sl_lang != NUL && round == 1 | |
1604 && apply_autocmds(EVENT_SPELLFILEMISSING, lang, | |
1605 curbuf->b_fname, FALSE, curbuf)) | |
1606 continue; | |
1607 break; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13308
diff
changeset
|
1608 } |
714 | 1609 break; |
307 | 1610 } |
1611 | |
1612 if (r == FAIL) | |
649 | 1613 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
1614 smsg( |
2660 | 1615 #ifdef VMS |
1616 _("Warning: Cannot find word list \"%s_%s.spl\" or \"%s_ascii.spl\""), | |
1617 #else | |
1618 _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), | |
1619 #endif | |
483 | 1620 lang, spell_enc(), lang); |
649 | 1621 } |
501 | 1622 else if (sl.sl_slang != NULL) |
1623 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1624 // At least one file was loaded, now load ALL the additions. |
310 | 1625 STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl"); |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
1626 do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl); |
310 | 1627 } |
30558
8e73ecbee60d
patch 9.0.0614: SpellFileMissing autocmd may delete buffer
Bram Moolenaar <Bram@vim.org>
parents:
30509
diff
changeset
|
1628 |
8e73ecbee60d
patch 9.0.0614: SpellFileMissing autocmd may delete buffer
Bram Moolenaar <Bram@vim.org>
parents:
30509
diff
changeset
|
1629 --curbuf->b_locked; |
310 | 1630 } |
1631 | |
1632 /* | |
1633 * Return the encoding used for spell checking: Use 'encoding', except that we | |
1634 * use "latin1" for "latin9". And limit to 60 characters (just in case). | |
1635 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1636 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1637 spell_enc(void) |
310 | 1638 { |
1639 | |
1640 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0) | |
1641 return p_enc; | |
1642 return (char_u *)"latin1"; | |
236 | 1643 } |
1644 | |
1645 /* | |
385 | 1646 * Get the name of the .spl file for the internal wordlist into |
1647 * "fname[MAXPATHL]". | |
1648 */ | |
1649 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1650 int_wordlist_spl(char_u *fname) |
385 | 1651 { |
2660 | 1652 vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL, |
385 | 1653 int_wordlist, spell_enc()); |
1654 } | |
1655 | |
1656 /* | |
625 | 1657 * Allocate a new slang_T for language "lang". "lang" can be NULL. |
236 | 1658 * Caller must fill "sl_next". |
1659 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1660 slang_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1661 slang_alloc(char_u *lang) |
236 | 1662 { |
1663 slang_T *lp; | |
1664 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1665 lp = ALLOC_CLEAR_ONE(slang_T); |
236 | 1666 if (lp != NULL) |
1667 { | |
625 | 1668 if (lang != NULL) |
1669 lp->sl_name = vim_strsave(lang); | |
323 | 1670 ga_init2(&lp->sl_rep, sizeof(fromto_T), 10); |
625 | 1671 ga_init2(&lp->sl_repsal, sizeof(fromto_T), 10); |
483 | 1672 lp->sl_compmax = MAXWLEN; |
1673 lp->sl_compsylmax = MAXWLEN; | |
625 | 1674 hash_init(&lp->sl_wordcount); |
1675 } | |
1676 | |
236 | 1677 return lp; |
1678 } | |
1679 | |
1680 /* | |
1681 * Free the contents of an slang_T and the structure itself. | |
1682 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1683 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1684 slang_free(slang_T *lp) |
236 | 1685 { |
1686 vim_free(lp->sl_name); | |
310 | 1687 vim_free(lp->sl_fname); |
1688 slang_clear(lp); | |
1689 vim_free(lp); | |
1690 } | |
1691 | |
1692 /* | |
1693 * Clear an slang_T so that the file can be reloaded. | |
1694 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1695 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1696 slang_clear(slang_T *lp) |
310 | 1697 { |
339 | 1698 garray_T *gap; |
1699 fromto_T *ftp; | |
344 | 1700 salitem_T *smp; |
339 | 1701 int i; |
625 | 1702 int round; |
323 | 1703 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1704 VIM_CLEAR(lp->sl_fbyts); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1705 VIM_CLEAR(lp->sl_kbyts); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1706 VIM_CLEAR(lp->sl_pbyts); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1707 |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1708 VIM_CLEAR(lp->sl_fidxs); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1709 VIM_CLEAR(lp->sl_kidxs); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1710 VIM_CLEAR(lp->sl_pidxs); |
323 | 1711 |
625 | 1712 for (round = 1; round <= 2; ++round) |
1713 { | |
1714 gap = round == 1 ? &lp->sl_rep : &lp->sl_repsal; | |
1715 while (gap->ga_len > 0) | |
1716 { | |
1717 ftp = &((fromto_T *)gap->ga_data)[--gap->ga_len]; | |
1718 vim_free(ftp->ft_from); | |
1719 vim_free(ftp->ft_to); | |
1720 } | |
1721 ga_clear(gap); | |
1722 } | |
344 | 1723 |
1724 gap = &lp->sl_sal; | |
375 | 1725 if (lp->sl_sofo) |
376 | 1726 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1727 // "ga_len" is set to 1 without adding an item for latin1 |
376 | 1728 if (gap->ga_data != NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1729 // SOFOFROM and SOFOTO items: free lists of wide characters. |
376 | 1730 for (i = 0; i < gap->ga_len; ++i) |
1731 vim_free(((int **)gap->ga_data)[i]); | |
1732 } | |
375 | 1733 else |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1734 // SAL items: free salitem_T items |
375 | 1735 while (gap->ga_len > 0) |
1736 { | |
1737 smp = &((salitem_T *)gap->ga_data)[--gap->ga_len]; | |
1738 vim_free(smp->sm_lead); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1739 // Don't free sm_oneof and sm_rules, they point into sm_lead. |
375 | 1740 vim_free(smp->sm_to); |
1741 vim_free(smp->sm_lead_w); | |
1742 vim_free(smp->sm_oneof_w); | |
1743 vim_free(smp->sm_to_w); | |
1744 } | |
344 | 1745 ga_clear(gap); |
323 | 1746 |
339 | 1747 for (i = 0; i < lp->sl_prefixcnt; ++i) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1748 vim_regfree(lp->sl_prefprog[i]); |
376 | 1749 lp->sl_prefixcnt = 0; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1750 VIM_CLEAR(lp->sl_prefprog); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1751 |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1752 VIM_CLEAR(lp->sl_info); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1753 |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1754 VIM_CLEAR(lp->sl_midword); |
339 | 1755 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1756 vim_regfree(lp->sl_compprog); |
483 | 1757 lp->sl_compprog = NULL; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1758 VIM_CLEAR(lp->sl_comprules); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1759 VIM_CLEAR(lp->sl_compstartflags); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1760 VIM_CLEAR(lp->sl_compallflags); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1761 |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1762 VIM_CLEAR(lp->sl_syllable); |
483 | 1763 ga_clear(&lp->sl_syl_items); |
481 | 1764 |
809 | 1765 ga_clear_strings(&lp->sl_comppat); |
1766 | |
625 | 1767 hash_clear_all(&lp->sl_wordcount, WC_KEY_OFF); |
1768 hash_init(&lp->sl_wordcount); | |
1769 | |
1770 hash_clear_all(&lp->sl_map_hash, 0); | |
1771 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1772 // Clear info from .sug file. |
625 | 1773 slang_clear_sug(lp); |
483 | 1774 |
1775 lp->sl_compmax = MAXWLEN; | |
501 | 1776 lp->sl_compminlen = 0; |
483 | 1777 lp->sl_compsylmax = MAXWLEN; |
1778 lp->sl_regions[0] = NUL; | |
236 | 1779 } |
1780 | |
1781 /* | |
625 | 1782 * Clear the info from the .sug file in "lp". |
1783 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1784 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1785 slang_clear_sug(slang_T *lp) |
625 | 1786 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1787 VIM_CLEAR(lp->sl_sbyts); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1788 VIM_CLEAR(lp->sl_sidxs); |
625 | 1789 close_spellbuf(lp->sl_sugbuf); |
1790 lp->sl_sugbuf = NULL; | |
1791 lp->sl_sugloaded = FALSE; | |
1792 lp->sl_sugtime = 0; | |
1793 } | |
1794 | |
1795 /* | |
307 | 1796 * Load one spell file and store the info into a slang_T. |
236 | 1797 * Invoked through do_in_runtimepath(). |
1798 */ | |
1799 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1800 spell_load_cb(char_u *fname, void *cookie) |
501 | 1801 { |
1802 spelload_T *slp = (spelload_T *)cookie; | |
1803 slang_T *slang; | |
1804 | |
1805 slang = spell_load_file(fname, slp->sl_lang, NULL, FALSE); | |
1806 if (slang != NULL) | |
1807 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1808 // When a previously loaded file has NOBREAK also use it for the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1809 // ".add" files. |
501 | 1810 if (slp->sl_nobreak && slang->sl_add) |
1811 slang->sl_nobreak = TRUE; | |
1812 else if (slang->sl_nobreak) | |
1813 slp->sl_nobreak = TRUE; | |
1814 | |
1815 slp->sl_slang = slang; | |
1816 } | |
310 | 1817 } |
1818 | |
625 | 1819 |
1820 /* | |
1821 * Add a word to the hashtable of common words. | |
1822 * If it's already there then the counter is increased. | |
1823 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1824 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1825 count_common_word( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1826 slang_T *lp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1827 char_u *word, |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
1828 int len, // word length, -1 for up to NUL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1829 int count) // 1 to count once, 10 to init |
625 | 1830 { |
1831 hash_T hash; | |
1832 hashitem_T *hi; | |
1833 wordcount_T *wc; | |
1834 char_u buf[MAXWLEN]; | |
1835 char_u *p; | |
1836 | |
1837 if (len == -1) | |
1838 p = word; | |
17653
cc68aca87c17
patch 8.1.1824: crash when correctly spelled word is very long
Bram Moolenaar <Bram@vim.org>
parents:
17434
diff
changeset
|
1839 else if (len >= MAXWLEN) |
cc68aca87c17
patch 8.1.1824: crash when correctly spelled word is very long
Bram Moolenaar <Bram@vim.org>
parents:
17434
diff
changeset
|
1840 return; |
625 | 1841 else |
1842 { | |
1843 vim_strncpy(buf, word, len); | |
1844 p = buf; | |
1845 } | |
1846 | |
1847 hash = hash_hash(p); | |
1848 hi = hash_lookup(&lp->sl_wordcount, p, hash); | |
1849 if (HASHITEM_EMPTY(hi)) | |
1850 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1851 wc = alloc(sizeof(wordcount_T) + STRLEN(p)); |
625 | 1852 if (wc == NULL) |
1853 return; | |
1854 STRCPY(wc->wc_word, p); | |
1855 wc->wc_count = count; | |
1856 hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); | |
1857 } | |
1858 else | |
1859 { | |
1860 wc = HI2WC(hi); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1861 if ((wc->wc_count += count) < (unsigned)count) // check for overflow |
625 | 1862 wc->wc_count = MAXWORDCOUNT; |
1863 } | |
1864 } | |
1865 | |
1866 /* | |
498 | 1867 * Return TRUE if byte "n" appears in "str". |
495 | 1868 * Like strchr() but independent of locale. |
1869 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1870 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1871 byte_in_str(char_u *str, int n) |
495 | 1872 { |
1873 char_u *p; | |
1874 | |
1875 for (p = str; *p != NUL; ++p) | |
498 | 1876 if (*p == n) |
495 | 1877 return TRUE; |
1878 return FALSE; | |
1879 } | |
1880 | |
483 | 1881 #define SY_MAXLEN 30 |
1882 typedef struct syl_item_S | |
1883 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1884 char_u sy_chars[SY_MAXLEN]; // the sequence of chars |
483 | 1885 int sy_len; |
1886 } syl_item_T; | |
1887 | |
1888 /* | |
1889 * Truncate "slang->sl_syllable" at the first slash and put the following items | |
1890 * in "slang->sl_syl_items". | |
1891 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1892 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1893 init_syl_tab(slang_T *slang) |
483 | 1894 { |
1895 char_u *p; | |
1896 char_u *s; | |
1897 int l; | |
1898 syl_item_T *syl; | |
1899 | |
1900 ga_init2(&slang->sl_syl_items, sizeof(syl_item_T), 4); | |
1901 p = vim_strchr(slang->sl_syllable, '/'); | |
1902 while (p != NULL) | |
1903 { | |
1904 *p++ = NUL; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1905 if (*p == NUL) // trailing slash |
483 | 1906 break; |
1907 s = p; | |
1908 p = vim_strchr(p, '/'); | |
1909 if (p == NULL) | |
835 | 1910 l = (int)STRLEN(s); |
483 | 1911 else |
835 | 1912 l = (int)(p - s); |
483 | 1913 if (l >= SY_MAXLEN) |
1914 return SP_FORMERROR; | |
1915 if (ga_grow(&slang->sl_syl_items, 1) == FAIL) | |
495 | 1916 return SP_OTHERERROR; |
483 | 1917 syl = ((syl_item_T *)slang->sl_syl_items.ga_data) |
1918 + slang->sl_syl_items.ga_len++; | |
1919 vim_strncpy(syl->sy_chars, s, l); | |
1920 syl->sy_len = l; | |
1921 } | |
1922 return OK; | |
1923 } | |
1924 | |
1925 /* | |
1926 * Count the number of syllables in "word". | |
1927 * When "word" contains spaces the syllables after the last space are counted. | |
1928 * Returns zero if syllables are not defines. | |
1929 */ | |
1930 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1931 count_syllables(slang_T *slang, char_u *word) |
483 | 1932 { |
1933 int cnt = 0; | |
1934 int skip = FALSE; | |
1935 char_u *p; | |
1936 int len; | |
1937 int i; | |
1938 syl_item_T *syl; | |
1939 int c; | |
1940 | |
1941 if (slang->sl_syllable == NULL) | |
1942 return 0; | |
1943 | |
1944 for (p = word; *p != NUL; p += len) | |
1945 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1946 // When running into a space reset counter. |
483 | 1947 if (*p == ' ') |
1948 { | |
1949 len = 1; | |
1950 cnt = 0; | |
1951 continue; | |
1952 } | |
1953 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1954 // Find longest match of syllable items. |
483 | 1955 len = 0; |
1956 for (i = 0; i < slang->sl_syl_items.ga_len; ++i) | |
1957 { | |
1958 syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + i; | |
1959 if (syl->sy_len > len | |
1960 && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0) | |
1961 len = syl->sy_len; | |
1962 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1963 if (len != 0) // found a match, count syllable |
483 | 1964 { |
1965 ++cnt; | |
1966 skip = FALSE; | |
1967 } | |
1968 else | |
1969 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1970 // No recognized syllable item, at least a syllable char then? |
483 | 1971 c = mb_ptr2char(p); |
1972 len = (*mb_ptr2len)(p); | |
1973 if (vim_strchr(slang->sl_syllable, c) == NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1974 skip = FALSE; // No, search for next syllable |
483 | 1975 else if (!skip) |
1976 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1977 ++cnt; // Yes, count it |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1978 skip = TRUE; // don't count following syllable chars |
483 | 1979 } |
1980 } | |
1981 } | |
1982 return cnt; | |
376 | 1983 } |
1984 | |
381 | 1985 /* |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1986 * Parse 'spelllang' and set w_s->b_langp accordingly. |
28457
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28169
diff
changeset
|
1987 * Returns NULL if it's OK, an untranslated error message otherwise. |
236 | 1988 */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
1989 char * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1990 did_set_spelllang(win_T *wp) |
236 | 1991 { |
1992 garray_T ga; | |
351 | 1993 char_u *splp; |
236 | 1994 char_u *region; |
416 | 1995 char_u region_cp[3]; |
355 | 1996 int filename; |
236 | 1997 int region_mask; |
503 | 1998 slang_T *slang; |
236 | 1999 int c; |
351 | 2000 char_u lang[MAXWLEN + 1]; |
323 | 2001 char_u spf_name[MAXPATHL]; |
351 | 2002 int len; |
2003 char_u *p; | |
381 | 2004 int round; |
385 | 2005 char_u *spf; |
389 | 2006 char_u *use_region = NULL; |
2007 int dont_use_region = FALSE; | |
501 | 2008 int nobreak = FALSE; |
503 | 2009 int i, j; |
2010 langp_T *lp, *lp2; | |
1185 | 2011 static int recursive = FALSE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
2012 char *ret_msg = NULL; |
1185 | 2013 char_u *spl_copy; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2014 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2015 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2016 set_bufref(&bufref, wp->w_buffer); |
1185 | 2017 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2018 // We don't want to do this recursively. May happen when a language is |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2019 // not available and the SpellFileMissing autocommand opens a new buffer |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2020 // in which 'spell' is set. |
1185 | 2021 if (recursive) |
2022 return NULL; | |
2023 recursive = TRUE; | |
236 | 2024 |
2025 ga_init2(&ga, sizeof(langp_T), 2); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2026 clear_midword(wp); |
236 | 2027 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2028 // Make a copy of 'spelllang', the SpellFileMissing autocommands may change |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2029 // it under our fingers. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2030 spl_copy = vim_strsave(wp->w_s->b_p_spl); |
1185 | 2031 if (spl_copy == NULL) |
2032 goto theend; | |
2033 | |
5477 | 2034 wp->w_s->b_cjk = 0; |
2035 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2036 // Loop over comma separated language names. |
1185 | 2037 for (splp = spl_copy; *splp != NUL; ) |
351 | 2038 { |
16277
5ef25fa57f71
patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
2039 // Get one language name. |
351 | 2040 copy_option_part(&splp, lang, MAXWLEN, ","); |
240 | 2041 region = NULL; |
835 | 2042 len = (int)STRLEN(lang); |
355 | 2043 |
20760
813b9a7064a4
patch 8.2.0932: missspelling spelllang
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2044 if (!valid_spelllang(lang)) |
16277
5ef25fa57f71
patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
2045 continue; |
5ef25fa57f71
patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
2046 |
5477 | 2047 if (STRCMP(lang, "cjk") == 0) |
2048 { | |
2049 wp->w_s->b_cjk = 1; | |
2050 continue; | |
2051 } | |
2052 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2053 // If the name ends in ".spl" use it as the name of the spell file. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2054 // If there is a region name let "region" point to it and remove it |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2055 // from the name. |
355 | 2056 if (len > 4 && fnamecmp(lang + len - 4, ".spl") == 0) |
236 | 2057 { |
355 | 2058 filename = TRUE; |
2059 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2060 // Locate a region and remove it from the file name. |
416 | 2061 p = vim_strchr(gettail(lang), '_'); |
2062 if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2]) | |
2063 && !ASCII_ISALPHA(p[3])) | |
2064 { | |
2065 vim_strncpy(region_cp, p + 1, 2); | |
2066 mch_memmove(p, p + 3, len - (p - lang) - 2); | |
2067 region = region_cp; | |
2068 } | |
2069 else | |
2070 dont_use_region = TRUE; | |
2071 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2072 // Check if we loaded this language before. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
2073 FOR_ALL_SPELL_LANGS(slang) |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2074 if (fullpathcmp(lang, slang->sl_fname, FALSE, TRUE) == FPC_SAME) |
355 | 2075 break; |
236 | 2076 } |
355 | 2077 else |
2078 { | |
2079 filename = FALSE; | |
2080 if (len > 3 && lang[len - 3] == '_') | |
2081 { | |
2082 region = lang + len - 2; | |
2083 len -= 3; | |
2084 lang[len] = NUL; | |
389 | 2085 } |
2086 else | |
2087 dont_use_region = TRUE; | |
355 | 2088 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2089 // Check if we loaded this language before. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
2090 FOR_ALL_SPELL_LANGS(slang) |
503 | 2091 if (STRICMP(lang, slang->sl_name) == 0) |
355 | 2092 break; |
2093 } | |
236 | 2094 |
416 | 2095 if (region != NULL) |
2096 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2097 // If the region differs from what was used before then don't |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2098 // use it for 'spellfile'. |
416 | 2099 if (use_region != NULL && STRCMP(region, use_region) != 0) |
2100 dont_use_region = TRUE; | |
2101 use_region = region; | |
2102 } | |
2103 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2104 // If not found try loading the language now. |
503 | 2105 if (slang == NULL) |
355 | 2106 { |
2107 if (filename) | |
2108 (void)spell_load_file(lang, lang, NULL, FALSE); | |
2109 else | |
1185 | 2110 { |
355 | 2111 spell_load_lang(lang); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2112 // SpellFileMissing autocommands may do anything, including |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2113 // destroying the buffer we are using... |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2114 if (!bufref_valid(&bufref)) |
1185 | 2115 { |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
2116 ret_msg = N_(e_spellfilemising_autocommand_deleted_buffer); |
1185 | 2117 goto theend; |
2118 } | |
2119 } | |
355 | 2120 } |
236 | 2121 |
307 | 2122 /* |
351 | 2123 * Loop over the languages, there can be several files for "lang". |
307 | 2124 */ |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
2125 FOR_ALL_SPELL_LANGS(slang) |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2126 if (filename ? fullpathcmp(lang, slang->sl_fname, FALSE, TRUE) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2127 == FPC_SAME |
503 | 2128 : STRICMP(lang, slang->sl_name) == 0) |
236 | 2129 { |
316 | 2130 region_mask = REGION_ALL; |
355 | 2131 if (!filename && region != NULL) |
236 | 2132 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2133 // find region in sl_regions |
503 | 2134 c = find_region(slang->sl_regions, region); |
307 | 2135 if (c == REGION_ALL) |
2136 { | |
503 | 2137 if (slang->sl_add) |
389 | 2138 { |
503 | 2139 if (*slang->sl_regions != NUL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2140 // This addition file is for other regions. |
389 | 2141 region_mask = 0; |
2142 } | |
2143 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2144 // This is probably an error. Give a warning and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2145 // accept the words anyway. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
2146 smsg(_("Warning: region %s not supported"), |
351 | 2147 region); |
307 | 2148 } |
2149 else | |
2150 region_mask = 1 << c; | |
236 | 2151 } |
307 | 2152 |
389 | 2153 if (region_mask != 0) |
307 | 2154 { |
389 | 2155 if (ga_grow(&ga, 1) == FAIL) |
2156 { | |
2157 ga_clear(&ga); | |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24872
diff
changeset
|
2158 ret_msg = e_out_of_memory; |
1185 | 2159 goto theend; |
389 | 2160 } |
503 | 2161 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang; |
389 | 2162 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask; |
2163 ++ga.ga_len; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2164 use_midword(slang, wp); |
503 | 2165 if (slang->sl_nobreak) |
501 | 2166 nobreak = TRUE; |
307 | 2167 } |
385 | 2168 } |
2169 } | |
2170 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2171 // round 0: load int_wordlist, if possible. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2172 // round 1: load first name in 'spellfile'. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2173 // round 2: load second name in 'spellfile. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2174 // etc. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2175 spf = curwin->w_s->b_p_spf; |
385 | 2176 for (round = 0; round == 0 || *spf != NUL; ++round) |
2177 { | |
2178 if (round == 0) | |
2179 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2180 // Internal wordlist, if there is one. |
385 | 2181 if (int_wordlist == NULL) |
381 | 2182 continue; |
385 | 2183 int_wordlist_spl(spf_name); |
381 | 2184 } |
2185 else | |
2186 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2187 // One entry in 'spellfile'. |
385 | 2188 copy_option_part(&spf, spf_name, MAXPATHL - 5, ","); |
2189 STRCAT(spf_name, ".spl"); | |
2190 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2191 // If it was already found above then skip it. |
385 | 2192 for (c = 0; c < ga.ga_len; ++c) |
500 | 2193 { |
2194 p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; | |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2195 if (p != NULL && fullpathcmp(spf_name, p, FALSE, TRUE) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2196 == FPC_SAME) |
385 | 2197 break; |
500 | 2198 } |
385 | 2199 if (c < ga.ga_len) |
381 | 2200 continue; |
2201 } | |
2202 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2203 // Check if it was loaded already. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
2204 FOR_ALL_SPELL_LANGS(slang) |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2205 if (fullpathcmp(spf_name, slang->sl_fname, FALSE, TRUE) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2206 == FPC_SAME) |
323 | 2207 break; |
503 | 2208 if (slang == NULL) |
323 | 2209 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2210 // Not loaded, try loading it now. The language name includes the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2211 // region name, the region is ignored otherwise. for int_wordlist |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2212 // use an arbitrary name. |
385 | 2213 if (round == 0) |
2214 STRCPY(lang, "internal wordlist"); | |
2215 else | |
2216 { | |
2217 vim_strncpy(lang, gettail(spf_name), MAXWLEN); | |
381 | 2218 p = vim_strchr(lang, '.'); |
2219 if (p != NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2220 *p = NUL; // truncate at ".encoding.add" |
381 | 2221 } |
503 | 2222 slang = spell_load_file(spf_name, lang, NULL, TRUE); |
501 | 2223 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2224 // If one of the languages has NOBREAK we assume the addition |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2225 // files also have this. |
503 | 2226 if (slang != NULL && nobreak) |
2227 slang->sl_nobreak = TRUE; | |
2228 } | |
2229 if (slang != NULL && ga_grow(&ga, 1) == OK) | |
323 | 2230 { |
389 | 2231 region_mask = REGION_ALL; |
2232 if (use_region != NULL && !dont_use_region) | |
2233 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2234 // find region in sl_regions |
503 | 2235 c = find_region(slang->sl_regions, use_region); |
389 | 2236 if (c != REGION_ALL) |
2237 region_mask = 1 << c; | |
503 | 2238 else if (*slang->sl_regions != NUL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2239 // This spell file is for other regions. |
389 | 2240 region_mask = 0; |
2241 } | |
2242 | |
2243 if (region_mask != 0) | |
2244 { | |
503 | 2245 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang; |
2246 LANGP_ENTRY(ga, ga.ga_len)->lp_sallang = NULL; | |
2247 LANGP_ENTRY(ga, ga.ga_len)->lp_replang = NULL; | |
389 | 2248 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask; |
2249 ++ga.ga_len; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2250 use_midword(slang, wp); |
389 | 2251 } |
323 | 2252 } |
2253 } | |
2254 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2255 // Everything is fine, store the new b_langp value. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2256 ga_clear(&wp->w_s->b_langp); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2257 wp->w_s->b_langp = ga; |
236 | 2258 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2259 // For each language figure out what language to use for sound folding and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2260 // REP items. If the language doesn't support it itself use another one |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2261 // with the same name. E.g. for "en-math" use "en". |
503 | 2262 for (i = 0; i < ga.ga_len; ++i) |
2263 { | |
2264 lp = LANGP_ENTRY(ga, i); | |
2265 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2266 // sound folding |
503 | 2267 if (lp->lp_slang->sl_sal.ga_len > 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2268 // language does sound folding itself |
503 | 2269 lp->lp_sallang = lp->lp_slang; |
2270 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2271 // find first similar language that does sound folding |
503 | 2272 for (j = 0; j < ga.ga_len; ++j) |
2273 { | |
2274 lp2 = LANGP_ENTRY(ga, j); | |
2275 if (lp2->lp_slang->sl_sal.ga_len > 0 | |
2276 && STRNCMP(lp->lp_slang->sl_name, | |
2277 lp2->lp_slang->sl_name, 2) == 0) | |
2278 { | |
2279 lp->lp_sallang = lp2->lp_slang; | |
2280 break; | |
2281 } | |
2282 } | |
2283 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2284 // REP items |
503 | 2285 if (lp->lp_slang->sl_rep.ga_len > 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2286 // language has REP items itself |
503 | 2287 lp->lp_replang = lp->lp_slang; |
2288 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2289 // find first similar language that has REP items |
503 | 2290 for (j = 0; j < ga.ga_len; ++j) |
2291 { | |
2292 lp2 = LANGP_ENTRY(ga, j); | |
2293 if (lp2->lp_slang->sl_rep.ga_len > 0 | |
2294 && STRNCMP(lp->lp_slang->sl_name, | |
2295 lp2->lp_slang->sl_name, 2) == 0) | |
2296 { | |
2297 lp->lp_replang = lp2->lp_slang; | |
2298 break; | |
2299 } | |
2300 } | |
2301 } | |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29595
diff
changeset
|
2302 redraw_win_later(wp, UPD_NOT_VALID); |
503 | 2303 |
1185 | 2304 theend: |
2305 vim_free(spl_copy); | |
2306 recursive = FALSE; | |
2307 return ret_msg; | |
236 | 2308 } |
2309 | |
2310 /* | |
376 | 2311 * Clear the midword characters for buffer "buf". |
2312 */ | |
2313 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2314 clear_midword(win_T *wp) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2315 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2316 CLEAR_FIELD(wp->w_s->b_spell_ismw); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2317 VIM_CLEAR(wp->w_s->b_spell_ismw_mb); |
376 | 2318 } |
2319 | |
2320 /* | |
2321 * Use the "sl_midword" field of language "lp" for buffer "buf". | |
2322 * They add up to any currently used midword characters. | |
2323 */ | |
2324 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2325 use_midword(slang_T *lp, win_T *wp) |
376 | 2326 { |
2327 char_u *p; | |
2328 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2329 if (lp->sl_midword == NULL) // there aren't any |
389 | 2330 return; |
2331 | |
376 | 2332 for (p = lp->sl_midword; *p != NUL; ) |
2333 if (has_mbyte) | |
2334 { | |
2335 int c, l, n; | |
2336 char_u *bp; | |
2337 | |
2338 c = mb_ptr2char(p); | |
474 | 2339 l = (*mb_ptr2len)(p); |
2340 if (c < 256 && l <= 2) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2341 wp->w_s->b_spell_ismw[c] = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2342 else if (wp->w_s->b_spell_ismw_mb == NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2343 // First multi-byte char in "b_spell_ismw_mb". |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2344 wp->w_s->b_spell_ismw_mb = vim_strnsave(p, l); |
376 | 2345 else |
2346 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2347 // Append multi-byte chars to "b_spell_ismw_mb". |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2348 n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2349 bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l); |
376 | 2350 if (bp != NULL) |
2351 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2352 vim_free(wp->w_s->b_spell_ismw_mb); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2353 wp->w_s->b_spell_ismw_mb = bp; |
376 | 2354 vim_strncpy(bp + n, p, l); |
2355 } | |
2356 } | |
2357 p += l; | |
2358 } | |
2359 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2360 wp->w_s->b_spell_ismw[*p++] = TRUE; |
376 | 2361 } |
2362 | |
2363 /* | |
236 | 2364 * Find the region "region[2]" in "rp" (points to "sl_regions"). |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2365 * Each region is simply stored as the two characters of its name. |
381 | 2366 * Returns the index if found (first is 0), REGION_ALL if not found. |
236 | 2367 */ |
2368 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2369 find_region(char_u *rp, char_u *region) |
236 | 2370 { |
2371 int i; | |
2372 | |
2373 for (i = 0; ; i += 2) | |
2374 { | |
2375 if (rp[i] == NUL) | |
2376 return REGION_ALL; | |
2377 if (rp[i] == region[0] && rp[i + 1] == region[1]) | |
2378 break; | |
2379 } | |
2380 return i / 2; | |
2381 } | |
2382 | |
2383 /* | |
323 | 2384 * Return case type of word: |
236 | 2385 * w word 0 |
300 | 2386 * Word WF_ONECAP |
2387 * W WORD WF_ALLCAP | |
2388 * WoRd wOrd WF_KEEPCAP | |
236 | 2389 */ |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2390 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2391 captype( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2392 char_u *word, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2393 char_u *end) // When NULL use up to NUL byte. |
236 | 2394 { |
2395 char_u *p; | |
2396 int c; | |
2397 int firstcap; | |
2398 int allcap; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2399 int past_second = FALSE; // past second word char |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2400 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2401 // find first letter |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2402 for (p = word; !spell_iswordp_nmw(p, curwin); MB_PTR_ADV(p)) |
323 | 2403 if (end == NULL ? *p == NUL : p >= end) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2404 return 0; // only non-word characters, illegal word |
310 | 2405 if (has_mbyte) |
2406 c = mb_ptr2char_adv(&p); | |
2407 else | |
2408 c = *p++; | |
324 | 2409 firstcap = allcap = SPELL_ISUPPER(c); |
236 | 2410 |
2411 /* | |
2412 * Need to check all letters to find a word with mixed upper/lower. | |
2413 * But a word with an upper char only at start is a ONECAP. | |
2414 */ | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2415 for ( ; end == NULL ? *p != NUL : p < end; MB_PTR_ADV(p)) |
5477 | 2416 if (spell_iswordp_nmw(p, curwin)) |
236 | 2417 { |
455 | 2418 c = PTR2CHAR(p); |
324 | 2419 if (!SPELL_ISUPPER(c)) |
236 | 2420 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2421 // UUl -> KEEPCAP |
236 | 2422 if (past_second && allcap) |
300 | 2423 return WF_KEEPCAP; |
236 | 2424 allcap = FALSE; |
2425 } | |
2426 else if (!allcap) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2427 // UlU -> KEEPCAP |
300 | 2428 return WF_KEEPCAP; |
236 | 2429 past_second = TRUE; |
2430 } | |
2431 | |
2432 if (allcap) | |
300 | 2433 return WF_ALLCAP; |
236 | 2434 if (firstcap) |
300 | 2435 return WF_ONECAP; |
236 | 2436 return 0; |
2437 } | |
2438 | |
474 | 2439 /* |
5519 | 2440 * Delete the internal wordlist and its .spl file. |
2441 */ | |
2442 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2443 spell_delete_wordlist(void) |
5519 | 2444 { |
2445 char_u fname[MAXPATHL]; | |
2446 | |
2447 if (int_wordlist != NULL) | |
2448 { | |
2449 mch_remove(int_wordlist); | |
2450 int_wordlist_spl(fname); | |
2451 mch_remove(fname); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2452 VIM_CLEAR(int_wordlist); |
5519 | 2453 } |
2454 } | |
2455 | |
355 | 2456 /* |
2457 * Free all languages. | |
2458 */ | |
2459 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2460 spell_free_all(void) |
355 | 2461 { |
503 | 2462 slang_T *slang; |
355 | 2463 buf_T *buf; |
2464 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2465 // Go through all buffers and handle 'spelllang'. <VN> |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9583
diff
changeset
|
2466 FOR_ALL_BUFFERS(buf) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2467 ga_clear(&buf->b_s.b_langp); |
355 | 2468 |
2469 while (first_lang != NULL) | |
2470 { | |
503 | 2471 slang = first_lang; |
2472 first_lang = slang->sl_next; | |
2473 slang_free(slang); | |
355 | 2474 } |
366 | 2475 |
5519 | 2476 spell_delete_wordlist(); |
381 | 2477 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2478 VIM_CLEAR(repl_to); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2479 VIM_CLEAR(repl_from); |
355 | 2480 } |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2481 |
236 | 2482 /* |
2483 * Clear all spelling tables and reload them. | |
307 | 2484 * Used after 'encoding' is set and when ":mkspell" was used. |
236 | 2485 */ |
2486 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2487 spell_reload(void) |
236 | 2488 { |
316 | 2489 win_T *wp; |
236 | 2490 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2491 // Initialize the table for spell_iswordp(). |
236 | 2492 init_spell_chartab(); |
2493 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2494 // Unload all allocated memory. |
355 | 2495 spell_free_all(); |
236 | 2496 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2497 // Go through all buffers and handle 'spelllang'. |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9583
diff
changeset
|
2498 FOR_ALL_WINDOWS(wp) |
236 | 2499 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2500 // Only load the wordlists when 'spelllang' is set and there is a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2501 // window for this buffer in which 'spell' is set. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2502 if (*wp->w_s->b_p_spl != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2503 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2504 if (wp->w_p_spell) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2505 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2506 (void)did_set_spelllang(wp); |
316 | 2507 break; |
2508 } | |
2509 } | |
236 | 2510 } |
2511 } | |
2512 | |
310 | 2513 /* |
625 | 2514 * Open a spell buffer. This is a nameless buffer that is not in the buffer |
2515 * list and only contains text lines. Can use a swapfile to reduce memory | |
2516 * use. | |
2517 * Most other fields are invalid! Esp. watch out for string options being | |
2518 * NULL and there is no undo info. | |
2519 * Returns NULL when out of memory. | |
2520 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2521 buf_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2522 open_spellbuf(void) |
625 | 2523 { |
2524 buf_T *buf; | |
2525 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
2526 buf = ALLOC_CLEAR_ONE(buf_T); |
625 | 2527 if (buf != NULL) |
2528 { | |
2529 buf->b_spell = TRUE; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2530 buf->b_p_swf = TRUE; // may create a swap file |
5204
7aca84c0cd37
updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2531 #ifdef FEAT_CRYPT |
7aca84c0cd37
updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2532 buf->b_p_key = empty_option; |
7aca84c0cd37
updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2533 #endif |
625 | 2534 ml_open(buf); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2535 ml_open_file(buf); // create swap file now |
625 | 2536 } |
2537 return buf; | |
2538 } | |
2539 | |
2540 /* | |
2541 * Close the buffer used for spell info. | |
2542 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2543 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2544 close_spellbuf(buf_T *buf) |
625 | 2545 { |
2546 if (buf != NULL) | |
2547 { | |
2548 ml_close(buf, TRUE); | |
2549 vim_free(buf); | |
2550 } | |
2551 } | |
2552 | |
307 | 2553 /* |
2554 * Init the chartab used for spelling for ASCII. | |
2555 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2556 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2557 clear_spell_chartab(spelltab_T *sp) |
307 | 2558 { |
324 | 2559 int i; |
307 | 2560 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2561 // Init everything to FALSE (zero). |
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2562 CLEAR_FIELD(sp->st_isw); |
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2563 CLEAR_FIELD(sp->st_isu); |
307 | 2564 for (i = 0; i < 256; ++i) |
324 | 2565 { |
307 | 2566 sp->st_fold[i] = i; |
324 | 2567 sp->st_upper[i] = i; |
2568 } | |
307 | 2569 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2570 // We include digits. A word shouldn't start with a digit, but handling |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2571 // that is done separately. |
307 | 2572 for (i = '0'; i <= '9'; ++i) |
2573 sp->st_isw[i] = TRUE; | |
2574 for (i = 'A'; i <= 'Z'; ++i) | |
2575 { | |
2576 sp->st_isw[i] = TRUE; | |
2577 sp->st_isu[i] = TRUE; | |
2578 sp->st_fold[i] = i + 0x20; | |
2579 } | |
2580 for (i = 'a'; i <= 'z'; ++i) | |
324 | 2581 { |
307 | 2582 sp->st_isw[i] = TRUE; |
324 | 2583 sp->st_upper[i] = i - 0x20; |
2584 } | |
307 | 2585 } |
2586 | |
2587 /* | |
2588 * Init the chartab used for spelling. Only depends on 'encoding'. | |
2589 * Called once while starting up and when 'encoding' changes. | |
2590 * The default is to use isalpha(), but the spell file should define the word | |
2591 * characters to make it possible that 'encoding' differs from the current | |
390 | 2592 * locale. For utf-8 we don't use isalpha() but our own functions. |
307 | 2593 */ |
2594 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2595 init_spell_chartab(void) |
307 | 2596 { |
2597 int i; | |
2598 | |
2599 did_set_spelltab = FALSE; | |
2600 clear_spell_chartab(&spelltab); | |
2601 if (enc_dbcs) | |
2602 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2603 // DBCS: assume double-wide characters are word characters. |
307 | 2604 for (i = 128; i <= 255; ++i) |
2605 if (MB_BYTE2LEN(i) == 2) | |
2606 spelltab.st_isw[i] = TRUE; | |
2607 } | |
324 | 2608 else if (enc_utf8) |
2609 { | |
2610 for (i = 128; i < 256; ++i) | |
2611 { | |
2140
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2612 int f = utf_fold(i); |
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2613 int u = utf_toupper(i); |
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2614 |
324 | 2615 spelltab.st_isu[i] = utf_isupper(i); |
2616 spelltab.st_isw[i] = spelltab.st_isu[i] || utf_islower(i); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2617 // The folded/upper-cased value is different between latin1 and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2618 // utf8 for 0xb5, causing E763 for no good reason. Use the latin1 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2619 // value for utf-8 to avoid this. |
2140
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2620 spelltab.st_fold[i] = (f < 256) ? f : i; |
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2621 spelltab.st_upper[i] = (u < 256) ? u : i; |
324 | 2622 } |
2623 } | |
307 | 2624 else |
2625 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2626 // Rough guess: use locale-dependent library functions. |
307 | 2627 for (i = 128; i < 256; ++i) |
2628 { | |
2629 if (MB_ISUPPER(i)) | |
2630 { | |
324 | 2631 spelltab.st_isw[i] = TRUE; |
307 | 2632 spelltab.st_isu[i] = TRUE; |
2633 spelltab.st_fold[i] = MB_TOLOWER(i); | |
2634 } | |
324 | 2635 else if (MB_ISLOWER(i)) |
2636 { | |
2637 spelltab.st_isw[i] = TRUE; | |
2638 spelltab.st_upper[i] = MB_TOUPPER(i); | |
2639 } | |
307 | 2640 } |
2641 } | |
2642 } | |
2643 | |
2644 | |
2645 /* | |
358 | 2646 * Return TRUE if "p" points to a word character. |
366 | 2647 * As a special case we see "midword" characters as word character when it is |
358 | 2648 * followed by a word character. This finds they'there but not 'they there'. |
366 | 2649 * Thus this only works properly when past the first character of the word. |
358 | 2650 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
2651 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2652 spell_iswordp( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2653 char_u *p, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2654 win_T *wp) // buffer used |
358 | 2655 { |
2656 char_u *s; | |
366 | 2657 int l; |
2658 int c; | |
2659 | |
2660 if (has_mbyte) | |
2661 { | |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2662 l = mb_ptr2len(p); |
358 | 2663 s = p; |
366 | 2664 if (l == 1) |
2665 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2666 // be quick for ASCII |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2667 if (wp->w_s->b_spell_ismw[*p]) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2668 s = p + 1; // skip a mid-word character |
366 | 2669 } |
2670 else | |
2671 { | |
2672 c = mb_ptr2char(p); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2673 if (c < 256 ? wp->w_s->b_spell_ismw[c] |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2674 : (wp->w_s->b_spell_ismw_mb != NULL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2675 && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) |
366 | 2676 s = p + l; |
2677 } | |
2678 | |
390 | 2679 c = mb_ptr2char(s); |
2680 if (c > 255) | |
5477 | 2681 return spell_mb_isword_class(mb_get_class(s), wp); |
390 | 2682 return spelltab.st_isw[c]; |
366 | 2683 } |
2684 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2685 return spelltab.st_isw[wp->w_s->b_spell_ismw[*p] ? p[1] : p[0]]; |
376 | 2686 } |
2687 | |
2688 /* | |
2689 * Return TRUE if "p" points to a word character. | |
2690 * Unlike spell_iswordp() this doesn't check for "midword" characters. | |
2691 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
2692 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2693 spell_iswordp_nmw(char_u *p, win_T *wp) |
376 | 2694 { |
390 | 2695 int c; |
2696 | |
2697 if (has_mbyte) | |
2698 { | |
2699 c = mb_ptr2char(p); | |
2700 if (c > 255) | |
5477 | 2701 return spell_mb_isword_class(mb_get_class(p), wp); |
390 | 2702 return spelltab.st_isw[c]; |
2703 } | |
376 | 2704 return spelltab.st_isw[*p]; |
358 | 2705 } |
2706 | |
372 | 2707 /* |
1580 | 2708 * Return TRUE if word class indicates a word character. |
2709 * Only for characters above 255. | |
2710 * Unicode subscript and superscript are not considered word characters. | |
5477 | 2711 * See also dbcs_class() and utf_class() in mbyte.c. |
2712 */ | |
2713 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2714 spell_mb_isword_class(int cl, win_T *wp) |
5477 | 2715 { |
2716 if (wp->w_s->b_cjk) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2717 // East Asian characters are not considered word characters. |
5477 | 2718 return cl == 2 || cl == 0x2800; |
17434
26e8d42987ca
patch 8.1.1715: emoji characters are seen as word characters for spelling
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2719 return cl >= 2 && cl != 0x2070 && cl != 0x2080 && cl != 3; |
1580 | 2720 } |
2721 | |
2722 /* | |
372 | 2723 * Return TRUE if "p" points to a word character. |
2724 * Wide version of spell_iswordp(). | |
2725 */ | |
2726 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2727 spell_iswordp_w(int *p, win_T *wp) |
372 | 2728 { |
2729 int *s; | |
2730 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2731 if (*p < 256 ? wp->w_s->b_spell_ismw[*p] |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2732 : (wp->w_s->b_spell_ismw_mb != NULL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2733 && vim_strchr(wp->w_s->b_spell_ismw_mb, *p) != NULL)) |
372 | 2734 s = p + 1; |
2735 else | |
2736 s = p; | |
2737 | |
390 | 2738 if (*s > 255) |
372 | 2739 { |
2740 if (enc_utf8) | |
5477 | 2741 return spell_mb_isword_class(utf_class(*s), wp); |
372 | 2742 if (enc_dbcs) |
5477 | 2743 return spell_mb_isword_class( |
2744 dbcs_class((unsigned)*s >> 8, *s & 0xff), wp); | |
372 | 2745 return 0; |
2746 } | |
2747 return spelltab.st_isw[*s]; | |
2748 } | |
2749 | |
358 | 2750 /* |
324 | 2751 * Case-fold "str[len]" into "buf[buflen]". The result is NUL terminated. |
2752 * Uses the character definitions from the .spl file. | |
307 | 2753 * When using a multi-byte 'encoding' the length may change! |
2754 * Returns FAIL when something wrong. | |
2755 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2756 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2757 spell_casefold( |
24872
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2758 win_T *wp, |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2759 char_u *str, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2760 int len, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2761 char_u *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2762 int buflen) |
307 | 2763 { |
2764 int i; | |
2765 | |
2766 if (len >= buflen) | |
2767 { | |
2768 buf[0] = NUL; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2769 return FAIL; // result will not fit |
307 | 2770 } |
2771 | |
2772 if (has_mbyte) | |
2773 { | |
324 | 2774 int outi = 0; |
2775 char_u *p; | |
307 | 2776 int c; |
2777 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2778 // Fold one character at a time. |
324 | 2779 for (p = str; p < str + len; ) |
307 | 2780 { |
2781 if (outi + MB_MAXBYTES > buflen) | |
2782 { | |
2783 buf[outi] = NUL; | |
2784 return FAIL; | |
2785 } | |
474 | 2786 c = mb_cptr2char_adv(&p); |
24872
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2787 |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2788 // Exception: greek capital sigma 0x03A3 folds to 0x03C3, except |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2789 // when it is the last character in a word, then it folds to |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2790 // 0x03C2. |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2791 if (c == 0x03a3 || c == 0x03c2) |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2792 { |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2793 if (p == str + len || !spell_iswordp(p, wp)) |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2794 c = 0x03c2; |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2795 else |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2796 c = 0x03c3; |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2797 } |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2798 else |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2799 c = SPELL_TOFOLD(c); |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2800 |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
2801 outi += mb_char2bytes(c, buf + outi); |
307 | 2802 } |
2803 buf[outi] = NUL; | |
2804 } | |
2805 else | |
2806 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2807 // Be quick for non-multibyte encodings. |
307 | 2808 for (i = 0; i < len; ++i) |
324 | 2809 buf[i] = spelltab.st_fold[str[i]]; |
307 | 2810 buf[i] = NUL; |
2811 } | |
2812 | |
2813 return OK; | |
2814 } | |
2815 | |
344 | 2816 /* |
475 | 2817 * Check if the word at line "lnum" column "col" is required to start with a |
2818 * capital. This uses 'spellcapcheck' of the current buffer. | |
2819 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
2820 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2821 check_need_cap(linenr_T lnum, colnr_T col) |
475 | 2822 { |
2823 int need_cap = FALSE; | |
2824 char_u *line; | |
2825 char_u *line_copy = NULL; | |
2826 char_u *p; | |
2827 colnr_T endcol; | |
2828 regmatch_T regmatch; | |
2829 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2830 if (curwin->w_s->b_cap_prog == NULL) |
475 | 2831 return FALSE; |
2832 | |
2833 line = ml_get_curline(); | |
2834 endcol = 0; | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
2835 if (getwhitecols(line) >= (int)col) |
475 | 2836 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2837 // At start of line, check if previous line is empty or sentence |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2838 // ends there. |
475 | 2839 if (lnum == 1) |
2840 need_cap = TRUE; | |
2841 else | |
2842 { | |
2843 line = ml_get(lnum - 1); | |
2844 if (*skipwhite(line) == NUL) | |
2845 need_cap = TRUE; | |
2846 else | |
2847 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2848 // Append a space in place of the line break. |
475 | 2849 line_copy = concat_str(line, (char_u *)" "); |
2850 line = line_copy; | |
835 | 2851 endcol = (colnr_T)STRLEN(line); |
475 | 2852 } |
2853 } | |
2854 } | |
2855 else | |
2856 endcol = col; | |
2857 | |
2858 if (endcol > 0) | |
2859 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2860 // Check if sentence ends before the bad word. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2861 regmatch.regprog = curwin->w_s->b_cap_prog; |
475 | 2862 regmatch.rm_ic = FALSE; |
2863 p = line + endcol; | |
2864 for (;;) | |
2865 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2866 MB_PTR_BACK(line, p); |
5477 | 2867 if (p == line || spell_iswordp_nmw(p, curwin)) |
475 | 2868 break; |
2869 if (vim_regexec(®match, p, 0) | |
2870 && regmatch.endp[0] == line + endcol) | |
2871 { | |
2872 need_cap = TRUE; | |
2873 break; | |
2874 } | |
2875 } | |
6375 | 2876 curwin->w_s->b_cap_prog = regmatch.regprog; |
475 | 2877 } |
2878 | |
2879 vim_free(line_copy); | |
2880 | |
2881 return need_cap; | |
2882 } | |
2883 | |
2884 | |
2885 /* | |
372 | 2886 * ":spellrepall" |
2887 */ | |
2888 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2889 ex_spellrepall(exarg_T *eap UNUSED) |
372 | 2890 { |
2891 pos_T pos = curwin->w_cursor; | |
2892 char_u *frompat; | |
2893 int addlen; | |
2894 char_u *line; | |
2895 char_u *p; | |
2896 int save_ws = p_ws; | |
483 | 2897 linenr_T prev_lnum = 0; |
372 | 2898 |
2899 if (repl_from == NULL || repl_to == NULL) | |
2900 { | |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
2901 emsg(_(e_no_previous_spell_replacement)); |
372 | 2902 return; |
2903 } | |
835 | 2904 addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from)); |
2905 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
2906 frompat = alloc(STRLEN(repl_from) + 7); |
372 | 2907 if (frompat == NULL) |
2908 return; | |
2909 sprintf((char *)frompat, "\\V\\<%s\\>", repl_from); | |
2910 p_ws = FALSE; | |
2911 | |
483 | 2912 sub_nsubs = 0; |
2913 sub_nlines = 0; | |
372 | 2914 curwin->w_cursor.lnum = 0; |
2915 while (!got_int) | |
2916 { | |
19475
5512aa74cb62
patch 8.2.0295: highlighting for :s wrong when using different separator
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
2917 if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 |
372 | 2918 || u_save_cursor() == FAIL) |
2919 break; | |
2920 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2921 // Only replace when the right word isn't there yet. This happens |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2922 // when changing "etc" to "etc.". |
372 | 2923 line = ml_get_curline(); |
2924 if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, | |
2925 repl_to, STRLEN(repl_to)) != 0) | |
2926 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
2927 p = alloc(STRLEN(line) + addlen + 1); |
372 | 2928 if (p == NULL) |
2929 break; | |
2930 mch_memmove(p, line, curwin->w_cursor.col); | |
2931 STRCPY(p + curwin->w_cursor.col, repl_to); | |
2932 STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from)); | |
2933 ml_replace(curwin->w_cursor.lnum, p, FALSE); | |
2934 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); | |
28848
ba81f4ed59e2
patch 8.2.4947: text properties not adjusted when accepting spell suggestion
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
2935 if (curbuf->b_has_textprop && addlen != 0) |
ba81f4ed59e2
patch 8.2.4947: text properties not adjusted when accepting spell suggestion
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
2936 adjust_prop_columns(curwin->w_cursor.lnum, |
ba81f4ed59e2
patch 8.2.4947: text properties not adjusted when accepting spell suggestion
Bram Moolenaar <Bram@vim.org>
parents:
28457
diff
changeset
|
2937 curwin->w_cursor.col, addlen, APC_SUBSTITUTE); |
483 | 2938 |
2939 if (curwin->w_cursor.lnum != prev_lnum) | |
2940 { | |
2941 ++sub_nlines; | |
2942 prev_lnum = curwin->w_cursor.lnum; | |
2943 } | |
2944 ++sub_nsubs; | |
372 | 2945 } |
835 | 2946 curwin->w_cursor.col += (colnr_T)STRLEN(repl_to); |
372 | 2947 } |
2948 | |
2949 p_ws = save_ws; | |
2950 curwin->w_cursor = pos; | |
2951 vim_free(frompat); | |
2952 | |
483 | 2953 if (sub_nsubs == 0) |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
2954 semsg(_(e_not_found_str), repl_from); |
483 | 2955 else |
2956 do_sub_msg(FALSE); | |
372 | 2957 } |
2958 | |
2959 /* | |
324 | 2960 * Make a copy of "word", with the first letter upper or lower cased, to |
2961 * "wcopy[MAXWLEN]". "word" must not be empty. | |
2962 * The result is NUL terminated. | |
323 | 2963 */ |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2964 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2965 onecap_copy( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2966 char_u *word, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2967 char_u *wcopy, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2968 int upper) // TRUE: first letter made upper case |
323 | 2969 { |
2970 char_u *p; | |
2971 int c; | |
2972 int l; | |
2973 | |
2974 p = word; | |
2975 if (has_mbyte) | |
474 | 2976 c = mb_cptr2char_adv(&p); |
323 | 2977 else |
2978 c = *p++; | |
2979 if (upper) | |
324 | 2980 c = SPELL_TOUPPER(c); |
323 | 2981 else |
324 | 2982 c = SPELL_TOFOLD(c); |
323 | 2983 if (has_mbyte) |
2984 l = mb_char2bytes(c, wcopy); | |
2985 else | |
2986 { | |
2987 l = 1; | |
2988 wcopy[0] = c; | |
2989 } | |
376 | 2990 vim_strncpy(wcopy + l, p, MAXWLEN - l - 1); |
323 | 2991 } |
2992 | |
2993 /* | |
324 | 2994 * Make a copy of "word" with all the letters upper cased into |
2995 * "wcopy[MAXWLEN]". The result is NUL terminated. | |
323 | 2996 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
2997 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2998 allcap_copy(char_u *word, char_u *wcopy) |
323 | 2999 { |
3000 char_u *s; | |
3001 char_u *d; | |
3002 int c; | |
3003 | |
3004 d = wcopy; | |
3005 for (s = word; *s != NUL; ) | |
3006 { | |
3007 if (has_mbyte) | |
474 | 3008 c = mb_cptr2char_adv(&s); |
323 | 3009 else |
3010 c = *s++; | |
492 | 3011 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3012 // We only change 0xdf to SS when we are certain latin1 is used. It |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3013 // would cause weird errors in other 8-bit encodings. |
492 | 3014 if (enc_latin1like && c == 0xdf) |
3015 { | |
3016 c = 'S'; | |
3017 if (d - wcopy >= MAXWLEN - 1) | |
3018 break; | |
3019 *d++ = c; | |
3020 } | |
3021 else | |
3022 c = SPELL_TOUPPER(c); | |
323 | 3023 |
3024 if (has_mbyte) | |
3025 { | |
3026 if (d - wcopy >= MAXWLEN - MB_MAXBYTES) | |
3027 break; | |
3028 d += mb_char2bytes(c, d); | |
3029 } | |
3030 else | |
3031 { | |
3032 if (d - wcopy >= MAXWLEN - 1) | |
3033 break; | |
3034 *d++ = c; | |
3035 } | |
3036 } | |
3037 *d = NUL; | |
3038 } | |
3039 | |
3040 /* | |
455 | 3041 * Case-folding may change the number of bytes: Count nr of chars in |
3042 * fword[flen] and return the byte length of that many chars in "word". | |
3043 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
3044 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3045 nofold_len(char_u *fword, int flen, char_u *word) |
455 | 3046 { |
3047 char_u *p; | |
3048 int i = 0; | |
3049 | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3050 for (p = fword; p < fword + flen; MB_PTR_ADV(p)) |
455 | 3051 ++i; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3052 for (p = word; i > 0; MB_PTR_ADV(p)) |
455 | 3053 --i; |
3054 return (int)(p - word); | |
3055 } | |
3056 | |
323 | 3057 /* |
324 | 3058 * Copy "fword" to "cword", fixing case according to "flags". |
323 | 3059 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
3060 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3061 make_case_word(char_u *fword, char_u *cword, int flags) |
323 | 3062 { |
3063 if (flags & WF_ALLCAP) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3064 // Make it all upper-case |
323 | 3065 allcap_copy(fword, cword); |
3066 else if (flags & WF_ONECAP) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3067 // Make the first letter upper-case |
324 | 3068 onecap_copy(fword, cword, TRUE); |
323 | 3069 else |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3070 // Use goodword as-is. |
323 | 3071 STRCPY(cword, fword); |
3072 } | |
3073 | |
372 | 3074 #if defined(FEAT_EVAL) || defined(PROTO) |
3075 /* | |
3076 * Soundfold a string, for soundfold(). | |
3077 * Result is in allocated memory, NULL for an error. | |
3078 */ | |
3079 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3080 eval_soundfold(char_u *word) |
372 | 3081 { |
3082 langp_T *lp; | |
3083 char_u sound[MAXWLEN]; | |
500 | 3084 int lpi; |
372 | 3085 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3086 if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3087 // Use the sound-folding of the first language that supports it. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3088 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3089 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3090 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
372 | 3091 if (lp->lp_slang->sl_sal.ga_len > 0) |
3092 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3093 // soundfold the word |
375 | 3094 spell_soundfold(lp->lp_slang, word, FALSE, sound); |
372 | 3095 return vim_strsave(sound); |
3096 } | |
500 | 3097 } |
372 | 3098 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3099 // No language with sound folding, return word as-is. |
372 | 3100 return vim_strsave(word); |
3101 } | |
3102 #endif | |
3103 | |
323 | 3104 /* |
3105 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". | |
485 | 3106 * |
3107 * There are many ways to turn a word into a sound-a-like representation. The | |
3108 * oldest is Soundex (1918!). A nice overview can be found in "Approximate | |
3109 * swedish name matching - survey and test of different algorithms" by Klas | |
3110 * Erikson. | |
3111 * | |
3112 * We support two methods: | |
3113 * 1. SOFOFROM/SOFOTO do a simple character mapping. | |
3114 * 2. SAL items define a more advanced sound-folding (and much slower). | |
323 | 3115 */ |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
3116 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3117 spell_soundfold( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3118 slang_T *slang, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3119 char_u *inword, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3120 int folded, // "inword" is already case-folded |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3121 char_u *res) |
375 | 3122 { |
3123 char_u fword[MAXWLEN]; | |
3124 char_u *word; | |
3125 | |
3126 if (slang->sl_sofo) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3127 // SOFOFROM and SOFOTO used |
375 | 3128 spell_soundfold_sofo(slang, inword, res); |
3129 else | |
3130 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3131 // SAL items used. Requires the word to be case-folded. |
375 | 3132 if (folded) |
3133 word = inword; | |
3134 else | |
3135 { | |
24872
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
3136 (void)spell_casefold(curwin, |
59cfa23bd9eb
patch 8.2.2974: Greek spell checking uses wrong case folding
Bram Moolenaar <Bram@vim.org>
parents:
23422
diff
changeset
|
3137 inword, (int)STRLEN(inword), fword, MAXWLEN); |
375 | 3138 word = fword; |
3139 } | |
3140 | |
3141 if (has_mbyte) | |
3142 spell_soundfold_wsal(slang, word, res); | |
3143 else | |
3144 spell_soundfold_sal(slang, word, res); | |
3145 } | |
3146 } | |
3147 | |
3148 /* | |
3149 * Perform sound folding of "inword" into "res" according to SOFOFROM and | |
3150 * SOFOTO lines. | |
3151 */ | |
3152 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3153 spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) |
375 | 3154 { |
3155 char_u *s; | |
3156 int ri = 0; | |
3157 int c; | |
3158 | |
3159 if (has_mbyte) | |
3160 { | |
3161 int prevc = 0; | |
3162 int *ip; | |
3163 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3164 // The sl_sal_first[] table contains the translation for chars up to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3165 // 255, sl_sal the rest. |
375 | 3166 for (s = inword; *s != NUL; ) |
3167 { | |
474 | 3168 c = mb_cptr2char_adv(&s); |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3169 if (enc_utf8 ? utf_class(c) == 0 : VIM_ISWHITE(c)) |
375 | 3170 c = ' '; |
3171 else if (c < 256) | |
3172 c = slang->sl_sal_first[c]; | |
3173 else | |
3174 { | |
3175 ip = ((int **)slang->sl_sal.ga_data)[c & 0xff]; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3176 if (ip == NULL) // empty list, can't match |
375 | 3177 c = NUL; |
3178 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3179 for (;;) // find "c" in the list |
375 | 3180 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3181 if (*ip == 0) // not found |
375 | 3182 { |
3183 c = NUL; | |
3184 break; | |
3185 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3186 if (*ip == c) // match! |
375 | 3187 { |
3188 c = ip[1]; | |
3189 break; | |
3190 } | |
3191 ip += 2; | |
3192 } | |
3193 } | |
3194 | |
3195 if (c != NUL && c != prevc) | |
3196 { | |
3197 ri += mb_char2bytes(c, res + ri); | |
3198 if (ri + MB_MAXBYTES > MAXWLEN) | |
3199 break; | |
3200 prevc = c; | |
3201 } | |
3202 } | |
3203 } | |
3204 else | |
3205 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3206 // The sl_sal_first[] table contains the translation. |
375 | 3207 for (s = inword; (c = *s) != NUL; ++s) |
3208 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3209 if (VIM_ISWHITE(c)) |
375 | 3210 c = ' '; |
3211 else | |
3212 c = slang->sl_sal_first[c]; | |
3213 if (c != NUL && (ri == 0 || res[ri - 1] != c)) | |
3214 res[ri++] = c; | |
3215 } | |
3216 } | |
3217 | |
3218 res[ri] = NUL; | |
3219 } | |
3220 | |
3221 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3222 spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res) |
323 | 3223 { |
344 | 3224 salitem_T *smp; |
323 | 3225 char_u word[MAXWLEN]; |
375 | 3226 char_u *s = inword; |
323 | 3227 char_u *t; |
344 | 3228 char_u *pf; |
323 | 3229 int i, j, z; |
344 | 3230 int reslen; |
323 | 3231 int n, k = 0; |
3232 int z0; | |
3233 int k0; | |
3234 int n0; | |
3235 int c; | |
3236 int pri; | |
3237 int p0 = -333; | |
3238 int c0; | |
3239 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3240 // Remove accents, if wanted. We actually remove all non-word characters. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3241 // But keep white space. We need a copy, the word may be changed here. |
323 | 3242 if (slang->sl_rem_accents) |
3243 { | |
3244 t = word; | |
375 | 3245 while (*s != NUL) |
323 | 3246 { |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3247 if (VIM_ISWHITE(*s)) |
344 | 3248 { |
3249 *t++ = ' '; | |
3250 s = skipwhite(s); | |
3251 } | |
323 | 3252 else |
3253 { | |
5477 | 3254 if (spell_iswordp_nmw(s, curwin)) |
323 | 3255 *t++ = *s; |
3256 ++s; | |
3257 } | |
3258 } | |
3259 *t = NUL; | |
3260 } | |
3261 else | |
2768 | 3262 vim_strncpy(word, s, MAXWLEN - 1); |
323 | 3263 |
344 | 3264 smp = (salitem_T *)slang->sl_sal.ga_data; |
323 | 3265 |
3266 /* | |
3267 * This comes from Aspell phonet.cpp. Converted from C++ to C. | |
324 | 3268 * Changed to keep spaces. |
323 | 3269 */ |
344 | 3270 i = reslen = z = 0; |
323 | 3271 while ((c = word[i]) != NUL) |
3272 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3273 // Start with the first rule that has the character in the word. |
323 | 3274 n = slang->sl_sal_first[c]; |
3275 z0 = 0; | |
3276 | |
3277 if (n >= 0) | |
3278 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3279 // check all rules for the same letter |
344 | 3280 for (; (s = smp[n].sm_lead)[0] == c; ++n) |
323 | 3281 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3282 // Quickly skip entries that don't match the word. Most |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
3283 // entries are less than three chars, optimize for that. |
344 | 3284 k = smp[n].sm_leadlen; |
3285 if (k > 1) | |
323 | 3286 { |
344 | 3287 if (word[i + 1] != s[1]) |
3288 continue; | |
3289 if (k > 2) | |
3290 { | |
3291 for (j = 2; j < k; ++j) | |
3292 if (word[i + j] != s[j]) | |
3293 break; | |
3294 if (j < k) | |
3295 continue; | |
3296 } | |
323 | 3297 } |
3298 | |
375 | 3299 if ((pf = smp[n].sm_oneof) != NULL) |
323 | 3300 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3301 // Check for match with one of the chars in "sm_oneof". |
344 | 3302 while (*pf != NUL && *pf != word[i + k]) |
3303 ++pf; | |
3304 if (*pf == NUL) | |
3305 continue; | |
3306 ++k; | |
323 | 3307 } |
344 | 3308 s = smp[n].sm_rules; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3309 pri = 5; // default priority |
323 | 3310 |
3311 p0 = *s; | |
3312 k0 = k; | |
3313 while (*s == '-' && k > 1) | |
3314 { | |
3315 k--; | |
3316 s++; | |
3317 } | |
3318 if (*s == '<') | |
3319 s++; | |
344 | 3320 if (VIM_ISDIGIT(*s)) |
323 | 3321 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3322 // determine priority |
323 | 3323 pri = *s - '0'; |
3324 s++; | |
3325 } | |
3326 if (*s == '^' && *(s + 1) == '^') | |
3327 s++; | |
3328 | |
3329 if (*s == NUL | |
3330 || (*s == '^' | |
324 | 3331 && (i == 0 || !(word[i - 1] == ' ' |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3332 || spell_iswordp(word + i - 1, curwin))) |
323 | 3333 && (*(s + 1) != '$' |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3334 || (!spell_iswordp(word + i + k0, curwin)))) |
323 | 3335 || (*s == '$' && i > 0 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3336 && spell_iswordp(word + i - 1, curwin) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3337 && (!spell_iswordp(word + i + k0, curwin)))) |
323 | 3338 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3339 // search for followup rules, if: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3340 // followup and k > 1 and NO '-' in searchstring |
323 | 3341 c0 = word[i + k - 1]; |
3342 n0 = slang->sl_sal_first[c0]; | |
3343 | |
3344 if (slang->sl_followup && k > 1 && n0 >= 0 | |
344 | 3345 && p0 != '-' && word[i + k] != NUL) |
323 | 3346 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3347 // test follow-up rule for "word[i + k]" |
344 | 3348 for ( ; (s = smp[n0].sm_lead)[0] == c0; ++n0) |
323 | 3349 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3350 // Quickly skip entries that don't match the word. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3351 // |
344 | 3352 k0 = smp[n0].sm_leadlen; |
3353 if (k0 > 1) | |
323 | 3354 { |
344 | 3355 if (word[i + k] != s[1]) |
3356 continue; | |
3357 if (k0 > 2) | |
3358 { | |
3359 pf = word + i + k + 1; | |
3360 for (j = 2; j < k0; ++j) | |
3361 if (*pf++ != s[j]) | |
3362 break; | |
3363 if (j < k0) | |
3364 continue; | |
3365 } | |
323 | 3366 } |
344 | 3367 k0 += k - 1; |
3368 | |
375 | 3369 if ((pf = smp[n0].sm_oneof) != NULL) |
323 | 3370 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3371 // Check for match with one of the chars in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3372 // "sm_oneof". |
344 | 3373 while (*pf != NUL && *pf != word[i + k0]) |
3374 ++pf; | |
3375 if (*pf == NUL) | |
3376 continue; | |
3377 ++k0; | |
323 | 3378 } |
344 | 3379 |
3380 p0 = 5; | |
3381 s = smp[n0].sm_rules; | |
323 | 3382 while (*s == '-') |
3383 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3384 // "k0" gets NOT reduced because |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3385 // "if (k0 == k)" |
323 | 3386 s++; |
3387 } | |
3388 if (*s == '<') | |
3389 s++; | |
344 | 3390 if (VIM_ISDIGIT(*s)) |
323 | 3391 { |
3392 p0 = *s - '0'; | |
3393 s++; | |
3394 } | |
3395 | |
3396 if (*s == NUL | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3397 // *s == '^' cuts |
323 | 3398 || (*s == '$' |
376 | 3399 && !spell_iswordp(word + i + k0, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3400 curwin))) |
323 | 3401 { |
3402 if (k0 == k) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3403 // this is just a piece of the string |
323 | 3404 continue; |
3405 | |
3406 if (p0 < pri) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3407 // priority too low |
323 | 3408 continue; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3409 // rule fits; stop search |
323 | 3410 break; |
3411 } | |
3412 } | |
3413 | |
344 | 3414 if (p0 >= pri && smp[n0].sm_lead[0] == c0) |
323 | 3415 continue; |
3416 } | |
3417 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3418 // replace string |
344 | 3419 s = smp[n].sm_to; |
389 | 3420 if (s == NULL) |
3421 s = (char_u *)""; | |
344 | 3422 pf = smp[n].sm_rules; |
3423 p0 = (vim_strchr(pf, '<') != NULL) ? 1 : 0; | |
323 | 3424 if (p0 == 1 && z == 0) |
3425 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3426 // rule with '<' is used |
344 | 3427 if (reslen > 0 && *s != NUL && (res[reslen - 1] == c |
3428 || res[reslen - 1] == *s)) | |
3429 reslen--; | |
323 | 3430 z0 = 1; |
3431 z = 1; | |
3432 k0 = 0; | |
372 | 3433 while (*s != NUL && word[i + k0] != NUL) |
323 | 3434 { |
3435 word[i + k0] = *s; | |
3436 k0++; | |
3437 s++; | |
3438 } | |
3439 if (k > k0) | |
1619 | 3440 STRMOVE(word + i + k0, word + i + k); |
323 | 3441 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3442 // new "actual letter" |
323 | 3443 c = word[i]; |
3444 } | |
3445 else | |
3446 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3447 // no '<' rule used |
323 | 3448 i += k - 1; |
3449 z = 0; | |
344 | 3450 while (*s != NUL && s[1] != NUL && reslen < MAXWLEN) |
323 | 3451 { |
344 | 3452 if (reslen == 0 || res[reslen - 1] != *s) |
372 | 3453 res[reslen++] = *s; |
323 | 3454 s++; |
3455 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3456 // new "actual letter" |
323 | 3457 c = *s; |
344 | 3458 if (strstr((char *)pf, "^^") != NULL) |
323 | 3459 { |
3460 if (c != NUL) | |
372 | 3461 res[reslen++] = c; |
1619 | 3462 STRMOVE(word, word + i + 1); |
323 | 3463 i = 0; |
3464 z0 = 1; | |
3465 } | |
3466 } | |
3467 break; | |
3468 } | |
3469 } | |
3470 } | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3471 else if (VIM_ISWHITE(c)) |
324 | 3472 { |
3473 c = ' '; | |
3474 k = 1; | |
3475 } | |
323 | 3476 |
3477 if (z0 == 0) | |
3478 { | |
344 | 3479 if (k && !p0 && reslen < MAXWLEN && c != NUL |
3480 && (!slang->sl_collapse || reslen == 0 | |
3481 || res[reslen - 1] != c)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3482 // condense only double letters |
372 | 3483 res[reslen++] = c; |
323 | 3484 |
3485 i++; | |
3486 z = 0; | |
3487 k = 0; | |
3488 } | |
3489 } | |
3490 | |
344 | 3491 res[reslen] = NUL; |
323 | 3492 } |
3493 | |
372 | 3494 /* |
3495 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". | |
3496 * Multi-byte version of spell_soundfold(). | |
3497 */ | |
3498 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3499 spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) |
372 | 3500 { |
375 | 3501 salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; |
372 | 3502 int word[MAXWLEN]; |
3503 int wres[MAXWLEN]; | |
3504 int l; | |
3505 char_u *s; | |
3506 int *ws; | |
3507 char_u *t; | |
3508 int *pf; | |
3509 int i, j, z; | |
3510 int reslen; | |
3511 int n, k = 0; | |
3512 int z0; | |
3513 int k0; | |
3514 int n0; | |
3515 int c; | |
3516 int pri; | |
3517 int p0 = -333; | |
3518 int c0; | |
3519 int did_white = FALSE; | |
3520 | 3520 int wordlen; |
3521 | |
372 | 3522 |
3523 /* | |
3524 * Convert the multi-byte string to a wide-character string. | |
3525 * Remove accents, if wanted. We actually remove all non-word characters. | |
3526 * But keep white space. | |
3527 */ | |
3520 | 3528 wordlen = 0; |
372 | 3529 for (s = inword; *s != NUL; ) |
3530 { | |
3531 t = s; | |
474 | 3532 c = mb_cptr2char_adv(&s); |
372 | 3533 if (slang->sl_rem_accents) |
3534 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3535 if (enc_utf8 ? utf_class(c) == 0 : VIM_ISWHITE(c)) |
372 | 3536 { |
3537 if (did_white) | |
3538 continue; | |
3539 c = ' '; | |
3540 did_white = TRUE; | |
3541 } | |
3542 else | |
3543 { | |
3544 did_white = FALSE; | |
5477 | 3545 if (!spell_iswordp_nmw(t, curwin)) |
372 | 3546 continue; |
3547 } | |
3548 } | |
3520 | 3549 word[wordlen++] = c; |
3550 } | |
3551 word[wordlen] = NUL; | |
372 | 3552 |
3553 /* | |
3520 | 3554 * This algorithm comes from Aspell phonet.cpp. |
372 | 3555 * Converted from C++ to C. Added support for multi-byte chars. |
3556 * Changed to keep spaces. | |
3557 */ | |
3558 i = reslen = z = 0; | |
3559 while ((c = word[i]) != NUL) | |
3560 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3561 // Start with the first rule that has the character in the word. |
372 | 3562 n = slang->sl_sal_first[c & 0xff]; |
3563 z0 = 0; | |
3564 | |
3565 if (n >= 0) | |
3566 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3567 // Check all rules for the same index byte. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3568 // If c is 0x300 need extra check for the end of the array, as |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3569 // (c & 0xff) is NUL. |
2455
9367de3e2e1b
Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents:
2454
diff
changeset
|
3570 for (; ((ws = smp[n].sm_lead_w)[0] & 0xff) == (c & 0xff) |
9367de3e2e1b
Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents:
2454
diff
changeset
|
3571 && ws[0] != NUL; ++n) |
372 | 3572 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3573 // Quickly skip entries that don't match the word. Most |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
3574 // entries are less than three chars, optimize for that. |
375 | 3575 if (c != ws[0]) |
3576 continue; | |
372 | 3577 k = smp[n].sm_leadlen; |
3578 if (k > 1) | |
3579 { | |
3580 if (word[i + 1] != ws[1]) | |
3581 continue; | |
3582 if (k > 2) | |
3583 { | |
3584 for (j = 2; j < k; ++j) | |
3585 if (word[i + j] != ws[j]) | |
3586 break; | |
3587 if (j < k) | |
3588 continue; | |
3589 } | |
3590 } | |
3591 | |
375 | 3592 if ((pf = smp[n].sm_oneof_w) != NULL) |
372 | 3593 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3594 // Check for match with one of the chars in "sm_oneof". |
372 | 3595 while (*pf != NUL && *pf != word[i + k]) |
3596 ++pf; | |
3597 if (*pf == NUL) | |
3598 continue; | |
3599 ++k; | |
3600 } | |
3601 s = smp[n].sm_rules; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3602 pri = 5; // default priority |
372 | 3603 |
3604 p0 = *s; | |
3605 k0 = k; | |
3606 while (*s == '-' && k > 1) | |
3607 { | |
3608 k--; | |
3609 s++; | |
3610 } | |
3611 if (*s == '<') | |
3612 s++; | |
3613 if (VIM_ISDIGIT(*s)) | |
3614 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3615 // determine priority |
372 | 3616 pri = *s - '0'; |
3617 s++; | |
3618 } | |
3619 if (*s == '^' && *(s + 1) == '^') | |
3620 s++; | |
3621 | |
3622 if (*s == NUL | |
3623 || (*s == '^' | |
3624 && (i == 0 || !(word[i - 1] == ' ' | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3625 || spell_iswordp_w(word + i - 1, curwin))) |
372 | 3626 && (*(s + 1) != '$' |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3627 || (!spell_iswordp_w(word + i + k0, curwin)))) |
372 | 3628 || (*s == '$' && i > 0 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3629 && spell_iswordp_w(word + i - 1, curwin) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3630 && (!spell_iswordp_w(word + i + k0, curwin)))) |
372 | 3631 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3632 // search for followup rules, if: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3633 // followup and k > 1 and NO '-' in searchstring |
372 | 3634 c0 = word[i + k - 1]; |
3635 n0 = slang->sl_sal_first[c0 & 0xff]; | |
3636 | |
3637 if (slang->sl_followup && k > 1 && n0 >= 0 | |
3638 && p0 != '-' && word[i + k] != NUL) | |
3639 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3640 // Test follow-up rule for "word[i + k]"; loop over |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3641 // all entries with the same index byte. |
372 | 3642 for ( ; ((ws = smp[n0].sm_lead_w)[0] & 0xff) |
3643 == (c0 & 0xff); ++n0) | |
3644 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3645 // Quickly skip entries that don't match the word. |
375 | 3646 if (c0 != ws[0]) |
3647 continue; | |
372 | 3648 k0 = smp[n0].sm_leadlen; |
3649 if (k0 > 1) | |
3650 { | |
3651 if (word[i + k] != ws[1]) | |
3652 continue; | |
3653 if (k0 > 2) | |
3654 { | |
3655 pf = word + i + k + 1; | |
3656 for (j = 2; j < k0; ++j) | |
3657 if (*pf++ != ws[j]) | |
3658 break; | |
3659 if (j < k0) | |
3660 continue; | |
3661 } | |
3662 } | |
3663 k0 += k - 1; | |
3664 | |
375 | 3665 if ((pf = smp[n0].sm_oneof_w) != NULL) |
372 | 3666 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3667 // Check for match with one of the chars in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3668 // "sm_oneof". |
372 | 3669 while (*pf != NUL && *pf != word[i + k0]) |
3670 ++pf; | |
3671 if (*pf == NUL) | |
3672 continue; | |
3673 ++k0; | |
3674 } | |
3675 | |
3676 p0 = 5; | |
3677 s = smp[n0].sm_rules; | |
3678 while (*s == '-') | |
3679 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3680 // "k0" gets NOT reduced because |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3681 // "if (k0 == k)" |
372 | 3682 s++; |
3683 } | |
3684 if (*s == '<') | |
3685 s++; | |
3686 if (VIM_ISDIGIT(*s)) | |
3687 { | |
3688 p0 = *s - '0'; | |
3689 s++; | |
3690 } | |
3691 | |
3692 if (*s == NUL | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3693 // *s == '^' cuts |
372 | 3694 || (*s == '$' |
376 | 3695 && !spell_iswordp_w(word + i + k0, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3696 curwin))) |
372 | 3697 { |
3698 if (k0 == k) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3699 // this is just a piece of the string |
372 | 3700 continue; |
3701 | |
3702 if (p0 < pri) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3703 // priority too low |
372 | 3704 continue; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3705 // rule fits; stop search |
372 | 3706 break; |
3707 } | |
3708 } | |
3709 | |
3710 if (p0 >= pri && (smp[n0].sm_lead_w[0] & 0xff) | |
3711 == (c0 & 0xff)) | |
3712 continue; | |
3713 } | |
3714 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3715 // replace string |
372 | 3716 ws = smp[n].sm_to_w; |
3717 s = smp[n].sm_rules; | |
3718 p0 = (vim_strchr(s, '<') != NULL) ? 1 : 0; | |
3719 if (p0 == 1 && z == 0) | |
3720 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3721 // rule with '<' is used |
389 | 3722 if (reslen > 0 && ws != NULL && *ws != NUL |
3723 && (wres[reslen - 1] == c | |
372 | 3724 || wres[reslen - 1] == *ws)) |
3725 reslen--; | |
3726 z0 = 1; | |
3727 z = 1; | |
3728 k0 = 0; | |
389 | 3729 if (ws != NULL) |
3730 while (*ws != NUL && word[i + k0] != NUL) | |
3731 { | |
3732 word[i + k0] = *ws; | |
3733 k0++; | |
3734 ws++; | |
3735 } | |
372 | 3736 if (k > k0) |
3737 mch_memmove(word + i + k0, word + i + k, | |
3520 | 3738 sizeof(int) * (wordlen - (i + k) + 1)); |
372 | 3739 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3740 // new "actual letter" |
372 | 3741 c = word[i]; |
3742 } | |
3743 else | |
3744 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3745 // no '<' rule used |
372 | 3746 i += k - 1; |
3747 z = 0; | |
389 | 3748 if (ws != NULL) |
3749 while (*ws != NUL && ws[1] != NUL | |
3750 && reslen < MAXWLEN) | |
3751 { | |
3752 if (reslen == 0 || wres[reslen - 1] != *ws) | |
3753 wres[reslen++] = *ws; | |
3754 ws++; | |
3755 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3756 // new "actual letter" |
389 | 3757 if (ws == NULL) |
3758 c = NUL; | |
3759 else | |
3760 c = *ws; | |
372 | 3761 if (strstr((char *)s, "^^") != NULL) |
3762 { | |
3763 if (c != NUL) | |
3764 wres[reslen++] = c; | |
3765 mch_memmove(word, word + i + 1, | |
3520 | 3766 sizeof(int) * (wordlen - (i + 1) + 1)); |
372 | 3767 i = 0; |
3768 z0 = 1; | |
3769 } | |
3770 } | |
3771 break; | |
3772 } | |
3773 } | |
3774 } | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3775 else if (VIM_ISWHITE(c)) |
372 | 3776 { |
3777 c = ' '; | |
3778 k = 1; | |
3779 } | |
3780 | |
3781 if (z0 == 0) | |
3782 { | |
3783 if (k && !p0 && reslen < MAXWLEN && c != NUL | |
3784 && (!slang->sl_collapse || reslen == 0 | |
3785 || wres[reslen - 1] != c)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3786 // condense only double letters |
372 | 3787 wres[reslen++] = c; |
3788 | |
3789 i++; | |
3790 z = 0; | |
3791 k = 0; | |
3792 } | |
3793 } | |
3794 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3795 // Convert wide characters in "wres" to a multi-byte string in "res". |
372 | 3796 l = 0; |
3797 for (n = 0; n < reslen; ++n) | |
3798 { | |
3799 l += mb_char2bytes(wres[n], res + l); | |
3800 if (l + MB_MAXBYTES > MAXWLEN) | |
3801 break; | |
3802 } | |
3803 res[l] = NUL; | |
3804 } | |
3805 | |
324 | 3806 /* |
714 | 3807 * ":spellinfo" |
3808 */ | |
3809 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3810 ex_spellinfo(exarg_T *eap UNUSED) |
714 | 3811 { |
3812 int lpi; | |
3813 langp_T *lp; | |
3814 char_u *p; | |
3815 | |
3816 if (no_spell_checking(curwin)) | |
3817 return; | |
3818 | |
3819 msg_start(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3820 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len && !got_int; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3821 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3822 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3823 msg_puts("file: "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3824 msg_puts((char *)lp->lp_slang->sl_fname); |
714 | 3825 msg_putchar('\n'); |
3826 p = lp->lp_slang->sl_info; | |
3827 if (p != NULL) | |
3828 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3829 msg_puts((char *)p); |
714 | 3830 msg_putchar('\n'); |
3831 } | |
3832 } | |
3833 msg_end(); | |
3834 } | |
3835 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3836 #define DUMPFLAG_KEEPCASE 1 // round 2: keep-case tree |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3837 #define DUMPFLAG_COUNT 2 // include word count |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3838 #define DUMPFLAG_ICASE 4 // ignore case when finding matches |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3839 #define DUMPFLAG_ONECAP 8 // pattern starts with capital |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3840 #define DUMPFLAG_ALLCAP 16 // pattern is all capitals |
625 | 3841 |
351 | 3842 /* |
3843 * ":spelldump" | |
3844 */ | |
3845 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3846 ex_spelldump(exarg_T *eap) |
351 | 3847 { |
5382 | 3848 char_u *spl; |
3849 long dummy; | |
3850 | |
701 | 3851 if (no_spell_checking(curwin)) |
3852 return; | |
26441
65ab0b035dd8
patch 8.2.3751: cannot assign a lambda to an option that takes a function
Bram Moolenaar <Bram@vim.org>
parents:
25567
diff
changeset
|
3853 (void)get_option_value((char_u*)"spl", &dummy, &spl, NULL, OPT_LOCAL); |
5382 | 3854 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3855 // Create a new empty buffer in a new window. |
701 | 3856 do_cmdline_cmd((char_u *)"new"); |
5382 | 3857 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3858 // enable spelling locally in the new window |
28457
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28169
diff
changeset
|
3859 set_option_value_give_err((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL); |
4dcccb2673fe
patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents:
28169
diff
changeset
|
3860 set_option_value_give_err((char_u*)"spl", dummy, spl, OPT_LOCAL); |
5382 | 3861 vim_free(spl); |
3862 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10950
diff
changeset
|
3863 if (!BUFEMPTY()) |
701 | 3864 return; |
3865 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3866 spell_dump_compl(NULL, 0, NULL, eap->forceit ? DUMPFLAG_COUNT : 0); |
701 | 3867 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3868 // Delete the empty line that we started with. |
701 | 3869 if (curbuf->b_ml.ml_line_count > 1) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3870 ml_delete(curbuf->b_ml.ml_line_count); |
701 | 3871 |
29732
89e1d67814a9
patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents:
29595
diff
changeset
|
3872 redraw_later(UPD_NOT_VALID); |
701 | 3873 } |
3874 | |
3875 /* | |
3876 * Go through all possible words and: | |
3877 * 1. When "pat" is NULL: dump a list of all words in the current buffer. | |
3878 * "ic" and "dir" are not used. | |
3879 * 2. When "pat" is not NULL: add matching words to insert mode completion. | |
3880 */ | |
3881 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3882 spell_dump_compl( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3883 char_u *pat, // leading part of the word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3884 int ic, // ignore case |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3885 int *dir, // direction for adding matches |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3886 int dumpflags_arg) // DUMPFLAG_* |
701 | 3887 { |
351 | 3888 langp_T *lp; |
3889 slang_T *slang; | |
3890 idx_T arridx[MAXWLEN]; | |
3891 int curi[MAXWLEN]; | |
3892 char_u word[MAXWLEN]; | |
3893 int c; | |
3894 char_u *byts; | |
3895 idx_T *idxs; | |
3896 linenr_T lnum = 0; | |
3897 int round; | |
3898 int depth; | |
3899 int n; | |
3900 int flags; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3901 char_u *region_names = NULL; // region names being used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3902 int do_region = TRUE; // dump region names and numbers |
381 | 3903 char_u *p; |
500 | 3904 int lpi; |
701 | 3905 int dumpflags = dumpflags_arg; |
3906 int patlen; | |
3907 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3908 // When ignoring case or when the pattern starts with capital pass this on |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3909 // to dump_word(). |
710 | 3910 if (pat != NULL) |
3911 { | |
3912 if (ic) | |
3913 dumpflags |= DUMPFLAG_ICASE; | |
3914 else | |
3915 { | |
3916 n = captype(pat, NULL); | |
3917 if (n == WF_ONECAP) | |
3918 dumpflags |= DUMPFLAG_ONECAP; | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3919 else if (n == WF_ALLCAP && (int)STRLEN(pat) > mb_ptr2len(pat)) |
710 | 3920 dumpflags |= DUMPFLAG_ALLCAP; |
3921 } | |
3922 } | |
351 | 3923 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3924 // Find out if we can support regions: All languages must support the same |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3925 // regions or none at all. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3926 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3927 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3928 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
381 | 3929 p = lp->lp_slang->sl_regions; |
3930 if (p[0] != 0) | |
3931 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3932 if (region_names == NULL) // first language with regions |
381 | 3933 region_names = p; |
3934 else if (STRCMP(region_names, p) != 0) | |
3935 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3936 do_region = FALSE; // region names are different |
381 | 3937 break; |
3938 } | |
3939 } | |
3940 } | |
3941 | |
3942 if (do_region && region_names != NULL) | |
3943 { | |
701 | 3944 if (pat == NULL) |
3945 { | |
3946 vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names); | |
3947 ml_append(lnum++, IObuff, (colnr_T)0, FALSE); | |
3948 } | |
381 | 3949 } |
3950 else | |
3951 do_region = FALSE; | |
3952 | |
3953 /* | |
3954 * Loop over all files loaded for the entries in 'spelllang'. | |
3955 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3956 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3957 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3958 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
351 | 3959 slang = lp->lp_slang; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3960 if (slang->sl_fbyts == NULL) // reloading failed |
500 | 3961 continue; |
351 | 3962 |
701 | 3963 if (pat == NULL) |
3964 { | |
3965 vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname); | |
3966 ml_append(lnum++, IObuff, (colnr_T)0, FALSE); | |
3967 } | |
3968 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3969 // When matching with a pattern and there are no prefixes only use |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3970 // parts of the tree that match "pat". |
701 | 3971 if (pat != NULL && slang->sl_pbyts == NULL) |
835 | 3972 patlen = (int)STRLEN(pat); |
701 | 3973 else |
840 | 3974 patlen = -1; |
351 | 3975 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3976 // round 1: case-folded tree |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3977 // round 2: keep-case tree |
351 | 3978 for (round = 1; round <= 2; ++round) |
3979 { | |
3980 if (round == 1) | |
3981 { | |
701 | 3982 dumpflags &= ~DUMPFLAG_KEEPCASE; |
351 | 3983 byts = slang->sl_fbyts; |
3984 idxs = slang->sl_fidxs; | |
3985 } | |
3986 else | |
3987 { | |
701 | 3988 dumpflags |= DUMPFLAG_KEEPCASE; |
351 | 3989 byts = slang->sl_kbyts; |
3990 idxs = slang->sl_kidxs; | |
3991 } | |
3992 if (byts == NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3993 continue; // array is empty |
351 | 3994 |
3995 depth = 0; | |
3996 arridx[0] = 0; | |
3997 curi[0] = 1; | |
701 | 3998 while (depth >= 0 && !got_int |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
3999 && (pat == NULL || !ins_compl_interrupted())) |
351 | 4000 { |
4001 if (curi[depth] > byts[arridx[depth]]) | |
4002 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4003 // Done all bytes at this node, go up one level. |
351 | 4004 --depth; |
4005 line_breakcheck(); | |
10277
154d5a2e7395
commit https://github.com/vim/vim/commit/472e85970ee3a80abd824bef510df12e9cfe9e96
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4006 ins_compl_check_keys(50, FALSE); |
351 | 4007 } |
4008 else | |
4009 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4010 // Do one more byte at this node. |
351 | 4011 n = arridx[depth] + curi[depth]; |
4012 ++curi[depth]; | |
4013 c = byts[n]; | |
29385
5b7b5b372e2d
patch 9.0.0035: spell dump may go beyond end of an array
Bram Moolenaar <Bram@vim.org>
parents:
29102
diff
changeset
|
4014 if (c == 0 || depth >= MAXWLEN - 1) |
351 | 4015 { |
29385
5b7b5b372e2d
patch 9.0.0035: spell dump may go beyond end of an array
Bram Moolenaar <Bram@vim.org>
parents:
29102
diff
changeset
|
4016 // End of word or reached maximum length, deal with the |
5b7b5b372e2d
patch 9.0.0035: spell dump may go beyond end of an array
Bram Moolenaar <Bram@vim.org>
parents:
29102
diff
changeset
|
4017 // word. |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4018 // Don't use keep-case words in the fold-case tree, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4019 // they will appear in the keep-case tree. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4020 // Only use the word when the region matches. |
351 | 4021 flags = (int)idxs[n]; |
4022 if ((round == 2 || (flags & WF_KEEPCAP) == 0) | |
500 | 4023 && (flags & WF_NEEDCOMP) == 0 |
381 | 4024 && (do_region |
4025 || (flags & WF_REGION) == 0 | |
390 | 4026 || (((unsigned)flags >> 16) |
351 | 4027 & lp->lp_region) != 0)) |
4028 { | |
4029 word[depth] = NUL; | |
381 | 4030 if (!do_region) |
4031 flags &= ~WF_REGION; | |
355 | 4032 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4033 // Dump the basic word if there is no prefix or |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4034 // when it's the first one. |
390 | 4035 c = (unsigned)flags >> 24; |
355 | 4036 if (c == 0 || curi[depth] == 2) |
701 | 4037 { |
4038 dump_word(slang, word, pat, dir, | |
4039 dumpflags, flags, lnum); | |
4040 if (pat == NULL) | |
4041 ++lnum; | |
4042 } | |
351 | 4043 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4044 // Apply the prefix, if there is one. |
355 | 4045 if (c != 0) |
701 | 4046 lnum = dump_prefixes(slang, word, pat, dir, |
4047 dumpflags, flags, lnum); | |
351 | 4048 } |
4049 } | |
4050 else | |
4051 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4052 // Normal char, go one level deeper. |
351 | 4053 word[depth++] = c; |
4054 arridx[depth] = idxs[n]; | |
4055 curi[depth] = 1; | |
701 | 4056 |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26441
diff
changeset
|
4057 // Check if this character matches with the pattern. |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4058 // If not skip the whole tree below it. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4059 // Always ignore case here, dump_word() will check |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4060 // proper case later. This isn't exactly right when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4061 // length changes for multi-byte characters with |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4062 // ignore case... |
710 | 4063 if (depth <= patlen |
4064 && MB_STRNICMP(word, pat, depth) != 0) | |
701 | 4065 --depth; |
351 | 4066 } |
4067 } | |
4068 } | |
4069 } | |
4070 } | |
4071 } | |
4072 | |
4073 /* | |
4074 * Dump one word: apply case modifications and append a line to the buffer. | |
701 | 4075 * When "lnum" is zero add insert mode completion. |
4076 */ | |
4077 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4078 dump_word( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4079 slang_T *slang, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4080 char_u *word, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4081 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4082 int *dir, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4083 int dumpflags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4084 int wordflags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4085 linenr_T lnum) |
351 | 4086 { |
4087 int keepcap = FALSE; | |
4088 char_u *p; | |
625 | 4089 char_u *tw; |
351 | 4090 char_u cword[MAXWLEN]; |
381 | 4091 char_u badword[MAXWLEN + 10]; |
4092 int i; | |
710 | 4093 int flags = wordflags; |
4094 | |
4095 if (dumpflags & DUMPFLAG_ONECAP) | |
4096 flags |= WF_ONECAP; | |
4097 if (dumpflags & DUMPFLAG_ALLCAP) | |
4098 flags |= WF_ALLCAP; | |
351 | 4099 |
625 | 4100 if ((dumpflags & DUMPFLAG_KEEPCASE) == 0 && (flags & WF_CAPMASK) != 0) |
351 | 4101 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4102 // Need to fix case according to "flags". |
351 | 4103 make_case_word(word, cword, flags); |
4104 p = cword; | |
4105 } | |
4106 else | |
4107 { | |
4108 p = word; | |
625 | 4109 if ((dumpflags & DUMPFLAG_KEEPCASE) |
4110 && ((captype(word, NULL) & WF_KEEPCAP) == 0 | |
389 | 4111 || (flags & WF_FIXCAP) != 0)) |
351 | 4112 keepcap = TRUE; |
4113 } | |
625 | 4114 tw = p; |
351 | 4115 |
701 | 4116 if (pat == NULL) |
4117 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4118 // Add flags and regions after a slash. |
701 | 4119 if ((flags & (WF_BANNED | WF_RARE | WF_REGION)) || keepcap) |
4120 { | |
4121 STRCPY(badword, p); | |
4122 STRCAT(badword, "/"); | |
4123 if (keepcap) | |
4124 STRCAT(badword, "="); | |
4125 if (flags & WF_BANNED) | |
4126 STRCAT(badword, "!"); | |
4127 else if (flags & WF_RARE) | |
4128 STRCAT(badword, "?"); | |
4129 if (flags & WF_REGION) | |
4130 for (i = 0; i < 7; ++i) | |
4131 if (flags & (0x10000 << i)) | |
4132 sprintf((char *)badword + STRLEN(badword), "%d", i + 1); | |
4133 p = badword; | |
4134 } | |
4135 | |
4136 if (dumpflags & DUMPFLAG_COUNT) | |
4137 { | |
4138 hashitem_T *hi; | |
4139 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4140 // Include the word count for ":spelldump!". |
701 | 4141 hi = hash_find(&slang->sl_wordcount, tw); |
4142 if (!HASHITEM_EMPTY(hi)) | |
4143 { | |
4144 vim_snprintf((char *)IObuff, IOSIZE, "%s\t%d", | |
625 | 4145 tw, HI2WC(hi)->wc_count); |
701 | 4146 p = IObuff; |
4147 } | |
4148 } | |
4149 | |
4150 ml_append(lnum, p, (colnr_T)0, FALSE); | |
4151 } | |
710 | 4152 else if (((dumpflags & DUMPFLAG_ICASE) |
4153 ? MB_STRNICMP(p, pat, STRLEN(pat)) == 0 | |
4154 : STRNCMP(p, pat, STRLEN(pat)) == 0) | |
701 | 4155 && ins_compl_add_infercase(p, (int)STRLEN(p), |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4156 p_ic, NULL, *dir, FALSE) == OK) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4157 // if dir was BACKWARD then honor it just once |
710 | 4158 *dir = FORWARD; |
351 | 4159 } |
4160 | |
4161 /* | |
372 | 4162 * For ":spelldump": Find matching prefixes for "word". Prepend each to |
4163 * "word" and append a line to the buffer. | |
701 | 4164 * When "lnum" is zero add insert mode completion. |
351 | 4165 * Return the updated line number. |
4166 */ | |
4167 static linenr_T | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4168 dump_prefixes( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4169 slang_T *slang, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4170 char_u *word, // case-folded word |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4171 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4172 int *dir, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4173 int dumpflags, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4174 int flags, // flags with prefix ID |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4175 linenr_T startlnum) |
351 | 4176 { |
4177 idx_T arridx[MAXWLEN]; | |
4178 int curi[MAXWLEN]; | |
4179 char_u prefix[MAXWLEN]; | |
455 | 4180 char_u word_up[MAXWLEN]; |
4181 int has_word_up = FALSE; | |
351 | 4182 int c; |
4183 char_u *byts; | |
4184 idx_T *idxs; | |
4185 linenr_T lnum = startlnum; | |
4186 int depth; | |
4187 int n; | |
4188 int len; | |
4189 int i; | |
4190 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4191 // If the word starts with a lower-case letter make the word with an |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4192 // upper-case letter in word_up[]. |
455 | 4193 c = PTR2CHAR(word); |
4194 if (SPELL_TOUPPER(c) != c) | |
4195 { | |
4196 onecap_copy(word, word_up, TRUE); | |
4197 has_word_up = TRUE; | |
4198 } | |
4199 | |
351 | 4200 byts = slang->sl_pbyts; |
4201 idxs = slang->sl_pidxs; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4202 if (byts != NULL) // array not is empty |
351 | 4203 { |
4204 /* | |
4205 * Loop over all prefixes, building them byte-by-byte in prefix[]. | |
390 | 4206 * When at the end of a prefix check that it supports "flags". |
351 | 4207 */ |
4208 depth = 0; | |
4209 arridx[0] = 0; | |
4210 curi[0] = 1; | |
4211 while (depth >= 0 && !got_int) | |
4212 { | |
390 | 4213 n = arridx[depth]; |
4214 len = byts[n]; | |
4215 if (curi[depth] > len) | |
351 | 4216 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4217 // Done all bytes at this node, go up one level. |
351 | 4218 --depth; |
4219 line_breakcheck(); | |
4220 } | |
4221 else | |
4222 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4223 // Do one more byte at this node. |
390 | 4224 n += curi[depth]; |
351 | 4225 ++curi[depth]; |
4226 c = byts[n]; | |
4227 if (c == 0) | |
4228 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4229 // End of prefix, find out how many IDs there are. |
351 | 4230 for (i = 1; i < len; ++i) |
4231 if (byts[n + i] != 0) | |
4232 break; | |
4233 curi[depth] += i - 1; | |
4234 | |
455 | 4235 c = valid_word_prefix(i, n, flags, word, slang, FALSE); |
4236 if (c != 0) | |
351 | 4237 { |
376 | 4238 vim_strncpy(prefix + depth, word, MAXWLEN - depth - 1); |
701 | 4239 dump_word(slang, prefix, pat, dir, dumpflags, |
455 | 4240 (c & WF_RAREPFX) ? (flags | WF_RARE) |
701 | 4241 : flags, lnum); |
4242 if (lnum != 0) | |
4243 ++lnum; | |
351 | 4244 } |
455 | 4245 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4246 // Check for prefix that matches the word when the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4247 // first letter is upper-case, but only if the prefix has |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4248 // a condition. |
455 | 4249 if (has_word_up) |
4250 { | |
4251 c = valid_word_prefix(i, n, flags, word_up, slang, | |
4252 TRUE); | |
4253 if (c != 0) | |
4254 { | |
4255 vim_strncpy(prefix + depth, word_up, | |
4256 MAXWLEN - depth - 1); | |
701 | 4257 dump_word(slang, prefix, pat, dir, dumpflags, |
455 | 4258 (c & WF_RAREPFX) ? (flags | WF_RARE) |
701 | 4259 : flags, lnum); |
4260 if (lnum != 0) | |
4261 ++lnum; | |
455 | 4262 } |
4263 } | |
351 | 4264 } |
4265 else | |
4266 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4267 // Normal char, go one level deeper. |
351 | 4268 prefix[depth++] = c; |
4269 arridx[depth] = idxs[n]; | |
4270 curi[depth] = 1; | |
4271 } | |
4272 } | |
4273 } | |
4274 } | |
4275 | |
4276 return lnum; | |
4277 } | |
4278 | |
498 | 4279 /* |
626 | 4280 * Move "p" to the end of word "start". |
4281 * Uses the spell-checking word characters. | |
498 | 4282 */ |
4283 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4284 spell_to_word_end(char_u *start, win_T *win) |
498 | 4285 { |
4286 char_u *p = start; | |
4287 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
4288 while (*p != NUL && spell_iswordp(p, win)) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4289 MB_PTR_ADV(p); |
498 | 4290 return p; |
4291 } | |
4292 | |
475 | 4293 /* |
626 | 4294 * For Insert mode completion CTRL-X s: |
4295 * Find start of the word in front of column "startcol". | |
4296 * We don't check if it is badly spelled, with completion we can only change | |
4297 * the word in front of the cursor. | |
475 | 4298 * Returns the column number of the word. |
4299 */ | |
4300 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4301 spell_word_start(int startcol) |
475 | 4302 { |
4303 char_u *line; | |
4304 char_u *p; | |
4305 int col = 0; | |
4306 | |
498 | 4307 if (no_spell_checking(curwin)) |
475 | 4308 return startcol; |
4309 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4310 // Find a word character before "startcol". |
475 | 4311 line = ml_get_curline(); |
4312 for (p = line + startcol; p > line; ) | |
4313 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4314 MB_PTR_BACK(line, p); |
5477 | 4315 if (spell_iswordp_nmw(p, curwin)) |
475 | 4316 break; |
4317 } | |
4318 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4319 // Go back to start of the word. |
475 | 4320 while (p > line) |
4321 { | |
835 | 4322 col = (int)(p - line); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4323 MB_PTR_BACK(line, p); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
4324 if (!spell_iswordp(p, curwin)) |
475 | 4325 break; |
4326 col = 0; | |
4327 } | |
4328 | |
535 | 4329 return col; |
4330 } | |
4331 | |
4332 /* | |
4333 * Need to check for 'spellcapcheck' now, the word is removed before | |
4334 * expand_spelling() is called. Therefore the ugly global variable. | |
4335 */ | |
4336 static int spell_expand_need_cap; | |
4337 | |
4338 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4339 spell_expand_check_cap(colnr_T col) |
535 | 4340 { |
475 | 4341 spell_expand_need_cap = check_need_cap(curwin->w_cursor.lnum, col); |
4342 } | |
4343 | |
4344 /* | |
4345 * Get list of spelling suggestions. | |
4346 * Used for Insert mode completion CTRL-X ?. | |
4347 * Returns the number of matches. The matches are in "matchp[]", array of | |
4348 * allocated strings. | |
4349 */ | |
4350 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4351 expand_spelling( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4352 linenr_T lnum UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4353 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4354 char_u ***matchp) |
475 | 4355 { |
4356 garray_T ga; | |
4357 | |
625 | 4358 spell_suggest_list(&ga, pat, 100, spell_expand_need_cap, TRUE); |
475 | 4359 *matchp = ga.ga_data; |
4360 return ga.ga_len; | |
4361 } | |
4362 | |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4363 /* |
20760
813b9a7064a4
patch 8.2.0932: missspelling spelllang
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4364 * Return TRUE if "val" is a valid 'spelllang' value. |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4365 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4366 int |
20760
813b9a7064a4
patch 8.2.0932: missspelling spelllang
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4367 valid_spelllang(char_u *val) |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4368 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4369 return valid_name(val, ".-_,@"); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4370 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4371 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4372 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4373 * Return TRUE if "val" is a valid 'spellfile' value. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4374 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4375 int |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4376 valid_spellfile(char_u *val) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4377 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4378 char_u *s; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4379 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4380 for (s = val; *s != NUL; ++s) |
29595
5233acfa06f1
patch 9.0.0138: not enough characters accepted for 'spellfile'
Bram Moolenaar <Bram@vim.org>
parents:
29385
diff
changeset
|
4381 if (!vim_is_fname_char(*s)) |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4382 return FALSE; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4383 return TRUE; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4384 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4385 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4386 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4387 * Handle side effects of setting 'spell'. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4388 * Return an error message or NULL for success. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4389 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4390 char * |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4391 did_set_spell_option(int is_spellfile) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4392 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4393 char *errmsg = NULL; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4394 win_T *wp; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4395 int l; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4396 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4397 if (is_spellfile) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4398 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4399 l = (int)STRLEN(curwin->w_s->b_p_spf); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4400 if (l > 0 && (l < 4 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4401 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0)) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
4402 errmsg = e_invalid_argument; |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4403 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4404 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4405 if (errmsg == NULL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4406 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4407 FOR_ALL_WINDOWS(wp) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4408 if (wp->w_buffer == curbuf && wp->w_p_spell) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4409 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4410 errmsg = did_set_spelllang(wp); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4411 break; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4412 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4413 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4414 return errmsg; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4415 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4416 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4417 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4418 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4419 * Return error message when failed, NULL when OK. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4420 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4421 char * |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4422 compile_cap_prog(synblock_T *synblock) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4423 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4424 regprog_T *rp = synblock->b_cap_prog; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4425 char_u *re; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4426 |
18305
f4db8631d9c5
patch 8.1.2147: crash when allocating memory fails
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
4427 if (synblock->b_p_spc == NULL || *synblock->b_p_spc == NUL) |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4428 synblock->b_cap_prog = NULL; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4429 else |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4430 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4431 // Prepend a ^ so that we only match at one column |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4432 re = concat_str((char_u *)"^", synblock->b_p_spc); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4433 if (re != NULL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4434 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4435 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4436 vim_free(re); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4437 if (synblock->b_cap_prog == NULL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4438 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4439 synblock->b_cap_prog = rp; // restore the previous program |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26771
diff
changeset
|
4440 return e_invalid_argument; |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4441 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4442 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4443 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4444 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4445 vim_regfree(rp); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4446 return NULL; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4447 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4448 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4449 #endif // FEAT_SPELL |