| 1 | #ifndef NVIM_VIM_H |
| 2 | #define NVIM_VIM_H |
| 3 | |
| 4 | #include "nvim/types.h" |
| 5 | #include "nvim/pos.h" // for linenr_T, MAXCOL, etc... |
| 6 | |
| 7 | // Some defines from the old feature.h |
| 8 | #define SESSION_FILE "Session.vim" |
| 9 | #define MAX_MSG_HIST_LEN 200 |
| 10 | #define SYS_OPTWIN_FILE "$VIMRUNTIME/optwin.vim" |
| 11 | #define RUNTIME_DIRNAME "runtime" |
| 12 | |
| 13 | |
| 14 | #include "auto/config.h" |
| 15 | #define HAVE_PATHDEF |
| 16 | |
| 17 | // Check if configure correctly managed to find sizeof(int). If this failed, |
| 18 | // it becomes zero. This is likely a problem of not being able to run the |
| 19 | // test program. Other items from configure may also be wrong then! |
| 20 | #if (SIZEOF_INT == 0) |
| 21 | # error Configure did not run properly. |
| 22 | #endif |
| 23 | |
| 24 | #include "nvim/os/os_defs.h" // bring lots of system header files |
| 25 | |
| 26 | /// length of a buffer to store a number in ASCII (64 bits binary + NUL) |
| 27 | enum { NUMBUFLEN = 65 }; |
| 28 | |
| 29 | #define MAX_TYPENR 65535 |
| 30 | |
| 31 | #define ROOT_UID 0 |
| 32 | |
| 33 | #include "nvim/keymap.h" |
| 34 | #include "nvim/macros.h" |
| 35 | |
| 36 | #include "nvim/gettext.h" |
| 37 | |
| 38 | // special attribute addition: Put message in history |
| 39 | #define MSG_HIST 0x1000 |
| 40 | |
| 41 | |
| 42 | // values for State |
| 43 | // |
| 44 | // The lower bits up to 0x20 are used to distinguish normal/visual/op_pending |
| 45 | // and cmdline/insert+replace mode. This is used for mapping. If none of |
| 46 | // these bits are set, no mapping is done. |
| 47 | // The upper bits are used to distinguish between other states. |
| 48 | |
| 49 | #define NORMAL 0x01 // Normal mode, command expected |
| 50 | #define VISUAL 0x02 // Visual mode - use get_real_state() |
| 51 | #define OP_PENDING 0x04 // Normal mode, operator is pending - use |
| 52 | // get_real_state() |
| 53 | #define CMDLINE 0x08 // Editing command line |
| 54 | #define INSERT 0x10 // Insert mode |
| 55 | #define LANGMAP 0x20 // Language mapping, can be combined with |
| 56 | // INSERT and CMDLINE |
| 57 | |
| 58 | #define REPLACE_FLAG 0x40 // Replace mode flag |
| 59 | #define REPLACE (REPLACE_FLAG + INSERT) |
| 60 | # define VREPLACE_FLAG 0x80 // Virtual-replace mode flag |
| 61 | # define VREPLACE (REPLACE_FLAG + VREPLACE_FLAG + INSERT) |
| 62 | #define LREPLACE (REPLACE_FLAG + LANGMAP) |
| 63 | |
| 64 | #define NORMAL_BUSY (0x100 + NORMAL) // Normal mode, busy with a command |
| 65 | #define HITRETURN (0x200 + NORMAL) // waiting for return or command |
| 66 | #define ASKMORE 0x300 // Asking if you want --more-- |
| 67 | #define SETWSIZE 0x400 // window size has changed |
| 68 | #define ABBREV 0x500 // abbreviation instead of mapping |
| 69 | #define EXTERNCMD 0x600 // executing an external command |
| 70 | #define SHOWMATCH (0x700 + INSERT) // show matching paren |
| 71 | #define CONFIRM 0x800 // ":confirm" prompt |
| 72 | #define SELECTMODE 0x1000 // Select mode, only for mappings |
| 73 | #define TERM_FOCUS 0x2000 // Terminal focus mode |
| 74 | #define CMDPREVIEW 0x4000 // Showing 'inccommand' command "live" preview. |
| 75 | |
| 76 | // all mode bits used for mapping |
| 77 | #define MAP_ALL_MODES (0x3f | SELECTMODE | TERM_FOCUS) |
| 78 | |
| 79 | /// Directions. |
| 80 | typedef enum { |
| 81 | kDirectionNotSet = 0, |
| 82 | FORWARD = 1, |
| 83 | BACKWARD = (-1), |
| 84 | FORWARD_FILE = 3, |
| 85 | BACKWARD_FILE = (-3), |
| 86 | } Direction; |
| 87 | |
| 88 | // return values for functions |
| 89 | #if !(defined(OK) && (OK == 1)) |
| 90 | // OK already defined to 1 in MacOS X curses, skip this |
| 91 | # define OK 1 |
| 92 | #endif |
| 93 | #define FAIL 0 |
| 94 | #define NOTDONE 2 // not OK or FAIL but skipped |
| 95 | |
| 96 | // Type values for type(). |
| 97 | #define VAR_TYPE_NUMBER 0 |
| 98 | #define VAR_TYPE_STRING 1 |
| 99 | #define VAR_TYPE_FUNC 2 |
| 100 | #define VAR_TYPE_LIST 3 |
| 101 | #define VAR_TYPE_DICT 4 |
| 102 | #define VAR_TYPE_FLOAT 5 |
| 103 | #define VAR_TYPE_BOOL 6 |
| 104 | |
| 105 | |
| 106 | // values for xp_context when doing command line completion |
| 107 | |
| 108 | enum { |
| 109 | EXPAND_UNSUCCESSFUL = -2, |
| 110 | EXPAND_OK = -1, |
| 111 | EXPAND_NOTHING = 0, |
| 112 | EXPAND_COMMANDS, |
| 113 | EXPAND_FILES, |
| 114 | EXPAND_DIRECTORIES, |
| 115 | EXPAND_SETTINGS, |
| 116 | EXPAND_BOOL_SETTINGS, |
| 117 | EXPAND_TAGS, |
| 118 | EXPAND_OLD_SETTING, |
| 119 | EXPAND_HELP, |
| 120 | EXPAND_BUFFERS, |
| 121 | EXPAND_EVENTS, |
| 122 | EXPAND_MENUS, |
| 123 | EXPAND_SYNTAX, |
| 124 | EXPAND_HIGHLIGHT, |
| 125 | EXPAND_AUGROUP, |
| 126 | EXPAND_USER_VARS, |
| 127 | EXPAND_MAPPINGS, |
| 128 | EXPAND_TAGS_LISTFILES, |
| 129 | EXPAND_FUNCTIONS, |
| 130 | EXPAND_USER_FUNC, |
| 131 | EXPAND_EXPRESSION, |
| 132 | EXPAND_MENUNAMES, |
| 133 | EXPAND_USER_COMMANDS, |
| 134 | EXPAND_USER_CMD_FLAGS, |
| 135 | EXPAND_USER_NARGS, |
| 136 | EXPAND_USER_COMPLETE, |
| 137 | EXPAND_ENV_VARS, |
| 138 | EXPAND_LANGUAGE, |
| 139 | EXPAND_COLORS, |
| 140 | EXPAND_COMPILER, |
| 141 | EXPAND_USER_DEFINED, |
| 142 | EXPAND_USER_LIST, |
| 143 | EXPAND_SHELLCMD, |
| 144 | EXPAND_CSCOPE, |
| 145 | EXPAND_SIGN, |
| 146 | EXPAND_PROFILE, |
| 147 | EXPAND_BEHAVE, |
| 148 | EXPAND_FILETYPE, |
| 149 | EXPAND_FILES_IN_PATH, |
| 150 | EXPAND_OWNSYNTAX, |
| 151 | EXPAND_LOCALES, |
| 152 | EXPAND_HISTORY, |
| 153 | EXPAND_USER, |
| 154 | EXPAND_SYNTIME, |
| 155 | EXPAND_USER_ADDR_TYPE, |
| 156 | EXPAND_PACKADD, |
| 157 | EXPAND_MESSAGES, |
| 158 | EXPAND_MAPCLEAR, |
| 159 | EXPAND_ARGLIST, |
| 160 | EXPAND_CHECKHEALTH, |
| 161 | }; |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | // Minimal size for block 0 of a swap file. |
| 167 | // NOTE: This depends on size of struct block0! It's not done with a sizeof(), |
| 168 | // because struct block0 is defined in memline.c (Sorry). |
| 169 | // The maximal block size is arbitrary. |
| 170 | |
| 171 | #define MIN_SWAP_PAGE_SIZE 1048 |
| 172 | #define MAX_SWAP_PAGE_SIZE 50000 |
| 173 | |
| 174 | |
| 175 | |
| 176 | // Boolean constants |
| 177 | |
| 178 | #ifndef TRUE |
| 179 | # define FALSE 0 // note: this is an int, not a long! |
| 180 | # define TRUE 1 |
| 181 | #endif |
| 182 | |
| 183 | #define MAYBE 2 // sometimes used for a variant on TRUE |
| 184 | |
| 185 | #define STATUS_HEIGHT 1 // height of a status line under a window |
| 186 | #define QF_WINHEIGHT 10 // default height for quickfix window |
| 187 | |
| 188 | |
| 189 | // Buffer sizes |
| 190 | |
| 191 | #ifndef CMDBUFFSIZE |
| 192 | # define CMDBUFFSIZE 256 // size of the command processing buffer |
| 193 | #endif |
| 194 | |
| 195 | #define LSIZE 512 // max. size of a line in the tags file |
| 196 | |
| 197 | #define DIALOG_MSG_SIZE 1000 // buffer size for dialog_msg() |
| 198 | |
| 199 | enum { FOLD_TEXT_LEN = 51 }; //!< buffer size for get_foldtext() |
| 200 | |
| 201 | |
| 202 | // Maximum length of key sequence to be mapped. |
| 203 | // Must be able to hold an Amiga resize report. |
| 204 | |
| 205 | #define MAXMAPLEN 50 |
| 206 | |
| 207 | // Size in bytes of the hash used in the undo file. |
| 208 | #define UNDO_HASH_SIZE 32 |
| 209 | |
| 210 | |
| 211 | // defines to avoid typecasts from (char_u *) to (char *) and back |
| 212 | // (vim_strchr() is now in strings.c) |
| 213 | |
| 214 | #define STRLEN(s) strlen((char *)(s)) |
| 215 | #define STRCPY(d, s) strcpy((char *)(d), (char *)(s)) |
| 216 | #define STRNCPY(d, s, n) strncpy((char *)(d), (char *)(s), (size_t)(n)) |
| 217 | #define STRLCPY(d, s, n) xstrlcpy((char *)(d), (char *)(s), (size_t)(n)) |
| 218 | #define STRCMP(d, s) strcmp((char *)(d), (char *)(s)) |
| 219 | #define STRNCMP(d, s, n) strncmp((char *)(d), (char *)(s), (size_t)(n)) |
| 220 | #ifdef HAVE_STRCASECMP |
| 221 | # define STRICMP(d, s) strcasecmp((char *)(d), (char *)(s)) |
| 222 | #else |
| 223 | # ifdef HAVE_STRICMP |
| 224 | # define STRICMP(d, s) stricmp((char *)(d), (char *)(s)) |
| 225 | # else |
| 226 | # define STRICMP(d, s) vim_stricmp((char *)(d), (char *)(s)) |
| 227 | # endif |
| 228 | #endif |
| 229 | |
| 230 | // Like strcpy() but allows overlapped source and destination. |
| 231 | #define STRMOVE(d, s) memmove((d), (s), STRLEN(s) + 1) |
| 232 | |
| 233 | #ifdef HAVE_STRNCASECMP |
| 234 | # define STRNICMP(d, s, n) strncasecmp((char *)(d), (char *)(s), (size_t)(n)) |
| 235 | #else |
| 236 | # ifdef HAVE_STRNICMP |
| 237 | # define STRNICMP(d, s, n) strnicmp((char *)(d), (char *)(s), (size_t)(n)) |
| 238 | # else |
| 239 | # define STRNICMP(d, s, n) vim_strnicmp((char *)(d), (char *)(s), (size_t)(n)) |
| 240 | # endif |
| 241 | #endif |
| 242 | |
| 243 | #define STRRCHR(s, c) (char_u *)strrchr((const char *)(s), (c)) |
| 244 | |
| 245 | #define STRCAT(d, s) strcat((char *)(d), (char *)(s)) |
| 246 | #define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n)) |
| 247 | #define STRLCAT(d, s, n) xstrlcat((char *)(d), (char *)(s), (size_t)(n)) |
| 248 | |
| 249 | # define vim_strpbrk(s, cs) (char_u *)strpbrk((char *)(s), (char *)(cs)) |
| 250 | |
| 251 | #include "nvim/message.h" |
| 252 | |
| 253 | // Prefer using emsgf(), because perror() may send the output to the wrong |
| 254 | // destination and mess up the screen. |
| 255 | #define PERROR(msg) (void) emsgf("%s: %s", msg, strerror(errno)) |
| 256 | |
| 257 | #define SHOWCMD_COLS 10 // columns needed by shown command |
| 258 | #define STL_MAX_ITEM 80 // max nr of %<flag> in statusline |
| 259 | |
| 260 | /// Compare file names |
| 261 | /// |
| 262 | /// On some systems case in a file name does not matter, on others it does. |
| 263 | /// |
| 264 | /// @note Does not account for maximum name lengths and things like "../dir", |
| 265 | /// thus it is not 100% accurate. OS may also use different algorythm for |
| 266 | /// case-insensitive comparison. |
| 267 | /// |
| 268 | /// @param[in] x First file name to compare. |
| 269 | /// @param[in] y Second file name to compare. |
| 270 | /// |
| 271 | /// @return 0 for equal file names, non-zero otherwise. |
| 272 | #define fnamecmp(x, y) path_fnamecmp((const char *)(x), (const char *)(y)) |
| 273 | #define fnamencmp(x, y, n) path_fnamencmp((const char *)(x), \ |
| 274 | (const char *)(y), \ |
| 275 | (size_t)(n)) |
| 276 | |
| 277 | |
| 278 | // Enums need a typecast to be used as array index (for Ultrix). |
| 279 | #define HL_ATTR(n) highlight_attr[(int)(n)] |
| 280 | |
| 281 | /// Maximum number of bytes in a multi-byte character. It can be one 32-bit |
| 282 | /// character of up to 6 bytes, or one 16-bit character of up to three bytes |
| 283 | /// plus six following composing characters of three bytes each. |
| 284 | #define MB_MAXBYTES 21 |
| 285 | |
| 286 | // This has to go after the include of proto.h, as proto/gui.pro declares |
| 287 | // functions of these names. The declarations would break if the defines had |
| 288 | // been seen at that stage. But it must be before globals.h, where error_ga |
| 289 | // is declared. |
| 290 | #ifndef WIN32 |
| 291 | # define mch_errmsg(str) fprintf(stderr, "%s", (str)) |
| 292 | # define mch_msg(str) printf("%s", (str)) |
| 293 | #endif |
| 294 | |
| 295 | #include "nvim/globals.h" // global variables and messages |
| 296 | #include "nvim/buffer_defs.h" // buffer and windows |
| 297 | #include "nvim/ex_cmds_defs.h" // Ex command defines |
| 298 | |
| 299 | // Used for flags in do_in_path() |
| 300 | #define DIP_ALL 0x01 // all matches, not just the first one |
| 301 | #define DIP_DIR 0x02 // find directories instead of files |
| 302 | #define DIP_ERR 0x04 // give an error message when none found |
| 303 | #define DIP_START 0x08 // also use "start" directory in 'packpath' |
| 304 | #define DIP_OPT 0x10 // also use "opt" directory in 'packpath' |
| 305 | #define DIP_NORTP 0x20 // do not use 'runtimepath' |
| 306 | #define DIP_NOAFTER 0x40 // skip "after" directories |
| 307 | #define DIP_AFTER 0x80 // only use "after" directories |
| 308 | |
| 309 | // Lowest number used for window ID. Cannot have this many windows per tab. |
| 310 | #define LOWEST_WIN_ID 1000 |
| 311 | |
| 312 | // BSD is supposed to cover FreeBSD and similar systems. |
| 313 | #if (defined(BSD) || defined(__FreeBSD_kernel__)) && defined(S_ISCHR) |
| 314 | # define OPEN_CHR_FILES |
| 315 | #endif |
| 316 | |
| 317 | // Replacement for nchar used by nv_replace(). |
| 318 | #define REPLACE_CR_NCHAR -1 |
| 319 | #define REPLACE_NL_NCHAR -2 |
| 320 | |
| 321 | #endif // NVIM_VIM_H |
| 322 | |