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