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