Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 11 | * |
| 12 | * Macros should be ALL_CAPS. An exception is for where a function is |
| 13 | * replaced and an argument is not used more than once. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 17 | * Position comparisons |
| 18 | */ |
Bram Moolenaar | 29ddebe | 2019-01-26 17:28:26 +0100 | [diff] [blame] | 19 | #define LT_POS(a, b) (((a).lnum != (b).lnum) \ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 20 | ? (a).lnum < (b).lnum \ |
| 21 | : (a).col != (b).col \ |
| 22 | ? (a).col < (b).col \ |
| 23 | : (a).coladd < (b).coladd) |
Bram Moolenaar | 29ddebe | 2019-01-26 17:28:26 +0100 | [diff] [blame] | 24 | #define LT_POSP(a, b) (((a)->lnum != (b)->lnum) \ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 25 | ? (a)->lnum < (b)->lnum \ |
| 26 | : (a)->col != (b)->col \ |
| 27 | ? (a)->col < (b)->col \ |
| 28 | : (a)->coladd < (b)->coladd) |
Bram Moolenaar | 29ddebe | 2019-01-26 17:28:26 +0100 | [diff] [blame] | 29 | #define EQUAL_POS(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col) && ((a).coladd == (b).coladd)) |
Bram Moolenaar | abab0b0 | 2019-03-30 18:47:01 +0100 | [diff] [blame] | 30 | #define CLEAR_POS(a) do {(a)->lnum = 0; (a)->col = 0; (a)->coladd = 0;} while (0) |
Bram Moolenaar | e8f5ec0 | 2020-06-01 17:28:35 +0200 | [diff] [blame] | 31 | #define EMPTY_POS(a) ((a).lnum == 0 && (a).col == 0 && (a).coladd == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 32 | |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 33 | #define LTOREQ_POS(a, b) (LT_POS(a, b) || EQUAL_POS(a, b)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | |
| 35 | /* |
Bram Moolenaar | 9c7e6dd | 2020-04-12 20:55:20 +0200 | [diff] [blame] | 36 | * VIM_ISWHITE() differs from isspace() because it doesn't include <CR> and |
| 37 | * <LF> and the like. |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 38 | */ |
Bram Moolenaar | 9c7e6dd | 2020-04-12 20:55:20 +0200 | [diff] [blame] | 39 | #define VIM_ISWHITE(x) ((x) == ' ' || (x) == '\t') |
| 40 | #define IS_WHITE_OR_NUL(x) ((x) == ' ' || (x) == '\t' || (x) == NUL) |
Christian Brabandt | 00cb247 | 2023-09-05 20:46:25 +0200 | [diff] [blame] | 41 | #define IS_WHITE_NL_OR_NUL(x) ((x) == ' ' || (x) == '\t' || (x) == '\n' || (x) == NUL) |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 42 | |
| 43 | /* |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 44 | * LINEEMPTY() - return TRUE if the line is empty |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 45 | */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 46 | #define LINEEMPTY(p) (*ml_get(p) == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | |
| 48 | /* |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 49 | * BUFEMPTY() - return TRUE if the current buffer is empty |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 50 | */ |
Bram Moolenaar | b5aedf3 | 2017-03-12 18:23:53 +0100 | [diff] [blame] | 51 | #define BUFEMPTY() (curbuf->b_ml.ml_line_count == 1 && *ml_get((linenr_T)1) == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 52 | |
Keith Thompson | 184f71c | 2024-01-04 21:19:04 +0100 | [diff] [blame] | 53 | // The is*() and to*() functions declared in <ctype.h> have |
| 54 | // undefined behavior for values other than EOF outside the range of |
| 55 | // unsigned char. If plain char is signed, a call with a negative |
| 56 | // value has undefined behavior. These macros cast the argument to |
| 57 | // unsigned char. (Most implementations behave more or less sanely |
| 58 | // with negative values, and most character values in practice are |
| 59 | // positive, but we want to avoid undefined behavior anyway.) |
| 60 | #define SAFE_isalnum(c) (isalnum ((unsigned char)(c))) |
| 61 | #define SAFE_isalpha(c) (isalpha ((unsigned char)(c))) |
| 62 | #define SAFE_isblank(c) (isblank ((unsigned char)(c))) |
| 63 | #define SAFE_iscntrl(c) (iscntrl ((unsigned char)(c))) |
| 64 | #define SAFE_isdigit(c) (isdigit ((unsigned char)(c))) |
| 65 | #define SAFE_isgraph(c) (isgraph ((unsigned char)(c))) |
| 66 | #define SAFE_islower(c) (islower ((unsigned char)(c))) |
| 67 | #define SAFE_isprint(c) (isprint ((unsigned char)(c))) |
| 68 | #define SAFE_ispunct(c) (ispunct ((unsigned char)(c))) |
| 69 | #define SAFE_isspace(c) (isspace ((unsigned char)(c))) |
| 70 | #define SAFE_isupper(c) (isupper ((unsigned char)(c))) |
| 71 | #define SAFE_isxdigit(c) (isxdigit((unsigned char)(c))) |
| 72 | #define SAFE_tolower(c) (tolower ((unsigned char)(c))) |
| 73 | #define SAFE_toupper(c) (toupper ((unsigned char)(c))) |
| 74 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 75 | /* |
| 76 | * toupper() and tolower() that use the current locale. |
Bram Moolenaar | deefb63 | 2007-08-15 18:41:34 +0000 | [diff] [blame] | 77 | * On some systems toupper()/tolower() only work on lower/uppercase |
| 78 | * characters, first use islower() or isupper() then. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | * Careful: Only call TOUPPER_LOC() and TOLOWER_LOC() with a character in the |
| 80 | * range 0 - 255. toupper()/tolower() on some systems can't handle others. |
Bram Moolenaar | deefb63 | 2007-08-15 18:41:34 +0000 | [diff] [blame] | 81 | * Note: It is often better to use MB_TOLOWER() and MB_TOUPPER(), because many |
| 82 | * toupper() and tolower() implementations only work for ASCII. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 83 | */ |
| 84 | #ifdef MSWIN |
| 85 | # define TOUPPER_LOC(c) toupper_tab[(c) & 255] |
| 86 | # define TOLOWER_LOC(c) tolower_tab[(c) & 255] |
| 87 | #else |
| 88 | # ifdef BROKEN_TOUPPER |
Keith Thompson | 184f71c | 2024-01-04 21:19:04 +0100 | [diff] [blame] | 89 | # define TOUPPER_LOC(c) (SAFE_islower(c) ? SAFE_toupper(c) : (c)) |
| 90 | # define TOLOWER_LOC(c) (SAFE_isupper(c) ? SAFE_tolower(c) : (c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 91 | # else |
Keith Thompson | 184f71c | 2024-01-04 21:19:04 +0100 | [diff] [blame] | 92 | # define TOUPPER_LOC SAFE_toupper |
| 93 | # define TOLOWER_LOC SAFE_tolower |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 94 | # endif |
| 95 | #endif |
| 96 | |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 97 | // toupper() and tolower() for ASCII only and ignore the current locale. |
Bram Moolenaar | 424bcae | 2022-01-31 14:59:41 +0000 | [diff] [blame] | 98 | #define TOUPPER_ASC(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) - ('a' - 'A')) |
| 99 | #define TOLOWER_ASC(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) + ('a' - 'A')) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 100 | |
| 101 | /* |
| 102 | * MB_ISLOWER() and MB_ISUPPER() are to be used on multi-byte characters. But |
Bram Moolenaar | 7862282 | 2005-08-23 21:00:13 +0000 | [diff] [blame] | 103 | * don't use them for negative values! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 104 | */ |
Bram Moolenaar | 264b74f | 2019-01-24 17:18:42 +0100 | [diff] [blame] | 105 | #define MB_ISLOWER(c) vim_islower(c) |
| 106 | #define MB_ISUPPER(c) vim_isupper(c) |
| 107 | #define MB_TOLOWER(c) vim_tolower(c) |
| 108 | #define MB_TOUPPER(c) vim_toupper(c) |
Bram Moolenaar | 59de417 | 2020-06-09 19:34:54 +0200 | [diff] [blame] | 109 | #define MB_CASEFOLD(c) (enc_utf8 ? utf_fold(c) : MB_TOLOWER(c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 110 | |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 111 | // Use our own isdigit() replacement, because on MS-Windows isdigit() returns |
| 112 | // non-zero for superscript 1. Also avoids that isdigit() crashes for numbers |
| 113 | // below 0 and above 255. |
Bram Moolenaar | 2d473ab | 2013-06-12 17:12:24 +0200 | [diff] [blame] | 114 | #define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10) |
| 115 | |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 116 | // Like isalpha() but reject non-ASCII characters. Can't be used with a |
| 117 | // special key (negative value). |
Bram Moolenaar | 424bcae | 2022-01-31 14:59:41 +0000 | [diff] [blame] | 118 | #define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26) |
| 119 | #define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26) |
| 120 | #define ASCII_ISALPHA(c) (ASCII_ISUPPER(c) || ASCII_ISLOWER(c)) |
| 121 | #define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 122 | |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 123 | // Returns empty string if it is NULL. |
Bram Moolenaar | 669cac0 | 2016-02-25 15:25:03 +0100 | [diff] [blame] | 124 | #define EMPTY_IF_NULL(x) ((x) ? (x) : (char_u *)"") |
Bram Moolenaar | 42a4512 | 2015-07-10 17:56:23 +0200 | [diff] [blame] | 125 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | #ifdef FEAT_LANGMAP |
| 127 | /* |
| 128 | * Adjust chars in a language according to 'langmap' option. |
Bram Moolenaar | 28e8d27 | 2009-02-21 19:28:48 +0000 | [diff] [blame] | 129 | * NOTE that there is no noticeable overhead if 'langmap' is not set. |
| 130 | * When set the overhead for characters < 256 is small. |
Bram Moolenaar | 4391cf9 | 2014-11-05 17:44:52 +0100 | [diff] [blame] | 131 | * Don't apply 'langmap' if the character comes from the Stuff buffer or from |
| 132 | * a mapping and the langnoremap option was set. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 133 | * The do-while is just to ignore a ';' after the macro. |
| 134 | */ |
Bram Moolenaar | 264b74f | 2019-01-24 17:18:42 +0100 | [diff] [blame] | 135 | # define LANGMAP_ADJUST(c, condition) \ |
Bram Moolenaar | 28e8d27 | 2009-02-21 19:28:48 +0000 | [diff] [blame] | 136 | do { \ |
Bram Moolenaar | 4391cf9 | 2014-11-05 17:44:52 +0100 | [diff] [blame] | 137 | if (*p_langmap \ |
| 138 | && (condition) \ |
Bram Moolenaar | 920694c | 2016-08-21 17:45:02 +0200 | [diff] [blame] | 139 | && (p_lrm || (!p_lrm && KeyTyped)) \ |
Bram Moolenaar | 4391cf9 | 2014-11-05 17:44:52 +0100 | [diff] [blame] | 140 | && !KeyStuffed \ |
| 141 | && (c) >= 0) \ |
Bram Moolenaar | 28e8d27 | 2009-02-21 19:28:48 +0000 | [diff] [blame] | 142 | { \ |
| 143 | if ((c) < 256) \ |
| 144 | c = langmap_mapchar[c]; \ |
| 145 | else \ |
| 146 | c = langmap_adjust_mb(c); \ |
| 147 | } \ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 148 | } while (0) |
Bram Moolenaar | 28e8d27 | 2009-02-21 19:28:48 +0000 | [diff] [blame] | 149 | #else |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 150 | # define LANGMAP_ADJUST(c, condition) // nop |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 151 | #endif |
| 152 | |
| 153 | /* |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 154 | * VIM_ISBREAK() is used very often if 'linebreak' is set, use a macro to make |
| 155 | * it work fast. Only works for single byte characters! |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 156 | */ |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 157 | #define VIM_ISBREAK(c) ((c) < 256 && breakat_flags[(char_u)(c)]) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 158 | |
| 159 | /* |
| 160 | * On VMS file names are different and require a translation. |
| 161 | * On the Mac open() has only two arguments. |
| 162 | */ |
| 163 | #ifdef VMS |
| 164 | # define mch_access(n, p) access(vms_fixfilename(n), (p)) |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 165 | // see mch_open() comment |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 166 | # define mch_fopen(n, p) fopen(vms_fixfilename(n), (p)) |
Bram Moolenaar | 467676d | 2020-12-30 13:14:45 +0100 | [diff] [blame] | 167 | # define mch_fstat(n, p) fstat((n), (p)) |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 168 | # undef HAVE_LSTAT // VMS does not have lstat() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 169 | # define mch_stat(n, p) stat(vms_fixfilename(n), (p)) |
| 170 | #else |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 171 | # ifndef MSWIN |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | # define mch_access(n, p) access((n), (p)) |
| 173 | # endif |
Bram Moolenaar | c753478 | 2020-08-05 12:10:50 +0200 | [diff] [blame] | 174 | |
K.Takata | c351dc1 | 2022-01-24 11:24:08 +0000 | [diff] [blame] | 175 | // Use 64-bit fstat function on MS-Windows. |
Bram Moolenaar | c753478 | 2020-08-05 12:10:50 +0200 | [diff] [blame] | 176 | // NOTE: This condition is the same as for the stat_T type. |
K.Takata | c351dc1 | 2022-01-24 11:24:08 +0000 | [diff] [blame] | 177 | # ifdef MSWIN |
Bram Moolenaar | c753478 | 2020-08-05 12:10:50 +0200 | [diff] [blame] | 178 | # define mch_fstat(n, p) _fstat64((n), (p)) |
| 179 | # else |
| 180 | # define mch_fstat(n, p) fstat((n), (p)) |
| 181 | # endif |
| 182 | |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 183 | # ifdef MSWIN // has its own mch_stat() function |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 184 | # define mch_stat(n, p) vim_stat((n), (p)) |
| 185 | # else |
| 186 | # ifdef STAT_IGNORES_SLASH |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 187 | # define mch_stat(n, p) vim_stat((n), (p)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 188 | # else |
| 189 | # define mch_stat(n, p) stat((n), (p)) |
| 190 | # endif |
| 191 | # endif |
| 192 | #endif |
| 193 | |
Bram Moolenaar | 269ec65 | 2004-07-29 08:43:53 +0000 | [diff] [blame] | 194 | #ifdef HAVE_LSTAT |
| 195 | # define mch_lstat(n, p) lstat((n), (p)) |
| 196 | #else |
LemonBoy | 23c5ebe | 2024-06-18 20:43:51 +0200 | [diff] [blame] | 197 | # ifdef MSWIN |
| 198 | # define mch_lstat(n, p) vim_lstat((n), (p)) |
| 199 | # else |
| 200 | # define mch_lstat(n, p) mch_stat((n), (p)) |
| 201 | # endif |
Bram Moolenaar | 269ec65 | 2004-07-29 08:43:53 +0000 | [diff] [blame] | 202 | #endif |
| 203 | |
Bram Moolenaar | d057301 | 2017-10-28 21:11:06 +0200 | [diff] [blame] | 204 | #ifdef VMS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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") |
Bram Moolenaar | ff1d0d4 | 2007-05-10 17:24:16 +0000 | [diff] [blame] | 208 | * but it is not recommended, because it can destroy indexes etc. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 209 | */ |
Bram Moolenaar | d057301 | 2017-10-28 21:11:06 +0200 | [diff] [blame] | 210 | # define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 211 | #endif |
| 212 | |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 213 | // mch_open_rw(): invoke mch_open() with third argument for user R/W. |
| 214 | #if defined(UNIX) || defined(VMS) // open in rw------- mode |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 215 | # define mch_open_rw(n, f) mch_open((n), (f), (mode_t)0600) |
| 216 | #else |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 217 | # if defined(MSWIN) // open read/write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 218 | # define mch_open_rw(n, f) mch_open((n), (f), S_IREAD | S_IWRITE) |
| 219 | # else |
| 220 | # define mch_open_rw(n, f) mch_open((n), (f), 0) |
| 221 | # endif |
| 222 | #endif |
| 223 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 224 | #ifdef STARTUPTIME |
Bram Moolenaar | 6f47002 | 2018-04-10 18:47:20 +0200 | [diff] [blame] | 225 | # define TIME_MSG(s) do { if (time_fd != NULL) time_msg(s, NULL); } while (0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 226 | #else |
Bram Moolenaar | 6f47002 | 2018-04-10 18:47:20 +0200 | [diff] [blame] | 227 | # define TIME_MSG(s) do { /**/ } while (0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 228 | #endif |
| 229 | |
Bram Moolenaar | 1f0bfe5 | 2018-07-29 16:09:22 +0200 | [diff] [blame] | 230 | #define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 231 | |
| 232 | #ifdef FEAT_ARABIC |
Bram Moolenaar | 6ed545e | 2022-05-09 20:09:23 +0100 | [diff] [blame] | 233 | # define ARABIC_CHAR(ch) (((ch) & 0xFF00) == 0x0600) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 234 | # define UTF_COMPOSINGLIKE(p1, p2) utf_composinglike((p1), (p2)) |
| 235 | #else |
| 236 | # define UTF_COMPOSINGLIKE(p1, p2) utf_iscomposing(utf_ptr2char(p2)) |
| 237 | #endif |
| 238 | |
| 239 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 240 | // Whether to draw the vertical bar on the right side of the cell. |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 241 | # define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & MODE_CMDLINE) || cmdmsg_rl)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 242 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 243 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 244 | /* |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 245 | * MB_PTR_ADV(): advance a pointer to the next character, taking care of |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 246 | * multi-byte characters if needed. |
Bram Moolenaar | 91acfff | 2017-03-12 19:22:36 +0100 | [diff] [blame] | 247 | * MB_PTR_BACK(): backup a pointer to the previous character, taking care of |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 248 | * multi-byte characters if needed. |
Bram Moolenaar | fd37168 | 2005-01-14 21:42:54 +0000 | [diff] [blame] | 249 | * MB_COPY_CHAR(f, t): copy one char from "f" to "t" and advance the pointers. |
Bram Moolenaar | 78984f5 | 2005-08-01 07:19:10 +0000 | [diff] [blame] | 250 | * PTR2CHAR(): get character from pointer. |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 251 | */ |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 252 | // Advance multi-byte pointer, skip over composing chars. |
Bram Moolenaar | 1614a14 | 2019-10-06 22:00:13 +0200 | [diff] [blame] | 253 | #define MB_PTR_ADV(p) p += (*mb_ptr2len)(p) |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 254 | // Advance multi-byte pointer, do not skip over composing chars. |
Bram Moolenaar | 1614a14 | 2019-10-06 22:00:13 +0200 | [diff] [blame] | 255 | #define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p) |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 256 | // Backup multi-byte pointer. Only use with "p" > "s" ! |
kylo252 | 9dac9b1 | 2022-03-27 20:05:17 +0100 | [diff] [blame] | 257 | #define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, (p) - 1) + 1) : 1 |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 258 | // get length of multi-byte char, not including composing chars |
Bram Moolenaar | 264b74f | 2019-01-24 17:18:42 +0100 | [diff] [blame] | 259 | #define MB_CPTR2LEN(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p)) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 260 | |
kylo252 | 9dac9b1 | 2022-03-27 20:05:17 +0100 | [diff] [blame] | 261 | #define MB_COPY_CHAR(f, t) do { if (has_mbyte) mb_copy_char(&(f), &(t)); else *(t)++ = *(f)++; } while (0) |
Bram Moolenaar | 264b74f | 2019-01-24 17:18:42 +0100 | [diff] [blame] | 262 | #define MB_CHARLEN(p) (has_mbyte ? mb_charlen(p) : (int)STRLEN(p)) |
| 263 | #define MB_CHAR2LEN(c) (has_mbyte ? mb_char2len(c) : 1) |
| 264 | #define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p)) |
Bram Moolenaar | c9471b1 | 2023-05-09 15:00:00 +0100 | [diff] [blame] | 265 | #define MB_CHAR2BYTES(c, b) do { if (has_mbyte) (b) += (*mb_char2bytes)((c), (b)); else *(b)++ = (c); } while (0) |
Bram Moolenaar | 498efdb | 2006-09-05 14:31:54 +0000 | [diff] [blame] | 266 | |
| 267 | #ifdef FEAT_AUTOCHDIR |
Bram Moolenaar | 6f47002 | 2018-04-10 18:47:20 +0200 | [diff] [blame] | 268 | # define DO_AUTOCHDIR do { if (p_acd) do_autochdir(); } while (0) |
Bram Moolenaar | 498efdb | 2006-09-05 14:31:54 +0000 | [diff] [blame] | 269 | #else |
Bram Moolenaar | 6f47002 | 2018-04-10 18:47:20 +0200 | [diff] [blame] | 270 | # define DO_AUTOCHDIR do { /**/ } while (0) |
Bram Moolenaar | 498efdb | 2006-09-05 14:31:54 +0000 | [diff] [blame] | 271 | #endif |
Bram Moolenaar | 3368ea2 | 2010-09-21 16:56:35 +0200 | [diff] [blame] | 272 | |
Bram Moolenaar | abab0b0 | 2019-03-30 18:47:01 +0100 | [diff] [blame] | 273 | #define RESET_BINDING(wp) do { (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE; \ |
| 274 | } while (0) |
Bram Moolenaar | 43335ea | 2015-09-09 20:59:37 +0200 | [diff] [blame] | 275 | |
| 276 | #ifdef FEAT_DIFF |
| 277 | # define PLINES_NOFILL(x) plines_nofill(x) |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 278 | # define PLINES_WIN_NOFILL(w, l, h) plines_win_nofill((w), (l), (h)) |
Bram Moolenaar | 43335ea | 2015-09-09 20:59:37 +0200 | [diff] [blame] | 279 | #else |
| 280 | # define PLINES_NOFILL(x) plines(x) |
Bram Moolenaar | db4d88c | 2022-12-31 15:13:22 +0000 | [diff] [blame] | 281 | # define PLINES_WIN_NOFILL(w, l, h) plines_win((w), (l), (h)) |
Bram Moolenaar | 43335ea | 2015-09-09 20:59:37 +0200 | [diff] [blame] | 282 | #endif |
Bram Moolenaar | 93c88e0 | 2015-09-15 14:12:05 +0200 | [diff] [blame] | 283 | |
Bram Moolenaar | 509ce2a | 2016-03-11 22:52:15 +0100 | [diff] [blame] | 284 | #if defined(FEAT_JOB_CHANNEL) || defined(FEAT_CLIENTSERVER) |
Bram Moolenaar | 93c88e0 | 2015-09-15 14:12:05 +0200 | [diff] [blame] | 285 | # define MESSAGE_QUEUE |
| 286 | #endif |
Bram Moolenaar | 136f29a | 2016-02-27 20:14:15 +0100 | [diff] [blame] | 287 | |
Bram Moolenaar | 96caa55 | 2022-09-17 21:57:43 +0100 | [diff] [blame] | 288 | #include <float.h> |
| 289 | #if defined(HAVE_MATH_H) |
| 290 | // for isnan() and isinf() |
| 291 | # include <math.h> |
| 292 | #endif |
| 293 | |
Bram Moolenaar | 73e28dc | 2022-09-17 21:08:33 +0100 | [diff] [blame] | 294 | #if defined(FEAT_EVAL) |
Bram Moolenaar | fefecb0 | 2016-02-27 21:27:20 +0100 | [diff] [blame] | 295 | # ifdef USING_FLOAT_STUFF |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 296 | # ifdef MSWIN |
Bram Moolenaar | fefecb0 | 2016-02-27 21:27:20 +0100 | [diff] [blame] | 297 | # ifndef isnan |
| 298 | # define isnan(x) _isnan(x) |
Bram Moolenaar | ebfec1c | 2023-01-22 21:14:53 +0000 | [diff] [blame] | 299 | static __inline int isinf(double x) |
| 300 | { return !_finite(x) && !_isnan(x); } |
Bram Moolenaar | fefecb0 | 2016-02-27 21:27:20 +0100 | [diff] [blame] | 301 | # endif |
Bram Moolenaar | 136f29a | 2016-02-27 20:14:15 +0100 | [diff] [blame] | 302 | # else |
Bram Moolenaar | fefecb0 | 2016-02-27 21:27:20 +0100 | [diff] [blame] | 303 | # ifndef HAVE_ISNAN |
Bram Moolenaar | ebfec1c | 2023-01-22 21:14:53 +0000 | [diff] [blame] | 304 | static inline int isnan(double x) |
| 305 | { return x != x; } |
Bram Moolenaar | fefecb0 | 2016-02-27 21:27:20 +0100 | [diff] [blame] | 306 | # endif |
| 307 | # ifndef HAVE_ISINF |
Bram Moolenaar | ebfec1c | 2023-01-22 21:14:53 +0000 | [diff] [blame] | 308 | static inline int isinf(double x) |
| 309 | { return !isnan(x) && isnan(x - x); } |
Bram Moolenaar | fefecb0 | 2016-02-27 21:27:20 +0100 | [diff] [blame] | 310 | # endif |
Bram Moolenaar | 136f29a | 2016-02-27 20:14:15 +0100 | [diff] [blame] | 311 | # endif |
Bram Moolenaar | fefecb0 | 2016-02-27 21:27:20 +0100 | [diff] [blame] | 312 | # if !defined(INFINITY) |
| 313 | # if defined(DBL_MAX) |
Bram Moolenaar | 98500fd | 2016-11-06 14:17:16 +0100 | [diff] [blame] | 314 | # ifdef VMS |
| 315 | # define INFINITY DBL_MAX |
| 316 | # else |
| 317 | # define INFINITY (DBL_MAX+DBL_MAX) |
| 318 | # endif |
Bram Moolenaar | fefecb0 | 2016-02-27 21:27:20 +0100 | [diff] [blame] | 319 | # else |
| 320 | # define INFINITY (1.0 / 0.0) |
| 321 | # endif |
| 322 | # endif |
| 323 | # if !defined(NAN) |
| 324 | # define NAN (INFINITY-INFINITY) |
| 325 | # endif |
Bram Moolenaar | 863e80b | 2017-06-04 20:30:00 +0200 | [diff] [blame] | 326 | # if !defined(DBL_EPSILON) |
| 327 | # define DBL_EPSILON 2.2204460492503131e-16 |
| 328 | # endif |
Bram Moolenaar | 136f29a | 2016-02-27 20:14:15 +0100 | [diff] [blame] | 329 | # endif |
| 330 | #endif |
Bram Moolenaar | 8402684 | 2016-07-17 20:37:43 +0200 | [diff] [blame] | 331 | |
Bram Moolenaar | 8a7d654 | 2020-01-26 15:56:19 +0100 | [diff] [blame] | 332 | #ifdef FEAT_EVAL |
| 333 | # define FUNCARG(fp, j) ((char_u **)(fp->uf_args.ga_data))[j] |
| 334 | #endif |
| 335 | |
Bram Moolenaar | 8402684 | 2016-07-17 20:37:43 +0200 | [diff] [blame] | 336 | /* |
| 337 | * In a hashtab item "hi_key" points to "di_key" in a dictitem. |
| 338 | * This avoids adding a pointer to the hashtab item. |
| 339 | * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer. |
| 340 | * HIKEY2DI() converts a hashitem key pointer to a dictitem pointer. |
| 341 | * HI2DI() converts a hashitem pointer to a dictitem pointer. |
| 342 | */ |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 343 | #define DI2HIKEY(di) ((di)->di_key) |
kylo252 | 9dac9b1 | 2022-03-27 20:05:17 +0100 | [diff] [blame] | 344 | #define HIKEY2DI(p) ((dictitem_T *)((p) - offsetof(dictitem_T, di_key))) |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 345 | #define HI2DI(hi) HIKEY2DI((hi)->hi_key) |
| 346 | |
| 347 | /* |
| 348 | * Flush control functions. |
| 349 | */ |
| 350 | #ifdef FEAT_GUI |
| 351 | # define mch_enable_flush() gui_enable_flush() |
| 352 | # define mch_disable_flush() gui_disable_flush() |
| 353 | #else |
| 354 | # define mch_enable_flush() |
| 355 | # define mch_disable_flush() |
| 356 | #endif |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 357 | |
| 358 | /* |
| 359 | * Like vim_free(), and also set the pointer to NULL. |
| 360 | */ |
| 361 | #define VIM_CLEAR(p) \ |
| 362 | do { \ |
Hirohito Higashi | e4e0a24 | 2025-03-19 20:25:21 +0100 | [diff] [blame] | 363 | vim_free(p); \ |
| 364 | (p) = NULL; \ |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 365 | } while (0) |
Bram Moolenaar | ac9fb18 | 2019-04-27 13:04:13 +0200 | [diff] [blame] | 366 | |
John Marriott | 79f6ffd | 2024-10-31 10:06:54 +0100 | [diff] [blame] | 367 | /* |
| 368 | * Free a string and set it's pointer to NULL and length to 0 |
| 369 | */ |
| 370 | #define VIM_CLEAR_STRING(s) \ |
| 371 | do { \ |
| 372 | VIM_CLEAR(s.string); \ |
| 373 | s.length = 0; \ |
| 374 | } while (0) |
| 375 | |
Bram Moolenaar | 9bf703d | 2019-11-30 19:44:38 +0100 | [diff] [blame] | 376 | // Whether a command index indicates a user command. |
Bram Moolenaar | ac9fb18 | 2019-04-27 13:04:13 +0200 | [diff] [blame] | 377 | #define IS_USER_CMDIDX(idx) ((int)(idx) < 0) |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 378 | |
Bram Moolenaar | 8cdbd5b | 2019-06-16 15:50:45 +0200 | [diff] [blame] | 379 | // Give an error in curwin is a popup window and evaluate to TRUE. |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 380 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 381 | # define WIN_IS_POPUP(wp) ((wp)->w_popup_flags != 0) |
Bram Moolenaar | 3c01c4a | 2020-02-01 23:04:24 +0100 | [diff] [blame] | 382 | # define ERROR_IF_POPUP_WINDOW error_if_popup_window(FALSE) |
| 383 | # define ERROR_IF_ANY_POPUP_WINDOW error_if_popup_window(TRUE) |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 384 | #else |
Bram Moolenaar | e52e0c8 | 2020-02-28 22:20:10 +0100 | [diff] [blame] | 385 | # define WIN_IS_POPUP(wp) 0 |
Bram Moolenaar | 8cdbd5b | 2019-06-16 15:50:45 +0200 | [diff] [blame] | 386 | # define ERROR_IF_POPUP_WINDOW 0 |
Bram Moolenaar | 3c01c4a | 2020-02-01 23:04:24 +0100 | [diff] [blame] | 387 | # define ERROR_IF_ANY_POPUP_WINDOW 0 |
Bram Moolenaar | 284d1c2 | 2020-02-01 22:39:32 +0100 | [diff] [blame] | 388 | #endif |
| 389 | #if defined(FEAT_PROP_POPUP) && defined(FEAT_TERMINAL) |
| 390 | # define ERROR_IF_TERM_POPUP_WINDOW error_if_term_popup_window() |
| 391 | #else |
Bram Moolenaar | 219c7d0 | 2020-02-01 21:57:29 +0100 | [diff] [blame] | 392 | # define ERROR_IF_TERM_POPUP_WINDOW 0 |
Bram Moolenaar | 815b76b | 2019-06-01 14:15:52 +0200 | [diff] [blame] | 393 | #endif |
Bram Moolenaar | e31ee86 | 2020-01-07 20:59:34 +0100 | [diff] [blame] | 394 | |
| 395 | |
| 396 | #ifdef ABORT_ON_INTERNAL_ERROR |
ichizok | 7e5fe38 | 2023-04-15 13:17:50 +0100 | [diff] [blame] | 397 | # define ESTACK_CHECK_DECLARATION int estack_len_before |
| 398 | # define ESTACK_CHECK_SETUP do { estack_len_before = exestack.ga_len; } while (0) |
| 399 | # define ESTACK_CHECK_NOW \ |
| 400 | do { \ |
| 401 | if (estack_len_before != exestack.ga_len) \ |
| 402 | siemsg("Exestack length expected: %d, actual: %d", estack_len_before, exestack.ga_len); \ |
| 403 | } while (0) |
| 404 | # define CHECK_CURBUF \ |
| 405 | do { \ |
| 406 | if (curwin != NULL && curwin->w_buffer != curbuf) \ |
| 407 | iemsg("curbuf != curwin->w_buffer"); \ |
| 408 | } while (0) |
Bram Moolenaar | e31ee86 | 2020-01-07 20:59:34 +0100 | [diff] [blame] | 409 | #else |
ichizok | 7e5fe38 | 2023-04-15 13:17:50 +0100 | [diff] [blame] | 410 | # define ESTACK_CHECK_DECLARATION do { /**/ } while (0) |
| 411 | # define ESTACK_CHECK_SETUP do { /**/ } while (0) |
| 412 | # define ESTACK_CHECK_NOW do { /**/ } while (0) |
| 413 | # define CHECK_CURBUF do { /**/ } while (0) |
Bram Moolenaar | e31ee86 | 2020-01-07 20:59:34 +0100 | [diff] [blame] | 414 | #endif |
Bram Moolenaar | 7e9f351 | 2020-05-13 22:44:22 +0200 | [diff] [blame] | 415 | |
| 416 | // Inline the condition for performance. |
ichizok | 7e5fe38 | 2023-04-15 13:17:50 +0100 | [diff] [blame] | 417 | #define CHECK_LIST_MATERIALIZE(l) \ |
| 418 | do { \ |
| 419 | if ((l)->lv_first == &range_list_item) \ |
| 420 | range_list_materialize(l); \ |
| 421 | } while (0) |
Bram Moolenaar | 7e9f351 | 2020-05-13 22:44:22 +0200 | [diff] [blame] | 422 | |
Bram Moolenaar | 3557816 | 2021-08-02 19:10:38 +0200 | [diff] [blame] | 423 | // Inlined version of ga_grow() with optimized condition that it fails. |
kylo252 | 9dac9b1 | 2022-03-27 20:05:17 +0100 | [diff] [blame] | 424 | #define GA_GROW_FAILS(gap, n) unlikely((((gap)->ga_maxlen - (gap)->ga_len < (n)) ? ga_grow_inner((gap), (n)) : OK) == FAIL) |
Bram Moolenaar | 3557816 | 2021-08-02 19:10:38 +0200 | [diff] [blame] | 425 | // Inlined version of ga_grow() with optimized condition that it succeeds. |
kylo252 | 9dac9b1 | 2022-03-27 20:05:17 +0100 | [diff] [blame] | 426 | #define GA_GROW_OK(gap, n) likely((((gap)->ga_maxlen - (gap)->ga_len < (n)) ? ga_grow_inner((gap), (n)) : OK) == OK) |
Bram Moolenaar | 4fa1175 | 2021-03-03 13:26:02 +0100 | [diff] [blame] | 427 | |
| 428 | #ifndef MIN |
| 429 | # define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 430 | #endif |
| 431 | #ifndef MAX |
| 432 | # define MAX(a, b) ((a) > (b) ? (a) : (b)) |
| 433 | #endif |
K.Takata | eeec254 | 2021-06-02 13:28:16 +0200 | [diff] [blame] | 434 | |
| 435 | // Length of the array. |
| 436 | #define ARRAY_LENGTH(a) (sizeof(a) / sizeof((a)[0])) |
Yegappan Lakshmanan | 14113fd | 2023-03-07 17:13:51 +0000 | [diff] [blame] | 437 | |
| 438 | #ifdef FEAT_MENU |
| 439 | #define FOR_ALL_MENUS(m) \ |
| 440 | for ((m) = root_menu; (m) != NULL; (m) = (m)->next) |
| 441 | #define FOR_ALL_CHILD_MENUS(p, c) \ |
| 442 | for ((c) = (p)->children; (c) != NULL; (c) = (c)->next) |
| 443 | #endif |
| 444 | |
| 445 | #define FOR_ALL_WINDOWS(wp) \ |
| 446 | for ((wp) = firstwin; (wp) != NULL; (wp) = (wp)->w_next) |
| 447 | #define FOR_ALL_FRAMES(frp, first_frame) \ |
| 448 | for ((frp) = first_frame; (frp) != NULL; (frp) = (frp)->fr_next) |
| 449 | #define FOR_ALL_TABPAGES(tp) \ |
| 450 | for ((tp) = first_tabpage; (tp) != NULL; (tp) = (tp)->tp_next) |
| 451 | #define FOR_ALL_WINDOWS_IN_TAB(tp, wp) \ |
| 452 | for ((wp) = ((tp) == NULL || (tp) == curtab) \ |
| 453 | ? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next) |
| 454 | /* |
| 455 | * When using this macro "break" only breaks out of the inner loop. Use "goto" |
| 456 | * to break out of the tabpage loop. |
| 457 | */ |
| 458 | #define FOR_ALL_TAB_WINDOWS(tp, wp) \ |
| 459 | for ((tp) = first_tabpage; (tp) != NULL; (tp) = (tp)->tp_next) \ |
| 460 | for ((wp) = ((tp) == curtab) \ |
| 461 | ? firstwin : (tp)->tp_firstwin; (wp); (wp) = (wp)->w_next) |
| 462 | |
| 463 | #define FOR_ALL_POPUPWINS(wp) \ |
| 464 | for ((wp) = first_popupwin; (wp) != NULL; (wp) = (wp)->w_next) |
| 465 | #define FOR_ALL_POPUPWINS_IN_TAB(tp, wp) \ |
| 466 | for ((wp) = (tp)->tp_first_popupwin; (wp) != NULL; (wp) = (wp)->w_next) |
| 467 | |
| 468 | #define FOR_ALL_BUFFERS(buf) \ |
| 469 | for ((buf) = firstbuf; (buf) != NULL; (buf) = (buf)->b_next) |
| 470 | |
| 471 | #define FOR_ALL_BUF_WININFO(buf, wip) \ |
| 472 | for ((wip) = (buf)->b_wininfo; (wip) != NULL; (wip) = (wip)->wi_next) |
| 473 | |
| 474 | // Iterate through all the signs placed in a buffer |
| 475 | #define FOR_ALL_SIGNS_IN_BUF(buf, sign) \ |
| 476 | for ((sign) = (buf)->b_signlist; (sign) != NULL; (sign) = (sign)->se_next) |
| 477 | |
| 478 | #ifdef FEAT_SPELL |
| 479 | #define FOR_ALL_SPELL_LANGS(slang) \ |
| 480 | for ((slang) = first_lang; (slang) != NULL; (slang) = (slang)->sl_next) |
| 481 | #endif |
| 482 | |
| 483 | // Iterate over all the items in a List |
| 484 | #define FOR_ALL_LIST_ITEMS(l, li) \ |
| 485 | for ((li) = (l) == NULL ? NULL : (l)->lv_first; (li) != NULL; (li) = (li)->li_next) |
| 486 | |
| 487 | // Iterate over all the items in a hash table |
| 488 | #define FOR_ALL_HASHTAB_ITEMS(ht, hi, todo) \ |
| 489 | for ((hi) = (ht)->ht_array; (todo) > 0; ++(hi)) |
Yegappan Lakshmanan | 9cb865e | 2025-03-23 16:42:16 +0100 | [diff] [blame] | 490 | |
| 491 | #define TUPLE_LEN(t) (t->tv_items.ga_len) |
| 492 | #define TUPLE_ITEM(t, i) \ |
| 493 | (((typval_T *)t->tv_items.ga_data) + i) |