annotate src/spell.c @ 19940:724417668d42 v8.2.0526

patch 8.2.0526: Gcc 9 complains about empty statement Commit: https://github.com/vim/vim/commit/86b9a3e8cd24335195dbe377b98bed1ba291268d Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 7 19:57:29 2020 +0200 patch 8.2.0526: Gcc 9 complains about empty statement Problem: Gcc 9 complains about empty statement. Solution: Add {}. (Dominique Pelle, closes https://github.com/vim/vim/issues/5894)
author Bram Moolenaar <Bram@vim.org>
date Tue, 07 Apr 2020 20:00:04 +0200
parents 435726a03481
children aadd1cae2ff5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
2 *
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
4 *
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
8 */
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
9
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
10 /*
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
11 * spell.c: code for spell checking
226
4e7dca477fee updated for version 7.0063
vimboss
parents: 223
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
15 * The spell checking mechanism uses a tree (aka trie). Each node in the tree
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
16 * has a list of bytes that can appear (siblings). For each byte there is a
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
17 * pointer to the node with the byte that follows in the word (child).
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
18 *
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
19 * A NUL byte is used where the word may end. The bytes are sorted, so that
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
20 * binary searching can be used and the NUL bytes are at the start. The
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
21 * number of possible bytes is stored before the list of bytes.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
22 *
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
23 * The tree uses two arrays: "byts" stores the characters, "idxs" stores
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
24 * either the next index or flags. The tree starts at index 0. For example,
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
25 * to lookup "vi" this sequence is followed:
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
26 * i = 0
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
27 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
28 * n = where "v" appears in byts[i + 1] to byts[i + len]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
29 * i = idxs[n]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
30 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
31 * n = where "i" appears in byts[i + 1] to byts[i + len]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
32 * i = idxs[n]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
33 * len = byts[i]
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
34 * find that byts[i + 1] is 0, idxs[i + 1] has flags for "vi".
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
35 *
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
36 * There are two word trees: one with case-folded words and one with words in
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
37 * original case. The second one is only used for keep-case words and is
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
38 * usually small.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
39 *
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
40 * There is one additional tree for when not all prefixes are applied when
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
41 * generating the .spl file. This tree stores all the possible prefixes, as
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
42 * if they were words. At each word (prefix) end the prefix nr is stored, the
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
43 * following word must support this prefix nr. And the condition nr is
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
44 * stored, used to lookup the condition that the word must match with.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
45 *
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
46 * Thanks to Olaf Seibert for providing an example implementation of this tree
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
47 * and the compression mechanism.
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
48 * LZ trie ideas:
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
49 * http://www.irb.hr/hr/home/ristov/papers/RistovLZtrieRevision1.pdf
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
50 * More papers: http://www-igm.univ-mlv.fr/~laporte/publi_en.html
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
51 *
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
52 * Matching involves checking the caps type: Onecap ALLCAP KeepCap.
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
53 *
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
54 * Why doesn't Vim use aspell/ispell/myspell/etc.?
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
55 * See ":help develop-spell".
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
56 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
59 #include "vim.h"
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
60
737
59971e227f8c updated for version 7.0222
vimboss
parents: 718
diff changeset
61 #if defined(FEAT_SPELL) || defined(PROTO)
223
5175af353b81 updated for version 7.0062
vimboss
parents:
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
65 #endif
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
70 #define VIMSUGMAGICL 6
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
71 #define VIMSUGVERSION 1
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
74 #define SP_BANNED -1
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
75 #define SP_OK 0
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
76 #define SP_RARE 1
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
77 #define SP_LOCAL 2
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
78 #define SP_BAD 3
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
79
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
80 /*
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
81 * Structure to store info for word matching.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
82 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
83 typedef struct matchinf_S
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
120 } matchinf_T;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
146 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
147 * Main spell-checking function.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
148 * "ptr" points to a character that could be the start of a word.
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
149 * "*attrp" is set to the highlight index for a badly spelled word. For a
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
150 * non-word or when it's OK it remains unchanged.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
151 * This must only be called when 'spelllang' is not empty.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
152 *
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
153 * "capcol" is used to check for a Capitalised word after the end of a
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
154 * sentence. If it's zero then perform the check. Return the column where to
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
155 * check next, or -1 when no sentence end was found. If it's NULL then don't
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
156 * worry.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
157 *
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
158 * Returns the length of the word in bytes, also when it's OK, so that the
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
159 * caller can skip over the word.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
160 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
172 int c;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
173 int wrongcaplen = 0;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
174 int lpi;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
175 int count_word = docount;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
179 if (*ptr <= ' ')
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
180 return 1;
690
0e922220d322 updated for version 7.0208
vimboss
parents: 649
diff changeset
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
0e922220d322 updated for version 7.0208
vimboss
parents: 649
diff changeset
184 return 1;
0e922220d322 updated for version 7.0208
vimboss
parents: 649
diff changeset
185
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
186 vim_memset(&mi, 0, sizeof(matchinf_T));
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
191 if (*ptr >= '0' && *ptr <= '9')
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
196 mi.mi_end = skiphex(ptr + 2);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
197 else
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
198 mi.mi_end = skipdigits(ptr);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
199 nrlen = (int)(mi.mi_end - ptr);
584
5953bf5509ec updated for version 7.0166
vimboss
parents: 548
diff changeset
200 }
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
203 mi.mi_word = ptr;
584
5953bf5509ec updated for version 7.0166
vimboss
parents: 548
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
206 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
214 c = PTR2CHAR(ptr);
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
215 if (!SPELL_ISUPPER(c))
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
216 wrongcaplen = (int)(mi.mi_fend - ptr);
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
217 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
218 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
219 if (capcol != NULL)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
220 *capcol = -1;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
224 mi.mi_end = mi.mi_fend;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
235
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
236 (void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword,
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
237 MAXWLEN + 1);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
238 mi.mi_fwordlen = (int)STRLEN(mi.mi_fword);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
241 mi.mi_result = SP_BAD;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
242 mi.mi_result2 = SP_BAD;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
243
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
244 /*
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
245 * Loop over the languages specified in 'spelllang'.
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
246 * We check them all, because a word may be matched longer in another
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
247 * language.
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
255 if (mi.mi_lp->lp_slang->sl_fidxs == NULL)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
256 continue;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
259 find_word(&mi, FIND_FOLDWORD);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
262 find_word(&mi, FIND_KEEPWORD);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
265 find_prefix(&mi, FIND_FOLDWORD);
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
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
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
269 if (mi.mi_lp->lp_slang->sl_nobreak && mi.mi_result == SP_BAD
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
270 && mi.mi_result2 != SP_BAD)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
271 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
272 mi.mi_result = mi.mi_result2;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
273 mi.mi_end = mi.mi_end2;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
274 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
277 if (count_word && mi.mi_result == SP_OK)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
278 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
279 count_common_word(mi.mi_lp->lp_slang, ptr,
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
280 (int)(mi.mi_end - ptr), 1);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
281 count_word = FALSE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
282 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
283 }
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
284
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
285 if (mi.mi_result != SP_OK)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
289 if (nrlen > 0)
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
290 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
291 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
292 return nrlen;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
293 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
297 else if (!spell_iswordp_nmw(ptr, wp))
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
300 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
301 regmatch_T regmatch;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
302 int r;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
306 regmatch.rm_ic = FALSE;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
307 r = vim_regexec(&regmatch, ptr, 0);
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
308 wp->w_s->b_cap_prog = regmatch.regprog;
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
309 if (r)
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
310 *capcol = (int)(regmatch.endp[0] - ptr);
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
311 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
312
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
313 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
314 return (*mb_ptr2len)(ptr);
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
315 return 1;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
316 }
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
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
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
323 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
324 char_u *p, *fp;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
325 int save_result = mi.mi_result;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
330 if (mi.mi_lp->lp_slang->sl_fidxs != NULL)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
331 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
332 p = mi.mi_word;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
333 fp = mi.mi_fword;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
334 for (;;)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
338 if (p >= mi.mi_end)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
339 break;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
340 mi.mi_compoff = (int)(fp - mi.mi_fword);
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
341 find_word(&mi, FIND_COMPOUND);
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
342 if (mi.mi_result != SP_BAD)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
343 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
344 mi.mi_end = p;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
345 break;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
346 }
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
347 }
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
348 mi.mi_result = save_result;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
349 }
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
350 }
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
351
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
352 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED)
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
353 *attrp = HLF_SPB;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
354 else if (mi.mi_result == SP_RARE)
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
355 *attrp = HLF_SPR;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
356 else
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
357 *attrp = HLF_SPL;
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
358 }
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
359
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
360 if (wrongcaplen > 0 && (mi.mi_result == SP_OK || mi.mi_result == SP_RARE))
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
363 *attrp = HLF_SPC;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
364 return wrongcaplen;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
365 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
366
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
367 return (int)(mi.mi_end - ptr);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
368 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
369
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
370 /*
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
371 * Check if the word at "mip->mi_word" is in the tree.
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
372 * When "mode" is FIND_FOLDWORD check in fold-case word tree.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
373 * When "mode" is FIND_KEEPWORD check in keep-case word tree.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
374 * When "mode" is FIND_PREFIX check for word after prefix in fold-case word
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
375 * tree.
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
376 *
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
377 * For a match mip->mi_result is updated.
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
378 */
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
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
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
381 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
385 int endidxcnt = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
386 int len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
387 int wlen = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
388 int flen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
389 int c;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
390 char_u *ptr;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
391 idx_T lo, hi, m;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
392 char_u *s;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
393 char_u *p;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
394 int res = SP_BAD;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
395 slang_T *slang = mip->mi_lp->lp_slang;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
396 unsigned flags;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
397 char_u *byts;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
398 idx_T *idxs;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
399 int word_ends;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
400 int prefix_found;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
401 int nobreak_result;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
402
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
403 if (mode == FIND_KEEPWORD || mode == FIND_KEEPCOMPOUND)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
408 byts = slang->sl_kbyts;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
409 idxs = slang->sl_kidxs;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
410
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
413 wlen += mip->mi_compoff;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
414 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
415 else
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
420 byts = slang->sl_fbyts;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
421 idxs = slang->sl_fidxs;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
422
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
423 if (mode == FIND_PREFIX)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
426 wlen = mip->mi_prefixlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
427 flen -= mip->mi_prefixlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
428 }
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
429 else if (mode == FIND_COMPOUND)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
432 wlen = mip->mi_compoff;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
433 flen -= mip->mi_compoff;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
434 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
435
243
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
436 }
8ff168d3720a updated for version 7.0068
vimboss
parents: 240
diff changeset
437
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
440
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
441 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
442 * Repeat advancing in the tree until:
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
443 * - there is a byte that doesn't match,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
444 * - we reach the end of the tree,
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
445 * - or we reach the end of the line.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
446 */
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
447 for (;;)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
448 {
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
449 if (flen <= 0 && *mip->mi_fend != NUL)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
450 flen = fold_more(mip);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
451
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
452 len = byts[arridx++];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
456 if (byts[arridx] == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
457 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
458 if (endidxcnt == MAXWLEN)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
462 return;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
463 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
464 endlen[endidxcnt] = wlen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
465 endidx[endidxcnt++] = arridx++;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
466 --len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
470 while (len > 0 && byts[arridx] == 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
471 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
472 ++arridx;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
473 --len;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
474 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
477 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
480 if (ptr[wlen] == NUL)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
481 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
486 c = ' ';
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
487 lo = arridx;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
488 hi = arridx + len - 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
489 while (lo < hi)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
490 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
491 m = (lo + hi) / 2;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
492 if (byts[m] > c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
493 hi = m - 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
494 else if (byts[m] < c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
495 lo = m + 1;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
496 else
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
497 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
498 lo = hi = m;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
499 break;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
500 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
501 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
504 if (hi < lo || byts[lo] != c)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
505 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
508 arridx = idxs[lo];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
509 ++wlen;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
510 --flen;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
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
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
514 if (c == ' ')
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
515 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
516 for (;;)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
517 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
518 if (flen <= 0 && *mip->mi_fend != NUL)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
519 flen = fold_more(mip);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
520 if (ptr[wlen] != ' ' && ptr[wlen] != TAB)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
521 break;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
522 ++wlen;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
523 --flen;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
524 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
525 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
526 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
527
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
528 /*
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
529 * Verify that one of the possible endings is valid. Try the longest
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
530 * first.
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
531 */
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
532 while (endidxcnt > 0)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
533 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
534 --endidxcnt;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
535 arridx = endidx[endidxcnt];
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
536 wlen = endlen[endidxcnt];
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
537
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
541 {
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
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
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
544 word_ends = FALSE;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
545 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
546 else
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
550 prefix_found = FALSE;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
551
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
552 if (mode != FIND_KEEPWORD && has_mbyte)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
557 p = mip->mi_word;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
558 if (STRNCMP(ptr, p, wlen) != 0)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
562 wlen = (int)(p - mip->mi_word);
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
563 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
564 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
570 res = SP_BAD;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
571 for (len = byts[arridx - 1]; len > 0 && byts[arridx] == 0;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
572 --len, ++arridx)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
573 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
574 flags = idxs[arridx];
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
580 if (mode == FIND_FOLDWORD)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
581 {
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
582 if (mip->mi_cend != mip->mi_word + wlen)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
586 mip->mi_cend = mip->mi_word + wlen;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
587 mip->mi_capflags = captype(mip->mi_word, mip->mi_cend);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
588 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
589
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
590 if (mip->mi_capflags == WF_KEEPCAP
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
591 || !spell_valid_case(mip->mi_capflags, flags))
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
592 continue;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
593 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
598 else if (mode == FIND_PREFIX && !prefix_found)
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
599 {
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
600 c = valid_word_prefix(mip->mi_prefcnt, mip->mi_prefarridx,
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
601 flags,
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
602 mip->mi_word + mip->mi_cprefixlen, slang,
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
603 FALSE);
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
604 if (c == 0)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
605 continue;
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
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
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
608 if (c & WF_RAREPFX)
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
609 flags |= WF_RARE;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
610 prefix_found = TRUE;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
611 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
612
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
613 if (slang->sl_nobreak)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
614 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
615 if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
616 && (flags & WF_BANNED) == 0)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
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
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
620 mip->mi_result = SP_OK;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
621 break;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
622 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
623 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
624
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
625 else if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
626 || !word_ends))
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
633 if (((unsigned)flags >> 24) == 0
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
634 || wlen - mip->mi_compoff < slang->sl_compminlen)
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
638 if (has_mbyte
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
639 && slang->sl_compminlen > 0
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
640 && mb_charlen_len(mip->mi_word + mip->mi_compoff,
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
641 wlen - mip->mi_compoff) < slang->sl_compminlen)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
642 continue;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
646 if (!word_ends && mip->mi_complen + mip->mi_compextra + 2
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
647 > slang->sl_compmax
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
648 && slang->sl_compsylmax == MAXWLEN)
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
649 continue;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
653 if (mip->mi_complen > 0 && (flags & WF_NOCOMPBEF))
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
654 continue;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
655 if (!word_ends && (flags & WF_NOCOMPAFT))
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
656 continue;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
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
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
659 if (!byte_in_str(mip->mi_complen == 0
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
660 ? slang->sl_compstartflags
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
661 : slang->sl_compallflags,
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
662 ((unsigned)flags >> 24)))
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
663 continue;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
667 if (match_checkcompoundpattern(ptr, wlen, &slang->sl_comppat))
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
668 continue;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
669
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
670 if (mode == FIND_COMPOUND)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
671 {
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
672 int capflags;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
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
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
676 if (has_mbyte && STRNCMP(ptr, mip->mi_word,
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
677 mip->mi_compoff) != 0)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
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
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
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
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
683 }
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
684 else
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
685 p = mip->mi_word + mip->mi_compoff;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
686 capflags = captype(p, mip->mi_word + wlen);
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
687 if (capflags == WF_KEEPCAP || (capflags == WF_ALLCAP
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
688 && (flags & WF_FIXCAP) != 0))
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
689 continue;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
690
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
691 if (capflags != WF_ALLCAP)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
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
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
698 if (spell_iswordp_nmw(p, mip->mi_win)
490
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
699 ? capflags == WF_ONECAP
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
700 : (flags & WF_ONECAP) != 0
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
701 && capflags != WF_ONECAP)
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
702 continue;
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
703 }
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
704 }
4321aae7e769 updated for version 7.0134
vimboss
parents: 485
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
709 mip->mi_compflags[mip->mi_complen] = ((unsigned)flags >> 24);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
710 mip->mi_compflags[mip->mi_complen + 1] = NUL;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
711 if (word_ends)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
712 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
713 char_u fword[MAXWLEN];
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
714
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
715 if (slang->sl_compsylmax < MAXWLEN)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
718 if (ptr == mip->mi_word)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
719 (void)spell_casefold(ptr, wlen, fword, MAXWLEN);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
720 else
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
721 vim_strncpy(fword, ptr, endlen[endidxcnt]);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
722 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
723 if (!can_compound(slang, fword, mip->mi_compflags))
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
724 continue;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
725 }
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
726 else if (slang->sl_comprules != NULL
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
730 continue;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
731 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
734 else if (flags & WF_NEEDCOMP)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
735 continue;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
736
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
737 nobreak_result = SP_OK;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
738
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
739 if (!word_ends)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
740 {
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
741 int save_result = mip->mi_result;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
742 char_u *save_end = mip->mi_end;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
743 langp_T *save_lp = mip->mi_lp;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
744 int lpi;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
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
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
751 if (slang->sl_nobreak)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
752 mip->mi_result = SP_BAD;
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
755 mip->mi_compoff = endlen[endidxcnt];
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
756 if (has_mbyte && mode == FIND_KEEPWORD)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
762 p = mip->mi_fword;
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
763 if (STRNCMP(ptr, p, wlen) != 0)
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
767 mip->mi_compoff = (int)(p - mip->mi_fword);
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
768 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
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
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
773 ++mip->mi_complen;
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
774 if (flags & WF_COMPROOT)
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
775 ++mip->mi_compextra;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
780 {
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
781 if (slang->sl_nobreak)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
784 if (mip->mi_lp->lp_slang->sl_fidxs == NULL
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
785 || !mip->mi_lp->lp_slang->sl_nobreak)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
786 continue;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
787 }
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
788
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
789 find_word(mip, FIND_COMPOUND);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
794 if (!slang->sl_nobreak || mip->mi_result == SP_BAD)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
797 mip->mi_compoff = wlen;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
798 find_word(mip, FIND_KEEPCOMPOUND);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
803 if (!slang->sl_nobreak || mip->mi_result == SP_BAD)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
806 mip->mi_compoff = c;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
807 find_prefix(mip, FIND_COMPOUND);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
808 }
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 817
diff changeset
809 #endif
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
810 }
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
811
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
812 if (!slang->sl_nobreak)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
813 break;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
814 }
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
815 --mip->mi_complen;
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
816 if (flags & WF_COMPROOT)
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
817 --mip->mi_compextra;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
818 mip->mi_lp = save_lp;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
819
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
820 if (slang->sl_nobreak)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
821 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
822 nobreak_result = mip->mi_result;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
823 mip->mi_result = save_result;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
824 mip->mi_end = save_end;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
825 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
826 else
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
827 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
828 if (mip->mi_result == SP_OK)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
829 break;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
830 continue;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
831 }
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
832 }
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
833
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
834 if (flags & WF_BANNED)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
835 res = SP_BANNED;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
836 else if (flags & WF_REGION)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
839 if ((mip->mi_lp->lp_region & (flags >> 16)) != 0)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
840 res = SP_OK;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
841 else
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
842 res = SP_LOCAL;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
843 }
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
844 else if (flags & WF_RARE)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
845 res = SP_RARE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
846 else
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
847 res = SP_OK;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
852 if (nobreak_result == SP_BAD)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
853 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
854 if (mip->mi_result2 > res)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
855 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
856 mip->mi_result2 = res;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
857 mip->mi_end2 = mip->mi_word + wlen;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
858 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
859 else if (mip->mi_result2 == res
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
860 && mip->mi_end2 < mip->mi_word + wlen)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
861 mip->mi_end2 = mip->mi_word + wlen;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
862 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
863 else if (mip->mi_result > res)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
864 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
865 mip->mi_result = res;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
866 mip->mi_end = mip->mi_word + wlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
867 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
868 else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
869 mip->mi_end = mip->mi_word + wlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
870
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
871 if (mip->mi_result == SP_OK)
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
872 break;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
873 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
874
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
875 if (mip->mi_result == SP_OK)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
876 break;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
877 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
878 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
879
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
880 /*
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
881 * Return TRUE if there is a match between the word ptr[wlen] and
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
882 * CHECKCOMPOUNDPATTERN rules, assuming that we will concatenate with another
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
883 * word.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
884 * A match means that the first part of CHECKCOMPOUNDPATTERN matches at the
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
885 * end of ptr[wlen] and the second part matches after it.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
892 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
893 int i;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
894 char_u *p;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
895 int len;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
896
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
897 for (i = 0; i + 1 < gap->ga_len; i += 2)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
898 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
899 p = ((char_u **)gap->ga_data)[i + 1];
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
900 if (STRNCMP(ptr + wlen, p, STRLEN(p)) == 0)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
904 p = ((char_u **)gap->ga_data)[i];
1771
1f90fab89ce3 updated for version 7.2-069
vimboss
parents: 1762
diff changeset
905 len = (int)STRLEN(p);
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
906 if (len <= wlen && STRNCMP(ptr + wlen - len, p, len) == 0)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
907 return TRUE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
908 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
909 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
910 return FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
911 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
912
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
913 /*
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
914 * Return TRUE if "flags" is a valid sequence of compound flags and "word"
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
915 * does not have too many syllables.
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
919 {
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
920 char_u uflags[MAXWLEN * 2];
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
921 int i;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
922 char_u *p;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
923
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
924 if (slang->sl_compprog == NULL)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
925 return FALSE;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
926 if (enc_utf8)
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
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
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
929 p = uflags;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
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
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
932 *p = NUL;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
933 p = uflags;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
934 }
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
935 else
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
936 p = flags;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
937 if (!vim_regexec_prog(&slang->sl_compprog, FALSE, p, 0))
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
938 return FALSE;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
943 if (slang->sl_compsylmax < MAXWLEN
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
944 && count_syllables(slang, word) > slang->sl_compsylmax)
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
945 return (int)STRLEN(flags) < slang->sl_compmax;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
946 return TRUE;
482
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
947 }
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
948
6f8b578776ab updated for version 7.0131
vimboss
parents: 481
diff changeset
949 /*
1762
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
950 * Return TRUE if the compound flags in compflags[] match the start of any
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
951 * compound rule. This is used to stop trying a compound if the flags
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
952 * collected so far can't possibly match any compound rule.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
953 * Caller must check that slang->sl_comprules is not NULL.
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
957 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
958 char_u *p;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
959 int i;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
960 int c;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
963 for (p = slang->sl_comprules; *p != NUL; ++p)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
967 for (i = 0; ; ++i)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
968 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
969 c = compflags[i];
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
972 return TRUE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
975 if (*p == '[')
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
976 {
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
977 int match = FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
980 ++p;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
981 while (*p != ']' && *p != NUL)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
982 if (*p++ == c)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
983 match = TRUE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
986 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
989 ++p;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
990 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
993 p = vim_strchr(p, '/');
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
994 if (p == NULL)
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
995 break;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
996 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
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
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1000 return FALSE;
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1001 }
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1002
158a68529622 updated for version 7.2-060
vimboss
parents: 1759
diff changeset
1003 /*
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1004 * Return non-zero if the prefix indicated by "arridx" matches with the prefix
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1005 * ID in "flags" for the word "word".
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1006 * The WF_RAREPFX flag is included in the return value for a rare prefix.
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1016 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1017 int prefcnt;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1018 int pidx;
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1019 regprog_T **rp;
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1020 int prefid;
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1021
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1022 prefid = (unsigned)flags >> 24;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1023 for (prefcnt = totprefcnt - 1; prefcnt >= 0; --prefcnt)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1024 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1025 pidx = slang->sl_pidxs[arridx + prefcnt];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1028 if (prefid != (pidx & 0xff))
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1029 continue;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1033 if ((flags & WF_HAS_AFF) && (pidx & WF_PFX_NC))
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
1034 continue;
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
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
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1038 rp = &slang->sl_prefprog[((unsigned)pidx >> 8) & 0xffff];
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1039 if (*rp != NULL)
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1040 {
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
1041 if (!vim_regexec_prog(rp, FALSE, word, 0))
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1042 continue;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1043 }
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1044 else if (cond_req)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1045 continue;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
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
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1048 return pidx;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1049 }
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
1050 return 0;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1051 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1052
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1053 /*
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1054 * Check if the word at "mip->mi_word" has a matching prefix.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1055 * If it does, then check the following word.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1056 *
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1057 * If "mode" is "FIND_COMPOUND" then do the same after another word, find a
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1058 * prefix in a compound word.
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1059 *
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1060 * For a match mip->mi_result is updated.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1061 */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1064 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1065 idx_T arridx = 0;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1066 int len;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1067 int wlen = 0;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1068 int flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1069 int c;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1070 char_u *ptr;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1071 idx_T lo, hi, m;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1072 slang_T *slang = mip->mi_lp->lp_slang;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1073 char_u *byts;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1074 idx_T *idxs;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1075
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1076 byts = slang->sl_pbyts;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1084 if (mode == FIND_COMPOUND)
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
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
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1087 ptr += mip->mi_compoff;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1088 flen -= mip->mi_compoff;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1089 }
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1090 idxs = slang->sl_pidxs;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1091
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1092 /*
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1093 * Repeat advancing in the tree until:
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1094 * - there is a byte that doesn't match,
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1095 * - we reach the end of the tree,
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1096 * - or we reach the end of the line.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1097 */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1098 for (;;)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1099 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1100 if (flen == 0 && *mip->mi_fend != NUL)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1101 flen = fold_more(mip);
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1102
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1103 len = byts[arridx++];
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1107 if (byts[arridx] == 0)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1113 mip->mi_prefarridx = arridx;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1114 mip->mi_prefcnt = len;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1115 while (len > 0 && byts[arridx] == 0)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1116 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1117 ++arridx;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1118 --len;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1119 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1120 mip->mi_prefcnt -= len;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1123 mip->mi_prefixlen = wlen;
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
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
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1126 mip->mi_prefixlen += mip->mi_compoff;
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1127
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1128 if (has_mbyte)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
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
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1131 mip->mi_cprefixlen = nofold_len(mip->mi_fword,
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1132 mip->mi_prefixlen, mip->mi_word);
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1133 }
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
1134 else
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
1135 mip->mi_cprefixlen = mip->mi_prefixlen;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1136 find_word(mip, FIND_PREFIX);
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1137
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1138
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1141 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1144 if (ptr[wlen] == NUL)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1145 break;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1148 c = ptr[wlen];
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1149 lo = arridx;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1150 hi = arridx + len - 1;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1151 while (lo < hi)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1152 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1153 m = (lo + hi) / 2;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1154 if (byts[m] > c)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1155 hi = m - 1;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1156 else if (byts[m] < c)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1157 lo = m + 1;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1158 else
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1159 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1160 lo = hi = m;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1161 break;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1162 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1163 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1166 if (hi < lo || byts[lo] != c)
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1167 break;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1170 arridx = idxs[lo];
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1171 ++wlen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1172 --flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1173 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1174 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1175
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1176 /*
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1177 * Need to fold at least one more character. Do until next non-word character
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1178 * for efficiency. Include the non-word character too.
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1179 * Return the length of the folded chars in bytes.
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1180 */
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1183 {
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1184 int flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1185 char_u *p;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1186
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1187 p = mip->mi_fend;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1195
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1196 (void)spell_casefold(p, (int)(mip->mi_fend - p),
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1197 mip->mi_fword + mip->mi_fwordlen,
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1198 MAXWLEN - mip->mi_fwordlen);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1199 flen = (int)STRLEN(mip->mi_fword + mip->mi_fwordlen);
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1200 mip->mi_fwordlen += flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1201 return flen;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1202 }
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1203
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1204 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1205 * Check case flags for a word. Return TRUE if the word has the requested
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1206 * case.
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1212 {
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
1213 return ((wordflags == WF_ALLCAP && (treeflags & WF_FIXCAP) == 0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1214 || ((treeflags & (WF_ALLCAP | WF_KEEPCAP)) == 0
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
1215 && ((treeflags & WF_ONECAP) == 0
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
1216 || (wordflags & WF_ONECAP) != 0)));
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1217 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1218
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1219 /*
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1220 * Return TRUE if spell checking is not enabled.
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1229 return TRUE;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1230 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1231 return FALSE;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1232 }
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1233
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1234 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1235 * Move to next spell error.
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1236 * "curline" is FALSE for "[s", "]s", "[S" and "]S".
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1237 * "curline" is TRUE to find word under/after cursor in the same line.
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1238 * For Insert mode completion "dir" is BACKWARD and "curline" is TRUE: move
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1239 * to after badly spelled word before the cursor.
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1240 * Return 0 if not found, length of the badly spelled word otherwise.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1241 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1250 {
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1251 linenr_T lnum;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1252 pos_T found_pos;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1253 int found_len = 0;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1254 char_u *line;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1255 char_u *p;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1256 char_u *endp;
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1257 hlf_T attr;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1258 int len;
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
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
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
1261 #endif
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1262 int col;
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1263 int can_spell;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1264 char_u *buf = NULL;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1265 int buflen = 0;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1266 int skip = 0;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1267 int capcol = -1;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1268 int found_one = FALSE;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1269 int wrapped = FALSE;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1270
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1271 if (no_spell_checking(wp))
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1272 return 0;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1273
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1274 /*
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1275 * Start looking for bad word at the start of the line, because we can't
817
6897668c467f updated for version 7.0c03
vimboss
parents: 810
diff changeset
1276 * start halfway a word, we don't know where it starts or ends.
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1277 *
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1278 * When searching backwards, we continue in the line to find the last
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1279 * bad word (in the cursor line: before the cursor).
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1280 *
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1281 * We concatenate the start of the next line, so that wrapped words work
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1282 * (e.g. "et<line-break>cetera"). Doesn't work when searching backwards
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1283 * though...
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1284 */
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1287
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1288 while (!got_int)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1289 {
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1290 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1291
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1292 len = (int)STRLEN(line);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1293 if (buflen < len + MAXWLEN + 2)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1294 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1295 vim_free(buf);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1296 buflen = len + MAXWLEN + 2;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1297 buf = alloc(buflen);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1298 if (buf == NULL)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1299 break;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1300 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1303 if (lnum == 1)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1304 capcol = 0;
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1309 else if (curline && wp == curwin)
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
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
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1313 if (check_need_cap(lnum, col))
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1314 capcol = col;
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
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
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1318 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1319 }
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1323 STRCPY(buf, line);
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1324 if (lnum < wp->w_buffer->b_ml.ml_line_count)
883
7c28790fa8b4 updated for version 7.0-009
vimboss
parents: 866
diff changeset
1325 spell_cat_line(buf + STRLEN(buf),
7c28790fa8b4 updated for version 7.0-009
vimboss
parents: 866
diff changeset
1326 ml_get_buf(wp->w_buffer, lnum + 1, FALSE), MAXWLEN);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1327
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1328 p = buf + skip;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1329 endp = buf + len;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1330 while (p < endp)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1334 if (dir == BACKWARD
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1335 && lnum == wp->w_cursor.lnum
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1336 && !wrapped
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1337 && (colnr_T)(p - buf) >= wp->w_cursor.col)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1338 break;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
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
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1341 attr = HLF_COUNT;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1342 len = spell_check(wp, p, &attr, &capcol, FALSE);
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1343
534
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1344 if (attr != HLF_COUNT)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1347 if (allwords || attr == HLF_SPB)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1351 if (dir == BACKWARD
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1352 || lnum != wp->w_cursor.lnum
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1353 || (lnum == wp->w_cursor.lnum
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1354 && (wrapped
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1355 || (colnr_T)(curline ? p - buf + len
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1356 : p - buf)
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1357 > wp->w_cursor.col)))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1358 {
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
1359 #ifdef FEAT_SYN_HL
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1360 if (has_syntax)
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1361 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1362 col = (int)(p - buf);
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1363 (void)syn_get_id(wp, lnum, (colnr_T)col,
1504
1b55bbf5c580 updated for version 7.1-219
vimboss
parents: 1337
diff changeset
1364 FALSE, &can_spell, FALSE);
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1365 if (!can_spell)
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1366 attr = HLF_COUNT;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1367 }
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1368 else
737
59971e227f8c updated for version 7.0222
vimboss
parents: 718
diff changeset
1369 #endif
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1370 can_spell = TRUE;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1371
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1372 if (can_spell)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1373 {
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1374 found_one = TRUE;
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1375 found_pos.lnum = lnum;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1376 found_pos.col = (int)(p - buf);
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1377 found_pos.coladd = 0;
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1378 if (dir == FORWARD)
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
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
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1381 wp->w_cursor = found_pos;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1382 vim_free(buf);
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1383 if (attrp != NULL)
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1384 *attrp = attr;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1385 return len;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1386 }
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1390 found_pos.col += len;
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1391 found_len = len;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1392 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1393 }
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1394 else
b933657f7c9d updated for version 7.0g01
vimboss
parents: 844
diff changeset
1395 found_one = TRUE;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1396 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1397 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
1400 p += len;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1401 capcol -= len;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1402 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1403
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1404 if (dir == BACKWARD && found_pos.lnum != 0)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1407 wp->w_cursor = found_pos;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1408 vim_free(buf);
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1409 return found_len;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1410 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1411
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1421 if (dir == BACKWARD)
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1422 {
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1423 if (lnum > 1)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1424 --lnum;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1427 else
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1431 lnum = wp->w_buffer->b_ml.ml_line_count;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1432 wrapped = TRUE;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1433 if (!shortmess(SHM_SEARCH))
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1434 give_warning((char_u *)_(top_bot_msg), TRUE);
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1435 }
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1436 capcol = -1;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1437 }
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1438 else
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1439 {
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1440 if (lnum < wp->w_buffer->b_ml.ml_line_count)
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1441 ++lnum;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1444 else
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1448 lnum = 1;
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1449 wrapped = TRUE;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1450 if (!shortmess(SHM_SEARCH))
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1451 give_warning((char_u *)_(bot_top_msg), TRUE);
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
1452 }
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1457 break;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
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
c6296b0ad9ea updated for version 7.0151
vimboss
parents: 532
diff changeset
1461 if (attr == HLF_COUNT)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1462 skip = (int)(p - endp);
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1463 else
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1464 skip = 0;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1467 --capcol;
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1470 if (*skipwhite(line) == NUL)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1471 capcol = 0;
249
f146656fb903 updated for version 7.0069
vimboss
parents: 243
diff changeset
1472 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1473
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1474 line_breakcheck();
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1475 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1476
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1477 vim_free(buf);
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1478 return 0;
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1479 }
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1480
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1481 /*
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1482 * For spell checking: concatenate the start of the following line "line" into
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1483 * "buf", blanking-out special characters. Copy less then "maxlen" bytes.
1577
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1484 * Keep the blanks at the start of the next line, this is used in win_line()
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1485 * to skip those bytes if the word was OK.
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1486 */
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
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
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1489 {
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1490 char_u *p;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1491 int n;
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1492
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1493 p = skipwhite(line);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1494 while (vim_strchr((char_u *)"*#/\"\t", *p) != NULL)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1495 p = skipwhite(p + 1);
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1496
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1497 if (*p != NUL)
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
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
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1501 n = (int)(p - line) + 1;
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1502 if (n < maxlen - 1)
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1503 {
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1504 vim_memset(buf, ' ', n);
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1505 vim_strncpy(buf + n, p, maxlen - 1 - n);
3ee896333e3e updated for version 7.1-290
vimboss
parents: 1521
diff changeset
1506 }
346
8ed2a5098a31 updated for version 7.0090
vimboss
parents: 344
diff changeset
1507 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1508 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1509
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1510 /*
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1511 * Structure used for the cookie argument of do_in_runtimepath().
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
1512 */
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1513 typedef struct spelload_S
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1518 } spelload_T;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1519
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1520 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1521 * Load word list(s) for "lang" from Vim spell file(s).
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1522 * "lang" must be the language without the region: e.g., "en".
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1523 */
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1526 {
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1527 char_u fname_enc[85];
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1528 int r;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1529 spelload_T sl;
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1530 int round;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1534 STRCPY(sl.sl_lang, lang);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1535 sl.sl_slang = NULL;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1536 sl.sl_nobreak = FALSE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1540 for (round = 1; round <= 2; ++round)
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1541 {
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1542 /*
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1543 * Find the first spell file for "lang" in 'runtimepath' and load it.
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1544 */
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1545 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
2660
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1546 #ifdef VMS
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1547 "spell/%s_%s.spl",
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1548 #else
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1549 "spell/%s.%s.spl",
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1550 #endif
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
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
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1553
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1554 if (r == FAIL && *sl.sl_lang != NUL)
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
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
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1557 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5,
2660
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1558 #ifdef VMS
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1559 "spell/%s_ascii.spl",
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1560 #else
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1561 "spell/%s.ascii.spl",
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1562 #endif
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
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
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1565
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1566 if (r == FAIL && *sl.sl_lang != NUL && round == 1
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1567 && apply_autocmds(EVENT_SPELLFILEMISSING, lang,
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1568 curbuf->b_fname, FALSE, curbuf))
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1569 continue;
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1570 break;
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13308
diff changeset
1571 }
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
1572 break;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1573 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1574
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1575 if (r == FAIL)
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
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
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1578 #ifdef VMS
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1579 _("Warning: Cannot find word list \"%s_%s.spl\" or \"%s_ascii.spl\""),
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1580 #else
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1581 _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""),
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1582 #endif
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1583 lang, spell_enc(), lang);
649
8157079cea85 updated for version 7.0191
vimboss
parents: 638
diff changeset
1584 }
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1585 else if (sl.sl_slang != NULL)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
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
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1590 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1591 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1592
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1593 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1594 * Return the encoding used for spell checking: Use 'encoding', except that we
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1595 * use "latin1" for "latin9". And limit to 60 characters (just in case).
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
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
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1599 {
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1600
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1601 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1602 return p_enc;
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1603 return (char_u *)"latin1";
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1604 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1605
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1606 /*
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1607 * Get the name of the .spl file for the internal wordlist into
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1608 * "fname[MAXPATHL]".
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1609 */
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1612 {
2660
e19ecdb13f34 updated for version 7.3.080
Bram Moolenaar <bram@vim.org>
parents: 2656
diff changeset
1613 vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL,
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1614 int_wordlist, spell_enc());
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1615 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1616
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1617 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1618 * Allocate a new slang_T for language "lang". "lang" can be NULL.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1619 * Caller must fill "sl_next".
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1623 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1624 slang_T *lp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1627 if (lp != NULL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1628 {
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1629 if (lang != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1630 lp->sl_name = vim_strsave(lang);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1631 ga_init2(&lp->sl_rep, sizeof(fromto_T), 10);
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1632 ga_init2(&lp->sl_repsal, sizeof(fromto_T), 10);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1633 lp->sl_compmax = MAXWLEN;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1634 lp->sl_compsylmax = MAXWLEN;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1635 hash_init(&lp->sl_wordcount);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1636 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1637
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1638 return lp;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1639 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1640
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1641 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1642 * Free the contents of an slang_T and the structure itself.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1646 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1647 vim_free(lp->sl_name);
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1648 vim_free(lp->sl_fname);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1649 slang_clear(lp);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1650 vim_free(lp);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1651 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1652
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1653 /*
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1654 * Clear an slang_T so that the file can be reloaded.
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
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
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1658 {
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1659 garray_T *gap;
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1660 fromto_T *ftp;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
1661 salitem_T *smp;
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
1662 int i;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1663 int round;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1672
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1673 for (round = 1; round <= 2; ++round)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1674 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1675 gap = round == 1 ? &lp->sl_rep : &lp->sl_repsal;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1676 while (gap->ga_len > 0)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1677 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1678 ftp = &((fromto_T *)gap->ga_data)[--gap->ga_len];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1679 vim_free(ftp->ft_from);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1680 vim_free(ftp->ft_to);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1681 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1682 ga_clear(gap);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1683 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
1684
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
1685 gap = &lp->sl_sal;
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1686 if (lp->sl_sofo)
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
1691 for (i = 0; i < gap->ga_len; ++i)
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
1692 vim_free(((int **)gap->ga_data)[i]);
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
1693 }
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1696 while (gap->ga_len > 0)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1697 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1698 smp = &((salitem_T *)gap->ga_data)[--gap->ga_len];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1701 vim_free(smp->sm_to);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1702 vim_free(smp->sm_lead_w);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1703 vim_free(smp->sm_oneof_w);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1704 vim_free(smp->sm_to_w);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
1705 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
1706 ga_clear(gap);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1707
339
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
64221fecdfa1 updated for version 7.0088
vimboss
parents: 334
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1724 ga_clear(&lp->sl_syl_items);
481
66080ac5dab7 updated for version 7.0130
vimboss
parents: 479
diff changeset
1725
809
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
1726 ga_clear_strings(&lp->sl_comppat);
4f1b94b51e99 updated for version 7.0b02
vimboss
parents: 737
diff changeset
1727
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1728 hash_clear_all(&lp->sl_wordcount, WC_KEY_OFF);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1729 hash_init(&lp->sl_wordcount);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1730
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1731 hash_clear_all(&lp->sl_map_hash, 0);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1734 slang_clear_sug(lp);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1735
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1736 lp->sl_compmax = MAXWLEN;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1737 lp->sl_compminlen = 0;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1738 lp->sl_compsylmax = MAXWLEN;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1739 lp->sl_regions[0] = NUL;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1740 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1741
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1742 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1743 * Clear the info from the .sug file in "lp".
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1750 close_spellbuf(lp->sl_sugbuf);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1751 lp->sl_sugbuf = NULL;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1752 lp->sl_sugloaded = FALSE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1753 lp->sl_sugtime = 0;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1754 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1755
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1756 /*
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
1757 * Load one spell file and store the info into a slang_T.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1758 * Invoked through do_in_runtimepath().
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1759 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1762 {
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1763 spelload_T *slp = (spelload_T *)cookie;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1764 slang_T *slang;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1765
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1766 slang = spell_load_file(fname, slp->sl_lang, NULL, FALSE);
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1767 if (slang != NULL)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1771 if (slp->sl_nobreak && slang->sl_add)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1772 slang->sl_nobreak = TRUE;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1773 else if (slang->sl_nobreak)
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1774 slp->sl_nobreak = TRUE;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1775
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1776 slp->sl_slang = slang;
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1777 }
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1778 }
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
1779
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1780
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1781 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1782 * Add a word to the hashtable of common words.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1783 * If it's already there then the counter is increased.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1791 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1792 hash_T hash;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1793 hashitem_T *hi;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1794 wordcount_T *wc;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1795 char_u buf[MAXWLEN];
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1796 char_u *p;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1797
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1798 if (len == -1)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1802 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1803 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1804 vim_strncpy(buf, word, len);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1805 p = buf;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1806 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1807
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1808 hash = hash_hash(p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1809 hi = hash_lookup(&lp->sl_wordcount, p, hash);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1810 if (HASHITEM_EMPTY(hi))
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1813 if (wc == NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1814 return;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1815 STRCPY(wc->wc_word, p);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1816 wc->wc_count = count;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1817 hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1818 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1819 else
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1820 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1823 wc->wc_count = MAXWORDCOUNT;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1824 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1825 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1826
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
1827 /*
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1828 * Return TRUE if byte "n" appears in "str".
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1829 * Like strchr() but independent of locale.
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
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
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1833 {
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1834 char_u *p;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1835
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1836 for (p = str; *p != NUL; ++p)
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
1837 if (*p == n)
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1838 return TRUE;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1839 return FALSE;
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1840 }
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1841
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1842 #define SY_MAXLEN 30
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1843 typedef struct syl_item_S
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1846 int sy_len;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1847 } syl_item_T;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1848
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1849 /*
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1850 * Truncate "slang->sl_syllable" at the first slash and put the following items
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1851 * in "slang->sl_syl_items".
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1855 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1856 char_u *p;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1857 char_u *s;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1858 int l;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1859 syl_item_T *syl;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1860
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1861 ga_init2(&slang->sl_syl_items, sizeof(syl_item_T), 4);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1862 p = vim_strchr(slang->sl_syllable, '/');
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1863 while (p != NULL)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1864 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1867 break;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1868 s = p;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1869 p = vim_strchr(p, '/');
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1870 if (p == NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1871 l = (int)STRLEN(s);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1872 else
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
1873 l = (int)(p - s);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1874 if (l >= SY_MAXLEN)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1875 return SP_FORMERROR;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1876 if (ga_grow(&slang->sl_syl_items, 1) == FAIL)
495
409dced94617 updated for version 7.0136
vimboss
parents: 492
diff changeset
1877 return SP_OTHERERROR;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1878 syl = ((syl_item_T *)slang->sl_syl_items.ga_data)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1879 + slang->sl_syl_items.ga_len++;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1880 vim_strncpy(syl->sy_chars, s, l);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1881 syl->sy_len = l;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1882 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1883 return OK;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1884 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1885
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1886 /*
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1887 * Count the number of syllables in "word".
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1888 * When "word" contains spaces the syllables after the last space are counted.
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1889 * Returns zero if syllables are not defines.
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1890 */
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1893 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1894 int cnt = 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1895 int skip = FALSE;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1896 char_u *p;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1897 int len;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1898 int i;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1899 syl_item_T *syl;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1900 int c;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1901
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1902 if (slang->sl_syllable == NULL)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1903 return 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1904
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1905 for (p = word; *p != NUL; p += len)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1908 if (*p == ' ')
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1909 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1910 len = 1;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1911 cnt = 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1912 continue;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1913 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1916 len = 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1917 for (i = 0; i < slang->sl_syl_items.ga_len; ++i)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1918 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1919 syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + i;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1920 if (syl->sy_len > len
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1921 && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1922 len = syl->sy_len;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1925 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1926 ++cnt;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1927 skip = FALSE;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1928 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1929 else
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1932 c = mb_ptr2char(p);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1933 len = (*mb_ptr2len)(p);
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1936 else if (!skip)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1940 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1941 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1942 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
1943 return cnt;
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
1944 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
1945
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1948 * Returns NULL if it's OK, an error message otherwise.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1952 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1953 garray_T ga;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1954 char_u *splp;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1955 char_u *region;
416
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
1956 char_u region_cp[3];
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
1957 int filename;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1958 int region_mask;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1959 slang_T *slang;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1960 int c;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1961 char_u lang[MAXWLEN + 1];
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
1962 char_u spf_name[MAXPATHL];
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1963 int len;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
1964 char_u *p;
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
1965 int round;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
1966 char_u *spf;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
1967 char_u *use_region = NULL;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
1968 int dont_use_region = FALSE;
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
1969 int nobreak = FALSE;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1970 int i, j;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
1971 langp_T *lp, *lp2;
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
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
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
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
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
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
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
1982 if (recursive)
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
1983 return NULL;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
1984 recursive = TRUE;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
1985
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
1992 if (spl_copy == NULL)
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
1993 goto theend;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
1994
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
1995 wp->w_s->b_cjk = 0;
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
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
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
1998 for (splp = spl_copy; *splp != NUL; )
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2001 copy_option_part(&splp, lang, MAXWLEN, ",");
240
693800033ceb updated for version 7.0067
vimboss
parents: 236
diff changeset
2002 region = NULL;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
2003 len = (int)STRLEN(lang);
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
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
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2008 if (STRCMP(lang, "cjk") == 0)
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2009 {
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2010 wp->w_s->b_cjk = 1;
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2011 continue;
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2012 }
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
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
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2017 if (len > 4 && fnamecmp(lang + len - 4, ".spl") == 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2018 {
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2019 filename = TRUE;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
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
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2022 p = vim_strchr(gettail(lang), '_');
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2023 if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2])
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2024 && !ASCII_ISALPHA(p[3]))
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2025 {
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2026 vim_strncpy(region_cp, p + 1, 2);
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2027 mch_memmove(p, p + 3, len - (p - lang) - 2);
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2028 region = region_cp;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2029 }
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2030 else
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2031 dont_use_region = TRUE;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
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
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2036 break;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2037 }
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2038 else
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2039 {
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2040 filename = FALSE;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2041 if (len > 3 && lang[len - 3] == '_')
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2042 {
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2043 region = lang + len - 2;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2044 len -= 3;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2045 lang[len] = NUL;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2046 }
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2047 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2048 dont_use_region = TRUE;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2052 if (STRICMP(lang, slang->sl_name) == 0)
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2053 break;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2054 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2055
416
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2056 if (region != NULL)
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
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
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2060 if (use_region != NULL && STRCMP(region, use_region) != 0)
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2061 dont_use_region = TRUE;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2062 use_region = region;
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
2063 }
3da34f87c760 updated for version 7.0109
vimboss
parents: 398
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2066 if (slang == NULL)
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2067 {
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2068 if (filename)
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2069 (void)spell_load_file(lang, lang, NULL, FALSE);
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2070 else
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2071 {
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
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
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
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
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2078 goto theend;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2079 }
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2080 }
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2081 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2082
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2083 /*
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2084 * Loop over the languages, there can be several files for "lang".
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2089 : STRICMP(lang, slang->sl_name) == 0)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2090 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2091 region_mask = REGION_ALL;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2092 if (!filename && region != NULL)
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2095 c = find_region(slang->sl_regions, region);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2096 if (c == REGION_ALL)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2097 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2098 if (slang->sl_add)
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2099 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
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
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2102 region_mask = 0;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2103 }
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
2108 region);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2109 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2110 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2111 region_mask = 1 << c;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2112 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2113
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2114 if (region_mask != 0)
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2115 {
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2116 if (ga_grow(&ga, 1) == FAIL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2117 {
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2118 ga_clear(&ga);
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2119 ret_msg = e_outofmem;
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2120 goto theend;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2121 }
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2122 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2123 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2126 if (slang->sl_nobreak)
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
2127 nobreak = TRUE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2128 }
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2129 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2130 }
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2137 for (round = 0; round == 0 || *spf != NUL; ++round)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2138 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2139 if (round == 0)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2142 if (int_wordlist == NULL)
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2143 continue;
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2144 int_wordlist_spl(spf_name);
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2145 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2146 else
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2149 copy_option_part(&spf, spf_name, MAXPATHL - 5, ",");
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2150 STRCAT(spf_name, ".spl");
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2153 for (c = 0; c < ga.ga_len; ++c)
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
2154 {
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2158 break;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
2159 }
385
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2160 if (c < ga.ga_len)
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2161 continue;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2162 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2168 break;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2169 if (slang == NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2174 if (round == 0)
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2175 STRCPY(lang, "internal wordlist");
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2176 else
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2177 {
bd4c7ce1da02 updated for version 7.0100
vimboss
parents: 381
diff changeset
2178 vim_strncpy(lang, gettail(spf_name), MAXWLEN);
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2179 p = vim_strchr(lang, '.');
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
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
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2182 }
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2183 slang = spell_load_file(spf_name, lang, NULL, TRUE);
501
ce2181d14aa0 updated for version 7.0139
vimboss
parents: 500
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2187 if (slang != NULL && nobreak)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2188 slang->sl_nobreak = TRUE;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2189 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2190 if (slang != NULL && ga_grow(&ga, 1) == OK)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2191 {
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2192 region_mask = REGION_ALL;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2193 if (use_region != NULL && !dont_use_region)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2196 c = find_region(slang->sl_regions, use_region);
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2197 if (c != REGION_ALL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2198 region_mask = 1 << c;
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
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
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2201 region_mask = 0;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2202 }
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2203
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2204 if (region_mask != 0)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2205 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2206 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2207 LANGP_ENTRY(ga, ga.ga_len)->lp_sallang = NULL;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2208 LANGP_ENTRY(ga, ga.ga_len)->lp_replang = NULL;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2209 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
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
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2212 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2213 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2214 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2223 for (i = 0; i < ga.ga_len; ++i)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2224 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2225 lp = LANGP_ENTRY(ga, i);
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2230 lp->lp_sallang = lp->lp_slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2233 for (j = 0; j < ga.ga_len; ++j)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2234 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2235 lp2 = LANGP_ENTRY(ga, j);
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2236 if (lp2->lp_slang->sl_sal.ga_len > 0
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2237 && STRNCMP(lp->lp_slang->sl_name,
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2238 lp2->lp_slang->sl_name, 2) == 0)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2239 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2240 lp->lp_sallang = lp2->lp_slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2241 break;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2242 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2243 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2248 lp->lp_replang = lp->lp_slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
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
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2251 for (j = 0; j < ga.ga_len; ++j)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2252 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2253 lp2 = LANGP_ENTRY(ga, j);
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2254 if (lp2->lp_slang->sl_rep.ga_len > 0
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2255 && STRNCMP(lp->lp_slang->sl_name,
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2256 lp2->lp_slang->sl_name, 2) == 0)
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2257 {
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2258 lp->lp_replang = lp2->lp_slang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2259 break;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2260 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2261 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2262 }
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2263
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2264 theend:
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2265 vim_free(spl_copy);
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2266 recursive = FALSE;
5891
7965cb6a435a updated for version 7.4.288
Bram Moolenaar <bram@vim.org>
parents: 5735
diff changeset
2267 redraw_win_later(wp, NOT_VALID);
1185
184d2020d8f1 updated for version 7.1a-001
vimboss
parents: 1087
diff changeset
2268 return ret_msg;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2269 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2270
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2271 /*
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2272 * Clear the midword characters for buffer "buf".
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2273 */
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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 {
1bac28a53fae Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents: 2229
diff changeset
2277 vim_memset(wp->w_s->b_spell_ismw, 0, 256);
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2279 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2280
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2281 /*
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2282 * Use the "sl_midword" field of language "lp" for buffer "buf".
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2283 * They add up to any currently used midword characters.
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2284 */
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2287 {
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2288 char_u *p;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2291 return;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
2292
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2293 for (p = lp->sl_midword; *p != NUL; )
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2294 if (has_mbyte)
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2295 {
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2296 int c, l, n;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2297 char_u *bp;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2298
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2299 c = mb_ptr2char(p);
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2300 l = (*mb_ptr2len)(p);
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2306 else
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2311 if (bp != NULL)
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2315 vim_strncpy(bp + n, p, l);
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2316 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2317 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2318 p += l;
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2319 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2322 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2323
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2324 /*
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
2327 * Returns the index if found (first is 0), REGION_ALL if not found.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2328 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2331 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2332 int i;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2333
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2334 for (i = 0; ; i += 2)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2335 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2336 if (rp[i] == NUL)
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2337 return REGION_ALL;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2338 if (rp[i] == region[0] && rp[i + 1] == region[1])
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2339 break;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2340 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2341 return i / 2;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2342 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2343
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2344 /*
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2345 * Return case type of word:
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2346 * w word 0
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2347 * Word WF_ONECAP
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2348 * W WORD WF_ALLCAP
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2349 * WoRd wOrd WF_KEEPCAP
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2355 {
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2356 char_u *p;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2357 int c;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2358 int firstcap;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2366 if (has_mbyte)
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2367 c = mb_ptr2char_adv(&p);
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2368 else
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2369 c = *p++;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2370 firstcap = allcap = SPELL_ISUPPER(c);
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2371
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2372 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2373 * Need to check all letters to find a word with mixed upper/lower.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2374 * But a word with an upper char only at start is a ONECAP.
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2377 if (spell_iswordp_nmw(p, curwin))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2378 {
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2379 c = PTR2CHAR(p);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2380 if (!SPELL_ISUPPER(c))
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2383 if (past_second && allcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2384 return WF_KEEPCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2385 allcap = FALSE;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2386 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2389 return WF_KEEPCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2390 past_second = TRUE;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2391 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2392
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2393 if (allcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2394 return WF_ALLCAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2395 if (firstcap)
300
86cd0a77d2ae updated for version 7.0079
vimboss
parents: 290
diff changeset
2396 return WF_ONECAP;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2397 return 0;
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2398 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2399
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2400 /*
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2401 * Delete the internal wordlist and its .spl file.
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2402 */
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
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
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2405 {
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2406 char_u fname[MAXPATHL];
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2407
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2408 if (int_wordlist != NULL)
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2409 {
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2410 mch_remove(int_wordlist);
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2411 int_wordlist_spl(fname);
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
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
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2414 }
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2415 }
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2416
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2417 /*
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2418 * Free all languages.
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2419 */
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
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
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2422 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2423 slang_T *slang;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2424 buf_T *buf;
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
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
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2429
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2430 while (first_lang != NULL)
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2431 {
503
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2432 slang = first_lang;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2433 first_lang = slang->sl_next;
c9ec7077a195 updated for version 7.0141
vimboss
parents: 502
diff changeset
2434 slang_free(slang);
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2435 }
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2436
5519
fa31c5b82424 updated for version 7.4.108
Bram Moolenaar <bram@vim.org>
parents: 5506
diff changeset
2437 spell_delete_wordlist();
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
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
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2441 }
15605
62b3805506b3 patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
2442
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2443 /*
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2444 * Clear all spelling tables and reload them.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2445 * Used after 'encoding' is set and when ":mkspell" was used.
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2446 */
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2449 {
316
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2450 win_T *wp;
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2453 init_spell_chartab();
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
2456 spell_free_all();
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
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
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2468 break;
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2469 }
96789bc4346a updated for version 7.0083
vimboss
parents: 310
diff changeset
2470 }
236
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2471 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2472 }
4707450c2b33 updated for version 7.0066
vimboss
parents: 233
diff changeset
2473
310
04bf54c587f4 updated for version 7.0082
vimboss
parents: 307
diff changeset
2474 /*
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2475 * Open a spell buffer. This is a nameless buffer that is not in the buffer
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2476 * list and only contains text lines. Can use a swapfile to reduce memory
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2477 * use.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2478 * Most other fields are invalid! Esp. watch out for string options being
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2479 * NULL and there is no undo info.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2480 * Returns NULL when out of memory.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2484 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2485 buf_T *buf;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2488 if (buf != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2489 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2497 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2498 return buf;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2499 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2500
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2501 /*
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2502 * Close the buffer used for spell info.
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2506 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2507 if (buf != NULL)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2508 {
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2509 ml_close(buf, TRUE);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2510 vim_free(buf);
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2511 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2512 }
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
2513
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2514 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2515 * Init the chartab used for spelling for ASCII.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2516 * EBCDIC is not supported!
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2520 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2521 int i;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2522
18814
7e7ec935e7c8 patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18358
diff changeset
2523 // Init everything to FALSE.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2524 vim_memset(sp->st_isw, FALSE, sizeof(sp->st_isw));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2525 vim_memset(sp->st_isu, FALSE, sizeof(sp->st_isu));
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2526 for (i = 0; i < 256; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2527 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2528 sp->st_fold[i] = i;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2529 sp->st_upper[i] = i;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2530 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2534 for (i = '0'; i <= '9'; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2535 sp->st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2536 for (i = 'A'; i <= 'Z'; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2537 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2538 sp->st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2539 sp->st_isu[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2540 sp->st_fold[i] = i + 0x20;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2541 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2542 for (i = 'a'; i <= 'z'; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2543 {
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2544 sp->st_isw[i] = TRUE;
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2545 sp->st_upper[i] = i - 0x20;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2546 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2547 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2548
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2549 /*
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2550 * Init the chartab used for spelling. Only depends on 'encoding'.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2551 * Called once while starting up and when 'encoding' changes.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2552 * The default is to use isalpha(), but the spell file should define the word
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2553 * characters to make it possible that 'encoding' differs from the current
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2554 * locale. For utf-8 we don't use isalpha() but our own functions.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2555 */
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2558 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2559 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2560
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2561 did_set_spelltab = FALSE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2562 clear_spell_chartab(&spelltab);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2563 if (enc_dbcs)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2566 for (i = 128; i <= 255; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2567 if (MB_BYTE2LEN(i) == 2)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2568 spelltab.st_isw[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2569 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2570 else if (enc_utf8)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2571 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2572 for (i = 128; i < 256; ++i)
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
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
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2577 spelltab.st_isu[i] = utf_isupper(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
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
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2584 }
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2585 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2586 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2589 for (i = 128; i < 256; ++i)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2590 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2591 if (MB_ISUPPER(i))
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2592 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2593 spelltab.st_isw[i] = TRUE;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2594 spelltab.st_isu[i] = TRUE;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2595 spelltab.st_fold[i] = MB_TOLOWER(i);
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2596 }
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2597 else if (MB_ISLOWER(i))
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2598 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2599 spelltab.st_isw[i] = TRUE;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2600 spelltab.st_upper[i] = MB_TOUPPER(i);
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2601 }
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2602 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2603 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2604 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2605
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2606
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2607 /*
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2608 * Return TRUE if "p" points to a word character.
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2609 * As a special case we see "midword" characters as word character when it is
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2610 * followed by a word character. This finds they'there but not 'they there'.
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2611 * Thus this only works properly when past the first character of the word.
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
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
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2617 {
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2618 char_u *s;
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2619 int l;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2620 int c;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2621
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2622 if (has_mbyte)
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
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
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2625 s = p;
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2626 if (l == 1)
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
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
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2631 }
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2632 else
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2633 {
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
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
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2638 s = p + l;
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2639 }
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2640
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2641 c = mb_ptr2char(s);
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2642 if (c > 255)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2643 return spell_mb_isword_class(mb_get_class(s), wp);
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2644 return spelltab.st_isw[c];
366
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
2645 }
b498dee21bd3 updated for version 7.0095
vimboss
parents: 358
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2648 }
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2649
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2650 /*
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2651 * Return TRUE if "p" points to a word character.
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2652 * Unlike spell_iswordp() this doesn't check for "midword" characters.
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2656 {
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2657 int c;
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2658
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2659 if (has_mbyte)
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2660 {
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2661 c = mb_ptr2char(p);
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2662 if (c > 255)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2663 return spell_mb_isword_class(mb_get_class(p), wp);
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2664 return spelltab.st_isw[c];
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2665 }
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2666 return spelltab.st_isw[*p];
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2667 }
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2668
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2669 /*
1580
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
2670 * Return TRUE if word class indicates a word character.
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
2671 * Only for characters above 255.
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
2672 * Unicode subscript and superscript are not considered word characters.
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2673 * See also dbcs_class() and utf_class() in mbyte.c.
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2674 */
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
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
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2677 {
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
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
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
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
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
2682 }
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
2683
5e75d07bfe75 updated for version 7.1-293
vimboss
parents: 1577
diff changeset
2684 /*
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2685 * Return TRUE if "p" points to a word character.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2686 * Wide version of spell_iswordp().
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2687 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2690 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2691 int *s;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2696 s = p + 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2697 else
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2698 s = p;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2699
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
2700 if (*s > 255)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2701 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2702 if (enc_utf8)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2703 return spell_mb_isword_class(utf_class(*s), wp);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2704 if (enc_dbcs)
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2705 return spell_mb_isword_class(
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2706 dbcs_class((unsigned)*s >> 8, *s & 0xff), wp);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2707 return 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2708 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2709 return spelltab.st_isw[*s];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2710 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2711
358
e111db373ca4 updated for version 7.0093
vimboss
parents: 355
diff changeset
2712 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2713 * Case-fold "str[len]" into "buf[buflen]". The result is NUL terminated.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2714 * Uses the character definitions from the .spl file.
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2715 * When using a multi-byte 'encoding' the length may change!
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2716 * Returns FAIL when something wrong.
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2724 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2725 int i;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2726
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2727 if (len >= buflen)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2728 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2731 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2732
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2733 if (has_mbyte)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2734 {
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2735 int outi = 0;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2736 char_u *p;
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2737 int c;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2740 for (p = str; p < str + len; )
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2741 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2742 if (outi + MB_MAXBYTES > buflen)
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2743 {
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2744 buf[outi] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2745 return FAIL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2746 }
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2747 c = mb_cptr2char_adv(&p);
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2748 outi += mb_char2bytes(SPELL_TOFOLD(c), buf + outi);
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2749 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2750 buf[outi] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2751 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2752 else
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
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
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2755 for (i = 0; i < len; ++i)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2756 buf[i] = spelltab.st_fold[str[i]];
307
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2757 buf[i] = NUL;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2758 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2759
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2760 return OK;
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2761 }
7010607c5753 updated for version 7.0081
vimboss
parents: 302
diff changeset
2762
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
2763 /*
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2764 * Check if the word at line "lnum" column "col" is required to start with a
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2765 * capital. This uses 'spellcapcheck' of the current buffer.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2769 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2770 int need_cap = FALSE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2771 char_u *line;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2772 char_u *line_copy = NULL;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2773 char_u *p;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2774 colnr_T endcol;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2775 regmatch_T regmatch;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2778 return FALSE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2779
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2780 line = ml_get_curline();
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2786 if (lnum == 1)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2787 need_cap = TRUE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2788 else
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2789 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2790 line = ml_get(lnum - 1);
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2791 if (*skipwhite(line) == NUL)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2792 need_cap = TRUE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2793 else
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2796 line_copy = concat_str(line, (char_u *)" ");
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2797 line = line_copy;
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
2798 endcol = (colnr_T)STRLEN(line);
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2799 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2800 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2801 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2802 else
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2803 endcol = col;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2804
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2805 if (endcol > 0)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2809 regmatch.rm_ic = FALSE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2810 p = line + endcol;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2811 for (;;)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
2814 if (p == line || spell_iswordp_nmw(p, curwin))
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2815 break;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2816 if (vim_regexec(&regmatch, p, 0)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2817 && regmatch.endp[0] == line + endcol)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2818 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2819 need_cap = TRUE;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2820 break;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2821 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2822 }
6375
27a36d1013a6 updated for version 7.4.519
Bram Moolenaar <bram@vim.org>
parents: 6224
diff changeset
2823 curwin->w_s->b_cap_prog = regmatch.regprog;
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2824 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2825
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2826 vim_free(line_copy);
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2827
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2828 return need_cap;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2829 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2830
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2831
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
2832 /*
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2833 * ":spellrepall"
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2834 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2837 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2838 pos_T pos = curwin->w_cursor;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2839 char_u *frompat;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2840 int addlen;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2841 char_u *line;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2842 char_u *p;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2843 int save_ws = p_ws;
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2844 linenr_T prev_lnum = 0;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2845
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2846 if (repl_from == NULL || repl_to == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2849 return;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2850 }
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
2851 addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from));
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2854 if (frompat == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2855 return;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2856 sprintf((char *)frompat, "\\V\\<%s\\>", repl_from);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2857 p_ws = FALSE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2858
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2859 sub_nsubs = 0;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2860 sub_nlines = 0;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2861 curwin->w_cursor.lnum = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2862 while (!got_int)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2865 || u_save_cursor() == FAIL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2866 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2870 line = ml_get_curline();
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2871 if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col,
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2872 repl_to, STRLEN(repl_to)) != 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2875 if (p == NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2876 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2877 mch_memmove(p, line, curwin->w_cursor.col);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2878 STRCPY(p + curwin->w_cursor.col, repl_to);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2879 STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from));
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2880 ml_replace(curwin->w_cursor.lnum, p, FALSE);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2881 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2882
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2883 if (curwin->w_cursor.lnum != prev_lnum)
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2884 {
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2885 ++sub_nlines;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2886 prev_lnum = curwin->w_cursor.lnum;
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2887 }
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2888 ++sub_nsubs;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2889 }
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
2890 curwin->w_cursor.col += (colnr_T)STRLEN(repl_to);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2891 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2892
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2893 p_ws = save_ws;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2894 curwin->w_cursor = pos;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2895 vim_free(frompat);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2896
483
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
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
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2899 else
70afa17bfc01 updated for version 7.0132
vimboss
parents: 482
diff changeset
2900 do_sub_msg(FALSE);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2901 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2902
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
2903 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2904 * Make a copy of "word", with the first letter upper or lower cased, to
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2905 * "wcopy[MAXWLEN]". "word" must not be empty.
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2906 * The result is NUL terminated.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2913 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2914 char_u *p;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2915 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2916 int l;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2917
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2918 p = word;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2919 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2920 c = mb_cptr2char_adv(&p);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2921 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2922 c = *p++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2923 if (upper)
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2924 c = SPELL_TOUPPER(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2925 else
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2926 c = SPELL_TOFOLD(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2927 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2928 l = mb_char2bytes(c, wcopy);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2929 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2930 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2931 l = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2932 wcopy[0] = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2933 }
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
2934 vim_strncpy(wcopy + l, p, MAXWLEN - l - 1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2935 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2936
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2937 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2938 * Make a copy of "word" with all the letters upper cased into
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
2939 * "wcopy[MAXWLEN]". The result is NUL terminated.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2943 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2944 char_u *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2945 char_u *d;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2946 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2947
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2948 d = wcopy;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2949 for (s = word; *s != NUL; )
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2950 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2951 if (has_mbyte)
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
2952 c = mb_cptr2char_adv(&s);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2953 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2954 c = *s++;
492
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
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
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2958 if (enc_latin1like && c == 0xdf)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2959 {
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2960 c = 'S';
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2961 if (d - wcopy >= MAXWLEN - 1)
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2962 break;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2963 *d++ = c;
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2964 }
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2965 else
81c06952fb1d updated for version 7.0135
vimboss
parents: 490
diff changeset
2966 c = SPELL_TOUPPER(c);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2967
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2968 if (has_mbyte)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2969 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2970 if (d - wcopy >= MAXWLEN - MB_MAXBYTES)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2971 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2972 d += mb_char2bytes(c, d);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2973 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2974 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2975 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2976 if (d - wcopy >= MAXWLEN - 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2977 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2978 *d++ = c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2979 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2980 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2981 *d = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2982 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2983
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
2984 /*
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2985 * Case-folding may change the number of bytes: Count nr of chars in
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2986 * fword[flen] and return the byte length of that many chars in "word".
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
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
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2990 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2991 char_u *p;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2992 int i = 0;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
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
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
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
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2997 --i;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2998 return (int)(p - word);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
2999 }
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
3000
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3001 /*
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3002 * Copy "fword" to "cword", fixing case according to "flags".
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3006 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3009 allcap_copy(fword, cword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3012 onecap_copy(fword, cword, TRUE);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3015 STRCPY(cword, fword);
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3016 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3017
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3018 #if defined(FEAT_EVAL) || defined(PROTO)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3019 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3020 * Soundfold a string, for soundfold().
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3021 * Result is in allocated memory, NULL for an error.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3022 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3025 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3026 langp_T *lp;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3027 char_u sound[MAXWLEN];
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
3028 int lpi;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3035 if (lp->lp_slang->sl_sal.ga_len > 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3038 spell_soundfold(lp->lp_slang, word, FALSE, sound);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3039 return vim_strsave(sound);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3040 }
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
3041 }
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3044 return vim_strsave(word);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3045 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3046 #endif
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3047
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3048 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3049 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]".
485
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3050 *
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3051 * There are many ways to turn a word into a sound-a-like representation. The
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3052 * oldest is Soundex (1918!). A nice overview can be found in "Approximate
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3053 * swedish name matching - survey and test of different algorithms" by Klas
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3054 * Erikson.
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3055 *
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3056 * We support two methods:
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3057 * 1. SOFOFROM/SOFOTO do a simple character mapping.
13cf73878020 updated for version 7.0133
vimboss
parents: 483
diff changeset
3058 * 2. SAL items define a more advanced sound-folding (and much slower).
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3066 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3067 char_u fword[MAXWLEN];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3068 char_u *word;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3069
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3072 spell_soundfold_sofo(slang, inword, res);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3073 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3076 if (folded)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3077 word = inword;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3078 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3079 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3080 (void)spell_casefold(inword, (int)STRLEN(inword), fword, MAXWLEN);
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3081 word = fword;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3082 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3083
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3084 if (has_mbyte)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3085 spell_soundfold_wsal(slang, word, res);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3086 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3087 spell_soundfold_sal(slang, word, res);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3088 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3089 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3090
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3091 /*
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3092 * Perform sound folding of "inword" into "res" according to SOFOFROM and
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3093 * SOFOTO lines.
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3094 */
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3097 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3098 char_u *s;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3099 int ri = 0;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3100 int c;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3101
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3102 if (has_mbyte)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3103 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3104 int prevc = 0;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3105 int *ip;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3109 for (s = inword; *s != NUL; )
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3110 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3113 c = ' ';
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3114 else if (c < 256)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3115 c = slang->sl_sal_first[c];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3116 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3117 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3120 c = NUL;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3125 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3126 c = NUL;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3127 break;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3130 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3131 c = ip[1];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3132 break;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3133 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3134 ip += 2;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3135 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3136 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3137
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3138 if (c != NUL && c != prevc)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3139 {
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3140 ri += mb_char2bytes(c, res + ri);
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3141 if (ri + MB_MAXBYTES > MAXWLEN)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3142 break;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3143 prevc = c;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3144 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3145 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3146 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3147 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3150 for (s = inword; (c = *s) != NUL; ++s)
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3153 c = ' ';
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3154 else
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3155 c = slang->sl_sal_first[c];
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3156 if (c != NUL && (ri == 0 || res[ri - 1] != c))
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3157 res[ri++] = c;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3158 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3159 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3160
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3161 res[ri] = NUL;
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3162 }
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3163
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3166 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3167 salitem_T *smp;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3168 char_u word[MAXWLEN];
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3169 char_u *s = inword;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3170 char_u *t;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3171 char_u *pf;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3172 int i, j, z;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3173 int reslen;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3174 int n, k = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3175 int z0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3176 int k0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3177 int n0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3178 int c;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3179 int pri;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3180 int p0 = -333;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3181 int c0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3185 if (slang->sl_rem_accents)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3186 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3187 t = word;
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3188 while (*s != NUL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3191 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3192 *t++ = ' ';
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3193 s = skipwhite(s);
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3194 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3195 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3196 {
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3197 if (spell_iswordp_nmw(s, curwin))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3198 *t++ = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3199 ++s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3200 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3201 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3202 *t = NUL;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3203 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3204 else
2768
c5e47b752f07 updated for version 7.3.160
Bram Moolenaar <bram@vim.org>
parents: 2691
diff changeset
3205 vim_strncpy(word, s, MAXWLEN - 1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3206
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3207 smp = (salitem_T *)slang->sl_sal.ga_data;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3208
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3209 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3210 * This comes from Aspell phonet.cpp. Converted from C++ to C.
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3211 * Changed to keep spaces.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3212 */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3213 i = reslen = z = 0;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3214 while ((c = word[i]) != NUL)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3217 n = slang->sl_sal_first[c];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3218 z0 = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3219
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3220 if (n >= 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3223 for (; (s = smp[n].sm_lead)[0] == c; ++n)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3227 k = smp[n].sm_leadlen;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3228 if (k > 1)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3229 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3230 if (word[i + 1] != s[1])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3231 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3232 if (k > 2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3233 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3234 for (j = 2; j < k; ++j)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3235 if (word[i + j] != s[j])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3236 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3237 if (j < k)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3238 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3239 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3240 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3241
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3242 if ((pf = smp[n].sm_oneof) != NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3245 while (*pf != NUL && *pf != word[i + k])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3246 ++pf;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3247 if (*pf == NUL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3248 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3249 ++k;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3250 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3253
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3254 p0 = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3255 k0 = k;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3256 while (*s == '-' && k > 1)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3257 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3258 k--;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3259 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3260 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3261 if (*s == '<')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3262 s++;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3263 if (VIM_ISDIGIT(*s))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3266 pri = *s - '0';
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3267 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3268 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3269 if (*s == '^' && *(s + 1) == '^')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3270 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3271
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3272 if (*s == NUL
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3273 || (*s == '^'
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3284 c0 = word[i + k - 1];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3285 n0 = slang->sl_sal_first[c0];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3286
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3287 if (slang->sl_followup && k > 1 && n0 >= 0
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3288 && p0 != '-' && word[i + k] != NUL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3291 for ( ; (s = smp[n0].sm_lead)[0] == c0; ++n0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3295 k0 = smp[n0].sm_leadlen;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3296 if (k0 > 1)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3297 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3298 if (word[i + k] != s[1])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3299 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3300 if (k0 > 2)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3301 {
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3302 pf = word + i + k + 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3303 for (j = 2; j < k0; ++j)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3304 if (*pf++ != s[j])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3305 break;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3306 if (j < k0)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3307 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3308 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3309 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3310 k0 += k - 1;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3311
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3312 if ((pf = smp[n0].sm_oneof) != NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3316 while (*pf != NUL && *pf != word[i + k0])
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3317 ++pf;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3318 if (*pf == NUL)
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3319 continue;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3320 ++k0;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3321 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3322
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3323 p0 = 5;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3324 s = smp[n0].sm_rules;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3325 while (*s == '-')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3329 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3330 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3331 if (*s == '<')
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3332 s++;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3333 if (VIM_ISDIGIT(*s))
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3334 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3335 p0 = *s - '0';
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3336 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3337 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3338
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3341 || (*s == '$'
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3344 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3347 continue;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3348
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3353 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3354 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3355 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3356
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3357 if (p0 >= pri && smp[n0].sm_lead[0] == c0)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3358 continue;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3359 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3362 s = smp[n].sm_to;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3363 if (s == NULL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3364 s = (char_u *)"";
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3365 pf = smp[n].sm_rules;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3366 p0 = (vim_strchr(pf, '<') != NULL) ? 1 : 0;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3367 if (p0 == 1 && z == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3370 if (reslen > 0 && *s != NUL && (res[reslen - 1] == c
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3371 || res[reslen - 1] == *s))
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3372 reslen--;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3373 z0 = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3374 z = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3375 k0 = 0;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3376 while (*s != NUL && word[i + k0] != NUL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3377 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3378 word[i + k0] = *s;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3379 k0++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3380 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3381 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3382 if (k > k0)
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 1580
diff changeset
3383 STRMOVE(word + i + k0, word + i + k);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3386 c = word[i];
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3387 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3388 else
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3391 i += k - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3392 z = 0;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3393 while (*s != NUL && s[1] != NUL && reslen < MAXWLEN)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3394 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3395 if (reslen == 0 || res[reslen - 1] != *s)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3396 res[reslen++] = *s;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3397 s++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3400 c = *s;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3401 if (strstr((char *)pf, "^^") != NULL)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3402 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3403 if (c != NUL)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3404 res[reslen++] = c;
1619
b9740fb41986 updated for version 7.2a
vimboss
parents: 1580
diff changeset
3405 STRMOVE(word, word + i + 1);
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3406 i = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3407 z0 = 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3408 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3409 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3410 break;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3411 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3412 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
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
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3415 {
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3416 c = ' ';
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3417 k = 1;
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3418 }
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3419
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3420 if (z0 == 0)
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3421 {
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3422 if (k && !p0 && reslen < MAXWLEN && c != NUL
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3423 && (!slang->sl_collapse || reslen == 0
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3426 res[reslen++] = c;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3427
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3428 i++;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3429 z = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3430 k = 0;
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3431 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3432 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3433
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 339
diff changeset
3434 res[reslen] = NUL;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3435 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 316
diff changeset
3436
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3437 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3438 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]".
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3439 * Multi-byte version of spell_soundfold().
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3440 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3443 {
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3444 salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3445 int word[MAXWLEN];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3446 int wres[MAXWLEN];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3447 int l;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3448 char_u *s;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3449 int *ws;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3450 char_u *t;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3451 int *pf;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3452 int i, j, z;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3453 int reslen;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3454 int n, k = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3455 int z0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3456 int k0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3457 int n0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3458 int c;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3459 int pri;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3460 int p0 = -333;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3461 int c0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3462 int did_white = FALSE;
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3463 int wordlen;
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3464
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3465
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3466 /*
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3467 * Convert the multi-byte string to a wide-character string.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3468 * Remove accents, if wanted. We actually remove all non-word characters.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3469 * But keep white space.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3470 */
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3471 wordlen = 0;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3472 for (s = inword; *s != NUL; )
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3473 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3474 t = s;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 469
diff changeset
3475 c = mb_cptr2char_adv(&s);
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3476 if (slang->sl_rem_accents)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3479 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3480 if (did_white)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3481 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3482 c = ' ';
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3483 did_white = TRUE;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3484 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3485 else
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3486 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3487 did_white = FALSE;
5477
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
3488 if (!spell_iswordp_nmw(t, curwin))
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3489 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3490 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3491 }
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3492 word[wordlen++] = c;
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3493 }
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3494 word[wordlen] = NUL;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3495
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3496 /*
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3497 * This algorithm comes from Aspell phonet.cpp.
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3498 * Converted from C++ to C. Added support for multi-byte chars.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3499 * Changed to keep spaces.
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3500 */
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3501 i = reslen = z = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3502 while ((c = word[i]) != NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3505 n = slang->sl_sal_first[c & 0xff];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3506 z0 = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3507
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3508 if (n >= 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3518 if (c != ws[0])
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3519 continue;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3520 k = smp[n].sm_leadlen;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3521 if (k > 1)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3522 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3523 if (word[i + 1] != ws[1])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3524 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3525 if (k > 2)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3526 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3527 for (j = 2; j < k; ++j)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3528 if (word[i + j] != ws[j])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3529 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3530 if (j < k)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3531 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3532 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3533 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3534
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3535 if ((pf = smp[n].sm_oneof_w) != NULL)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3538 while (*pf != NUL && *pf != word[i + k])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3539 ++pf;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3540 if (*pf == NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3541 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3542 ++k;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3543 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3546
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3547 p0 = *s;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3548 k0 = k;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3549 while (*s == '-' && k > 1)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3550 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3551 k--;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3552 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3553 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3554 if (*s == '<')
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3555 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3556 if (VIM_ISDIGIT(*s))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3559 pri = *s - '0';
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3560 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3561 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3562 if (*s == '^' && *(s + 1) == '^')
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3563 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3564
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3565 if (*s == NUL
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3566 || (*s == '^'
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3577 c0 = word[i + k - 1];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3578 n0 = slang->sl_sal_first[c0 & 0xff];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3579
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3580 if (slang->sl_followup && k > 1 && n0 >= 0
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3581 && p0 != '-' && word[i + k] != NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3585 for ( ; ((ws = smp[n0].sm_lead_w)[0] & 0xff)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3586 == (c0 & 0xff); ++n0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3589 if (c0 != ws[0])
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3590 continue;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3591 k0 = smp[n0].sm_leadlen;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3592 if (k0 > 1)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3593 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3594 if (word[i + k] != ws[1])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3595 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3596 if (k0 > 2)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3597 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3598 pf = word + i + k + 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3599 for (j = 2; j < k0; ++j)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3600 if (*pf++ != ws[j])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3601 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3602 if (j < k0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3603 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3604 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3605 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3606 k0 += k - 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3607
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 372
diff changeset
3608 if ((pf = smp[n0].sm_oneof_w) != NULL)
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3612 while (*pf != NUL && *pf != word[i + k0])
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3613 ++pf;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3614 if (*pf == NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3615 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3616 ++k0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3617 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3618
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3619 p0 = 5;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3620 s = smp[n0].sm_rules;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3621 while (*s == '-')
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3625 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3626 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3627 if (*s == '<')
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3628 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3629 if (VIM_ISDIGIT(*s))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3630 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3631 p0 = *s - '0';
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3632 s++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3633 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3634
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3637 || (*s == '$'
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3640 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3643 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3644
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3649 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3650 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3651 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3652
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3653 if (p0 >= pri && (smp[n0].sm_lead_w[0] & 0xff)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3654 == (c0 & 0xff))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3655 continue;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3656 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3659 ws = smp[n].sm_to_w;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3660 s = smp[n].sm_rules;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3661 p0 = (vim_strchr(s, '<') != NULL) ? 1 : 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3662 if (p0 == 1 && z == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3665 if (reslen > 0 && ws != NULL && *ws != NUL
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3666 && (wres[reslen - 1] == c
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3667 || wres[reslen - 1] == *ws))
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3668 reslen--;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3669 z0 = 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3670 z = 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3671 k0 = 0;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3672 if (ws != NULL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3673 while (*ws != NUL && word[i + k0] != NUL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3674 {
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3675 word[i + k0] = *ws;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3676 k0++;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3677 ws++;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3678 }
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3679 if (k > k0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3680 mch_memmove(word + i + k0, word + i + k,
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3681 sizeof(int) * (wordlen - (i + k) + 1));
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3684 c = word[i];
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3685 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3686 else
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3689 i += k - 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3690 z = 0;
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3691 if (ws != NULL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3692 while (*ws != NUL && ws[1] != NUL
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3693 && reslen < MAXWLEN)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3694 {
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3695 if (reslen == 0 || wres[reslen - 1] != *ws)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3696 wres[reslen++] = *ws;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3697 ws++;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
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
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3700 if (ws == NULL)
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3701 c = NUL;
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3702 else
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
3703 c = *ws;
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3704 if (strstr((char *)s, "^^") != NULL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3705 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3706 if (c != NUL)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3707 wres[reslen++] = c;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3708 mch_memmove(word, word + i + 1,
3520
b14842cf382b updated for version 7.3.521
Bram Moolenaar <bram@vim.org>
parents: 3263
diff changeset
3709 sizeof(int) * (wordlen - (i + 1) + 1));
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3710 i = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3711 z0 = 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3712 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3713 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3714 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3715 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3716 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3719 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3720 c = ' ';
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3721 k = 1;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3722 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3723
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3724 if (z0 == 0)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3725 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3726 if (k && !p0 && reslen < MAXWLEN && c != NUL
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3727 && (!slang->sl_collapse || reslen == 0
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3730 wres[reslen++] = c;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3731
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3732 i++;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3733 z = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3734 k = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3735 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3736 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
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
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3739 l = 0;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3740 for (n = 0; n < reslen; ++n)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3741 {
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3742 l += mb_char2bytes(wres[n], res + l);
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3743 if (l + MB_MAXBYTES > MAXWLEN)
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3744 break;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3745 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3746 res[l] = NUL;
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3747 }
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
3748
324
548525d9da24 updated for version 7.0085
vimboss
parents: 323
diff changeset
3749 /*
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3750 * ":spellinfo"
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3751 */
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
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
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3754 {
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3755 int lpi;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3756 langp_T *lp;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3757 char_u *p;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3758
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3759 if (no_spell_checking(curwin))
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3760 return;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3761
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
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
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3768 msg_putchar('\n');
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3769 p = lp->lp_slang->sl_info;
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3770 if (p != NULL)
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
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
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3773 msg_putchar('\n');
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3774 }
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3775 }
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3776 msg_end();
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
3777 }
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 710
diff changeset
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
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
3784
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3785 /*
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3786 * ":spelldump"
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3787 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3790 {
5382
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
3791 char_u *spl;
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
3792 long dummy;
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
3793
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3794 if (no_spell_checking(curwin))
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3795 return;
5382
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
3796 get_option_value((char_u*)"spl", &dummy, &spl, OPT_LOCAL);
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
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
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3799 do_cmdline_cmd((char_u *)"new");
5382
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
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
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
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
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
3804 vim_free(spl);
70915ede509a updated for version 7.4.042
Bram Moolenaar <bram@vim.org>
parents: 5374
diff changeset
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
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3807 return;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3812 if (curbuf->b_ml.ml_line_count > 1)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3813 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3814
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3815 redraw_later(NOT_VALID);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3816 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3817
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3818 /*
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3819 * Go through all possible words and:
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3820 * 1. When "pat" is NULL: dump a list of all words in the current buffer.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3821 * "ic" and "dir" are not used.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3822 * 2. When "pat" is not NULL: add matching words to insert mode completion.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3823 */
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3830 {
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3831 langp_T *lp;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3832 slang_T *slang;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3833 idx_T arridx[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3834 int curi[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3835 char_u word[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3836 int c;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3837 char_u *byts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3838 idx_T *idxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3839 linenr_T lnum = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3840 int round;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3841 int depth;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3842 int n;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3846 char_u *p;
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
3847 int lpi;
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3848 int dumpflags = dumpflags_arg;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3849 int patlen;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3853 if (pat != NULL)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3854 {
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3855 if (ic)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3856 dumpflags |= DUMPFLAG_ICASE;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3857 else
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3858 {
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3859 n = captype(pat, NULL);
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3860 if (n == WF_ONECAP)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
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
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3863 dumpflags |= DUMPFLAG_ALLCAP;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3864 }
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
3865 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3872 p = lp->lp_slang->sl_regions;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3873 if (p[0] != 0)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
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
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3876 region_names = p;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3877 else if (STRCMP(region_names, p) != 0)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
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
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3880 break;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3881 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3882 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3883 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3884
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3885 if (do_region && region_names != NULL)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3886 {
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3887 if (pat == NULL)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3888 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3889 vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3890 ml_append(lnum++, IObuff, (colnr_T)0, FALSE);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3891 }
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3892 }
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3893 else
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3894 do_region = FALSE;
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3895
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3896 /*
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3897 * Loop over all files loaded for the entries in 'spelllang'.
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
3904 continue;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3905
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3906 if (pat == NULL)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3907 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3908 vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3909 ml_append(lnum++, IObuff, (colnr_T)0, FALSE);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3910 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3914 if (pat != NULL && slang->sl_pbyts == NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
3915 patlen = (int)STRLEN(pat);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3916 else
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 835
diff changeset
3917 patlen = -1;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3921 for (round = 1; round <= 2; ++round)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3922 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3923 if (round == 1)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3924 {
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3925 dumpflags &= ~DUMPFLAG_KEEPCASE;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3926 byts = slang->sl_fbyts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3927 idxs = slang->sl_fidxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3928 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3929 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3930 {
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3931 dumpflags |= DUMPFLAG_KEEPCASE;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3932 byts = slang->sl_kbyts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3933 idxs = slang->sl_kidxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3934 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3937
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3938 depth = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3939 arridx[0] = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3940 curi[0] = 1;
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3943 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3944 if (curi[depth] > byts[arridx[depth]])
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3947 --depth;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3950 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3951 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3954 n = arridx[depth] + curi[depth];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3955 ++curi[depth];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3956 c = byts[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3957 if (c == 0)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3963 flags = (int)idxs[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3964 if ((round == 2 || (flags & WF_KEEPCAP) == 0)
500
4772a5e3f9fa updated for version 7.0138
vimboss
parents: 498
diff changeset
3965 && (flags & WF_NEEDCOMP) == 0
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3966 && (do_region
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3967 || (flags & WF_REGION) == 0
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3968 || (((unsigned)flags >> 16)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3969 & lp->lp_region) != 0))
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3970 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3971 word[depth] = NUL;
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3972 if (!do_region)
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
3973 flags &= ~WF_REGION;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
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
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
3977 c = (unsigned)flags >> 24;
355
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
3978 if (c == 0 || curi[depth] == 2)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3979 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3980 dump_word(slang, word, pat, dir,
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3981 dumpflags, flags, lnum);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3982 if (pat == NULL)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3983 ++lnum;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3984 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
644578c9e219 updated for version 7.0092
vimboss
parents: 351
diff changeset
3987 if (c != 0)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3988 lnum = dump_prefixes(slang, word, pat, dir,
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
3989 dumpflags, flags, lnum);
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3990 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3991 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3992 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3995 word[depth++] = c;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3996 arridx[depth] = idxs[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
3997 curi[depth] = 1;
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4005 if (depth <= patlen
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4006 && MB_STRNICMP(word, pat, depth) != 0)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4007 --depth;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4008 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4009 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4010 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4011 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4012 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4013 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4014
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4015 /*
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4016 * Dump one word: apply case modifications and append a line to the buffer.
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4017 * When "lnum" is zero add insert mode completion.
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4018 */
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4028 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4029 int keepcap = FALSE;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4030 char_u *p;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4031 char_u *tw;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4032 char_u cword[MAXWLEN];
381
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
4033 char_u badword[MAXWLEN + 10];
997a094e44d2 updated for version 7.0099
vimboss
parents: 376
diff changeset
4034 int i;
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4035 int flags = wordflags;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4036
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4037 if (dumpflags & DUMPFLAG_ONECAP)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4038 flags |= WF_ONECAP;
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4039 if (dumpflags & DUMPFLAG_ALLCAP)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4040 flags |= WF_ALLCAP;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4041
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4042 if ((dumpflags & DUMPFLAG_KEEPCASE) == 0 && (flags & WF_CAPMASK) != 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4045 make_case_word(word, cword, flags);
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4046 p = cword;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4047 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4048 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4049 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4050 p = word;
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4051 if ((dumpflags & DUMPFLAG_KEEPCASE)
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4052 && ((captype(word, NULL) & WF_KEEPCAP) == 0
389
4fe8e1a7758e updated for version 7.0102
vimboss
parents: 388
diff changeset
4053 || (flags & WF_FIXCAP) != 0))
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4054 keepcap = TRUE;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4055 }
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4056 tw = p;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4057
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4058 if (pat == NULL)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4061 if ((flags & (WF_BANNED | WF_RARE | WF_REGION)) || keepcap)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4062 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4063 STRCPY(badword, p);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4064 STRCAT(badword, "/");
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4065 if (keepcap)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4066 STRCAT(badword, "=");
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4067 if (flags & WF_BANNED)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4068 STRCAT(badword, "!");
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4069 else if (flags & WF_RARE)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4070 STRCAT(badword, "?");
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4071 if (flags & WF_REGION)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4072 for (i = 0; i < 7; ++i)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4073 if (flags & (0x10000 << i))
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4074 sprintf((char *)badword + STRLEN(badword), "%d", i + 1);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4075 p = badword;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4076 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4077
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4078 if (dumpflags & DUMPFLAG_COUNT)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4079 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4080 hashitem_T *hi;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4083 hi = hash_find(&slang->sl_wordcount, tw);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4084 if (!HASHITEM_EMPTY(hi))
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4085 {
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4086 vim_snprintf((char *)IObuff, IOSIZE, "%s\t%d",
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4087 tw, HI2WC(hi)->wc_count);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4088 p = IObuff;
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4089 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4090 }
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4091
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4092 ml_append(lnum, p, (colnr_T)0, FALSE);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4093 }
710
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4094 else if (((dumpflags & DUMPFLAG_ICASE)
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4095 ? MB_STRNICMP(p, pat, STRLEN(pat)) == 0
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4096 : STRNCMP(p, pat, STRLEN(pat)) == 0)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
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
8165a037200b updated for version 7.0214
vimboss
parents: 701
diff changeset
4100 *dir = FORWARD;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4101 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4102
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4103 /*
372
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
4104 * For ":spelldump": Find matching prefixes for "word". Prepend each to
a698eb686ded updated for version 7.0096
vimboss
parents: 366
diff changeset
4105 * "word" and append a line to the buffer.
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4106 * When "lnum" is zero add insert mode completion.
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4107 * Return the updated line number.
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4108 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4118 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4119 idx_T arridx[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4120 int curi[MAXWLEN];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4121 char_u prefix[MAXWLEN];
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4122 char_u word_up[MAXWLEN];
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4123 int has_word_up = FALSE;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4124 int c;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4125 char_u *byts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4126 idx_T *idxs;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4127 linenr_T lnum = startlnum;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4128 int depth;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4129 int n;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4130 int len;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4131 int i;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4135 c = PTR2CHAR(word);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4136 if (SPELL_TOUPPER(c) != c)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4137 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4138 onecap_copy(word, word_up, TRUE);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4139 has_word_up = TRUE;
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4140 }
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4141
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4142 byts = slang->sl_pbyts;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4145 {
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4146 /*
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4147 * Loop over all prefixes, building them byte-by-byte in prefix[].
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
4148 * When at the end of a prefix check that it supports "flags".
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4149 */
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4150 depth = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4151 arridx[0] = 0;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4152 curi[0] = 1;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4153 while (depth >= 0 && !got_int)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4154 {
390
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
4155 n = arridx[depth];
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
4156 len = byts[n];
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
4157 if (curi[depth] > len)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4160 --depth;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4161 line_breakcheck();
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4162 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4163 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
bded5839a32e updated for version 7.0103
vimboss
parents: 389
diff changeset
4166 n += curi[depth];
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4167 ++curi[depth];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4168 c = byts[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4169 if (c == 0)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4172 for (i = 1; i < len; ++i)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4173 if (byts[n + i] != 0)
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4174 break;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4175 curi[depth] += i - 1;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4176
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4177 c = valid_word_prefix(i, n, flags, word, slang, FALSE);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4178 if (c != 0)
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4179 {
376
d2bc505a6d91 updated for version 7.0098
vimboss
parents: 375
diff changeset
4180 vim_strncpy(prefix + depth, word, MAXWLEN - depth - 1);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4181 dump_word(slang, prefix, pat, dir, dumpflags,
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4182 (c & WF_RAREPFX) ? (flags | WF_RARE)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4183 : flags, lnum);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4184 if (lnum != 0)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4185 ++lnum;
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4186 }
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
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
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4191 if (has_word_up)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4192 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4193 c = valid_word_prefix(i, n, flags, word_up, slang,
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4194 TRUE);
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4195 if (c != 0)
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4196 {
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4197 vim_strncpy(prefix + depth, word_up,
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4198 MAXWLEN - depth - 1);
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4199 dump_word(slang, prefix, pat, dir, dumpflags,
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4200 (c & WF_RAREPFX) ? (flags | WF_RARE)
701
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4201 : flags, lnum);
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4202 if (lnum != 0)
4cf1c5977c35 updated for version 7.0212
vimboss
parents: 698
diff changeset
4203 ++lnum;
455
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4204 }
e6e639f0cb97 updated for version 7.0121
vimboss
parents: 447
diff changeset
4205 }
351
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4206 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4207 else
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
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
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4210 prefix[depth++] = c;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4211 arridx[depth] = idxs[n];
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4212 curi[depth] = 1;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4213 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4214 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4215 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4216 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4217
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4218 return lnum;
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4219 }
a89aebda7f37 updated for version 7.0091
vimboss
parents: 346
diff changeset
4220
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
4221 /*
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
4222 * Move "p" to the end of word "start".
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
4223 * Uses the spell-checking word characters.
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
4224 */
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
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
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
4227 {
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
4228 char_u *p = start;
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
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
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
4232 return p;
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
4233 }
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
4234
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4235 /*
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
4236 * For Insert mode completion CTRL-X s:
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
4237 * Find start of the word in front of column "startcol".
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
4238 * We don't check if it is badly spelled, with completion we can only change
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
4239 * the word in front of the cursor.
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4240 * Returns the column number of the word.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4241 */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4244 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4245 char_u *line;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4246 char_u *p;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4247 int col = 0;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4248
498
f9ea3888b054 updated for version 7.0137
vimboss
parents: 495
diff changeset
4249 if (no_spell_checking(curwin))
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4250 return startcol;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4253 line = ml_get_curline();
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4254 for (p = line + startcol; p > line; )
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
853a76c7fded updated for version 7.4.088
Bram Moolenaar <bram@vim.org>
parents: 5382
diff changeset
4257 if (spell_iswordp_nmw(p, curwin))
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4258 break;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4259 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4262 while (p > line)
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4263 {
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 827
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4267 break;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4268 col = 0;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4269 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4270
535
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4271 return col;
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4272 }
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4273
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4274 /*
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4275 * Need to check for 'spellcapcheck' now, the word is removed before
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4276 * expand_spelling() is called. Therefore the ugly global variable.
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4277 */
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4278 static int spell_expand_need_cap;
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4279
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
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
792d1b60e546 updated for version 7.0152
vimboss
parents: 534
diff changeset
4282 {
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4283 spell_expand_need_cap = check_need_cap(curwin->w_cursor.lnum, col);
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4284 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4285
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4286 /*
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4287 * Get list of spelling suggestions.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4288 * Used for Insert mode completion CTRL-X ?.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4289 * Returns the number of matches. The matches are in "matchp[]", array of
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4290 * allocated strings.
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4291 */
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4297 {
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4298 garray_T ga;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4299
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 621
diff changeset
4300 spell_suggest_list(&ga, pat, 100, spell_expand_need_cap, TRUE);
475
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4301 *matchp = ga.ga_data;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4302 return ga.ga_len;
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
4303 }
e6dfeb0a0f53 updated for version 7.0128
vimboss
parents: 474
diff changeset
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