#define pchar(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
#ifdef FEAT_VIRTUALEDIT
# define lt(a, b) (((a).lnum != (b).lnum) \
? (a).lnum < (b).lnum \
: (a).col != (b).col \
? (a).col < (b).col \
: (a).coladd < (b).coladd)
# define ltp(a, b) (((a)->lnum != (b)->lnum) \
? (a)->lnum < (b)->lnum \
: (a)->col != (b)->col \
? (a)->col < (b)->col \
: (a)->coladd < (b)->coladd)
# define equalpos(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col) && ((a).coladd == (b).coladd))
# define clearpos(a) {(a)->lnum = 0; (a)->col = 0; (a)->coladd = 0;}
#else
# define lt(a, b) (((a).lnum != (b).lnum) \
? ((a).lnum < (b).lnum) : ((a).col < (b).col))
# define ltp(a, b) (((a)->lnum != (b)->lnum) \
? ((a)->lnum < (b)->lnum) : ((a)->col < (b)->col))
# define equalpos(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col))
# define clearpos(a) {(a)->lnum = 0; (a)->col = 0;}
#endif
#define ltoreq(a, b) (lt(a, b) || equalpos(a, b))
#define lineempty(p) (*ml_get(p) == NUL)
#define bufempty() (curbuf->b_ml.ml_line_count == 1 && *ml_get((linenr_T)1) == NUL)
#ifdef MSWIN
# define TOUPPER_LOC(c) toupper_tab[(c) & 255]
# define TOLOWER_LOC(c) tolower_tab[(c) & 255]
#else
# ifdef BROKEN_TOUPPER
# define TOUPPER_LOC(c) (islower(c) ? toupper(c) : (c))
# define TOLOWER_LOC(c) (isupper(c) ? tolower(c) : (c))
# else
# define TOUPPER_LOC toupper
# define TOLOWER_LOC tolower
# endif
#endif
#ifdef EBCDIC
# define TOUPPER_ASC(c) (islower(c) ? toupper(c) : (c))
# define TOLOWER_ASC(c) (isupper(c) ? tolower(c) : (c))
#else
# define TOUPPER_ASC(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) - ('a' - 'A'))
# define TOLOWER_ASC(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) + ('a' - 'A'))
#endif
#ifdef FEAT_MBYTE
# define MB_ISLOWER(c) vim_islower(c)
# define MB_ISUPPER(c) vim_isupper(c)
# define MB_TOLOWER(c) vim_tolower(c)
# define MB_TOUPPER(c) vim_toupper(c)
#else
# define MB_ISLOWER(c) islower(c)
# define MB_ISUPPER(c) isupper(c)
# define MB_TOLOWER(c) TOLOWER_LOC(c)
# define MB_TOUPPER(c) TOUPPER_LOC(c)
#endif
#ifdef EBCDIC
# define ASCII_ISALPHA(c) isalpha(c)
# define ASCII_ISALNUM(c) isalnum(c)
# define ASCII_ISLOWER(c) islower(c)
# define ASCII_ISUPPER(c) isupper(c)
#else
# define ASCII_ISALPHA(c) ((c) < 0x7f && isalpha(c))
# define ASCII_ISALNUM(c) ((c) < 0x7f && isalnum(c))
# define ASCII_ISLOWER(c) ((c) < 0x7f && islower(c))
# define ASCII_ISUPPER(c) ((c) < 0x7f && isupper(c))
#endif
#define VIM_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
#define CHARSIZE(c) (chartab[c] & CT_CELL_MASK)
#ifdef FEAT_LANGMAP
# define LANGMAP_ADJUST(c, condition) do { \
if (*p_langmap && (condition) && !KeyStuffed && (c) >= 0 && (c) < 256) \
c = langmap_mapchar[c]; \
} while (0)
#endif
#define vim_isbreak(c) (breakat_flags[(char_u)(c)])
#ifdef VMS
# define mch_access(n, p) access(vms_fixfilename(n), (p))
# define mch_fopen(n, p) fopen(vms_fixfilename(n), (p))
# define mch_fstat(n, p) fstat(vms_fixfilename(n), (p))
# define mch_stat(n, p) stat(vms_fixfilename(n), (p))
#else
# ifndef WIN32
# define mch_access(n, p) access((n), (p))
# endif
# if !(defined(FEAT_MBYTE) && defined(WIN3264))
# define mch_fopen(n, p) fopen((n), (p))
# endif
# define mch_fstat(n, p) fstat((n), (p))
# ifdef MSWIN
# define mch_stat(n, p) vim_stat((n), (p))
# else
# ifdef STAT_IGNORES_SLASH
# define mch_stat(n, p) (illegal_slash(n) ? -1 : stat((n), (p)))
# else
# define mch_stat(n, p) stat((n), (p))
# endif
# endif
#endif
#ifdef HAVE_LSTAT
# define mch_lstat(n, p) lstat((n), (p))
#else
# define mch_lstat(n, p) mch_stat((n), (p))
#endif
#ifdef MACOS_CLASSIC
# define mch_open(n, m, p) open((n), (m))
#else
# ifdef VMS
# define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p))
# else
# if !(defined(FEAT_MBYTE) && defined(WIN3264))
# define mch_open(n, m, p) open((n), (m), (p))
# endif
# endif
#endif
#if defined(UNIX) || defined(VMS)
# define mch_open_rw(n, f) mch_open((n), (f), (mode_t)0600)
#else
# if defined(MSDOS) || defined(MSWIN) || defined(OS2)
# define mch_open_rw(n, f) mch_open((n), (f), S_IREAD | S_IWRITE)
# else
# define mch_open_rw(n, f) mch_open((n), (f), 0)
# endif
#endif
#ifdef FEAT_CRYPT
# define ZENCODE(c, t) (t = decrypt_byte(), update_keys(c), t^(c))
# define ZDECODE(c) update_keys(c ^= decrypt_byte())
#endif
#ifdef STARTUPTIME
# define TIME_MSG(s) time_msg(s, NULL)
#else
# define TIME_MSG(s)
#endif
#ifdef FEAT_VREPLACE
# define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG))
#else
# define REPLACE_NORMAL(s) ((s) & REPLACE_FLAG)
#endif
#ifdef FEAT_ARABIC
# define UTF_COMPOSINGLIKE(p1, p2) utf_composinglike((p1), (p2))
#else
# define UTF_COMPOSINGLIKE(p1, p2) utf_iscomposing(utf_ptr2char(p2))
#endif
#ifdef FEAT_RIGHTLEFT
# define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & CMDLINE) || cmdmsg_rl))
#endif
#ifdef FEAT_MBYTE
# define mb_ptr_adv(p) p += has_mbyte ? (*mb_ptr2len)(p) : 1
# define mb_cptr_adv(p) p += enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1
# define mb_ptr_back(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1
# define mb_cptr2len(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p))
# define MB_COPY_CHAR(f, t) if (has_mbyte) mb_copy_char(&f, &t); else *t++ = *f++
# define MB_CHARLEN(p) (has_mbyte ? mb_charlen(p) : STRLEN(p))
# define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p))
#else
# define mb_ptr_adv(p) ++p
# define mb_cptr_adv(p) ++p
# define mb_ptr_back(s, p) --p
# define MB_COPY_CHAR(f, t) *t++ = *f++
# define MB_CHARLEN(p) STRLEN(p)
# define PTR2CHAR(p) ((int)*(p))
#endif
#ifdef FEAT_AUTOCHDIR
# define DO_AUTOCHDIR if (p_acd) do_autochdir();
#else
# define DO_AUTOCHDIR
#endif