Mercurial > vim
annotate src/macros.h @ 5180:4104bed69ea5 v7.4a.016
updated for version 7.4a.016
Problem: Features enabled in Makefile.
Solution: Undo accidental changes.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sat, 13 Jul 2013 15:39:33 +0200 |
parents | 84a8d1ba81c3 |
children | 662ae48e7e24 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 */ | |
8 | |
9 /* | |
10 * macros.h: macro definitions for often used code | |
11 */ | |
12 | |
13 /* | |
14 * pchar(lp, c) - put character 'c' at position 'lp' | |
15 */ | |
16 #define pchar(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c)) | |
17 | |
18 /* | |
19 * Position comparisons | |
20 */ | |
21 #ifdef FEAT_VIRTUALEDIT | |
22 # define lt(a, b) (((a).lnum != (b).lnum) \ | |
23 ? (a).lnum < (b).lnum \ | |
24 : (a).col != (b).col \ | |
25 ? (a).col < (b).col \ | |
26 : (a).coladd < (b).coladd) | |
27 # define ltp(a, b) (((a)->lnum != (b)->lnum) \ | |
28 ? (a)->lnum < (b)->lnum \ | |
29 : (a)->col != (b)->col \ | |
30 ? (a)->col < (b)->col \ | |
31 : (a)->coladd < (b)->coladd) | |
32 # define equalpos(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col) && ((a).coladd == (b).coladd)) | |
698 | 33 # define clearpos(a) {(a)->lnum = 0; (a)->col = 0; (a)->coladd = 0;} |
7 | 34 #else |
35 # define lt(a, b) (((a).lnum != (b).lnum) \ | |
36 ? ((a).lnum < (b).lnum) : ((a).col < (b).col)) | |
37 # define ltp(a, b) (((a)->lnum != (b)->lnum) \ | |
38 ? ((a)->lnum < (b)->lnum) : ((a)->col < (b)->col)) | |
39 # define equalpos(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col)) | |
698 | 40 # define clearpos(a) {(a)->lnum = 0; (a)->col = 0;} |
7 | 41 #endif |
42 | |
43 #define ltoreq(a, b) (lt(a, b) || equalpos(a, b)) | |
44 | |
45 /* | |
46 * lineempty() - return TRUE if the line is empty | |
47 */ | |
48 #define lineempty(p) (*ml_get(p) == NUL) | |
49 | |
50 /* | |
51 * bufempty() - return TRUE if the current buffer is empty | |
52 */ | |
53 #define bufempty() (curbuf->b_ml.ml_line_count == 1 && *ml_get((linenr_T)1) == NUL) | |
54 | |
55 /* | |
56 * toupper() and tolower() that use the current locale. | |
1365 | 57 * On some systems toupper()/tolower() only work on lower/uppercase |
58 * characters, first use islower() or isupper() then. | |
7 | 59 * Careful: Only call TOUPPER_LOC() and TOLOWER_LOC() with a character in the |
60 * range 0 - 255. toupper()/tolower() on some systems can't handle others. | |
1365 | 61 * Note: It is often better to use MB_TOLOWER() and MB_TOUPPER(), because many |
62 * toupper() and tolower() implementations only work for ASCII. | |
7 | 63 */ |
64 #ifdef MSWIN | |
65 # define TOUPPER_LOC(c) toupper_tab[(c) & 255] | |
66 # define TOLOWER_LOC(c) tolower_tab[(c) & 255] | |
67 #else | |
68 # ifdef BROKEN_TOUPPER | |
69 # define TOUPPER_LOC(c) (islower(c) ? toupper(c) : (c)) | |
70 # define TOLOWER_LOC(c) (isupper(c) ? tolower(c) : (c)) | |
71 # else | |
72 # define TOUPPER_LOC toupper | |
73 # define TOLOWER_LOC tolower | |
74 # endif | |
75 #endif | |
76 | |
77 /* toupper() and tolower() for ASCII only and ignore the current locale. */ | |
78 #ifdef EBCDIC | |
79 # define TOUPPER_ASC(c) (islower(c) ? toupper(c) : (c)) | |
80 # define TOLOWER_ASC(c) (isupper(c) ? tolower(c) : (c)) | |
81 #else | |
82 # define TOUPPER_ASC(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) - ('a' - 'A')) | |
83 # define TOLOWER_ASC(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) + ('a' - 'A')) | |
84 #endif | |
85 | |
86 /* | |
87 * MB_ISLOWER() and MB_ISUPPER() are to be used on multi-byte characters. But | |
492 | 88 * don't use them for negative values! |
7 | 89 */ |
90 #ifdef FEAT_MBYTE | |
492 | 91 # define MB_ISLOWER(c) vim_islower(c) |
92 # define MB_ISUPPER(c) vim_isupper(c) | |
93 # define MB_TOLOWER(c) vim_tolower(c) | |
94 # define MB_TOUPPER(c) vim_toupper(c) | |
7 | 95 #else |
96 # define MB_ISLOWER(c) islower(c) | |
97 # define MB_ISUPPER(c) isupper(c) | |
98 # define MB_TOLOWER(c) TOLOWER_LOC(c) | |
99 # define MB_TOUPPER(c) TOUPPER_LOC(c) | |
100 #endif | |
101 | |
4857
84a8d1ba81c3
updated for version 7.3.1175
Bram Moolenaar <bram@vim.org>
parents:
4849
diff
changeset
|
102 /* Use our own isdigit() replacement, because on MS-Windows isdigit() returns |
84a8d1ba81c3
updated for version 7.3.1175
Bram Moolenaar <bram@vim.org>
parents:
4849
diff
changeset
|
103 * non-zero for superscript 1. Also avoids that isdigit() crashes for numbers |
84a8d1ba81c3
updated for version 7.3.1175
Bram Moolenaar <bram@vim.org>
parents:
4849
diff
changeset
|
104 * below 0 and above 255. */ |
84a8d1ba81c3
updated for version 7.3.1175
Bram Moolenaar <bram@vim.org>
parents:
4849
diff
changeset
|
105 #define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10) |
84a8d1ba81c3
updated for version 7.3.1175
Bram Moolenaar <bram@vim.org>
parents:
4849
diff
changeset
|
106 |
7 | 107 /* Like isalpha() but reject non-ASCII characters. Can't be used with a |
108 * special key (negative value). */ | |
109 #ifdef EBCDIC | |
110 # define ASCII_ISALPHA(c) isalpha(c) | |
111 # define ASCII_ISALNUM(c) isalnum(c) | |
112 # define ASCII_ISLOWER(c) islower(c) | |
113 # define ASCII_ISUPPER(c) isupper(c) | |
114 #else | |
4849
fc7f985df537
updated for version 7.3.1171
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
115 # define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26) |
fc7f985df537
updated for version 7.3.1171
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
116 # define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26) |
4857
84a8d1ba81c3
updated for version 7.3.1175
Bram Moolenaar <bram@vim.org>
parents:
4849
diff
changeset
|
117 # define ASCII_ISALPHA(c) (ASCII_ISUPPER(c) || ASCII_ISLOWER(c)) |
84a8d1ba81c3
updated for version 7.3.1175
Bram Moolenaar <bram@vim.org>
parents:
4849
diff
changeset
|
118 # define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c)) |
7 | 119 #endif |
120 | |
121 /* macro version of chartab(). | |
122 * Only works with values 0-255! | |
123 * Doesn't work for UTF-8 mode with chars >= 0x80. */ | |
124 #define CHARSIZE(c) (chartab[c] & CT_CELL_MASK) | |
125 | |
126 #ifdef FEAT_LANGMAP | |
127 /* | |
128 * Adjust chars in a language according to 'langmap' option. | |
1811 | 129 * NOTE that there is no noticeable overhead if 'langmap' is not set. |
130 * When set the overhead for characters < 256 is small. | |
7 | 131 * Don't apply 'langmap' if the character comes from the Stuff buffer. |
132 * The do-while is just to ignore a ';' after the macro. | |
133 */ | |
1811 | 134 # ifdef FEAT_MBYTE |
135 # define LANGMAP_ADJUST(c, condition) \ | |
136 do { \ | |
2330 | 137 if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0) \ |
1811 | 138 { \ |
139 if ((c) < 256) \ | |
140 c = langmap_mapchar[c]; \ | |
141 else \ | |
142 c = langmap_adjust_mb(c); \ | |
143 } \ | |
7 | 144 } while (0) |
1811 | 145 # else |
146 # define LANGMAP_ADJUST(c, condition) \ | |
147 do { \ | |
2330 | 148 if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \ |
149 c = langmap_mapchar[c]; \ | |
1811 | 150 } while (0) |
151 # endif | |
152 #else | |
153 # define LANGMAP_ADJUST(c, condition) /* nop */ | |
7 | 154 #endif |
155 | |
156 /* | |
157 * vim_isbreak() is used very often if 'linebreak' is set, use a macro to make | |
158 * it work fast. | |
159 */ | |
160 #define vim_isbreak(c) (breakat_flags[(char_u)(c)]) | |
161 | |
162 /* | |
163 * On VMS file names are different and require a translation. | |
164 * On the Mac open() has only two arguments. | |
165 */ | |
166 #ifdef VMS | |
167 # define mch_access(n, p) access(vms_fixfilename(n), (p)) | |
168 /* see mch_open() comment */ | |
169 # define mch_fopen(n, p) fopen(vms_fixfilename(n), (p)) | |
170 # define mch_fstat(n, p) fstat(vms_fixfilename(n), (p)) | |
171 /* VMS does not have lstat() */ | |
172 # define mch_stat(n, p) stat(vms_fixfilename(n), (p)) | |
173 #else | |
174 # ifndef WIN32 | |
175 # define mch_access(n, p) access((n), (p)) | |
176 # endif | |
177 # if !(defined(FEAT_MBYTE) && defined(WIN3264)) | |
178 # define mch_fopen(n, p) fopen((n), (p)) | |
179 # endif | |
180 # define mch_fstat(n, p) fstat((n), (p)) | |
181 # ifdef MSWIN /* has it's own mch_stat() function */ | |
182 # define mch_stat(n, p) vim_stat((n), (p)) | |
183 # else | |
184 # ifdef STAT_IGNORES_SLASH | |
185 /* On Solaris stat() accepts "file/" as if it was "file". Return -1 if | |
186 * the name ends in "/" and it's not a directory. */ | |
187 # define mch_stat(n, p) (illegal_slash(n) ? -1 : stat((n), (p))) | |
188 # else | |
189 # define mch_stat(n, p) stat((n), (p)) | |
190 # endif | |
191 # endif | |
192 #endif | |
193 | |
21 | 194 #ifdef HAVE_LSTAT |
195 # define mch_lstat(n, p) lstat((n), (p)) | |
196 #else | |
197 # define mch_lstat(n, p) mch_stat((n), (p)) | |
198 #endif | |
199 | |
7 | 200 #ifdef MACOS_CLASSIC |
201 /* MacOS classic doesn't support perm but MacOS X does. */ | |
202 # define mch_open(n, m, p) open((n), (m)) | |
203 #else | |
204 # ifdef VMS | |
205 /* | |
206 * It is possible to force some record format with: | |
207 * # define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p)), "rat=cr", "rfm=stmlf", "mrs=0") | |
1199 | 208 * but it is not recommended, because it can destroy indexes etc. |
7 | 209 */ |
210 # define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p)) | |
211 # else | |
212 # if !(defined(FEAT_MBYTE) && defined(WIN3264)) | |
213 # define mch_open(n, m, p) open((n), (m), (p)) | |
214 # endif | |
215 # endif | |
216 #endif | |
217 | |
218 /* mch_open_rw(): invoke mch_open() with third argument for user R/W. */ | |
219 #if defined(UNIX) || defined(VMS) /* open in rw------- mode */ | |
220 # define mch_open_rw(n, f) mch_open((n), (f), (mode_t)0600) | |
221 #else | |
222 # if defined(MSDOS) || defined(MSWIN) || defined(OS2) /* open read/write */ | |
223 # define mch_open_rw(n, f) mch_open((n), (f), S_IREAD | S_IWRITE) | |
224 # else | |
225 # define mch_open_rw(n, f) mch_open((n), (f), 0) | |
226 # endif | |
227 #endif | |
228 | |
229 #ifdef STARTUPTIME | |
1972 | 230 # define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); } |
7 | 231 #else |
232 # define TIME_MSG(s) | |
233 #endif | |
234 | |
235 #ifdef FEAT_VREPLACE | |
236 # define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG)) | |
237 #else | |
238 # define REPLACE_NORMAL(s) ((s) & REPLACE_FLAG) | |
239 #endif | |
240 | |
241 #ifdef FEAT_ARABIC | |
242 # define UTF_COMPOSINGLIKE(p1, p2) utf_composinglike((p1), (p2)) | |
243 #else | |
244 # define UTF_COMPOSINGLIKE(p1, p2) utf_iscomposing(utf_ptr2char(p2)) | |
245 #endif | |
246 | |
247 #ifdef FEAT_RIGHTLEFT | |
248 /* Whether to draw the vertical bar on the right side of the cell. */ | |
249 # define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & CMDLINE) || cmdmsg_rl)) | |
250 #endif | |
13 | 251 |
39 | 252 /* |
253 * mb_ptr_adv(): advance a pointer to the next character, taking care of | |
254 * multi-byte characters if needed. | |
255 * mb_ptr_back(): backup a pointer to the previous character, taking care of | |
256 * multi-byte characters if needed. | |
98 | 257 * MB_COPY_CHAR(f, t): copy one char from "f" to "t" and advance the pointers. |
456 | 258 * PTR2CHAR(): get character from pointer. |
39 | 259 */ |
260 #ifdef FEAT_MBYTE | |
3693 | 261 /* Get the length of the character p points to */ |
262 # define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1) | |
474 | 263 /* Advance multi-byte pointer, skip over composing chars. */ |
264 # define mb_ptr_adv(p) p += has_mbyte ? (*mb_ptr2len)(p) : 1 | |
265 /* Advance multi-byte pointer, do not skip over composing chars. */ | |
266 # define mb_cptr_adv(p) p += enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1 | |
267 /* Backup multi-byte pointer. */ | |
377 | 268 # define mb_ptr_back(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1 |
474 | 269 /* get length of multi-byte char, not including composing chars */ |
270 # define mb_cptr2len(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p)) | |
271 | |
98 | 272 # define MB_COPY_CHAR(f, t) if (has_mbyte) mb_copy_char(&f, &t); else *t++ = *f++ |
1883 | 273 # define MB_CHARLEN(p) (has_mbyte ? mb_charlen(p) : (int)STRLEN(p)) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
3693
diff
changeset
|
274 # define MB_CHAR2LEN(c) (has_mbyte ? mb_char2len(c) : 1) |
474 | 275 # define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p)) |
39 | 276 #else |
3693 | 277 # define MB_PTR2LEN(p) 1 |
456 | 278 # define mb_ptr_adv(p) ++p |
474 | 279 # define mb_cptr_adv(p) ++p |
456 | 280 # define mb_ptr_back(s, p) --p |
281 # define MB_COPY_CHAR(f, t) *t++ = *f++ | |
282 # define MB_CHARLEN(p) STRLEN(p) | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
3693
diff
changeset
|
283 # define MB_CHAR2LEN(c) 1 |
474 | 284 # define PTR2CHAR(p) ((int)*(p)) |
39 | 285 #endif |
961 | 286 |
287 #ifdef FEAT_AUTOCHDIR | |
288 # define DO_AUTOCHDIR if (p_acd) do_autochdir(); | |
289 #else | |
290 # define DO_AUTOCHDIR | |
291 #endif | |
2583 | 292 |
293 #if defined(FEAT_SCROLLBIND) && defined(FEAT_CURSORBIND) | |
294 # define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE | |
295 #else | |
296 # if defined(FEAT_SCROLLBIND) | |
297 # define RESET_BINDING(wp) (wp)->w_p_scb = FALSE | |
298 # else | |
299 # if defined(FEAT_CURSORBIND) | |
300 # define RESET_BINDING(wp) (wp)->w_p_crb = FALSE | |
301 # else | |
302 # define RESET_BINDING(wp) | |
303 # endif | |
304 # endif | |
305 #endif |