Mercurial > vim
annotate runtime/doc/develop.txt @ 26596:ec6724c39b7d v8.2.3827
patch 8.2.3827: huntr badge does not really fit in the list
Commit: https://github.com/vim/vim/commit/f79cbf6512863c167bc794035df067e3a3e474f3
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 16 16:14:11 2021 +0000
patch 8.2.3827: huntr badge does not really fit in the list
Problem: Huntr badge does not really fit in the list.
Solution: Move the link to Huntr to the issue template.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 16 Dec 2021 17:15:04 +0100 |
parents | bbca88cd13d5 |
children | f8116058ca76 |
rev | line source |
---|---|
21991 | 1 *develop.txt* For Vim version 8.2. Last change: 2020 Aug 15 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Bram Moolenaar | |
5 | |
6 | |
7 Development of Vim. *development* | |
8 | |
9 This text is important for those who want to be involved in further developing | |
10 Vim. | |
11 | |
12 1. Design goals |design-goals| | |
13 2. Coding style |coding-style| | |
14 3. Design decisions |design-decisions| | |
15 4. Assumptions |design-assumptions| | |
16 | |
17 See the file README.txt in the "src" directory for an overview of the source | |
18 code. | |
19 | |
20 Vim is open source software. Everybody is encouraged to contribute to help | |
13857 | 21 improving Vim. For sending patches a unified diff "diff -u" is preferred. |
22 You can create a pull request on github, but it's not required. | |
4358 | 23 Also see http://vim.wikia.com/wiki/How_to_make_and_submit_a_patch. |
7 | 24 |
25 ============================================================================== | |
26 1. Design goals *design-goals* | |
27 | |
28 Most important things come first (roughly). | |
29 | |
30 Note that quite a few items are contradicting. This is intentional. A | |
31 balance must be found between them. | |
32 | |
33 | |
34 VIM IS... VI COMPATIBLE *design-compatible* | |
35 | |
36 First of all, it should be possible to use Vim as a drop-in replacement for | |
21676 | 37 Vi. When the user wants to, Vim can be used in compatible mode and hardly |
38 any differences with the original Vi will be noticed. | |
7 | 39 |
40 Exceptions: | |
41 - We don't reproduce obvious Vi bugs in Vim. | |
42 - There are different versions of Vi. I am using Version 3.7 (6/7/85) as a | |
43 reference. But support for other versions is also included when possible. | |
44 The Vi part of POSIX is not considered a definitive source. | |
45 - Vim adds new commands, you cannot rely on some command to fail because it | |
46 didn't exist in Vi. | |
47 - Vim will have a lot of features that Vi doesn't have. Going back from Vim | |
48 to Vi will be a problem, this cannot be avoided. | |
49 - Some things are hardly ever used (open mode, sending an e-mail when | |
50 crashing, etc.). Those will only be included when someone has a good reason | |
51 why it should be included and it's not too much work. | |
52 - For some items it is debatable whether Vi compatibility should be | |
53 maintained. There will be an option flag for these. | |
54 | |
55 | |
56 VIM IS... IMPROVED *design-improved* | |
57 | |
58 The IMproved bits of Vim should make it a better Vi, without becoming a | |
59 completely different editor. Extensions are done with a "Vi spirit". | |
60 - Use the keyboard as much as feasible. The mouse requires a third hand, | |
61 which we don't have. Many terminals don't have a mouse. | |
62 - When the mouse is used anyway, avoid the need to switch back to the | |
63 keyboard. Avoid mixing mouse and keyboard handling. | |
64 - Add commands and options in a consistent way. Otherwise people will have a | |
65 hard time finding and remembering them. Keep in mind that more commands and | |
66 options will be added later. | |
67 - A feature that people do not know about is a useless feature. Don't add | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
68 obscure features, or at least add hints in documentation that they exist. |
7 | 69 - Minimize using CTRL and other modifiers, they are more difficult to type. |
70 - There are many first-time and inexperienced Vim users. Make it easy for | |
71 them to start using Vim and learn more over time. | |
72 - There is no limit to the features that can be added. Selecting new features | |
73 is one based on (1) what users ask for, (2) how much effort it takes to | |
74 implement and (3) someone actually implementing it. | |
75 | |
76 | |
77 VIM IS... MULTI PLATFORM *design-multi-platform* | |
78 | |
79 Vim tries to help as many users on as many platforms as possible. | |
80 - Support many kinds of terminals. The minimal demands are cursor positioning | |
81 and clear-screen. Commands should only use key strokes that most keyboards | |
82 have. Support all the keys on the keyboard for mapping. | |
83 - Support many platforms. A condition is that there is someone willing to do | |
84 Vim development on that platform, and it doesn't mean messing up the code. | |
85 - Support many compilers and libraries. Not everybody is able or allowed to | |
86 install another compiler or GUI library. | |
87 - People switch from one platform to another, and from GUI to terminal | |
88 version. Features should be present in all versions, or at least in as many | |
89 as possible with a reasonable effort. Try to avoid that users must switch | |
90 between platforms to accomplish their work efficiently. | |
91 - That a feature is not possible on some platforms, or only possible on one | |
92 platform, does not mean it cannot be implemented. [This intentionally | |
93 contradicts the previous item, these two must be balanced.] | |
94 | |
95 | |
96 VIM IS... WELL DOCUMENTED *design-documented* | |
97 | |
98 - A feature that isn't documented is a useless feature. A patch for a new | |
99 feature must include the documentation. | |
100 - Documentation should be comprehensive and understandable. Using examples is | |
101 recommended. | |
102 - Don't make the text unnecessarily long. Less documentation means that an | |
103 item is easier to find. | |
104 | |
105 | |
106 VIM IS... HIGH SPEED AND SMALL IN SIZE *design-speed-size* | |
107 | |
108 Using Vim must not be a big attack on system resources. Keep it small and | |
109 fast. | |
110 - Computers are becoming faster and bigger each year. Vim can grow too, but | |
111 no faster than computers are growing. Keep Vim usable on older systems. | |
112 - Many users start Vim from a shell very often. Startup time must be short. | |
113 - Commands must work efficiently. The time they consume must be as small as | |
114 possible. Useful commands may take longer. | |
115 - Don't forget that some people use Vim over a slow connection. Minimize the | |
116 communication overhead. | |
117 - Items that add considerably to the size and are not used by many people | |
118 should be a feature that can be disabled. | |
119 - Vim is a component among other components. Don't turn it into a massive | |
120 application, but have it work well together with other programs. | |
121 | |
122 | |
123 VIM IS... MAINTAINABLE *design-maintain* | |
124 | |
125 - The source code should not become a mess. It should be reliable code. | |
126 - Use the same layout in all files to make it easy to read |coding-style|. | |
481 | 127 - Use comments in a useful way! Quoting the function name and argument names |
128 is NOT useful. Do explain what they are for. | |
7 | 129 - Porting to another platform should be made easy, without having to change |
130 too much platform-independent code. | |
131 - Use the object-oriented spirit: Put data and code together. Minimize the | |
132 knowledge spread to other parts of the code. | |
133 | |
134 | |
135 VIM IS... FLEXIBLE *design-flexible* | |
136 | |
137 Vim should make it easy for users to work in their preferred styles rather | |
138 than coercing its users into particular patterns of work. This can be for | |
139 items with a large impact (e.g., the 'compatible' option) or for details. The | |
140 defaults are carefully chosen such that most users will enjoy using Vim as it | |
141 is. Commands and options can be used to adjust Vim to the desire of the user | |
142 and its environment. | |
143 | |
144 | |
145 VIM IS... NOT *design-not* | |
146 | |
11914 | 147 - Vim is not a shell or an Operating System. It does provide a terminal |
148 window, in which you can run a shell or debugger. E.g. to be able to do | |
149 this over an ssh connection. But if you don't need a text editor with that | |
150 it is out of scope (use something like screen or tmux instead). | |
7 | 151 A satirical way to say this: "Unlike Emacs, Vim does not attempt to include |
152 everything but the kitchen sink, but some people say that you can clean one | |
153 with it. ;-)" | |
20115 | 154 To use Vim with gdb see |terminal-debugger|. Other (older) tools can be |
155 found at http://www.agide.org and http://clewn.sf.net. | |
7 | 156 - Vim is not a fancy GUI editor that tries to look nice at the cost of |
157 being less consistent over all platforms. But functional GUI features are | |
158 welcomed. | |
159 | |
160 ============================================================================== | |
161 2. Coding style *coding-style* | |
162 | |
163 These are the rules to use when making changes to the Vim source code. Please | |
164 stick to these rules, to keep the sources readable and maintainable. | |
165 | |
166 This list is not complete. Look in the source code for more examples. | |
167 | |
168 | |
169 MAKING CHANGES *style-changes* | |
170 | |
171 The basic steps to make changes to the code: | |
7707
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
172 1. Get the code from github. That makes it easier to keep your changed |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
173 version in sync with the main code base (it may be a while before your |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
174 changes will be included). You do need to spend some time learning git, |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
175 it's not the most user friendly tool. |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
176 2. Adjust the documentation. Doing this first gives you an impression of how |
7 | 177 your changes affect the user. |
7707
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
178 3. Make the source code changes. |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
179 4. Check ../doc/todo.txt if the change affects any listed item. |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
180 5. Make a patch with "git diff". You can also create a pull request on |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
181 github, but it's the diff that matters. |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
182 6. Make a note about what changed, preferably mentioning the problem and the |
10548
74effdaa369e
Updated runtime files.
Christian Brabandt <cb@256bit.org>
parents:
10198
diff
changeset
|
183 solution. Send an email to the |vim-dev| maillist with an explanation and |
7707
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
184 include the diff. Or create a pull request on github. |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
185 |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
186 |
13818
28ac7914b2b6
Update runtime files and translations
Christian Brabandt <cb@256bit.org>
parents:
13735
diff
changeset
|
187 C COMPILER *style-compiler* *ANSI-C* *C89* *C99* |
7707
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
188 |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
189 The minimal C compiler version supported is C89, also known as ANSI C. |
13716
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
190 Later standards, such as C99, are not widely supported, or at least not 100% |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
191 supported. Therefore we use only some of the C99 features and disallow some |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
192 (at least for now). |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
193 |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
194 Please don't make changes everywhere to use the C99 features, it causes merge |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
195 problems for existing patches. Only use them for new and changed code. |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
196 |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
197 Comments ~ |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
198 |
18719 | 199 Traditionally Vim uses /* comments */. We intend to keep it that way |
200 for file and function headers and larger blocks of code, E.g.: | |
201 /* | |
202 * The "foo" argument does something useful. | |
203 * Return OK or FAIL. | |
204 */ | |
205 For new code or lines of code that change, it is preferred to use // comments. | |
206 Especially when it comes after code: | |
13716
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
207 int some_var; // single line comment useful here |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
208 |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
209 Enums ~ |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
210 |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
211 The last item in an enum may have a trailing comma. C89 didn't allow this. |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
212 |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
213 Types ~ |
7707
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
214 |
13716
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
215 "long long" is allowed and can be expected to be 64 bits. Use %lld in printf |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
216 formats. Also "long long unsigned" with %llu. |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
217 |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
218 Not to be used ~ |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
219 |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
220 These C99 features are not to be used, because not enough compilers support |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
221 them: |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
222 - Declaration after Statements (MSVC 2012 does not support it). All |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
223 declarations need to be at the start of the block. |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
224 - Variable length arrays (even in C11 this is an optional feature). |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
225 - _Bool and _Complex types. |
30f9ebe3e602
patch 8.0.1730: no configure check for the used C99 features
Christian Brabandt <cb@256bit.org>
parents:
11914
diff
changeset
|
226 - "inline" (it's hardly ever needed, let the optimizer do its work) |
13726
d35b1702a1da
patch 8.0.1735: flexible array member feature not supported by HP-UX
Christian Brabandt <cb@256bit.org>
parents:
13716
diff
changeset
|
227 - flexible array members: Not supported by HP-UX C compiler (John Marriott) |
7 | 228 |
229 | |
230 USE OF COMMON FUNCTIONS *style-functions* | |
231 | |
232 Some functions that are common to use, have a special Vim version. Always | |
233 consider using the Vim version, because they were introduced with a reason. | |
234 | |
235 NORMAL NAME VIM NAME DIFFERENCE OF VIM VERSION | |
236 free() vim_free() Checks for freeing NULL | |
237 malloc() alloc() Checks for out of memory situation | |
238 malloc() lalloc() Like alloc(), but has long argument | |
239 strcpy() STRCPY() Includes cast to (char *), for char_u * args | |
240 strchr() vim_strchr() Accepts special characters | |
241 strrchr() vim_strrchr() Accepts special characters | |
242 isspace() vim_isspace() Can handle characters > 128 | |
1240 | 243 iswhite() vim_iswhite() Only TRUE for tab and space |
711 | 244 memcpy() mch_memmove() Handles overlapped copies |
245 bcopy() mch_memmove() Handles overlapped copies | |
7 | 246 memset() vim_memset() Uniform for all systems |
247 | |
248 | |
249 NAMES *style-names* | |
250 | |
251 Function names can not be more than 31 characters long (because of VMS). | |
252 | |
7707
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
253 Don't use "delete" or "this" as a variable name, C++ doesn't like it. |
7 | 254 |
255 Because of the requirement that Vim runs on as many systems as possible, we | |
256 need to avoid using names that are already defined by the system. This is a | |
257 list of names that are known to cause trouble. The name is given as a regexp | |
258 pattern. | |
259 | |
260 is.*() POSIX, ctype.h | |
261 to.*() POSIX, ctype.h | |
262 | |
263 d_.* POSIX, dirent.h | |
264 l_.* POSIX, fcntl.h | |
265 gr_.* POSIX, grp.h | |
266 pw_.* POSIX, pwd.h | |
267 sa_.* POSIX, signal.h | |
268 mem.* POSIX, string.h | |
269 str.* POSIX, string.h | |
270 wcs.* POSIX, string.h | |
271 st_.* POSIX, stat.h | |
272 tms_.* POSIX, times.h | |
273 tm_.* POSIX, time.h | |
274 c_.* POSIX, termios.h | |
275 MAX.* POSIX, limits.h | |
276 __.* POSIX, system | |
277 _[A-Z].* POSIX, system | |
278 E[A-Z0-9]* POSIX, errno.h | |
279 | |
1121 | 280 .*_t POSIX, for typedefs. Use .*_T instead. |
7 | 281 |
282 wait don't use as argument to a function, conflicts with types.h | |
283 index shadows global declaration | |
284 time shadows global declaration | |
285 new C++ reserved keyword | |
286 | |
3281 | 287 clear Mac curses.h |
288 echo Mac curses.h | |
289 instr Mac curses.h | |
290 meta Mac curses.h | |
291 newwin Mac curses.h | |
292 nl Mac curses.h | |
293 overwrite Mac curses.h | |
294 refresh Mac curses.h | |
295 scroll Mac curses.h | |
296 typeahead Mac curses.h | |
297 | |
7 | 298 basename() GNU string function |
299 dirname() GNU string function | |
300 get_env_value() Linux system function | |
301 | |
302 | |
303 VARIOUS *style-various* | |
304 | |
502 | 305 Typedef'ed names should end in "_T": > |
306 typedef int some_T; | |
7 | 307 Define'ed names should be uppercase: > |
308 #define SOME_THING | |
309 Features always start with "FEAT_": > | |
310 #define FEAT_FOO | |
311 | |
312 Don't use '\"', some compilers can't handle it. '"' works fine. | |
313 | |
314 Don't use: | |
315 #if HAVE_SOME | |
316 Some compilers can't handle that and complain that "HAVE_SOME" is not defined. | |
317 Use | |
318 #ifdef HAVE_SOME | |
319 or | |
320 #if defined(HAVE_SOME) | |
321 | |
322 | |
323 STYLE *style-examples* | |
324 | |
325 General rule: One statement per line. | |
326 | |
327 Wrong: if (cond) a = 1; | |
328 | |
329 OK: if (cond) | |
330 a = 1; | |
331 | |
332 Wrong: while (cond); | |
333 | |
334 OK: while (cond) | |
335 ; | |
336 | |
337 Wrong: do a = 1; while (cond); | |
338 | |
339 OK: do | |
340 a = 1; | |
341 while (cond); | |
342 | |
7707
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
343 Wrong: if (cond) { |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
344 cmd; |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
345 cmd; |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
346 } else { |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
347 cmd; |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
348 cmd; |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
349 } |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
350 |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
351 OK: if (cond) |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
352 { |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
353 cmd; |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
354 cmd; |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
355 } |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
356 else |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
357 { |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
358 cmd; |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
359 cmd; |
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
360 } |
7 | 361 |
15878 | 362 When a block has one line the braces can be left out. When an if/else has |
363 braces on one block, it usually looks better when the other block also has | |
364 braces: | |
365 OK: if (cond) | |
366 cmd; | |
367 else | |
368 cmd; | |
369 | |
370 OK: if (cond) | |
371 { | |
372 cmd; | |
373 } | |
374 else | |
375 { | |
376 cmd; | |
377 cmd; | |
378 } | |
379 | |
7876
93f747af7b58
commit https://github.com/vim/vim/commit/5e9b2fa9bb0e6061cf18457c173cd141a5dc9c92
Christian Brabandt <cb@256bit.org>
parents:
7707
diff
changeset
|
380 Use ANSI (new style) function declarations with the return type on a separate |
93f747af7b58
commit https://github.com/vim/vim/commit/5e9b2fa9bb0e6061cf18457c173cd141a5dc9c92
Christian Brabandt <cb@256bit.org>
parents:
7707
diff
changeset
|
381 indented line. |
7 | 382 |
383 Wrong: int function_name(int arg1, int arg2) | |
384 | |
385 OK: /* | |
386 * Explanation of what this function is used for. | |
387 * | |
388 * Return value explanation. | |
389 */ | |
390 int | |
7707
41768bcebc9b
commit https://github.com/vim/vim/commit/13d5aeef56e3140a8eb8f40c7062aa1c5700f76e
Christian Brabandt <cb@256bit.org>
parents:
5763
diff
changeset
|
391 function_name( |
15878 | 392 int arg1, // short comment about arg1 |
393 int arg2) // short comment about arg2 | |
7 | 394 { |
15878 | 395 int local; // comment about local |
7 | 396 |
397 local = arg1 * arg2; | |
398 | |
399 | |
400 | |
401 SPACES AND PUNCTUATION *style-spaces* | |
402 | |
403 No space between a function name and the bracket: | |
404 | |
405 Wrong: func (arg); | |
406 OK: func(arg); | |
407 | |
408 Do use a space after if, while, switch, etc. | |
409 | |
410 Wrong: if(arg) for(;;) | |
411 OK: if (arg) for (;;) | |
412 | |
413 Use a space after a comma and semicolon: | |
414 | |
415 Wrong: func(arg1,arg2); for (i = 0;i < 2;++i) | |
416 OK: func(arg1, arg2); for (i = 0; i < 2; ++i) | |
417 | |
418 Use a space before and after '=', '+', '/', etc. | |
419 | |
420 Wrong: var=a*5; | |
421 OK: var = a * 5; | |
422 | |
423 In general: Use empty lines to group lines of code together. Put a comment | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
424 just above the group of lines. This makes it easier to quickly see what is |
7 | 425 being done. |
426 | |
427 OK: /* Prepare for building the table. */ | |
428 get_first_item(); | |
429 table_idx = 0; | |
430 | |
431 /* Build the table */ | |
432 while (has_item()) | |
433 table[table_idx++] = next_item(); | |
434 | |
435 /* Finish up. */ | |
436 cleanup_items(); | |
437 generate_hash(table); | |
438 | |
439 ============================================================================== | |
440 3. Design decisions *design-decisions* | |
441 | |
442 Folding | |
443 | |
444 Several forms of folding should be possible for the same buffer. For example, | |
445 have one window that shows the text with function bodies folded, another | |
446 window that shows a function body. | |
447 | |
448 Folding is a way to display the text. It should not change the text itself. | |
449 Therefore the folding has been implemented as a filter between the text stored | |
450 in a buffer (buffer lines) and the text displayed in a window (logical lines). | |
451 | |
452 | |
453 Naming the window | |
454 | |
455 The word "window" is commonly used for several things: A window on the screen, | |
456 the xterm window, a window inside Vim to view a buffer. | |
457 To avoid confusion, other items that are sometimes called window have been | |
458 given another name. Here is an overview of the related items: | |
459 | |
460 screen The whole display. For the GUI it's something like 1024x768 | |
461 pixels. The Vim shell can use the whole screen or part of it. | |
462 shell The Vim application. This can cover the whole screen (e.g., | |
463 when running in a console) or part of it (xterm or GUI). | |
464 window View on a buffer. There can be several windows in Vim, | |
465 together with the command line, menubar, toolbar, etc. they | |
466 fit in the shell. | |
467 | |
468 | |
236 | 469 Spell checking *develop-spell* |
470 | |
471 When spell checking was going to be added to Vim a survey was done over the | |
472 available spell checking libraries and programs. Unfortunately, the result | |
473 was that none of them provided sufficient capabilities to be used as the spell | |
474 checking engine in Vim, for various reasons: | |
475 | |
21991 | 476 - Missing support for multibyte encodings. At least UTF-8 must be supported, |
236 | 477 so that more than one language can be used in the same file. |
323 | 478 Doing on-the-fly conversion is not always possible (would require iconv |
479 support). | |
236 | 480 - For the programs and libraries: Using them as-is would require installing |
323 | 481 them separately from Vim. That's mostly not impossible, but a drawback. |
236 | 482 - Performance: A few tests showed that it's possible to check spelling on the |
483 fly (while redrawing), just like syntax highlighting. But the mechanisms | |
625 | 484 used by other code are much slower. Myspell uses a hashtable, for example. |
485 The affix compression that most spell checkers use makes it slower too. | |
300 | 486 - For using an external program like aspell a communication mechanism would |
487 have to be setup. That's complicated to do in a portable way (Unix-only | |
488 would be relatively simple, but that's not good enough). And performance | |
489 will become a problem (lots of process switching involved). | |
236 | 490 - Missing support for words with non-word characters, such as "Etten-Leur" and |
491 "et al.", would require marking the pieces of them OK, lowering the | |
492 reliability. | |
493 - Missing support for regions or dialects. Makes it difficult to accept | |
494 all English words and highlight non-Canadian words differently. | |
495 - Missing support for rare words. Many words are correct but hardly ever used | |
496 and could be a misspelled often-used word. | |
323 | 497 - For making suggestions the speed is less important and requiring to install |
498 another program or library would be acceptable. But the word lists probably | |
499 differ, the suggestions may be wrong words. | |
7 | 500 |
625 | 501 |
502 Spelling suggestions *develop-spell-suggestions* | |
503 | |
504 For making suggestions there are two basic mechanisms: | |
505 1. Try changing the bad word a little bit and check for a match with a good | |
506 word. Or go through the list of good words, change them a little bit and | |
507 check for a match with the bad word. The changes are deleting a character, | |
508 inserting a character, swapping two characters, etc. | |
509 2. Perform soundfolding on both the bad word and the good words and then find | |
510 matches, possibly with a few changes like with the first mechanism. | |
511 | |
512 The first is good for finding typing mistakes. After experimenting with | |
513 hashtables and looking at solutions from other spell checkers the conclusion | |
514 was that a trie (a kind of tree structure) is ideal for this. Both for | |
515 reducing memory use and being able to try sensible changes. For example, when | |
516 inserting a character only characters that lead to good words need to be | |
517 tried. Other mechanisms (with hashtables) need to try all possible letters at | |
518 every position in the word. Also, a hashtable has the requirement that word | |
519 boundaries are identified separately, while a trie does not require this. | |
520 That makes the mechanism a lot simpler. | |
521 | |
522 Soundfolding is useful when someone knows how the words sounds but doesn't | |
523 know how it is spelled. For example, the word "dictionary" might be written | |
524 as "daktonerie". The number of changes that the first method would need to | |
525 try is very big, it's hard to find the good word that way. After soundfolding | |
526 the words become "tktnr" and "tkxnry", these differ by only two letters. | |
527 | |
528 To find words by their soundfolded equivalent (soundalike word) we need a list | |
529 of all soundfolded words. A few experiments have been done to find out what | |
530 the best method is. Alternatives: | |
531 1. Do the sound folding on the fly when looking for suggestions. This means | |
532 walking through the trie of good words, soundfolding each word and | |
533 checking how different it is from the bad word. This is very efficient for | |
534 memory use, but takes a long time. On a fast PC it takes a couple of | |
535 seconds for English, which can be acceptable for interactive use. But for | |
536 some languages it takes more than ten seconds (e.g., German, Catalan), | |
17667 | 537 which is unacceptably slow. For batch processing (automatic corrections) |
1197 | 538 it's too slow for all languages. |
625 | 539 2. Use a trie for the soundfolded words, so that searching can be done just |
540 like how it works without soundfolding. This requires remembering a list | |
541 of good words for each soundfolded word. This makes finding matches very | |
542 fast but requires quite a lot of memory, in the order of 1 to 10 Mbyte. | |
543 For some languages more than the original word list. | |
544 3. Like the second alternative, but reduce the amount of memory by using affix | |
545 compression and store only the soundfolded basic word. This is what Aspell | |
546 does. Disadvantage is that affixes need to be stripped from the bad word | |
547 before soundfolding it, which means that mistakes at the start and/or end | |
548 of the word will cause the mechanism to fail. Also, this becomes slow when | |
549 the bad word is quite different from the good word. | |
550 | |
551 The choice made is to use the second mechanism and use a separate file. This | |
552 way a user with sufficient memory can get very good suggestions while a user | |
553 who is short of memory or just wants the spell checking and no suggestions | |
554 doesn't use so much memory. | |
555 | |
556 | |
557 Word frequency | |
558 | |
559 For sorting suggestions it helps to know which words are common. In theory we | |
560 could store a word frequency with the word in the dictionary. However, this | |
561 requires storing a count per word. That degrades word tree compression a lot. | |
562 And maintaining the word frequency for all languages will be a heavy task. | |
563 Also, it would be nice to prefer words that are already in the text. This way | |
564 the words that appear in the specific text are preferred for suggestions. | |
565 | |
566 What has been implemented is to count words that have been seen during | |
567 displaying. A hashtable is used to quickly find the word count. The count is | |
568 initialized from words listed in COMMON items in the affix file, so that it | |
569 also works when starting a new file. | |
570 | |
571 This isn't ideal, because the longer Vim is running the higher the counts | |
1197 | 572 become. But in practice it is a noticeable improvement over not using the word |
625 | 573 count. |
574 | |
7 | 575 ============================================================================== |
576 4. Assumptions *design-assumptions* | |
577 | |
578 Size of variables: | |
579 char 8 bit signed | |
580 char_u 8 bit unsigned | |
625 | 581 int 32 or 64 bit signed (16 might be possible with limited features) |
582 unsigned 32 or 64 bit unsigned (16 as with ints) | |
7 | 583 long 32 or 64 bit signed, can hold a pointer |
584 | |
585 Note that some compilers cannot handle long lines or strings. The C89 | |
586 standard specifies a limit of 509 characters. | |
587 | |
14421 | 588 vim:tw=78:ts=8:noet:ft=help:norl: |