/* vi:set ts=8 sts=4 sw=4:
 *
 * VIM - Vi IMproved	by Bram Moolenaar
 *
 * Do ":help uganda"  in Vim to read copying and usage conditions.
 * Do ":help credits" in Vim to see a list of people who contributed.
 * See README.txt for an overview of the Vim source code.
 */
/*
 * search.c: code for normal mode searching commands
 */

#include "vim.h"

static void save_re_pat __ARGS((int idx, char_u *pat, int magic));
#ifdef FEAT_EVAL
static int first_submatch __ARGS((regmmatch_T *rp));
#endif
static int check_prevcol __ARGS((char_u *linep, int col, int ch, int *prevcol));
static int inmacro __ARGS((char_u *, char_u *));
static int check_linecomment __ARGS((char_u *line));
static int cls __ARGS((void));
static int skip_chars __ARGS((int, int));
#ifdef FEAT_TEXTOBJ
static void back_in_line __ARGS((void));
static void find_first_blank __ARGS((pos_T *));
static void findsent_forward __ARGS((long count, int at_start_sent));
#endif
#ifdef FEAT_FIND_ID
static void show_pat_in_path __ARGS((char_u *, int,
					 int, int, FILE *, linenr_T *, long));
#endif
#ifdef FEAT_VIMINFO
static void wvsp_one __ARGS((FILE *fp, int idx, char *s, int sc));
#endif

/*
 * This file contains various searching-related routines. These fall into
 * three groups:
 * 1. string searches (for /, ?, n, and N)
 * 2. character searches within a single line (for f, F, t, T, etc)
 * 3. "other" kinds of searches like the '%' command, and 'word' searches.
 */

/*
 * String searches
 *
 * The string search functions are divided into two levels:
 * lowest:  searchit(); uses an pos_T for starting position and found match.
 * Highest: do_search(); uses curwin->w_cursor; calls searchit().
 *
 * The last search pattern is remembered for repeating the same search.
 * This pattern is shared between the :g, :s, ? and / commands.
 * This is in search_regcomp().
 *
 * The actual string matching is done using a heavily modified version of
 * Henry Spencer's regular expression library.  See regexp.c.
 */

/* The offset for a search command is store in a soff struct */
/* Note: only spats[0].off is really used */
struct soffset
{
    int		dir;		/* search direction */
    int		line;		/* search has line offset */
    int		end;		/* search set cursor at end */
    long	off;		/* line or char offset */
};

/* A search pattern and its attributes are stored in a spat struct */
struct spat
{
    char_u	    *pat;	/* the pattern (in allocated memory) or NULL */
    int		    magic;	/* magicness of the pattern */
    int		    no_scs;	/* no smarcase for this pattern */
    struct soffset  off;
};

/*
 * Two search patterns are remembered: One for the :substitute command and
 * one for other searches.  last_idx points to the one that was used the last
 * time.
 */
static struct spat spats[2] =
{
    {NULL, TRUE, FALSE, {'/', 0, 0, 0L}},	/* last used search pat */
    {NULL, TRUE, FALSE, {'/', 0, 0, 0L}}	/* last used substitute pat */
};

static int last_idx = 0;	/* index in spats[] for RE_LAST */

#if defined(FEAT_AUTOCMD) || defined(FEAT_EVAL) || defined(PROTO)
/* copy of spats[], for keeping the search patterns while executing autocmds */
static struct spat  saved_spats[2];
static int	    saved_last_idx = 0;
# ifdef FEAT_SEARCH_EXTRA
static int	    saved_no_hlsearch = 0;
# endif
#endif

static char_u	    *mr_pattern = NULL;	/* pattern used by search_regcomp() */
#ifdef FEAT_RIGHTLEFT
static int	    mr_pattern_alloced = FALSE; /* mr_pattern was allocated */
#endif

#ifdef FEAT_FIND_ID
/*
 * Type used by find_pattern_in_path() to remember which included files have
 * been searched already.
 */
typedef struct SearchedFile
{
    FILE	*fp;		/* File pointer */
    char_u	*name;		/* Full name of file */
    linenr_T	lnum;		/* Line we were up to in file */
    int		matched;	/* Found a match in this file */
} SearchedFile;
#endif

/*
 * translate search pattern for vim_regcomp()
 *
 * pat_save == RE_SEARCH: save pat in spats[RE_SEARCH].pat (normal search cmd)
 * pat_save == RE_SUBST: save pat in spats[RE_SUBST].pat (:substitute command)
 * pat_save == RE_BOTH: save pat in both patterns (:global command)
 * pat_use  == RE_SEARCH: use previous search pattern if "pat" is NULL
 * pat_use  == RE_SUBST: use previous substitute pattern if "pat" is NULL
 * pat_use  == RE_LAST: use last used pattern if "pat" is NULL
 * options & SEARCH_HIS: put search string in history
 * options & SEARCH_KEEP: keep previous search pattern
 *
 * returns FAIL if failed, OK otherwise.
 */
    int
search_regcomp(pat, pat_save, pat_use, options, regmatch)
    char_u	*pat;
    int		pat_save;
    int		pat_use;
    int		options;
    regmmatch_T	*regmatch;	/* return: pattern and ignore-case flag */
{
    int		magic;
    int		i;

    rc_did_emsg = FALSE;
    magic = p_magic;

    /*
     * If no pattern given, use a previously defined pattern.
     */
    if (pat == NULL || *pat == NUL)
    {
	if (pat_use == RE_LAST)
	    i = last_idx;
	else
	    i = pat_use;
	if (spats[i].pat == NULL)	/* pattern was never defined */
	{
	    if (pat_use == RE_SUBST)
		EMSG(_(e_nopresub));
	    else
		EMSG(_(e_noprevre));
	    rc_did_emsg = TRUE;
	    return FAIL;
	}
	pat = spats[i].pat;
	magic = spats[i].magic;
	no_smartcase = spats[i].no_scs;
    }
#ifdef FEAT_CMDHIST
    else if (options & SEARCH_HIS)	/* put new pattern in history */
	add_to_history(HIST_SEARCH, pat, TRUE, NUL);
#endif

#ifdef FEAT_RIGHTLEFT
    if (mr_pattern_alloced)
    {
	vim_free(mr_pattern);
	mr_pattern_alloced = FALSE;
    }

    if (curwin->w_p_rl && *curwin->w_p_rlc == 's')
    {
	char_u *rev_pattern;

	rev_pattern = reverse_text(pat);
	if (rev_pattern == NULL)
	    mr_pattern = pat;	    /* out of memory, keep normal pattern. */
	else
	{
	    mr_pattern = rev_pattern;
	    mr_pattern_alloced = TRUE;
	}
    }
    else
#endif
	mr_pattern = pat;

    /*
     * Save the currently used pattern in the appropriate place,
     * unless the pattern should not be remembered.
     */
    if (!(options & SEARCH_KEEP))
    {
	/* search or global command */
	if (pat_save == RE_SEARCH || pat_save == RE_BOTH)
	    save_re_pat(RE_SEARCH, pat, magic);
	/* substitute or global command */
	if (pat_save == RE_SUBST || pat_save == RE_BOTH)
	    save_re_pat(RE_SUBST, pat, magic);
    }

    regmatch->rmm_ic = ignorecase(pat);
    regmatch->rmm_maxcol = 0;
    regmatch->regprog = vim_regcomp(pat, magic ? RE_MAGIC : 0);
    if (regmatch->regprog == NULL)
	return FAIL;
    return OK;
}

/*
 * Get search pattern used by search_regcomp().
 */
    char_u *
get_search_pat()
{
    return mr_pattern;
}

#if defined(FEAT_RIGHTLEFT) || defined(PROTO)
/*
 * Reverse text into allocated memory.
 * Returns the allocated string, NULL when out of memory.
 */
    char_u *
reverse_text(s)
    char_u *s;
{
    unsigned	len;
    unsigned	s_i, rev_i;
    char_u	*rev;

    /*
     * Reverse the pattern.
     */
    len = (unsigned)STRLEN(s);
    rev = alloc(len + 1);
    if (rev != NULL)
    {
	rev_i = len;
	for (s_i = 0; s_i < len; ++s_i)
	{
# ifdef FEAT_MBYTE
	    if (has_mbyte)
	    {
		int	mb_len;

		mb_len = (*mb_ptr2len)(s + s_i);
		rev_i -= mb_len;
		mch_memmove(rev + rev_i, s + s_i, mb_len);
		s_i += mb_len - 1;
	    }
	    else
# endif
		rev[--rev_i] = s[s_i];

	}
	rev[len] = NUL;
    }
    return rev;
}
#endif

    static void
save_re_pat(idx, pat, magic)
    int		idx;
    char_u	*pat;
    int		magic;
{
    if (spats[idx].pat != pat)
    {
	vim_free(spats[idx].pat);
	spats[idx].pat = vim_strsave(pat);
	spats[idx].magic = magic;
	spats[idx].no_scs = no_smartcase;
	last_idx = idx;
#ifdef FEAT_SEARCH_EXTRA
	/* If 'hlsearch' set and search pat changed: need redraw. */
	if (p_hls)
	    redraw_all_later(SOME_VALID);
	no_hlsearch = FALSE;
#endif
    }
}

#if defined(FEAT_AUTOCMD) || defined(FEAT_EVAL) || defined(PROTO)
/*
 * Save the search patterns, so they can be restored later.
 * Used before/after executing autocommands and user functions.
 */
static int save_level = 0;

    void
save_search_patterns()
{
    if (save_level++ == 0)
    {
	saved_spats[0] = spats[0];
	if (spats[0].pat != NULL)
	    saved_spats[0].pat = vim_strsave(spats[0].pat);
	saved_spats[1] = spats[1];
	if (spats[1].pat != NULL)
	    saved_spats[1].pat = vim_strsave(spats[1].pat);
	saved_last_idx = last_idx;
# ifdef FEAT_SEARCH_EXTRA
	saved_no_hlsearch = no_hlsearch;
# endif
    }
}

    void
restore_search_patterns()
{
    if (--save_level == 0)
    {
	vim_free(spats[0].pat);
	spats[0] = saved_spats[0];
	vim_free(spats[1].pat);
	spats[1] = saved_spats[1];
	last_idx = saved_last_idx;
# ifdef FEAT_SEARCH_EXTRA
	no_hlsearch = saved_no_hlsearch;
# endif
    }
}
#endif

#if defined(EXITFREE) || defined(PROTO)
    void
free_search_patterns()
{
    vim_free(spats[0].pat);
    vim_free(spats[1].pat);
}
#endif

/*
 * Return TRUE when case should be ignored for search pattern "pat".
 * Uses the 'ignorecase' and 'smartcase' options.
 */
    int
ignorecase(pat)
    char_u	*pat;
{
    char_u	*p;
    int		ic;

    ic = p_ic;
    if (ic && !no_smartcase && p_scs
#ifdef FEAT_INS_EXPAND
				&& !(ctrl_x_mode && curbuf->b_p_inf)
#endif
								    )
    {
	/* don't ignore case if pattern has uppercase */
	for (p = pat; *p; )
	{
#ifdef FEAT_MBYTE
	    int		l;

	    if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1)
	    {
		if (enc_utf8 && utf_isupper(utf_ptr2char(p)))
		{
		    ic = FALSE;
		    break;
		}
		p += l;
	    }
	    else
#endif
		if (*p == '\\' && p[1] != NUL)	/* skip "\S" et al. */
		    p += 2;
		else if (isupper(*p))
		{
		    ic = FALSE;
		    break;
		}
		else
		    ++p;
	}
    }
    no_smartcase = FALSE;

    return ic;
}

    char_u *
last_search_pat()
{
    return spats[last_idx].pat;
}

/*
 * Reset search direction to forward.  For "gd" and "gD" commands.
 */
    void
reset_search_dir()
{
    spats[0].off.dir = '/';
}

#if defined(FEAT_EVAL) || defined(FEAT_VIMINFO)
/*
 * Set the last search pattern.  For ":let @/ =" and viminfo.
 * Also set the saved search pattern, so that this works in an autocommand.
 */
    void
set_last_search_pat(s, idx, magic, setlast)
    char_u	*s;
    int		idx;
    int		magic;
    int		setlast;
{
    vim_free(spats[idx].pat);
    /* An empty string means that nothing should be matched. */
    if (*s == NUL)
	spats[idx].pat = NULL;
    else
	spats[idx].pat = vim_strsave(s);
    spats[idx].magic = magic;
    spats[idx].no_scs = FALSE;
    spats[idx].off.dir = '/';
    spats[idx].off.line = FALSE;
    spats[idx].off.end = FALSE;
    spats[idx].off.off = 0;
    if (setlast)
	last_idx = idx;
    if (save_level)
    {
	vim_free(saved_spats[idx].pat);
	saved_spats[idx] = spats[0];
	if (spats[idx].pat == NULL)
	    saved_spats[idx].pat = NULL;
	else
	    saved_spats[idx].pat = vim_strsave(spats[idx].pat);
	saved_last_idx = last_idx;
    }
# ifdef FEAT_SEARCH_EXTRA
    /* If 'hlsearch' set and search pat changed: need redraw. */
    if (p_hls && idx == last_idx && !no_hlsearch)
	redraw_all_later(SOME_VALID);
# endif
}
#endif

#ifdef FEAT_SEARCH_EXTRA
/*
 * Get a regexp program for the last used search pattern.
 * This is used for highlighting all matches in a window.
 * Values returned in regmatch->regprog and regmatch->rmm_ic.
 */
    void
last_pat_prog(regmatch)
    regmmatch_T	*regmatch;
{
    if (spats[last_idx].pat == NULL)
    {
	regmatch->regprog = NULL;
	return;
    }
    ++emsg_off;		/* So it doesn't beep if bad expr */
    (void)search_regcomp((char_u *)"", 0, last_idx, SEARCH_KEEP, regmatch);
    --emsg_off;
}
#endif

/*
 * lowest level search function.
 * Search for 'count'th occurrence of pattern 'pat' in direction 'dir'.
 * Start at position 'pos' and return the found position in 'pos'.
 *
 * if (options & SEARCH_MSG) == 0 don't give any messages
 * if (options & SEARCH_MSG) == SEARCH_NFMSG don't give 'notfound' messages
 * if (options & SEARCH_MSG) == SEARCH_MSG give all messages
 * if (options & SEARCH_HIS) put search pattern in history
 * if (options & SEARCH_END) return position at end of match
 * if (options & SEARCH_START) accept match at pos itself
 * if (options & SEARCH_KEEP) keep previous search pattern
 * if (options & SEARCH_FOLD) match only once in a closed fold
 * if (options & SEARCH_PEEK) check for typed char, cancel search
 *
 * Return FAIL (zero) for failure, non-zero for success.
 * When FEAT_EVAL is defined, returns the index of the first matching
 * subpattern plus one; one if there was none.
 */
/*ARGSUSED*/
    int
searchit(win, buf, pos, dir, pat, count, options, pat_use, stop_lnum, tm)
    win_T	*win;		/* window to search in; can be NULL for a
				   buffer without a window! */
    buf_T	*buf;
    pos_T	*pos;
    int		dir;
    char_u	*pat;
    long	count;
    int		options;
    int		pat_use;	/* which pattern to use when "pat" is empty */
    linenr_T	stop_lnum;	/* stop after this line number when != 0 */
    proftime_T	*tm;		/* timeout limit or NULL */
{
    int		found;
    linenr_T	lnum;		/* no init to shut up Apollo cc */
    regmmatch_T	regmatch;
    char_u	*ptr;
    colnr_T	matchcol;
    lpos_T	endpos;
    lpos_T	matchpos;
    int		loop;
    pos_T	start_pos;
    int		at_first_line;
    int		extra_col;
    int		match_ok;
    long	nmatched;
    int		submatch = 0;
    int		save_called_emsg = called_emsg;
#ifdef FEAT_SEARCH_EXTRA
    int		break_loop = FALSE;
#else
# define break_loop FALSE
#endif

    if (search_regcomp(pat, RE_SEARCH, pat_use,
		   (options & (SEARCH_HIS + SEARCH_KEEP)), &regmatch) == FAIL)
    {
	if ((options & SEARCH_MSG) && !rc_did_emsg)
	    EMSG2(_("E383: Invalid search string: %s"), mr_pattern);
	return FAIL;
    }

    if (options & SEARCH_START)
	extra_col = 0;
#ifdef FEAT_MBYTE
    /* Watch out for the "col" being MAXCOL - 2, used in a closed fold. */
    else if (has_mbyte && pos->lnum >= 1 && pos->lnum <= buf->b_ml.ml_line_count
						     && pos->col < MAXCOL - 2)
    {
	ptr = ml_get_buf(buf, pos->lnum, FALSE) + pos->col;
	if (*ptr == NUL)
	    extra_col = 1;
	else
	    extra_col = (*mb_ptr2len)(ptr);
    }
#endif
    else
	extra_col = 1;

    /*
     * find the string
     */
    called_emsg = FALSE;
    do	/* loop for count */
    {
	start_pos = *pos;	/* remember start pos for detecting no match */
	found = 0;		/* default: not found */
	at_first_line = TRUE;	/* default: start in first line */
	if (pos->lnum == 0)	/* correct lnum for when starting in line 0 */
	{
	    pos->lnum = 1;
	    pos->col = 0;
	    at_first_line = FALSE;  /* not in first line now */
	}

	/*
	 * Start searching in current line, unless searching backwards and
	 * we're in column 0.
	 * If we are searching backwards, in column 0, and not including the
	 * current position, gain some efficiency by skipping back a line.
	 * Otherwise begin the search in the current line.
	 */
	if (dir == BACKWARD && start_pos.col == 0
					     && (options & SEARCH_START) == 0)
	{
	    lnum = pos->lnum - 1;
	    at_first_line = FALSE;
	}
	else
	    lnum = pos->lnum;

	for (loop = 0; loop <= 1; ++loop)   /* loop twice if 'wrapscan' set */
	{
	    for ( ; lnum > 0 && lnum <= buf->b_ml.ml_line_count;
					   lnum += dir, at_first_line = FALSE)
	    {
		/* Stop after checking "stop_lnum", if it's set. */
		if (stop_lnum != 0 && (dir == FORWARD
				       ? lnum > stop_lnum : lnum < stop_lnum))
		    break;
#ifdef FEAT_RELTIME
		/* Stop after passing the "tm" time limit. */
		if (tm != NULL && profile_passed_limit(tm))
		    break;
#endif

		/*
		 * Look for a match somewhere in line "lnum".
		 */
		nmatched = vim_regexec_multi(&regmatch, win, buf,
						      lnum, (colnr_T)0,
#ifdef FEAT_RELTIME
						      tm
#else
						      NULL
#endif
						      );
		/* Abort searching on an error (e.g., out of stack). */
		if (called_emsg)
		    break;
		if (nmatched > 0)
		{
		    /* match may actually be in another line when using \zs */
		    matchpos = regmatch.startpos[0];
		    endpos = regmatch.endpos[0];
#ifdef FEAT_EVAL
		    submatch = first_submatch(&regmatch);
#endif
		    /* Line me be past end of buffer for "\n\zs". */
		    if (lnum + matchpos.lnum > buf->b_ml.ml_line_count)
			ptr = (char_u *)"";
		    else
			ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE);

		    /*
		     * Forward search in the first line: match should be after
		     * the start position. If not, continue at the end of the
		     * match (this is vi compatible) or on the next char.
		     */
		    if (dir == FORWARD && at_first_line)
		    {
			match_ok = TRUE;
			/*
			 * When the match starts in a next line it's certainly
			 * past the start position.
			 * When match lands on a NUL the cursor will be put
			 * one back afterwards, compare with that position,
			 * otherwise "/$" will get stuck on end of line.
			 */
			while (matchpos.lnum == 0
				&& ((options & SEARCH_END)
				    ?  (nmatched == 1
					&& (int)endpos.col - 1
					     < (int)start_pos.col + extra_col)
				    : ((int)matchpos.col
						  - (ptr[matchpos.col] == NUL)
					    < (int)start_pos.col + extra_col)))
			{
			    /*
			     * If vi-compatible searching, continue at the end
			     * of the match, otherwise continue one position
			     * forward.
			     */
			    if (vim_strchr(p_cpo, CPO_SEARCH) != NULL)
			    {
				if (nmatched > 1)
				{
				    /* end is in next line, thus no match in
				     * this line */
				    match_ok = FALSE;
				    break;
				}
				matchcol = endpos.col;
				/* for empty match: advance one char */
				if (matchcol == matchpos.col
						      && ptr[matchcol] != NUL)
				{
#ifdef FEAT_MBYTE
				    if (has_mbyte)
					matchcol +=
					  (*mb_ptr2len)(ptr + matchcol);
				    else
#endif
					++matchcol;
				}
			    }
			    else
			    {
				matchcol = matchpos.col;
				if (ptr[matchcol] != NUL)
				{
#ifdef FEAT_MBYTE
				    if (has_mbyte)
					matchcol += (*mb_ptr2len)(ptr
								  + matchcol);
				    else
#endif
					++matchcol;
				}
			    }
			    if (ptr[matchcol] == NUL
				    || (nmatched = vim_regexec_multi(&regmatch,
					      win, buf, lnum + matchpos.lnum,
					      matchcol,
#ifdef FEAT_RELTIME
					      tm
#else
					      NULL
#endif
					      )) == 0)
			    {
				match_ok = FALSE;
				break;
			    }
			    matchpos = regmatch.startpos[0];
			    endpos = regmatch.endpos[0];
# ifdef FEAT_EVAL
			    submatch = first_submatch(&regmatch);
# endif

			    /* Need to get the line pointer again, a
			     * multi-line search may have made it invalid. */
			    ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE);
			}
			if (!match_ok)
			    continue;
		    }
		    if (dir == BACKWARD)
		    {
			/*
			 * Now, if there are multiple matches on this line,
			 * we have to get the last one. Or the last one before
			 * the cursor, if we're on that line.
			 * When putting the new cursor at the end, compare
			 * relative to the end of the match.
			 */
			match_ok = FALSE;
			for (;;)
			{
			    /* Remember a position that is before the start
			     * position, we use it if it's the last match in
			     * the line.  Always accept a position after
			     * wrapping around. */
			    if (loop
				|| ((options & SEARCH_END)
				    ? (lnum + regmatch.endpos[0].lnum
							      < start_pos.lnum
					|| (lnum + regmatch.endpos[0].lnum
							     == start_pos.lnum
					     && (int)regmatch.endpos[0].col - 1
								   + extra_col
							<= (int)start_pos.col))
				    : (lnum + regmatch.startpos[0].lnum
							      < start_pos.lnum
					|| (lnum + regmatch.startpos[0].lnum
							     == start_pos.lnum
					     && (int)regmatch.startpos[0].col
								   + extra_col
						      <= (int)start_pos.col))))
			    {
				match_ok = TRUE;
				matchpos = regmatch.startpos[0];
				endpos = regmatch.endpos[0];
# ifdef FEAT_EVAL
				submatch = first_submatch(&regmatch);
# endif
			    }
			    else
				break;

			    /*
			     * We found a valid match, now check if there is
			     * another one after it.
			     * If vi-compatible searching, continue at the end
			     * of the match, otherwise continue one position
			     * forward.
			     */
			    if (vim_strchr(p_cpo, CPO_SEARCH) != NULL)
			    {
				if (nmatched > 1)
				    break;
				matchcol = endpos.col;
				/* for empty match: advance one char */
				if (matchcol == matchpos.col
						      && ptr[matchcol] != NUL)
				{
#ifdef FEAT_MBYTE
				    if (has_mbyte)
					matchcol +=
					  (*mb_ptr2len)(ptr + matchcol);
				    else
#endif
					++matchcol;
				}
			    }
			    else
			    {
				/* Stop when the match is in a next line. */
				if (matchpos.lnum > 0)
				    break;
				matchcol = matchpos.col;
				if (ptr[matchcol] != NUL)
				{
#ifdef FEAT_MBYTE
				    if (has_mbyte)
					matchcol +=
					  (*mb_ptr2len)(ptr + matchcol);
				    else
#endif
					++matchcol;
				}
			    }
			    if (ptr[matchcol] == NUL
				    || (nmatched = vim_regexec_multi(&regmatch,
					      win, buf, lnum + matchpos.lnum,
					      matchcol,
#ifdef FEAT_RELTIME
					      tm
#else
					      NULL
#endif
					    )) == 0)
				break;

			    /* Need to get the line pointer again, a
			     * multi-line search may have made it invalid. */
			    ptr = ml_get_buf(buf, lnum + matchpos.lnum, FALSE);
			}

			/*
			 * If there is only a match after the cursor, skip
			 * this match.
			 */
			if (!match_ok)
			    continue;
		    }

		    if (options & SEARCH_END && !(options & SEARCH_NOOF))
		    {
			pos->lnum = lnum + endpos.lnum;
			pos->col = endpos.col - 1;
#ifdef FEAT_MBYTE
			if (has_mbyte)
			{
			    /* 'e' offset may put us just below the last line */
			    if (pos->lnum > buf->b_ml.ml_line_count)
				ptr = (char_u *)"";
			    else
				ptr = ml_get_buf(buf, pos->lnum, FALSE);
			    pos->col -= (*mb_head_off)(ptr, ptr + pos->col);
			}
#endif
		    }
		    else
		    {
			pos->lnum = lnum + matchpos.lnum;
			pos->col = matchpos.col;
		    }
#ifdef FEAT_VIRTUALEDIT
		    pos->coladd = 0;
#endif
		    found = 1;

		    /* Set variables used for 'incsearch' highlighting. */
		    search_match_lines = endpos.lnum - matchpos.lnum;
		    search_match_endcol = endpos.col;
		    break;
		}
		line_breakcheck();	/* stop if ctrl-C typed */
		if (got_int)
		    break;

#ifdef FEAT_SEARCH_EXTRA
		/* Cancel searching if a character was typed.  Used for
		 * 'incsearch'.  Don't check too often, that would slowdown
		 * searching too much. */
		if ((options & SEARCH_PEEK)
			&& ((lnum - pos->lnum) & 0x3f) == 0
			&& char_avail())
		{
		    break_loop = TRUE;
		    break;
		}
#endif

		if (loop && lnum == start_pos.lnum)
		    break;	    /* if second loop, stop where started */
	    }
	    at_first_line = FALSE;

	    /*
	     * Stop the search if wrapscan isn't set, "stop_lnum" is
	     * specified, after an interrupt, after a match and after looping
	     * twice.
	     */
	    if (!p_ws || stop_lnum != 0 || got_int || called_emsg
					       || break_loop || found || loop)
		break;

	    /*
	     * If 'wrapscan' is set we continue at the other end of the file.
	     * If 'shortmess' does not contain 's', we give a message.
	     * This message is also remembered in keep_msg for when the screen
	     * is redrawn. The keep_msg is cleared whenever another message is
	     * written.
	     */
	    if (dir == BACKWARD)    /* start second loop at the other end */
		lnum = buf->b_ml.ml_line_count;
	    else
		lnum = 1;
	    if (!shortmess(SHM_SEARCH) && (options & SEARCH_MSG))
		give_warning((char_u *)_(dir == BACKWARD
					  ? top_bot_msg : bot_top_msg), TRUE);
	}
	if (got_int || called_emsg || break_loop)
	    break;
    }
    while (--count > 0 && found);   /* stop after count matches or no match */

    vim_free(regmatch.regprog);

    called_emsg |= save_called_emsg;

    if (!found)		    /* did not find it */
    {
	if (got_int)
	    EMSG(_(e_interr));
	else if ((options & SEARCH_MSG) == SEARCH_MSG)
	{
	    if (p_ws)
		EMSG2(_(e_patnotf2), mr_pattern);
	    else if (lnum == 0)
		EMSG2(_("E384: search hit TOP without match for: %s"),
								  mr_pattern);
	    else
		EMSG2(_("E385: search hit BOTTOM without match for: %s"),
								  mr_pattern);
	}
	return FAIL;
    }

    /* A pattern like "\n\zs" may go past the last line. */
    if (pos->lnum > buf->b_ml.ml_line_count)
    {
	pos->lnum = buf->b_ml.ml_line_count;
	pos->col = (int)STRLEN(ml_get_buf(buf, pos->lnum, FALSE));
	if (pos->col > 0)
	    --pos->col;
    }

    return submatch + 1;
}

#ifdef FEAT_EVAL
/*
 * Return the number of the first subpat that matched.
 */
    static int
first_submatch(rp)
    regmmatch_T	*rp;
{
    int		submatch;

    for (submatch = 1; ; ++submatch)
    {
	if (rp->startpos[submatch].lnum >= 0)
	    break;
	if (submatch == 9)
	{
	    submatch = 0;
	    break;
	}
    }
    return submatch;
}
#endif

/*
 * Highest level string search function.
 * Search for the 'count'th occurrence of pattern 'pat' in direction 'dirc'
 *		  If 'dirc' is 0: use previous dir.
 *    If 'pat' is NULL or empty : use previous string.
 *    If 'options & SEARCH_REV' : go in reverse of previous dir.
 *    If 'options & SEARCH_ECHO': echo the search command and handle options
 *    If 'options & SEARCH_MSG' : may give error message
 *    If 'options & SEARCH_OPT' : interpret optional flags
 *    If 'options & SEARCH_HIS' : put search pattern in history
 *    If 'options & SEARCH_NOOF': don't add offset to position
 *    If 'options & SEARCH_MARK': set previous context mark
 *    If 'options & SEARCH_KEEP': keep previous search pattern
 *    If 'options & SEARCH_START': accept match at curpos itself
 *    If 'options & SEARCH_PEEK': check for typed char, cancel search
 *
 * Careful: If spats[0].off.line == TRUE and spats[0].off.off == 0 this
 * makes the movement linewise without moving the match position.
 *
 * return 0 for failure, 1 for found, 2 for found and line offset added
 */
    int
do_search(oap, dirc, pat, count, options, tm)
    oparg_T	    *oap;	/* can be NULL */
    int		    dirc;	/* '/' or '?' */
    char_u	   *pat;
    long	    count;
    int		    options;
    proftime_T	    *tm;	/* timeout limit or NULL */
{
    pos_T	    pos;	/* position of the last match */
    char_u	    *searchstr;
    struct soffset  old_off;
    int		    retval;	/* Return value */
    char_u	    *p;
    long	    c;
    char_u	    *dircp;
    char_u	    *strcopy = NULL;
    char_u	    *ps;

    /*
     * A line offset is not remembered, this is vi compatible.
     */
    if (spats[0].off.line && vim_strchr(p_cpo, CPO_LINEOFF) != NULL)
    {
	spats[0].off.line = FALSE;
	spats[0].off.off = 0;
    }

    /*
     * Save the values for when (options & SEARCH_KEEP) is used.
     * (there is no "if ()" around this because gcc wants them initialized)
     */
    old_off = spats[0].off;

    pos = curwin->w_cursor;	/* start searching at the cursor position */

    /*
     * Find out the direction of the search.
     */
    if (dirc == 0)
	dirc = spats[0].off.dir;
    else
	spats[0].off.dir = dirc;
    if (options & SEARCH_REV)
    {
#ifdef WIN32
	/* There is a bug in the Visual C++ 2.2 compiler which means that
	 * dirc always ends up being '/' */
	dirc = (dirc == '/')  ?  '?'  :  '/';
#else
	if (dirc == '/')
	    dirc = '?';
	else
	    dirc = '/';
#endif
    }

#ifdef FEAT_FOLDING
    /* If the cursor is in a closed fold, don't find another match in the same
     * fold. */
    if (dirc == '/')
    {
	if (hasFolding(pos.lnum, NULL, &pos.lnum))
	    pos.col = MAXCOL - 2;	/* avoid overflow when adding 1 */
    }
    else
    {
	if (hasFolding(pos.lnum, &pos.lnum, NULL))
	    pos.col = 0;
    }
#endif

#ifdef FEAT_SEARCH_EXTRA
    /*
     * Turn 'hlsearch' highlighting back on.
     */
    if (no_hlsearch && !(options & SEARCH_KEEP))
    {
	redraw_all_later(SOME_VALID);
	no_hlsearch = FALSE;
    }
#endif

    /*
     * Repeat the search when pattern followed by ';', e.g. "/foo/;?bar".
     */
    for (;;)
    {
	searchstr = pat;
	dircp = NULL;
					    /* use previous pattern */
	if (pat == NULL || *pat == NUL || *pat == dirc)
	{
	    if (spats[RE_SEARCH].pat == NULL)	    /* no previous pattern */
	    {
		EMSG(_(e_noprevre));
		retval = 0;
		goto end_do_search;
	    }
	    /* make search_regcomp() use spats[RE_SEARCH].pat */
	    searchstr = (char_u *)"";
	}

	if (pat != NULL && *pat != NUL)	/* look for (new) offset */
	{
	    /*
	     * Find end of regular expression.
	     * If there is a matching '/' or '?', toss it.
	     */
	    ps = strcopy;
	    p = skip_regexp(pat, dirc, (int)p_magic, &strcopy);
	    if (strcopy != ps)
	    {
		/* made a copy of "pat" to change "\?" to "?" */
		searchcmdlen += (int)(STRLEN(pat) - STRLEN(strcopy));
		pat = strcopy;
		searchstr = strcopy;
	    }
	    if (*p == dirc)
	    {
		dircp = p;	/* remember where we put the NUL */
		*p++ = NUL;
	    }
	    spats[0].off.line = FALSE;
	    spats[0].off.end = FALSE;
	    spats[0].off.off = 0;
	    /*
	     * Check for a line offset or a character offset.
	     * For get_address (echo off) we don't check for a character
	     * offset, because it is meaningless and the 's' could be a
	     * substitute command.
	     */
	    if (*p == '+' || *p == '-' || VIM_ISDIGIT(*p))
		spats[0].off.line = TRUE;
	    else if ((options & SEARCH_OPT) &&
					(*p == 'e' || *p == 's' || *p == 'b'))
	    {
		if (*p == 'e')		/* end */
		    spats[0].off.end = SEARCH_END;
		++p;
	    }
	    if (VIM_ISDIGIT(*p) || *p == '+' || *p == '-')  /* got an offset */
	    {
					    /* 'nr' or '+nr' or '-nr' */
		if (VIM_ISDIGIT(*p) || VIM_ISDIGIT(*(p + 1)))
		    spats[0].off.off = atol((char *)p);
		else if (*p == '-')	    /* single '-' */
		    spats[0].off.off = -1;
		else			    /* single '+' */
		    spats[0].off.off = 1;
		++p;
		while (VIM_ISDIGIT(*p))	    /* skip number */
		    ++p;
	    }

	    /* compute length of search command for get_address() */
	    searchcmdlen += (int)(p - pat);

	    pat = p;			    /* put pat after search command */
	}

	if ((options & SEARCH_ECHO) && messaging()
					    && !cmd_silent && msg_silent == 0)
	{
	    char_u	*msgbuf;
	    char_u	*trunc;

	    if (*searchstr == NUL)
		p = spats[last_idx].pat;
	    else
		p = searchstr;
	    msgbuf = alloc((unsigned)(STRLEN(p) + 40));
	    if (msgbuf != NULL)
	    {
		msgbuf[0] = dirc;
#ifdef FEAT_MBYTE
		if (enc_utf8 && utf_iscomposing(utf_ptr2char(p)))
		{
		    /* Use a space to draw the composing char on. */
		    msgbuf[1] = ' ';
		    STRCPY(msgbuf + 2, p);
		}
		else
#endif
		    STRCPY(msgbuf + 1, p);
		if (spats[0].off.line || spats[0].off.end || spats[0].off.off)
		{
		    p = msgbuf + STRLEN(msgbuf);
		    *p++ = dirc;
		    if (spats[0].off.end)
			*p++ = 'e';
		    else if (!spats[0].off.line)
			*p++ = 's';
		    if (spats[0].off.off > 0 || spats[0].off.line)
			*p++ = '+';
		    if (spats[0].off.off != 0 || spats[0].off.line)
			sprintf((char *)p, "%ld", spats[0].off.off);
		    else
			*p = NUL;
		}

		msg_start();
		trunc = msg_strtrunc(msgbuf, FALSE);

#ifdef FEAT_RIGHTLEFT
		/* The search pattern could be shown on the right in rightleft
		 * mode, but the 'ruler' and 'showcmd' area use it too, thus
		 * it would be blanked out again very soon.  Show it on the
		 * left, but do reverse the text. */
		if (curwin->w_p_rl && *curwin->w_p_rlc == 's')
		{
		    char_u *r;

		    r = reverse_text(trunc != NULL ? trunc : msgbuf);
		    if (r != NULL)
		    {
			vim_free(trunc);
			trunc = r;
		    }
		}
#endif
		if (trunc != NULL)
		{
		    msg_outtrans(trunc);
		    vim_free(trunc);
		}
		else
		    msg_outtrans(msgbuf);
		msg_clr_eos();
		msg_check();
		vim_free(msgbuf);

		gotocmdline(FALSE);
		out_flush();
		msg_nowait = TRUE;	    /* don't wait for this message */
	    }
	}

	/*
	 * If there is a character offset, subtract it from the current
	 * position, so we don't get stuck at "?pat?e+2" or "/pat/s-2".
	 * Skip this if pos.col is near MAXCOL (closed fold).
	 * This is not done for a line offset, because then we would not be vi
	 * compatible.
	 */
	if (!spats[0].off.line && spats[0].off.off && pos.col < MAXCOL - 2)
	{
	    if (spats[0].off.off > 0)
	    {
		for (c = spats[0].off.off; c; --c)
		    if (decl(&pos) == -1)
			break;
		if (c)			/* at start of buffer */
		{
		    pos.lnum = 0;	/* allow lnum == 0 here */
		    pos.col = MAXCOL;
		}
	    }
	    else
	    {
		for (c = spats[0].off.off; c; ++c)
		    if (incl(&pos) == -1)
			break;
		if (c)			/* at end of buffer */
		{
		    pos.lnum = curbuf->b_ml.ml_line_count + 1;
		    pos.col = 0;
		}
	    }
	}

#ifdef FEAT_FKMAP	/* when in Farsi mode, reverse the character flow */
	if (p_altkeymap && curwin->w_p_rl)
	     lrFswap(searchstr,0);
#endif

	c = searchit(curwin, curbuf, &pos, dirc == '/' ? FORWARD : BACKWARD,
		searchstr, count, spats[0].off.end + (options &
		       (SEARCH_KEEP + SEARCH_PEEK + SEARCH_HIS
			+ SEARCH_MSG + SEARCH_START
			+ ((pat != NULL && *pat == ';') ? 0 : SEARCH_NOOF))),
		RE_LAST, (linenr_T)0, tm);

	if (dircp != NULL)
	    *dircp = dirc;	/* restore second '/' or '?' for normal_cmd() */
	if (c == FAIL)
	{
	    retval = 0;
	    goto end_do_search;
	}
	if (spats[0].off.end && oap != NULL)
	    oap->inclusive = TRUE;  /* 'e' includes last character */

	retval = 1;		    /* pattern found */

	/*
	 * Add character and/or line offset
	 */
	if (!(options & SEARCH_NOOF) || (pat != NULL && *pat == ';'))
	{
	    if (spats[0].off.line)	/* Add the offset to the line number. */
	    {
		c = pos.lnum + spats[0].off.off;
		if (c < 1)
		    pos.lnum = 1;
		else if (c > curbuf->b_ml.ml_line_count)
		    pos.lnum = curbuf->b_ml.ml_line_count;
		else
		    pos.lnum = c;
		pos.col = 0;

		retval = 2;	    /* pattern found, line offset added */
	    }
	    else if (pos.col < MAXCOL - 2)	/* just in case */
	    {
		/* to the right, check for end of file */
		if (spats[0].off.off > 0)
		{
		    for (c = spats[0].off.off; c; --c)
			if (incl(&pos) == -1)
			    break;
		}
		/* to the left, check for start of file */
		else
		{
		    if ((c = pos.col + spats[0].off.off) >= 0)
			pos.col = c;
		    else
			for (c = spats[0].off.off; c; ++c)
			    if (decl(&pos) == -1)
				break;
		}
	    }
	}

	/*
	 * The search command can be followed by a ';' to do another search.
	 * For example: "/pat/;/foo/+3;?bar"
	 * This is like doing another search command, except:
	 * - The remembered direction '/' or '?' is from the first search.
	 * - When an error happens the cursor isn't moved at all.
	 * Don't do this when called by get_address() (it handles ';' itself).
	 */
	if (!(options & SEARCH_OPT) || pat == NULL || *pat != ';')
	    break;

	dirc = *++pat;
	if (dirc != '?' && dirc != '/')
	{
	    retval = 0;
	    EMSG(_("E386: Expected '?' or '/'  after ';'"));
	    goto end_do_search;
	}
	++pat;
    }

    if (options & SEARCH_MARK)
	setpcmark();
    curwin->w_cursor = pos;
    curwin->w_set_curswant = TRUE;

end_do_search:
    if (options & SEARCH_KEEP)
	spats[0].off = old_off;
    vim_free(strcopy);

    return retval;
}

#if defined(FEAT_INS_EXPAND) || defined(PROTO)
/*
 * search_for_exact_line(buf, pos, dir, pat)
 *
 * Search for a line starting with the given pattern (ignoring leading
 * white-space), starting from pos and going in direction dir.	pos will
 * contain the position of the match found.    Blank lines match only if
 * ADDING is set.  if p_ic is set then the pattern must be in lowercase.
 * Return OK for success, or FAIL if no line found.
 */
    int
search_for_exact_line(buf, pos, dir, pat)
    buf_T	*buf;
    pos_T	*pos;
    int		dir;
    char_u	*pat;
{
    linenr_T	start = 0;
    char_u	*ptr;
    char_u	*p;

    if (buf->b_ml.ml_line_count == 0)
	return FAIL;
    for (;;)
    {
	pos->lnum += dir;
	if (pos->lnum < 1)
	{
	    if (p_ws)
	    {
		pos->lnum = buf->b_ml.ml_line_count;
		if (!shortmess(SHM_SEARCH))
		    give_warning((char_u *)_(top_bot_msg), TRUE);
	    }
	    else
	    {
		pos->lnum = 1;
		break;
	    }
	}
	else if (pos->lnum > buf->b_ml.ml_line_count)
	{
	    if (p_ws)
	    {
		pos->lnum = 1;
		if (!shortmess(SHM_SEARCH))
		    give_warning((char_u *)_(bot_top_msg), TRUE);
	    }
	    else
	    {
		pos->lnum = 1;
		break;
	    }
	}
	if (pos->lnum == start)
	    break;
	if (start == 0)
	    start = pos->lnum;
	ptr = ml_get_buf(buf, pos->lnum, FALSE);
	p = skipwhite(ptr);
	pos->col = (colnr_T) (p - ptr);

	/* when adding lines the matching line may be empty but it is not
	 * ignored because we are interested in the next line -- Acevedo */
	if ((compl_cont_status & CONT_ADDING)
					   && !(compl_cont_status & CONT_SOL))
	{
	    if ((p_ic ? MB_STRICMP(p, pat) : STRCMP(p, pat)) == 0)
		return OK;
	}
	else if (*p != NUL)	/* ignore empty lines */
	{	/* expanding lines or words */
	    if ((p_ic ? MB_STRNICMP(p, pat, compl_length)
				   : STRNCMP(p, pat, compl_length)) == 0)
		return OK;
	}
    }
    return FAIL;
}
#endif /* FEAT_INS_EXPAND */

/*
 * Character Searches
 */

/*
 * Search for a character in a line.  If "t_cmd" is FALSE, move to the
 * position of the character, otherwise move to just before the char.
 * Do this "cap->count1" times.
 * Return FAIL or OK.
 */
    int
searchc(cap, t_cmd)
    cmdarg_T	*cap;
    int		t_cmd;
{
    int			c = cap->nchar;	/* char to search for */
    int			dir = cap->arg;	/* TRUE for searching forward */
    long		count = cap->count1;	/* repeat count */
    static int		lastc = NUL;	/* last character searched for */
    static int		lastcdir;	/* last direction of character search */
    static int		last_t_cmd;	/* last search t_cmd */
    int			col;
    char_u		*p;
    int			len;
#ifdef FEAT_MBYTE
    static char_u	bytes[MB_MAXBYTES];
    static int		bytelen = 1;	/* >1 for multi-byte char */
#endif

    if (c != NUL)	/* normal search: remember args for repeat */
    {
	if (!KeyStuffed)    /* don't remember when redoing */
	{
	    lastc = c;
	    lastcdir = dir;
	    last_t_cmd = t_cmd;
#ifdef FEAT_MBYTE
	    bytelen = (*mb_char2bytes)(c, bytes);
	    if (cap->ncharC1 != 0)
	    {
		bytelen += (*mb_char2bytes)(cap->ncharC1, bytes + bytelen);
		if (cap->ncharC2 != 0)
		    bytelen += (*mb_char2bytes)(cap->ncharC2, bytes + bytelen);
	    }
#endif
	}
    }
    else		/* repeat previous search */
    {
	if (lastc == NUL)
	    return FAIL;
	if (dir)	/* repeat in opposite direction */
	    dir = -lastcdir;
	else
	    dir = lastcdir;
	t_cmd = last_t_cmd;
	c = lastc;
	/* For multi-byte re-use last bytes[] and bytelen. */
    }

    if (dir == BACKWARD)
	cap->oap->inclusive = FALSE;
    else
	cap->oap->inclusive = TRUE;

    p = ml_get_curline();
    col = curwin->w_cursor.col;
    len = (int)STRLEN(p);

    while (count--)
    {
#ifdef FEAT_MBYTE
	if (has_mbyte)
	{
	    for (;;)
	    {
		if (dir > 0)
		{
		    col += (*mb_ptr2len)(p + col);
		    if (col >= len)
			return FAIL;
		}
		else
		{
		    if (col == 0)
			return FAIL;
		    col -= (*mb_head_off)(p, p + col - 1) + 1;
		}
		if (bytelen == 1)
		{
		    if (p[col] == c)
			break;
		}
		else
		{
		    if (vim_memcmp(p + col, bytes, bytelen) == 0)
			break;
		}
	    }
	}
	else
#endif
	{
	    for (;;)
	    {
		if ((col += dir) < 0 || col >= len)
		    return FAIL;
		if (p[col] == c)
		    break;
	    }
	}
    }

    if (t_cmd)
    {
	/* backup to before the character (possibly double-byte) */
	col -= dir;
#ifdef FEAT_MBYTE
	if (has_mbyte)
	{
	    if (dir < 0)
		/* Landed on the search char which is bytelen long */
		col += bytelen - 1;
	    else
		/* To previous char, which may be multi-byte. */
		col -= (*mb_head_off)(p, p + col);
	}
#endif
    }
    curwin->w_cursor.col = col;

    return OK;
}

/*
 * "Other" Searches
 */

/*
 * findmatch - find the matching paren or brace
 *
 * Improvement over vi: Braces inside quotes are ignored.
 */
    pos_T *
findmatch(oap, initc)
    oparg_T   *oap;
    int	    initc;
{
    return findmatchlimit(oap, initc, 0, 0);
}

/*
 * Return TRUE if the character before "linep[col]" equals "ch".
 * Return FALSE if "col" is zero.
 * Update "*prevcol" to the column of the previous character, unless "prevcol"
 * is NULL.
 * Handles multibyte string correctly.
 */
    static int
check_prevcol(linep, col, ch, prevcol)
    char_u	*linep;
    int		col;
    int		ch;
    int		*prevcol;
{
    --col;
#ifdef FEAT_MBYTE
    if (col > 0 && has_mbyte)
	col -= (*mb_head_off)(linep, linep + col);
#endif
    if (prevcol)
	*prevcol = col;
    return (col >= 0 && linep[col] == ch) ? TRUE : FALSE;
}

/*
 * findmatchlimit -- find the matching paren or brace, if it exists within
 * maxtravel lines of here.  A maxtravel of 0 means search until falling off
 * the edge of the file.
 *
 * "initc" is the character to find a match for.  NUL means to find the
 * character at or after the cursor.
 *
 * flags: FM_BACKWARD	search backwards (when initc is '/', '*' or '#')
 *	  FM_FORWARD	search forwards (when initc is '/', '*' or '#')
 *	  FM_BLOCKSTOP	stop at start/end of block ({ or } in column 0)
 *	  FM_SKIPCOMM	skip comments (not implemented yet!)
 *
 * "oap" is only used to set oap->motion_type for a linewise motion, it be
 * NULL
 */

    pos_T *
findmatchlimit(oap, initc, flags, maxtravel)
    oparg_T	*oap;
    int		initc;
    int		flags;
    int		maxtravel;
{
    static pos_T pos;			/* current search position */
    int		findc = 0;		/* matching brace */
    int		c;
    int		count = 0;		/* cumulative number of braces */
    int		backwards = FALSE;	/* init for gcc */
    int		inquote = FALSE;	/* TRUE when inside quotes */
    char_u	*linep;			/* pointer to current line */
    char_u	*ptr;
    int		do_quotes;		/* check for quotes in current line */
    int		at_start;		/* do_quotes value at start position */
    int		hash_dir = 0;		/* Direction searched for # things */
    int		comment_dir = 0;	/* Direction searched for comments */
    pos_T	match_pos;		/* Where last slash-star was found */
    int		start_in_quotes;	/* start position is in quotes */
    int		traveled = 0;		/* how far we've searched so far */
    int		ignore_cend = FALSE;    /* ignore comment end */
    int		cpo_match;		/* vi compatible matching */
    int		cpo_bsl;		/* don't recognize backslashes */
    int		match_escaped = 0;	/* search for escaped match */
    int		dir;			/* Direction to search */
    int		comment_col = MAXCOL;   /* start of / / comment */
#ifdef FEAT_LISP
    int		lispcomm = FALSE;	/* inside of Lisp-style comment */
    int		lisp = curbuf->b_p_lisp; /* engage Lisp-specific hacks ;) */
#endif

    pos = curwin->w_cursor;
    linep = ml_get(pos.lnum);

    cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL);
    cpo_bsl = (vim_strchr(p_cpo, CPO_MATCHBSL) != NULL);

    /* Direction to search when initc is '/', '*' or '#' */
    if (flags & FM_BACKWARD)
	dir = BACKWARD;
    else if (flags & FM_FORWARD)
	dir = FORWARD;
    else
	dir = 0;

    /*
     * if initc given, look in the table for the matching character
     * '/' and '*' are special cases: look for start or end of comment.
     * When '/' is used, we ignore running backwards into an star-slash, for
     * "[*" command, we just want to find any comment.
     */
    if (initc == '/' || initc == '*')
    {
	comment_dir = dir;
	if (initc == '/')
	    ignore_cend = TRUE;
	backwards = (dir == FORWARD) ? FALSE : TRUE;
	initc = NUL;
    }
    else if (initc != '#' && initc != NUL)
    {
	/* 'matchpairs' is "x:y,x:y" */
	for (ptr = curbuf->b_p_mps; *ptr; ptr += 2)
	{
	    if (*ptr == initc)
	    {
		findc = initc;
		initc = ptr[2];
		backwards = TRUE;
		break;
	    }
	    ptr += 2;
	    if (*ptr == initc)
	    {
		findc = initc;
		initc = ptr[-2];
		backwards = FALSE;
		break;
	    }
	    if (ptr[1] != ',')
		break;
	}
	if (!findc)		/* invalid initc! */
	    return NULL;
    }
    /*
     * Either initc is '#', or no initc was given and we need to look under the
     * cursor.
     */
    else
    {
	if (initc == '#')
	{
	    hash_dir = dir;
	}
	else
	{
	    /*
	     * initc was not given, must look for something to match under
	     * or near the cursor.
	     * Only check for special things when 'cpo' doesn't have '%'.
	     */
	    if (!cpo_match)
	    {
		/* Are we before or at #if, #else etc.? */
		ptr = skipwhite(linep);
		if (*ptr == '#' && pos.col <= (colnr_T)(ptr - linep))
		{
		    ptr = skipwhite(ptr + 1);
		    if (   STRNCMP(ptr, "if", 2) == 0
			|| STRNCMP(ptr, "endif", 5) == 0
			|| STRNCMP(ptr, "el", 2) == 0)
			hash_dir = 1;
		}

		/* Are we on a comment? */
		else if (linep[pos.col] == '/')
		{
		    if (linep[pos.col + 1] == '*')
		    {
			comment_dir = FORWARD;
			backwards = FALSE;
			pos.col++;
		    }
		    else if (pos.col > 0 && linep[pos.col - 1] == '*')
		    {
			comment_dir = BACKWARD;
			backwards = TRUE;
			pos.col--;
		    }
		}
		else if (linep[pos.col] == '*')
		{
		    if (linep[pos.col + 1] == '/')
		    {
			comment_dir = BACKWARD;
			backwards = TRUE;
		    }
		    else if (pos.col > 0 && linep[pos.col - 1] == '/')
		    {
			comment_dir = FORWARD;
			backwards = FALSE;
		    }
		}
	    }

	    /*
	     * If we are not on a comment or the # at the start of a line, then
	     * look for brace anywhere on this line after the cursor.
	     */
	    if (!hash_dir && !comment_dir)
	    {
		/*
		 * Find the brace under or after the cursor.
		 * If beyond the end of the line, use the last character in
		 * the line.
		 */
		if (linep[pos.col] == NUL && pos.col)
		    --pos.col;
		for (;;)
		{
		    initc = linep[pos.col];
		    if (initc == NUL)
			break;

		    for (ptr = curbuf->b_p_mps; *ptr; ++ptr)
		    {
			if (*ptr == initc)
			{
			    findc = ptr[2];
			    backwards = FALSE;
			    break;
			}
			ptr += 2;
			if (*ptr == initc)
			{
			    findc = ptr[-2];
			    backwards = TRUE;
			    break;
			}
			if (!*++ptr)
			    break;
		    }
		    if (findc)
			break;
#ifdef FEAT_MBYTE
		    if (has_mbyte)
			pos.col += (*mb_ptr2len)(linep + pos.col);
		    else
#endif
			++pos.col;
		}
		if (!findc)
		{
		    /* no brace in the line, maybe use "  #if" then */
		    if (!cpo_match && *skipwhite(linep) == '#')
			hash_dir = 1;
		    else
			return NULL;
		}
		else if (!cpo_bsl)
		{
		    int col, bslcnt = 0;

		    /* Set "match_escaped" if there are an odd number of
		     * backslashes. */
		    for (col = pos.col; check_prevcol(linep, col, '\\', &col);)
			bslcnt++;
		    match_escaped = (bslcnt & 1);
		}
	    }
	}
	if (hash_dir)
	{
	    /*
	     * Look for matching #if, #else, #elif, or #endif
	     */
	    if (oap != NULL)
		oap->motion_type = MLINE;   /* Linewise for this case only */
	    if (initc != '#')
	    {
		ptr = skipwhite(skipwhite(linep) + 1);
		if (STRNCMP(ptr, "if", 2) == 0 || STRNCMP(ptr, "el", 2) == 0)
		    hash_dir = 1;
		else if (STRNCMP(ptr, "endif", 5) == 0)
		    hash_dir = -1;
		else
		    return NULL;
	    }
	    pos.col = 0;
	    while (!got_int)
	    {
		if (hash_dir > 0)
		{
		    if (pos.lnum == curbuf->b_ml.ml_line_count)
			break;
		}
		else if (pos.lnum == 1)
		    break;
		pos.lnum += hash_dir;
		linep = ml_get(pos.lnum);
		line_breakcheck();	/* check for CTRL-C typed */
		ptr = skipwhite(linep);
		if (*ptr != '#')
		    continue;
		pos.col = (colnr_T) (ptr - linep);
		ptr = skipwhite(ptr + 1);
		if (hash_dir > 0)
		{
		    if (STRNCMP(ptr, "if", 2) == 0)
			count++;
		    else if (STRNCMP(ptr, "el", 2) == 0)
		    {
			if (count == 0)
			    return &pos;
		    }
		    else if (STRNCMP(ptr, "endif", 5) == 0)
		    {
			if (count == 0)
			    return &pos;
			count--;
		    }
		}
		else
		{
		    if (STRNCMP(ptr, "if", 2) == 0)
		    {
			if (count == 0)
			    return &pos;
			count--;
		    }
		    else if (initc == '#' && STRNCMP(ptr, "el", 2) == 0)
		    {
			if (count == 0)
			    return &pos;
		    }
		    else if (STRNCMP(ptr, "endif", 5) == 0)
			count++;
		}
	    }
	    return NULL;
	}
    }

#ifdef FEAT_RIGHTLEFT
    /* This is just guessing: when 'rightleft' is set, search for a matching
     * paren/brace in the other direction. */
    if (curwin->w_p_rl && vim_strchr((char_u *)"()[]{}<>", initc) != NULL)
	backwards = !backwards;
#endif

    do_quotes = -1;
    start_in_quotes = MAYBE;
    clearpos(&match_pos);

    /* backward search: Check if this line contains a single-line comment */
    if ((backwards && comment_dir)
#ifdef FEAT_LISP
	    || lisp
#endif
	    )
	comment_col = check_linecomment(linep);
#ifdef FEAT_LISP
    if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col)
	lispcomm = TRUE;    /* find match inside this comment */
#endif
    while (!got_int)
    {
	/*
	 * Go to the next position, forward or backward. We could use
	 * inc() and dec() here, but that is much slower
	 */
	if (backwards)
	{
#ifdef FEAT_LISP
	    /* char to match is inside of comment, don't search outside */
	    if (lispcomm && pos.col < (colnr_T)comment_col)
		break;
#endif
	    if (pos.col == 0)		/* at start of line, go to prev. one */
	    {
		if (pos.lnum == 1)	/* start of file */
		    break;
		--pos.lnum;

		if (maxtravel > 0 && ++traveled > maxtravel)
		    break;

		linep = ml_get(pos.lnum);
		pos.col = (colnr_T)STRLEN(linep); /* pos.col on trailing NUL */
		do_quotes = -1;
		line_breakcheck();

		/* Check if this line contains a single-line comment */
		if (comment_dir
#ifdef FEAT_LISP
			|| lisp
#endif
			)
		    comment_col = check_linecomment(linep);
#ifdef FEAT_LISP
		/* skip comment */
		if (lisp && comment_col != MAXCOL)
		    pos.col = comment_col;
#endif
	    }
	    else
	    {
		--pos.col;
#ifdef FEAT_MBYTE
		if (has_mbyte)
		    pos.col -= (*mb_head_off)(linep, linep + pos.col);
#endif
	    }
	}
	else				/* forward search */
	{
	    if (linep[pos.col] == NUL
		    /* at end of line, go to next one */
#ifdef FEAT_LISP
		    /* don't search for match in comment */
		    || (lisp && comment_col != MAXCOL
					   && pos.col == (colnr_T)comment_col)
#endif
		    )
	    {
		if (pos.lnum == curbuf->b_ml.ml_line_count  /* end of file */
#ifdef FEAT_LISP
			/* line is exhausted and comment with it,
			 * don't search for match in code */
			 || lispcomm
#endif
			 )
		    break;
		++pos.lnum;

		if (maxtravel && traveled++ > maxtravel)
		    break;

		linep = ml_get(pos.lnum);
		pos.col = 0;
		do_quotes = -1;
		line_breakcheck();
#ifdef FEAT_LISP
		if (lisp)   /* find comment pos in new line */
		    comment_col = check_linecomment(linep);
#endif
	    }
	    else
	    {
#ifdef FEAT_MBYTE
		if (has_mbyte)
		    pos.col += (*mb_ptr2len)(linep + pos.col);
		else
#endif
		    ++pos.col;
	    }
	}

	/*
	 * If FM_BLOCKSTOP given, stop at a '{' or '}' in column 0.
	 */
	if (pos.col == 0 && (flags & FM_BLOCKSTOP) &&
					 (linep[0] == '{' || linep[0] == '}'))
	{
	    if (linep[0] == findc && count == 0)	/* match! */
		return &pos;
	    break;					/* out of scope */
	}

	if (comment_dir)
	{
	    /* Note: comments do not nest, and we ignore quotes in them */
	    /* TODO: ignore comment brackets inside strings */
	    if (comment_dir == FORWARD)
	    {
		if (linep[pos.col] == '*' && linep[pos.col + 1] == '/')
		{
		    pos.col++;
		    return &pos;
		}
	    }
	    else    /* Searching backwards */
	    {
		/*
		 * A comment may contain / * or / /, it may also start or end
		 * with / * /.	Ignore a / * after / /.
		 */
		if (pos.col == 0)
		    continue;
		else if (  linep[pos.col - 1] == '/'
			&& linep[pos.col] == '*'
			&& (int)pos.col < comment_col)
		{
		    count++;
		    match_pos = pos;
		    match_pos.col--;
		}
		else if (linep[pos.col - 1] == '*' && linep[pos.col] == '/')
		{
		    if (count > 0)
			pos = match_pos;
		    else if (pos.col > 1 && linep[pos.col - 2] == '/'
					       && (int)pos.col <= comment_col)
			pos.col -= 2;
		    else if (ignore_cend)
			continue;
		    else
			return NULL;
		    return &pos;
		}
	    }
	    continue;
	}

	/*
	 * If smart matching ('cpoptions' does not contain '%'), braces inside
	 * of quotes are ignored, but only if there is an even number of
	 * quotes in the line.
	 */
	if (cpo_match)
	    do_quotes = 0;
	else if (do_quotes == -1)
	{
	    /*
	     * Count the number of quotes in the line, skipping \" and '"'.
	     * Watch out for "\\".
	     */
	    at_start = do_quotes;
	    for (ptr = linep; *ptr; ++ptr)
	    {
		if (ptr == linep + pos.col + backwards)
		    at_start = (do_quotes & 1);
		if (*ptr == '"'
			&& (ptr == linep || ptr[-1] != '\'' || ptr[1] != '\''))
		    ++do_quotes;
		if (*ptr == '\\' && ptr[1] != NUL)
		    ++ptr;
	    }
	    do_quotes &= 1;	    /* result is 1 with even number of quotes */

	    /*
	     * If we find an uneven count, check current line and previous
	     * one for a '\' at the end.
	     */
	    if (!do_quotes)
	    {
		inquote = FALSE;
		if (ptr[-1] == '\\')
		{
		    do_quotes = 1;
		    if (start_in_quotes == MAYBE)
		    {
			/* Do we need to use at_start here? */
			inquote = TRUE;
			start_in_quotes = TRUE;
		    }
		    else if (backwards)
			inquote = TRUE;
		}
		if (pos.lnum > 1)
		{
		    ptr = ml_get(pos.lnum - 1);
		    if (*ptr && *(ptr + STRLEN(ptr) - 1) == '\\')
		    {
			do_quotes = 1;
			if (start_in_quotes == MAYBE)
			{
			    inquote = at_start;
			    if (inquote)
				start_in_quotes = TRUE;
			}
			else if (!backwards)
			    inquote = TRUE;
		    }

		    /* ml_get() only keeps one line, need to get linep again */
		    linep = ml_get(pos.lnum);
		}
	    }
	}
	if (start_in_quotes == MAYBE)
	    start_in_quotes = FALSE;

	/*
	 * If 'smartmatch' is set:
	 *   Things inside quotes are ignored by setting 'inquote'.  If we
	 *   find a quote without a preceding '\' invert 'inquote'.  At the
	 *   end of a line not ending in '\' we reset 'inquote'.
	 *
	 *   In lines with an uneven number of quotes (without preceding '\')
	 *   we do not know which part to ignore. Therefore we only set
	 *   inquote if the number of quotes in a line is even, unless this
	 *   line or the previous one ends in a '\'.  Complicated, isn't it?
	 */
	switch (c = linep[pos.col])
	{
	case NUL:
	    /* at end of line without trailing backslash, reset inquote */
	    if (pos.col == 0 || linep[pos.col - 1] != '\\')
	    {
		inquote = FALSE;
		start_in_quotes = FALSE;
	    }
	    break;

	case '"':
	    /* a quote that is preceded with an odd number of backslashes is
	     * ignored */
	    if (do_quotes)
	    {
		int col;

		for (col = pos.col - 1; col >= 0; --col)
		    if (linep[col] != '\\')
			break;
		if ((((int)pos.col - 1 - col) & 1) == 0)
		{
		    inquote = !inquote;
		    start_in_quotes = FALSE;
		}
	    }
	    break;

	/*
	 * If smart matching ('cpoptions' does not contain '%'):
	 *   Skip things in single quotes: 'x' or '\x'.  Be careful for single
	 *   single quotes, eg jon's.  Things like '\233' or '\x3f' are not
	 *   skipped, there is never a brace in them.
	 *   Ignore this when finding matches for `'.
	 */
	case '\'':
	    if (!cpo_match && initc != '\'' && findc != '\'')
	    {
		if (backwards)
		{
		    if (pos.col > 1)
		    {
			if (linep[pos.col - 2] == '\'')
			{
			    pos.col -= 2;
			    break;
			}
			else if (linep[pos.col - 2] == '\\' &&
				    pos.col > 2 && linep[pos.col - 3] == '\'')
			{
			    pos.col -= 3;
			    break;
			}
		    }
		}
		else if (linep[pos.col + 1])	/* forward search */
		{
		    if (linep[pos.col + 1] == '\\' &&
			    linep[pos.col + 2] && linep[pos.col + 3] == '\'')
		    {
			pos.col += 3;
			break;
		    }
		    else if (linep[pos.col + 2] == '\'')
		    {
			pos.col += 2;
			break;
		    }
		}
	    }
	    /* FALLTHROUGH */

	default:
#ifdef FEAT_LISP
	    /*
	     * For Lisp skip over backslashed (), {} and [].
	     * (actually, we skip #\( et al)
	     */
	    if (curbuf->b_p_lisp
		    && vim_strchr((char_u *)"(){}[]", c) != NULL
		    && pos.col > 1
		    && check_prevcol(linep, pos.col, '\\', NULL)
		    && check_prevcol(linep, pos.col - 1, '#', NULL))
		break;
#endif

	    /* Check for match outside of quotes, and inside of
	     * quotes when the start is also inside of quotes. */
	    if ((!inquote || start_in_quotes == TRUE)
		    && (c == initc || c == findc))
	    {
		int	col, bslcnt = 0;

		if (!cpo_bsl)
		{
		    for (col = pos.col; check_prevcol(linep, col, '\\', &col);)
			bslcnt++;
		}
		/* Only accept a match when 'M' is in 'cpo' or when ecaping is
		 * what we expect. */
		if (cpo_bsl || (bslcnt & 1) == match_escaped)
		{
		    if (c == initc)
			count++;
		    else
		    {
			if (count == 0)
			    return &pos;
			count--;
		    }
		}
	    }
	}
    }

    if (comment_dir == BACKWARD && count > 0)
    {
	pos = match_pos;
	return &pos;
    }
    return (pos_T *)NULL;	/* never found it */
}

/*
 * Check if line[] contains a / / comment.
 * Return MAXCOL if not, otherwise return the column.
 * TODO: skip strings.
 */
    static int
check_linecomment(line)
    char_u	*line;
{
    char_u  *p;

    p = line;
#ifdef FEAT_LISP
    /* skip Lispish one-line comments */
    if (curbuf->b_p_lisp)
    {
	if (vim_strchr(p, ';') != NULL) /* there may be comments */
	{
	    int instr = FALSE;	/* inside of string */

	    p = line;		/* scan from start */
	    while ((p = vim_strpbrk(p, (char_u *)"\";")) != NULL)
	    {
		if (*p == '"')
		{
		    if (instr)
		    {
			if (*(p - 1) != '\\') /* skip escaped quote */
			    instr = FALSE;
		    }
		    else if (p == line || ((p - line) >= 2
				      /* skip #\" form */
				      && *(p - 1) != '\\' && *(p - 2) != '#'))
			instr = TRUE;
		}
		else if (!instr && ((p - line) < 2
				    || (*(p - 1) != '\\' && *(p - 2) != '#')))
		    break;	/* found! */
		++p;
	    }
	}
	else
	    p = NULL;
    }
    else
#endif
    while ((p = vim_strchr(p, '/')) != NULL)
    {
	/* accept a double /, unless it's preceded with * and followed by *,
	 * because * / / * is an end and start of a C comment */
	if (p[1] == '/' && (p == line || p[-1] != '*' || p[2] != '*'))
	    break;
	++p;
    }

    if (p == NULL)
	return MAXCOL;
    return (int)(p - line);
}

/*
 * Move cursor briefly to character matching the one under the cursor.
 * Used for Insert mode and "r" command.
 * Show the match only if it is visible on the screen.
 * If there isn't a match, then beep.
 */
    void
showmatch(c)
    int		c;	    /* char to show match for */
{
    pos_T	*lpos, save_cursor;
    pos_T	mpos;
    colnr_T	vcol;
    long	save_so;
    long	save_siso;
#ifdef CURSOR_SHAPE
    int		save_state;
#endif
    colnr_T	save_dollar_vcol;
    char_u	*p;

    /*
     * Only show match for chars in the 'matchpairs' option.
     */
    /* 'matchpairs' is "x:y,x:y" */
    for (p = curbuf->b_p_mps; *p != NUL; p += 2)
    {
#ifdef FEAT_RIGHTLEFT
	if (*p == c && (curwin->w_p_rl ^ p_ri))
	    break;
#endif
	p += 2;
	if (*p == c
#ifdef FEAT_RIGHTLEFT
		&& !(curwin->w_p_rl ^ p_ri)
#endif
	   )
	    break;
	if (p[1] != ',')
	    return;
    }

    if ((lpos = findmatch(NULL, NUL)) == NULL)	    /* no match, so beep */
	vim_beep();
    else if (lpos->lnum >= curwin->w_topline)
    {
	if (!curwin->w_p_wrap)
	    getvcol(curwin, lpos, NULL, &vcol, NULL);
	if (curwin->w_p_wrap || (vcol >= curwin->w_leftcol
			       && vcol < curwin->w_leftcol + W_WIDTH(curwin)))
	{
	    mpos = *lpos;    /* save the pos, update_screen() may change it */
	    save_cursor = curwin->w_cursor;
	    save_so = p_so;
	    save_siso = p_siso;
	    /* Handle "$" in 'cpo': If the ')' is typed on top of the "$",
	     * stop displaying the "$". */
	    if (dollar_vcol > 0 && dollar_vcol == curwin->w_virtcol)
		dollar_vcol = 0;
	    ++curwin->w_virtcol;	/* do display ')' just before "$" */
	    update_screen(VALID);	/* show the new char first */

	    save_dollar_vcol = dollar_vcol;
#ifdef CURSOR_SHAPE
	    save_state = State;
	    State = SHOWMATCH;
	    ui_cursor_shape();		/* may show different cursor shape */
#endif
	    curwin->w_cursor = mpos;	/* move to matching char */
	    p_so = 0;			/* don't use 'scrolloff' here */
	    p_siso = 0;			/* don't use 'sidescrolloff' here */
	    showruler(FALSE);
	    setcursor();
	    cursor_on();		/* make sure that the cursor is shown */
	    out_flush();
#ifdef FEAT_GUI
	    if (gui.in_use)
	    {
		gui_update_cursor(TRUE, FALSE);
		gui_mch_flush();
	    }
#endif
	    /* Restore dollar_vcol(), because setcursor() may call curs_rows()
	     * which resets it if the matching position is in a previous line
	     * and has a higher column number. */
	    dollar_vcol = save_dollar_vcol;

	    /*
	     * brief pause, unless 'm' is present in 'cpo' and a character is
	     * available.
	     */
	    if (vim_strchr(p_cpo, CPO_SHOWMATCH) != NULL)
		ui_delay(p_mat * 100L, TRUE);
	    else if (!char_avail())
		ui_delay(p_mat * 100L, FALSE);
	    curwin->w_cursor = save_cursor;	/* restore cursor position */
	    p_so = save_so;
	    p_siso = save_siso;
#ifdef CURSOR_SHAPE
	    State = save_state;
	    ui_cursor_shape();		/* may show different cursor shape */
#endif
	}
    }
}

/*
 * findsent(dir, count) - Find the start of the next sentence in direction
 * "dir" Sentences are supposed to end in ".", "!" or "?" followed by white
 * space or a line break. Also stop at an empty line.
 * Return OK if the next sentence was found.
 */
    int
findsent(dir, count)
    int		dir;
    long	count;
{
    pos_T	pos, tpos;
    int		c;
    int		(*func) __ARGS((pos_T *));
    int		startlnum;
    int		noskip = FALSE;	    /* do not skip blanks */
    int		cpo_J;
    int		found_dot;

    pos = curwin->w_cursor;
    if (dir == FORWARD)
	func = incl;
    else
	func = decl;

    while (count--)
    {
	/*
	 * if on an empty line, skip upto a non-empty line
	 */
	if (gchar_pos(&pos) == NUL)
	{
	    do
		if ((*func)(&pos) == -1)
		    break;
	    while (gchar_pos(&pos) == NUL);
	    if (dir == FORWARD)
		goto found;
	}
	/*
	 * if on the start of a paragraph or a section and searching forward,
	 * go to the next line
	 */
	else if (dir == FORWARD && pos.col == 0 &&
						startPS(pos.lnum, NUL, FALSE))
	{
	    if (pos.lnum == curbuf->b_ml.ml_line_count)
		return FAIL;
	    ++pos.lnum;
	    goto found;
	}
	else if (dir == BACKWARD)
	    decl(&pos);

	/* go back to the previous non-blank char */
	found_dot = FALSE;
	while ((c = gchar_pos(&pos)) == ' ' || c == '\t' ||
	     (dir == BACKWARD && vim_strchr((char_u *)".!?)]\"'", c) != NULL))
	{
	    if (vim_strchr((char_u *)".!?", c) != NULL)
	    {
		/* Only skip over a '.', '!' and '?' once. */
		if (found_dot)
		    break;
		found_dot = TRUE;
	    }
	    if (decl(&pos) == -1)
		break;
	    /* when going forward: Stop in front of empty line */
	    if (lineempty(pos.lnum) && dir == FORWARD)
	    {
		incl(&pos);
		goto found;
	    }
	}

	/* remember the line where the search started */
	startlnum = pos.lnum;
	cpo_J = vim_strchr(p_cpo, CPO_ENDOFSENT) != NULL;

	for (;;)		/* find end of sentence */
	{
	    c = gchar_pos(&pos);
	    if (c == NUL || (pos.col == 0 && startPS(pos.lnum, NUL, FALSE)))
	    {
		if (dir == BACKWARD && pos.lnum != startlnum)
		    ++pos.lnum;
		break;
	    }
	    if (c == '.' || c == '!' || c == '?')
	    {
		tpos = pos;
		do
		    if ((c = inc(&tpos)) == -1)
			break;
		while (vim_strchr((char_u *)")]\"'", c = gchar_pos(&tpos))
			!= NULL);
		if (c == -1  || (!cpo_J && (c == ' ' || c == '\t')) || c == NUL
		    || (cpo_J && (c == ' ' && inc(&tpos) >= 0
			      && gchar_pos(&tpos) == ' ')))
		{
		    pos = tpos;
		    if (gchar_pos(&pos) == NUL) /* skip NUL at EOL */
			inc(&pos);
		    break;
		}
	    }
	    if ((*func)(&pos) == -1)
	    {
		if (count)
		    return FAIL;
		noskip = TRUE;
		break;
	    }
	}
found:
	    /* skip white space */
	while (!noskip && ((c = gchar_pos(&pos)) == ' ' || c == '\t'))
	    if (incl(&pos) == -1)
		break;
    }

    setpcmark();
    curwin->w_cursor = pos;
    return OK;
}

/*
 * Find the next paragraph or section in direction 'dir'.
 * Paragraphs are currently supposed to be separated by empty lines.
 * If 'what' is NUL we go to the next paragraph.
 * If 'what' is '{' or '}' we go to the next section.
 * If 'both' is TRUE also stop at '}'.
 * Return TRUE if the next paragraph or section was found.
 */
    int
findpar(pincl, dir, count, what, both)
    int		*pincl;	    /* Return: TRUE if last char is to be included */
    int		dir;
    long	count;
    int		what;
    int		both;
{
    linenr_T	curr;
    int		did_skip;   /* TRUE after separating lines have been skipped */
    int		first;	    /* TRUE on first line */
    int		posix = (vim_strchr(p_cpo, CPO_PARA) != NULL);
#ifdef FEAT_FOLDING
    linenr_T	fold_first; /* first line of a closed fold */
    linenr_T	fold_last;  /* last line of a closed fold */
    int		fold_skipped; /* TRUE if a closed fold was skipped this
				 iteration */
#endif

    curr = curwin->w_cursor.lnum;

    while (count--)
    {
	did_skip = FALSE;
	for (first = TRUE; ; first = FALSE)
	{
	    if (*ml_get(curr) != NUL)
		did_skip = TRUE;

#ifdef FEAT_FOLDING
	    /* skip folded lines */
	    fold_skipped = FALSE;
	    if (first && hasFolding(curr, &fold_first, &fold_last))
	    {
		curr = ((dir > 0) ? fold_last : fold_first) + dir;
		fold_skipped = TRUE;
	    }
#endif

	    /* POSIX has it's own ideas of what a paragraph boundary is and it
	     * doesn't match historical Vi: It also stops at a "{" in the
	     * first column and at an empty line. */
	    if (!first && did_skip && (startPS(curr, what, both)
			   || (posix && what == NUL && *ml_get(curr) == '{')))
		break;

#ifdef FEAT_FOLDING
	    if (fold_skipped)
		curr -= dir;
#endif
	    if ((curr += dir) < 1 || curr > curbuf->b_ml.ml_line_count)
	    {
		if (count)
		    return FALSE;
		curr -= dir;
		break;
	    }
	}
    }
    setpcmark();
    if (both && *ml_get(curr) == '}')	/* include line with '}' */
	++curr;
    curwin->w_cursor.lnum = curr;
    if (curr == curbuf->b_ml.ml_line_count && what != '}')
    {
	if ((curwin->w_cursor.col = (colnr_T)STRLEN(ml_get(curr))) != 0)
	{
	    --curwin->w_cursor.col;
	    *pincl = TRUE;
	}
    }
    else
	curwin->w_cursor.col = 0;
    return TRUE;
}

/*
 * check if the string 's' is a nroff macro that is in option 'opt'
 */
    static int
inmacro(opt, s)
    char_u	*opt;
    char_u	*s;
{
    char_u	*macro;

    for (macro = opt; macro[0]; ++macro)
    {
	/* Accept two characters in the option being equal to two characters
	 * in the line.  A space in the option matches with a space in the
	 * line or the line having ended. */
	if (       (macro[0] == s[0]
		    || (macro[0] == ' '
			&& (s[0] == NUL || s[0] == ' ')))
		&& (macro[1] == s[1]
		    || ((macro[1] == NUL || macro[1] == ' ')
			&& (s[0] == NUL || s[1] == NUL || s[1] == ' '))))
	    break;
	++macro;
	if (macro[0] == NUL)
	    break;
    }
    return (macro[0] != NUL);
}

/*
 * startPS: return TRUE if line 'lnum' is the start of a section or paragraph.
 * If 'para' is '{' or '}' only check for sections.
 * If 'both' is TRUE also stop at '}'
 */
    int
startPS(lnum, para, both)
    linenr_T	lnum;
    int		para;
    int		both;
{
    char_u	*s;

    s = ml_get(lnum);
    if (*s == para || *s == '\f' || (both && *s == '}'))
	return TRUE;
    if (*s == '.' && (inmacro(p_sections, s + 1) ||
					   (!para && inmacro(p_para, s + 1))))
	return TRUE;
    return FALSE;
}

/*
 * The following routines do the word searches performed by the 'w', 'W',
 * 'b', 'B', 'e', and 'E' commands.
 */

/*
 * To perform these searches, characters are placed into one of three
 * classes, and transitions between classes determine word boundaries.
 *
 * The classes are:
 *
 * 0 - white space
 * 1 - punctuation
 * 2 or higher - keyword characters (letters, digits and underscore)
 */

static int	cls_bigword;	/* TRUE for "W", "B" or "E" */

/*
 * cls() - returns the class of character at curwin->w_cursor
 *
 * If a 'W', 'B', or 'E' motion is being done (cls_bigword == TRUE), chars
 * from class 2 and higher are reported as class 1 since only white space
 * boundaries are of interest.
 */
    static int
cls()
{
    int	    c;

    c = gchar_cursor();
#ifdef FEAT_FKMAP	/* when 'akm' (Farsi mode), take care of Farsi blank */
    if (p_altkeymap && c == F_BLANK)
	return 0;
#endif
    if (c == ' ' || c == '\t' || c == NUL)
	return 0;
#ifdef FEAT_MBYTE
    if (enc_dbcs != 0 && c > 0xFF)
    {
	/* If cls_bigword, report multi-byte chars as class 1. */
	if (enc_dbcs == DBCS_KOR && cls_bigword)
	    return 1;

	/* process code leading/trailing bytes */
	return dbcs_class(((unsigned)c >> 8), (c & 0xFF));
    }
    if (enc_utf8)
    {
	c = utf_class(c);
	if (c != 0 && cls_bigword)
	    return 1;
	return c;
    }
#endif

    /* If cls_bigword is TRUE, report all non-blanks as class 1. */
    if (cls_bigword)
	return 1;

    if (vim_iswordc(c))
	return 2;
    return 1;
}


/*
 * fwd_word(count, type, eol) - move forward one word
 *
 * Returns FAIL if the cursor was already at the end of the file.
 * If eol is TRUE, last word stops at end of line (for operators).
 */
    int
fwd_word(count, bigword, eol)
    long	count;
    int		bigword;    /* "W", "E" or "B" */
    int		eol;
{
    int		sclass;	    /* starting class */
    int		i;
    int		last_line;

#ifdef FEAT_VIRTUALEDIT
    curwin->w_cursor.coladd = 0;
#endif
    cls_bigword = bigword;
    while (--count >= 0)
    {
#ifdef FEAT_FOLDING
	/* When inside a range of folded lines, move to the last char of the
	 * last line. */
	if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum))
	    coladvance((colnr_T)MAXCOL);
#endif
	sclass = cls();

	/*
	 * We always move at least one character, unless on the last
	 * character in the buffer.
	 */
	last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count);
	i = inc_cursor();
	if (i == -1 || (i >= 1 && last_line)) /* started at last char in file */
	    return FAIL;
	if (i >= 1 && eol && count == 0)      /* started at last char in line */
	    return OK;

	/*
	 * Go one char past end of current word (if any)
	 */
	if (sclass != 0)
	    while (cls() == sclass)
	    {
		i = inc_cursor();
		if (i == -1 || (i >= 1 && eol && count == 0))
		    return OK;
	    }

	/*
	 * go to next non-white
	 */
	while (cls() == 0)
	{
	    /*
	     * We'll stop if we land on a blank line
	     */
	    if (curwin->w_cursor.col == 0 && *ml_get_curline() == NUL)
		break;

	    i = inc_cursor();
	    if (i == -1 || (i >= 1 && eol && count == 0))
		return OK;
	}
    }
    return OK;
}

/*
 * bck_word() - move backward 'count' words
 *
 * If stop is TRUE and we are already on the start of a word, move one less.
 *
 * Returns FAIL if top of the file was reached.
 */
    int
bck_word(count, bigword, stop)
    long	count;
    int		bigword;
    int		stop;
{
    int		sclass;	    /* starting class */

#ifdef FEAT_VIRTUALEDIT
    curwin->w_cursor.coladd = 0;
#endif
    cls_bigword = bigword;
    while (--count >= 0)
    {
#ifdef FEAT_FOLDING
	/* When inside a range of folded lines, move to the first char of the
	 * first line. */
	if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL))
	    curwin->w_cursor.col = 0;
#endif
	sclass = cls();
	if (dec_cursor() == -1)		/* started at start of file */
	    return FAIL;

	if (!stop || sclass == cls() || sclass == 0)
	{
	    /*
	     * Skip white space before the word.
	     * Stop on an empty line.
	     */
	    while (cls() == 0)
	    {
		if (curwin->w_cursor.col == 0
				      && lineempty(curwin->w_cursor.lnum))
		    goto finished;
		if (dec_cursor() == -1) /* hit start of file, stop here */
		    return OK;
	    }

	    /*
	     * Move backward to start of this word.
	     */
	    if (skip_chars(cls(), BACKWARD))
		return OK;
	}

	inc_cursor();			/* overshot - forward one */
finished:
	stop = FALSE;
    }
    return OK;
}

/*
 * end_word() - move to the end of the word
 *
 * There is an apparent bug in the 'e' motion of the real vi. At least on the
 * System V Release 3 version for the 80386. Unlike 'b' and 'w', the 'e'
 * motion crosses blank lines. When the real vi crosses a blank line in an
 * 'e' motion, the cursor is placed on the FIRST character of the next
 * non-blank line. The 'E' command, however, works correctly. Since this
 * appears to be a bug, I have not duplicated it here.
 *
 * Returns FAIL if end of the file was reached.
 *
 * If stop is TRUE and we are already on the end of a word, move one less.
 * If empty is TRUE stop on an empty line.
 */
    int
end_word(count, bigword, stop, empty)
    long	count;
    int		bigword;
    int		stop;
    int		empty;
{
    int		sclass;	    /* starting class */

#ifdef FEAT_VIRTUALEDIT
    curwin->w_cursor.coladd = 0;
#endif
    cls_bigword = bigword;
    while (--count >= 0)
    {
#ifdef FEAT_FOLDING
	/* When inside a range of folded lines, move to the last char of the
	 * last line. */
	if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum))
	    coladvance((colnr_T)MAXCOL);
#endif
	sclass = cls();
	if (inc_cursor() == -1)
	    return FAIL;

	/*
	 * If we're in the middle of a word, we just have to move to the end
	 * of it.
	 */
	if (cls() == sclass && sclass != 0)
	{
	    /*
	     * Move forward to end of the current word
	     */
	    if (skip_chars(sclass, FORWARD))
		return FAIL;
	}
	else if (!stop || sclass == 0)
	{
	    /*
	     * We were at the end of a word. Go to the end of the next word.
	     * First skip white space, if 'empty' is TRUE, stop at empty line.
	     */
	    while (cls() == 0)
	    {
		if (empty && curwin->w_cursor.col == 0
					  && lineempty(curwin->w_cursor.lnum))
		    goto finished;
		if (inc_cursor() == -1)	    /* hit end of file, stop here */
		    return FAIL;
	    }

	    /*
	     * Move forward to the end of this word.
	     */
	    if (skip_chars(cls(), FORWARD))
		return FAIL;
	}
	dec_cursor();			/* overshot - one char backward */
finished:
	stop = FALSE;			/* we move only one word less */
    }
    return OK;
}

/*
 * Move back to the end of the word.
 *
 * Returns FAIL if start of the file was reached.
 */
    int
bckend_word(count, bigword, eol)
    long	count;
    int		bigword;    /* TRUE for "B" */
    int		eol;	    /* TRUE: stop at end of line. */
{
    int		sclass;	    /* starting class */
    int		i;

#ifdef FEAT_VIRTUALEDIT
    curwin->w_cursor.coladd = 0;
#endif
    cls_bigword = bigword;
    while (--count >= 0)
    {
	sclass = cls();
	if ((i = dec_cursor()) == -1)
	    return FAIL;
	if (eol && i == 1)
	    return OK;

	/*
	 * Move backward to before the start of this word.
	 */
	if (sclass != 0)
	{
	    while (cls() == sclass)
		if ((i = dec_cursor()) == -1 || (eol && i == 1))
		    return OK;
	}

	/*
	 * Move backward to end of the previous word
	 */
	while (cls() == 0)
	{
	    if (curwin->w_cursor.col == 0 && lineempty(curwin->w_cursor.lnum))
		break;
	    if ((i = dec_cursor()) == -1 || (eol && i == 1))
		return OK;
	}
    }
    return OK;
}

/*
 * Skip a row of characters of the same class.
 * Return TRUE when end-of-file reached, FALSE otherwise.
 */
    static int
skip_chars(cclass, dir)
    int		cclass;
    int		dir;
{
    while (cls() == cclass)
	if ((dir == FORWARD ? inc_cursor() : dec_cursor()) == -1)
	    return TRUE;
    return FALSE;
}

#ifdef FEAT_TEXTOBJ
/*
 * Go back to the start of the word or the start of white space
 */
    static void
back_in_line()
{
    int		sclass;		    /* starting class */

    sclass = cls();
    for (;;)
    {
	if (curwin->w_cursor.col == 0)	    /* stop at start of line */
	    break;
	dec_cursor();
	if (cls() != sclass)		    /* stop at start of word */
	{
	    inc_cursor();
	    break;
	}
    }
}

    static void
find_first_blank(posp)
    pos_T    *posp;
{
    int	    c;

    while (decl(posp) != -1)
    {
	c = gchar_pos(posp);
	if (!vim_iswhite(c))
	{
	    incl(posp);
	    break;
	}
    }
}

/*
 * Skip count/2 sentences and count/2 separating white spaces.
 */
    static void
findsent_forward(count, at_start_sent)
    long    count;
    int	    at_start_sent;	/* cursor is at start of sentence */
{
    while (count--)
    {
	findsent(FORWARD, 1L);
	if (at_start_sent)
	    find_first_blank(&curwin->w_cursor);
	if (count == 0 || at_start_sent)
	    decl(&curwin->w_cursor);
	at_start_sent = !at_start_sent;
    }
}

/*
 * Find word under cursor, cursor at end.
 * Used while an operator is pending, and in Visual mode.
 */
    int
current_word(oap, count, include, bigword)
    oparg_T	*oap;
    long	count;
    int		include;	/* TRUE: include word and white space */
    int		bigword;	/* FALSE == word, TRUE == WORD */
{
    pos_T	start_pos;
    pos_T	pos;
    int		inclusive = TRUE;
    int		include_white = FALSE;

    cls_bigword = bigword;
    clearpos(&start_pos);

#ifdef FEAT_VISUAL
    /* Correct cursor when 'selection' is exclusive */
    if (VIsual_active && *p_sel == 'e' && lt(VIsual, curwin->w_cursor))
	dec_cursor();

    /*
     * When Visual mode is not active, or when the VIsual area is only one
     * character, select the word and/or white space under the cursor.
     */
    if (!VIsual_active || equalpos(curwin->w_cursor, VIsual))
#endif
    {
	/*
	 * Go to start of current word or white space.
	 */
	back_in_line();
	start_pos = curwin->w_cursor;

	/*
	 * If the start is on white space, and white space should be included
	 * ("	word"), or start is not on white space, and white space should
	 * not be included ("word"), find end of word.
	 */
	if ((cls() == 0) == include)
	{
	    if (end_word(1L, bigword, TRUE, TRUE) == FAIL)
		return FAIL;
	}
	else
	{
	    /*
	     * If the start is not on white space, and white space should be
	     * included ("word	 "), or start is on white space and white
	     * space should not be included ("	 "), find start of word.
	     * If we end up in the first column of the next line (single char
	     * word) back up to end of the line.
	     */
	    fwd_word(1L, bigword, TRUE);
	    if (curwin->w_cursor.col == 0)
		decl(&curwin->w_cursor);
	    else
		oneleft();

	    if (include)
		include_white = TRUE;
	}

#ifdef FEAT_VISUAL
	if (VIsual_active)
	{
	    /* should do something when inclusive == FALSE ! */
	    VIsual = start_pos;
	    redraw_curbuf_later(INVERTED);	/* update the inversion */
	}
	else
#endif
	{
	    oap->start = start_pos;
	    oap->motion_type = MCHAR;
	}
	--count;
    }

    /*
     * When count is still > 0, extend with more objects.
     */
    while (count > 0)
    {
	inclusive = TRUE;
#ifdef FEAT_VISUAL
	if (VIsual_active && lt(curwin->w_cursor, VIsual))
	{
	    /*
	     * In Visual mode, with cursor at start: move cursor back.
	     */
	    if (decl(&curwin->w_cursor) == -1)
		return FAIL;
	    if (include != (cls() != 0))
	    {
		if (bck_word(1L, bigword, TRUE) == FAIL)
		    return FAIL;
	    }
	    else
	    {
		if (bckend_word(1L, bigword, TRUE) == FAIL)
		    return FAIL;
		(void)incl(&curwin->w_cursor);
	    }
	}
	else
#endif
	{
	    /*
	     * Move cursor forward one word and/or white area.
	     */
	    if (incl(&curwin->w_cursor) == -1)
		return FAIL;
	    if (include != (cls() == 0))
	    {
		if (fwd_word(1L, bigword, TRUE) == FAIL && count > 1)
		    return FAIL;
		/*
		 * If end is just past a new-line, we don't want to include
		 * the first character on the line.
		 * Put cursor on last char of white.
		 */
		if (oneleft() == FAIL)
		    inclusive = FALSE;
	    }
	    else
	    {
		if (end_word(1L, bigword, TRUE, TRUE) == FAIL)
		    return FAIL;
	    }
	}
	--count;
    }

    if (include_white && (cls() != 0
		 || (curwin->w_cursor.col == 0 && !inclusive)))
    {
	/*
	 * If we don't include white space at the end, move the start
	 * to include some white space there. This makes "daw" work
	 * better on the last word in a sentence (and "2daw" on last-but-one
	 * word).  Also when "2daw" deletes "word." at the end of the line
	 * (cursor is at start of next line).
	 * But don't delete white space at start of line (indent).
	 */
	pos = curwin->w_cursor;	/* save cursor position */
	curwin->w_cursor = start_pos;
	if (oneleft() == OK)
	{
	    back_in_line();
	    if (cls() == 0 && curwin->w_cursor.col > 0)
	    {
#ifdef FEAT_VISUAL
		if (VIsual_active)
		    VIsual = curwin->w_cursor;
		else
#endif
		    oap->start = curwin->w_cursor;
	    }
	}
	curwin->w_cursor = pos;	/* put cursor back at end */
    }

#ifdef FEAT_VISUAL
    if (VIsual_active)
    {
	if (*p_sel == 'e' && inclusive && ltoreq(VIsual, curwin->w_cursor))
	    inc_cursor();
	if (VIsual_mode == 'V')
	{
	    VIsual_mode = 'v';
	    redraw_cmdline = TRUE;		/* show mode later */
	}
    }
    else
#endif
	oap->inclusive = inclusive;

    return OK;
}

/*
 * Find sentence(s) under the cursor, cursor at end.
 * When Visual active, extend it by one or more sentences.
 */
    int
current_sent(oap, count, include)
    oparg_T	*oap;
    long	count;
    int		include;
{
    pos_T	start_pos;
    pos_T	pos;
    int		start_blank;
    int		c;
    int		at_start_sent;
    long	ncount;

    start_pos = curwin->w_cursor;
    pos = start_pos;
    findsent(FORWARD, 1L);	/* Find start of next sentence. */

#ifdef FEAT_VISUAL
    /*
     * When visual area is bigger than one character: Extend it.
     */
    if (VIsual_active && !equalpos(start_pos, VIsual))
    {
extend:
	if (lt(start_pos, VIsual))
	{
	    /*
	     * Cursor at start of Visual area.
	     * Find out where we are:
	     * - in the white space before a sentence
	     * - in a sentence or just after it
	     * - at the start of a sentence
	     */
	    at_start_sent = TRUE;
	    decl(&pos);
	    while (lt(pos, curwin->w_cursor))
	    {
		c = gchar_pos(&pos);
		if (!vim_iswhite(c))
		{
		    at_start_sent = FALSE;
		    break;
		}
		incl(&pos);
	    }
	    if (!at_start_sent)
	    {
		findsent(BACKWARD, 1L);
		if (equalpos(curwin->w_cursor, start_pos))
		    at_start_sent = TRUE;  /* exactly at start of sentence */
		else
		    /* inside a sentence, go to its end (start of next) */
		    findsent(FORWARD, 1L);
	    }
	    if (include)	/* "as" gets twice as much as "is" */
		count *= 2;
	    while (count--)
	    {
		if (at_start_sent)
		    find_first_blank(&curwin->w_cursor);
		c = gchar_cursor();
		if (!at_start_sent || (!include && !vim_iswhite(c)))
		    findsent(BACKWARD, 1L);
		at_start_sent = !at_start_sent;
	    }
	}
	else
	{
	    /*
	     * Cursor at end of Visual area.
	     * Find out where we are:
	     * - just before a sentence
	     * - just before or in the white space before a sentence
	     * - in a sentence
	     */
	    incl(&pos);
	    at_start_sent = TRUE;
	    if (!equalpos(pos, curwin->w_cursor)) /* not just before a sentence */
	    {
		at_start_sent = FALSE;
		while (lt(pos, curwin->w_cursor))
		{
		    c = gchar_pos(&pos);
		    if (!vim_iswhite(c))
		    {
			at_start_sent = TRUE;
			break;
		    }
		    incl(&pos);
		}
		if (at_start_sent)	/* in the sentence */
		    findsent(BACKWARD, 1L);
		else		/* in/before white before a sentence */
		    curwin->w_cursor = start_pos;
	    }

	    if (include)	/* "as" gets twice as much as "is" */
		count *= 2;
	    findsent_forward(count, at_start_sent);
	    if (*p_sel == 'e')
		++curwin->w_cursor.col;
	}
	return OK;
    }
#endif

    /*
     * If cursor started on blank, check if it is just before the start of the
     * next sentence.
     */
    while (c = gchar_pos(&pos), vim_iswhite(c))	/* vim_iswhite() is a macro */
	incl(&pos);
    if (equalpos(pos, curwin->w_cursor))
    {
	start_blank = TRUE;
	find_first_blank(&start_pos);	/* go back to first blank */
    }
    else
    {
	start_blank = FALSE;
	findsent(BACKWARD, 1L);
	start_pos = curwin->w_cursor;
    }
    if (include)
	ncount = count * 2;
    else
    {
	ncount = count;
	if (start_blank)
	    --ncount;
    }
    if (ncount > 0)
	findsent_forward(ncount, TRUE);
    else
	decl(&curwin->w_cursor);

    if (include)
    {
	/*
	 * If the blank in front of the sentence is included, exclude the
	 * blanks at the end of the sentence, go back to the first blank.
	 * If there are no trailing blanks, try to include leading blanks.
	 */
	if (start_blank)
	{
	    find_first_blank(&curwin->w_cursor);
	    c = gchar_pos(&curwin->w_cursor);	/* vim_iswhite() is a macro */
	    if (vim_iswhite(c))
		decl(&curwin->w_cursor);
	}
	else if (c = gchar_cursor(), !vim_iswhite(c))
	    find_first_blank(&start_pos);
    }

#ifdef FEAT_VISUAL
    if (VIsual_active)
    {
	/* avoid getting stuck with "is" on a single space before a sent. */
	if (equalpos(start_pos, curwin->w_cursor))
	    goto extend;
	if (*p_sel == 'e')
	    ++curwin->w_cursor.col;
	VIsual = start_pos;
	VIsual_mode = 'v';
	redraw_curbuf_later(INVERTED);	/* update the inversion */
    }
    else
#endif
    {
	/* include a newline after the sentence, if there is one */
	if (incl(&curwin->w_cursor) == -1)
	    oap->inclusive = TRUE;
	else
	    oap->inclusive = FALSE;
	oap->start = start_pos;
	oap->motion_type = MCHAR;
    }
    return OK;
}

/*
 * Find block under the cursor, cursor at end.
 * "what" and "other" are two matching parenthesis/paren/etc.
 */
    int
current_block(oap, count, include, what, other)
    oparg_T	*oap;
    long	count;
    int		include;	/* TRUE == include white space */
    int		what;		/* '(', '{', etc. */
    int		other;		/* ')', '}', etc. */
{
    pos_T	old_pos;
    pos_T	*pos = NULL;
    pos_T	start_pos;
    pos_T	*end_pos;
    pos_T	old_start, old_end;
    char_u	*save_cpo;
    int		sol = FALSE;		/* '{' at start of line */

    old_pos = curwin->w_cursor;
    old_end = curwin->w_cursor;		/* remember where we started */
    old_start = old_end;

    /*
     * If we start on '(', '{', ')', '}', etc., use the whole block inclusive.
     */
#ifdef FEAT_VISUAL
    if (!VIsual_active || equalpos(VIsual, curwin->w_cursor))
#endif
    {
	setpcmark();
	if (what == '{')		/* ignore indent */
	    while (inindent(1))
		if (inc_cursor() != 0)
		    break;
	if (gchar_cursor() == what)
	    /* cursor on '(' or '{', move cursor just after it */
	    ++curwin->w_cursor.col;
    }
#ifdef FEAT_VISUAL
    else if (lt(VIsual, curwin->w_cursor))
    {
	old_start = VIsual;
	curwin->w_cursor = VIsual;	    /* cursor at low end of Visual */
    }
    else
	old_end = VIsual;
#endif

    /*
     * Search backwards for unclosed '(', '{', etc..
     * Put this position in start_pos.
     * Ignore quotes here.
     */
    save_cpo = p_cpo;
    p_cpo = (char_u *)"%";
    while (count-- > 0)
    {
	if ((pos = findmatch(NULL, what)) == NULL)
	    break;
	curwin->w_cursor = *pos;
	start_pos = *pos;   /* the findmatch for end_pos will overwrite *pos */
    }
    p_cpo = save_cpo;

    /*
     * Search for matching ')', '}', etc.
     * Put this position in curwin->w_cursor.
     */
    if (pos == NULL || (end_pos = findmatch(NULL, other)) == NULL)
    {
	curwin->w_cursor = old_pos;
	return FAIL;
    }
    curwin->w_cursor = *end_pos;

    /*
     * Try to exclude the '(', '{', ')', '}', etc. when "include" is FALSE.
     * If the ending '}' is only preceded by indent, skip that indent.
     * But only if the resulting area is not smaller than what we started with.
     */
    while (!include)
    {
	incl(&start_pos);
	sol = (curwin->w_cursor.col == 0);
	decl(&curwin->w_cursor);
	if (what == '{')
	    while (inindent(1))
	    {
		sol = TRUE;
		if (decl(&curwin->w_cursor) != 0)
		    break;
	    }
#ifdef FEAT_VISUAL
	/*
	 * In Visual mode, when the resulting area is not bigger than what we
	 * started with, extend it to the next block, and then exclude again.
	 */
	if (!lt(start_pos, old_start) && !lt(old_end, curwin->w_cursor)
		&& VIsual_active)
	{
	    curwin->w_cursor = old_start;
	    decl(&curwin->w_cursor);
	    if ((pos = findmatch(NULL, what)) == NULL)
	    {
		curwin->w_cursor = old_pos;
		return FAIL;
	    }
	    start_pos = *pos;
	    curwin->w_cursor = *pos;
	    if ((end_pos = findmatch(NULL, other)) == NULL)
	    {
		curwin->w_cursor = old_pos;
		return FAIL;
	    }
	    curwin->w_cursor = *end_pos;
	}
	else
#endif
	    break;
    }

#ifdef FEAT_VISUAL
    if (VIsual_active)
    {
	if (*p_sel == 'e')
	    ++curwin->w_cursor.col;
	if (sol && gchar_cursor() != NUL)
	    inc(&curwin->w_cursor);	/* include the line break */
	VIsual = start_pos;
	VIsual_mode = 'v';
	redraw_curbuf_later(INVERTED);	/* update the inversion */
	showmode();
    }
    else
#endif
    {
	oap->start = start_pos;
	oap->motion_type = MCHAR;
	oap->inclusive = FALSE;
	if (sol)
	    incl(&curwin->w_cursor);
	else if (lt(start_pos, curwin->w_cursor))
	    /* Include the character under the cursor. */
	    oap->inclusive = TRUE;
	else
	    /* End is before the start (no text in between <>, [], etc.): don't
	     * operate on any text. */
	    curwin->w_cursor = start_pos;
    }

    return OK;
}

static int in_html_tag __ARGS((int));

/*
 * Return TRUE if the cursor is on a "<aaa>" tag.  Ignore "<aaa/>".
 * When "end_tag" is TRUE return TRUE if the cursor is on "</aaa>".
 */
    static int
in_html_tag(end_tag)
    int		end_tag;
{
    char_u	*line = ml_get_curline();
    char_u	*p;
    int		c;
    int		lc = NUL;
    pos_T	pos;

#ifdef FEAT_MBYTE
    if (enc_dbcs)
    {
	char_u	*lp = NULL;

	/* We search forward until the cursor, because searching backwards is
	 * very slow for DBCS encodings. */
	for (p = line; p < line + curwin->w_cursor.col; mb_ptr_adv(p))
	    if (*p == '>' || *p == '<')
	    {
		lc = *p;
		lp = p;
	    }
	if (*p != '<')	    /* check for '<' under cursor */
	{
	    if (lc != '<')
		return FALSE;
	    p = lp;
	}
    }
    else
#endif
    {
	for (p = line + curwin->w_cursor.col; p > line; )
	{
	    if (*p == '<')	/* find '<' under/before cursor */
		break;
	    mb_ptr_back(line, p);
	    if (*p == '>')	/* find '>' before cursor */
		break;
	}
	if (*p != '<')
	    return FALSE;
    }

    pos.lnum = curwin->w_cursor.lnum;
    pos.col = (colnr_T)(p - line);

    mb_ptr_adv(p);
    if (end_tag)
	/* check that there is a '/' after the '<' */
	return *p == '/';

    /* check that there is no '/' after the '<' */
    if (*p == '/')
	return FALSE;

    /* check that the matching '>' is not preceded by '/' */
    for (;;)
    {
	if (inc(&pos) < 0)
	    return FALSE;
	c = *ml_get_pos(&pos);
	if (c == '>')
	    break;
	lc = c;
    }
    return lc != '/';
}

/*
 * Find tag block under the cursor, cursor at end.
 */
    int
current_tagblock(oap, count_arg, include)
    oparg_T	*oap;
    long	count_arg;
    int		include;	/* TRUE == include white space */
{
    long	count = count_arg;
    long	n;
    pos_T	old_pos;
    pos_T	start_pos;
    pos_T	end_pos;
    pos_T	old_start, old_end;
    char_u	*spat, *epat;
    char_u	*p;
    char_u	*cp;
    int		len;
    int		r;
    int		do_include = include;
    int		save_p_ws = p_ws;
    int		retval = FAIL;

    p_ws = FALSE;

    old_pos = curwin->w_cursor;
    old_end = curwin->w_cursor;		    /* remember where we started */
    old_start = old_end;

    /*
     * If we start on "<aaa>" select that block.
     */
#ifdef FEAT_VISUAL
    if (!VIsual_active || equalpos(VIsual, curwin->w_cursor))
#endif
    {
	setpcmark();

	/* ignore indent */
	while (inindent(1))
	    if (inc_cursor() != 0)
		break;

	if (in_html_tag(FALSE))
	{
	    /* cursor on start tag, move to its '>' */
	    while (*ml_get_cursor() != '>')
		if (inc_cursor() < 0)
		    break;
	}
	else if (in_html_tag(TRUE))
	{
	    /* cursor on end tag, move to just before it */
	    while (*ml_get_cursor() != '<')
		if (dec_cursor() < 0)
		    break;
	    dec_cursor();
	    old_end = curwin->w_cursor;
	}
    }
#ifdef FEAT_VISUAL
    else if (lt(VIsual, curwin->w_cursor))
    {
	old_start = VIsual;
	curwin->w_cursor = VIsual;	    /* cursor at low end of Visual */
    }
    else
	old_end = VIsual;
#endif

again:
    /*
     * Search backwards for unclosed "<aaa>".
     * Put this position in start_pos.
     */
    for (n = 0; n < count; ++n)
    {
	if (do_searchpair((char_u *)"<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)",
		    (char_u *)"",
		    (char_u *)"</[^>]*>", BACKWARD, (char_u *)"", 0,
						  NULL, (linenr_T)0, 0L) <= 0)
	{
	    curwin->w_cursor = old_pos;
	    goto theend;
	}
    }
    start_pos = curwin->w_cursor;

    /*
     * Search for matching "</aaa>".  First isolate the "aaa".
     */
    inc_cursor();
    p = ml_get_cursor();
    for (cp = p; *cp != NUL && *cp != '>' && !vim_iswhite(*cp); mb_ptr_adv(cp))
	;
    len = (int)(cp - p);
    if (len == 0)
    {
	curwin->w_cursor = old_pos;
	goto theend;
    }
    spat = alloc(len + 29);
    epat = alloc(len + 9);
    if (spat == NULL || epat == NULL)
    {
	vim_free(spat);
	vim_free(epat);
	curwin->w_cursor = old_pos;
	goto theend;
    }
    sprintf((char *)spat, "<%.*s\\%%(\\_[^>]\\{-}[^/]>\\|>\\)\\c", len, p);
    sprintf((char *)epat, "</%.*s>\\c", len, p);

    r = do_searchpair(spat, (char_u *)"", epat, FORWARD, (char_u *)"",
						    0, NULL, (linenr_T)0, 0L);

    vim_free(spat);
    vim_free(epat);

    if (r < 1 || lt(curwin->w_cursor, old_end))
    {
	/* Can't find other end or it's before the previous end.  Could be a
	 * HTML tag that doesn't have a matching end.  Search backwards for
	 * another starting tag. */
	count = 1;
	curwin->w_cursor = start_pos;
	goto again;
    }

    if (do_include || r < 1)
    {
	/* Include up to the '>'. */
	while (*ml_get_cursor() != '>')
	    if (inc_cursor() < 0)
		break;
    }
    else
    {
	/* Exclude the '<' of the end tag. */
	if (*ml_get_cursor() == '<')
	    dec_cursor();
    }
    end_pos = curwin->w_cursor;

    if (!do_include)
    {
	/* Exclude the start tag. */
	curwin->w_cursor = start_pos;
	while (inc_cursor() >= 0)
	    if (*ml_get_cursor() == '>')
	    {
		inc_cursor();
		start_pos = curwin->w_cursor;
		break;
	    }
	curwin->w_cursor = end_pos;

	/* If we now have the same text as before reset "do_include" and try
	 * again. */
	if (equalpos(start_pos, old_start) && equalpos(end_pos, old_end))
	{
	    do_include = TRUE;
	    curwin->w_cursor = old_start;
	    count = count_arg;
	    goto again;
	}
    }

#ifdef FEAT_VISUAL
    if (VIsual_active)
    {
	/* If the end is before the start there is no text between tags, select
	 * the char under the cursor. */
	if (lt(end_pos, start_pos))
	    curwin->w_cursor = start_pos;
	else if (*p_sel == 'e')
	    ++curwin->w_cursor.col;
	VIsual = start_pos;
	VIsual_mode = 'v';
	redraw_curbuf_later(INVERTED);	/* update the inversion */
	showmode();
    }
    else
#endif
    {
	oap->start = start_pos;
	oap->motion_type = MCHAR;
	if (lt(end_pos, start_pos))
	{
	    /* End is before the start: there is no text between tags; operate
	     * on an empty area. */
	    curwin->w_cursor = start_pos;
	    oap->inclusive = FALSE;
	}
	else
	    oap->inclusive = TRUE;
    }
    retval = OK;

theend:
    p_ws = save_p_ws;
    return retval;
}

    int
current_par(oap, count, include, type)
    oparg_T	*oap;
    long	count;
    int		include;	/* TRUE == include white space */
    int		type;		/* 'p' for paragraph, 'S' for section */
{
    linenr_T	start_lnum;
    linenr_T	end_lnum;
    int		white_in_front;
    int		dir;
    int		start_is_white;
    int		prev_start_is_white;
    int		retval = OK;
    int		do_white = FALSE;
    int		t;
    int		i;

    if (type == 'S')	    /* not implemented yet */
	return FAIL;

    start_lnum = curwin->w_cursor.lnum;

#ifdef FEAT_VISUAL
    /*
     * When visual area is more than one line: extend it.
     */
    if (VIsual_active && start_lnum != VIsual.lnum)
    {
extend:
	if (start_lnum < VIsual.lnum)
	    dir = BACKWARD;
	else
	    dir = FORWARD;
	for (i = count; --i >= 0; )
	{
	    if (start_lnum ==
			   (dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count))
	    {
		retval = FAIL;
		break;
	    }

	    prev_start_is_white = -1;
	    for (t = 0; t < 2; ++t)
	    {
		start_lnum += dir;
		start_is_white = linewhite(start_lnum);
		if (prev_start_is_white == start_is_white)
		{
		    start_lnum -= dir;
		    break;
		}
		for (;;)
		{
		    if (start_lnum == (dir == BACKWARD
					    ? 1 : curbuf->b_ml.ml_line_count))
			break;
		    if (start_is_white != linewhite(start_lnum + dir)
			    || (!start_is_white
				    && startPS(start_lnum + (dir > 0
							     ? 1 : 0), 0, 0)))
			break;
		    start_lnum += dir;
		}
		if (!include)
		    break;
		if (start_lnum == (dir == BACKWARD
					    ? 1 : curbuf->b_ml.ml_line_count))
		    break;
		prev_start_is_white = start_is_white;
	    }
	}
	curwin->w_cursor.lnum = start_lnum;
	curwin->w_cursor.col = 0;
	return retval;
    }
#endif

    /*
     * First move back to the start_lnum of the paragraph or white lines
     */
    white_in_front = linewhite(start_lnum);
    while (start_lnum > 1)
    {
	if (white_in_front)	    /* stop at first white line */
	{
	    if (!linewhite(start_lnum - 1))
		break;
	}
	else		/* stop at first non-white line of start of paragraph */
	{
	    if (linewhite(start_lnum - 1) || startPS(start_lnum, 0, 0))
		break;
	}
	--start_lnum;
    }

    /*
     * Move past the end of any white lines.
     */
    end_lnum = start_lnum;
    while (end_lnum <= curbuf->b_ml.ml_line_count && linewhite(end_lnum))
	++end_lnum;

    --end_lnum;
    i = count;
    if (!include && white_in_front)
	--i;
    while (i--)
    {
	if (end_lnum == curbuf->b_ml.ml_line_count)
	    return FAIL;

	if (!include)
	    do_white = linewhite(end_lnum + 1);

	if (include || !do_white)
	{
	    ++end_lnum;
	    /*
	     * skip to end of paragraph
	     */
	    while (end_lnum < curbuf->b_ml.ml_line_count
		    && !linewhite(end_lnum + 1)
		    && !startPS(end_lnum + 1, 0, 0))
		++end_lnum;
	}

	if (i == 0 && white_in_front && include)
	    break;

	/*
	 * skip to end of white lines after paragraph
	 */
	if (include || do_white)
	    while (end_lnum < curbuf->b_ml.ml_line_count
						   && linewhite(end_lnum + 1))
		++end_lnum;
    }

    /*
     * If there are no empty lines at the end, try to find some empty lines at
     * the start (unless that has been done already).
     */
    if (!white_in_front && !linewhite(end_lnum) && include)
	while (start_lnum > 1 && linewhite(start_lnum - 1))
	    --start_lnum;

#ifdef FEAT_VISUAL
    if (VIsual_active)
    {
	/* Problem: when doing "Vipipip" nothing happens in a single white
	 * line, we get stuck there.  Trap this here. */
	if (VIsual_mode == 'V' && start_lnum == curwin->w_cursor.lnum)
	    goto extend;
	VIsual.lnum = start_lnum;
	VIsual_mode = 'V';
	redraw_curbuf_later(INVERTED);	/* update the inversion */
	showmode();
    }
    else
#endif
    {
	oap->start.lnum = start_lnum;
	oap->start.col = 0;
	oap->motion_type = MLINE;
    }
    curwin->w_cursor.lnum = end_lnum;
    curwin->w_cursor.col = 0;

    return OK;
}

static int find_next_quote __ARGS((char_u *top_ptr, int col, int quotechar, char_u *escape));
static int find_prev_quote __ARGS((char_u *line, int col_start, int quotechar, char_u *escape));

/*
 * Search quote char from string line[col].
 * Quote character escaped by one of the characters in "escape" is not counted
 * as a quote.
 * Returns column number of "quotechar" or -1 when not found.
 */
    static int
find_next_quote(line, col, quotechar, escape)
    char_u	*line;
    int		col;
    int		quotechar;
    char_u	*escape;	/* escape characters, can be NULL */
{
    int		c;

    for (;;)
    {
	c = line[col];
	if (c == NUL)
	    return -1;
	else if (escape != NULL && vim_strchr(escape, c))
	    ++col;
	else if (c == quotechar)
	    break;
#ifdef FEAT_MBYTE
	if (has_mbyte)
	    col += (*mb_ptr2len)(line + col);
	else
#endif
	    ++col;
    }
    return col;
}

/*
 * Search backwards in "line" from column "col_start" to find "quotechar".
 * Quote character escaped by one of the characters in "escape" is not counted
 * as a quote.
 * Return the found column or zero.
 */
    static int
find_prev_quote(line, col_start, quotechar, escape)
    char_u	*line;
    int		col_start;
    int		quotechar;
    char_u	*escape;	/* escape characters, can be NULL */
{
    int		n;

    while (col_start > 0)
    {
	--col_start;
#ifdef FEAT_MBYTE
	col_start -= (*mb_head_off)(line, line + col_start);
#endif
	n = 0;
	if (escape != NULL)
	    while (col_start - n > 0 && vim_strchr(escape,
					     line[col_start - n - 1]) != NULL)
	    ++n;
	if (n & 1)
	    col_start -= n;	/* uneven number of escape chars, skip it */
	else if (line[col_start] == quotechar)
	    break;
    }
    return col_start;
}

/*
 * Find quote under the cursor, cursor at end.
 * Returns TRUE if found, else FALSE.
 */
    int
current_quote(oap, count, include, quotechar)
    oparg_T	*oap;
    long	count;
    int		include;	/* TRUE == include quote char */
    int		quotechar;	/* Quote character */
{
    char_u	*line = ml_get_curline();
    int		col_end;
    int		col_start = curwin->w_cursor.col;
    int		inclusive = FALSE;
#ifdef FEAT_VISUAL
    int		vis_empty = TRUE;	/* Visual selection <= 1 char */
    int		vis_bef_curs = FALSE;	/* Visual starts before cursor */
    int		inside_quotes = FALSE;	/* Looks like "i'" done before */
    int		selected_quote = FALSE;	/* Has quote inside selection */
    int		i;

    /* Correct cursor when 'selection' is exclusive */
    if (VIsual_active)
    {
	vis_bef_curs = lt(VIsual, curwin->w_cursor);
	if (*p_sel == 'e' && vis_bef_curs)
	    dec_cursor();
	vis_empty = equalpos(VIsual, curwin->w_cursor);
    }

    if (!vis_empty)
    {
	/* Check if the existing selection exactly spans the text inside
	 * quotes. */
	if (vis_bef_curs)
	{
	    inside_quotes = VIsual.col > 0
			&& line[VIsual.col - 1] == quotechar
			&& line[curwin->w_cursor.col] != NUL
			&& line[curwin->w_cursor.col + 1] == quotechar;
	    i = VIsual.col;
	    col_end = curwin->w_cursor.col;
	}
	else
	{
	    inside_quotes = curwin->w_cursor.col > 0
			&& line[curwin->w_cursor.col - 1] == quotechar
			&& line[VIsual.col] != NUL
			&& line[VIsual.col + 1] == quotechar;
	    i = curwin->w_cursor.col;
	    col_end = VIsual.col;
	}

	/* Find out if we have a quote in the selection. */
	while (i <= col_end)
	    if (line[i++] == quotechar)
	    {
		selected_quote = TRUE;
		break;
	    }
    }

    if (!vis_empty && line[col_start] == quotechar)
    {
	/* Already selecting something and on a quote character.  Find the
	 * next quoted string. */
	if (vis_bef_curs)
	{
	    /* Assume we are on a closing quote: move to after the next
	     * opening quote. */
	    col_start = find_next_quote(line, col_start + 1, quotechar, NULL);
	    if (col_start < 0)
		return FALSE;
	    col_end = find_next_quote(line, col_start + 1, quotechar,
							      curbuf->b_p_qe);
	    if (col_end < 0)
	    {
		/* We were on a starting quote perhaps? */
		col_end = col_start;
		col_start = curwin->w_cursor.col;
	    }
	}
	else
	{
	    col_end = find_prev_quote(line, col_start, quotechar, NULL);
	    if (line[col_end] != quotechar)
		return FALSE;
	    col_start = find_prev_quote(line, col_end, quotechar,
							      curbuf->b_p_qe);
	    if (line[col_start] != quotechar)
	    {
		/* We were on an ending quote perhaps? */
		col_start = col_end;
		col_end = curwin->w_cursor.col;
	    }
	}
    }
    else
#endif

    if (line[col_start] == quotechar
#ifdef FEAT_VISUAL
	    || !vis_empty
#endif
	    )
    {
	int	first_col = col_start;

#ifdef FEAT_VISUAL
	if (!vis_empty)
	{
	    if (vis_bef_curs)
		first_col = find_next_quote(line, col_start, quotechar, NULL);
	    else
		first_col = find_prev_quote(line, col_start, quotechar, NULL);
	}
#endif
	/* The cursor is on a quote, we don't know if it's the opening or
	 * closing quote.  Search from the start of the line to find out.
	 * Also do this when there is a Visual area, a' may leave the cursor
	 * in between two strings. */
	col_start = 0;
	for (;;)
	{
	    /* Find open quote character. */
	    col_start = find_next_quote(line, col_start, quotechar, NULL);
	    if (col_start < 0 || col_start > first_col)
		return FALSE;
	    /* Find close quote character. */
	    col_end = find_next_quote(line, col_start + 1, quotechar,
							      curbuf->b_p_qe);
	    if (col_end < 0)
		return FALSE;
	    /* If is cursor between start and end quote character, it is
	     * target text object. */
	    if (col_start <= first_col && first_col <= col_end)
		break;
	    col_start = col_end + 1;
	}
    }
    else
    {
	/* Search backward for a starting quote. */
	col_start = find_prev_quote(line, col_start, quotechar, curbuf->b_p_qe);
	if (line[col_start] != quotechar)
	{
	    /* No quote before the cursor, look after the cursor. */
	    col_start = find_next_quote(line, col_start, quotechar, NULL);
	    if (col_start < 0)
		return FALSE;
	}

	/* Find close quote character. */
	col_end = find_next_quote(line, col_start + 1, quotechar,
							      curbuf->b_p_qe);
	if (col_end < 0)
	    return FALSE;
    }

    /* When "include" is TRUE, include spaces after closing quote or before
     * the starting quote. */
    if (include)
    {
	if (vim_iswhite(line[col_end + 1]))
	    while (vim_iswhite(line[col_end + 1]))
		++col_end;
	else
	    while (col_start > 0 && vim_iswhite(line[col_start - 1]))
		--col_start;
    }

    /* Set start position.  After vi" another i" must include the ".
     * For v2i" include the quotes. */
    if (!include && count < 2
#ifdef FEAT_VISUAL
	    && (vis_empty || !inside_quotes)
#endif
	    )
	++col_start;
    curwin->w_cursor.col = col_start;
#ifdef FEAT_VISUAL
    if (VIsual_active)
    {
	/* Set the start of the Visual area when the Visual area was empty, we
	 * were just inside quotes or the Visual area didn't start at a quote
	 * and didn't include a quote.
	 */
	if (vis_empty
		|| (vis_bef_curs
		    && !selected_quote
		    && (inside_quotes
			|| (line[VIsual.col] != quotechar
			    && (VIsual.col == 0
				|| line[VIsual.col - 1] != quotechar)))))
	{
	    VIsual = curwin->w_cursor;
	    redraw_curbuf_later(INVERTED);
	}
    }
    else
#endif
    {
	oap->start = curwin->w_cursor;
	oap->motion_type = MCHAR;
    }

    /* Set end position. */
    curwin->w_cursor.col = col_end;
    if ((include || count > 1
#ifdef FEAT_VISUAL
		/* After vi" another i" must include the ". */
		|| (!vis_empty && inside_quotes)
#endif
	) && inc_cursor() == 2)
	inclusive = TRUE;
#ifdef FEAT_VISUAL
    if (VIsual_active)
    {
	if (vis_empty || vis_bef_curs)
	{
	    /* decrement cursor when 'selection' is not exclusive */
	    if (*p_sel != 'e')
		dec_cursor();
	}
	else
	{
	    /* Cursor is at start of Visual area.  Set the end of the Visual
	     * area when it was just inside quotes or it didn't end at a
	     * quote. */
	    if (inside_quotes
		    || (!selected_quote
			&& line[VIsual.col] != quotechar
			&& (line[VIsual.col] == NUL
			    || line[VIsual.col + 1] != quotechar)))
	    {
		dec_cursor();
		VIsual = curwin->w_cursor;
	    }
	    curwin->w_cursor.col = col_start;
	}
	if (VIsual_mode == 'V')
	{
	    VIsual_mode = 'v';
	    redraw_cmdline = TRUE;		/* show mode later */
	}
    }
    else
#endif
    {
	/* Set inclusive and other oap's flags. */
	oap->inclusive = inclusive;
    }

    return OK;
}

#endif /* FEAT_TEXTOBJ */

#if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(FEAT_TEXTOBJ) \
	|| defined(PROTO)
/*
 * return TRUE if line 'lnum' is empty or has white chars only.
 */
    int
linewhite(lnum)
    linenr_T	lnum;
{
    char_u  *p;

    p = skipwhite(ml_get(lnum));
    return (*p == NUL);
}
#endif

#if defined(FEAT_FIND_ID) || defined(PROTO)
/*
 * Find identifiers or defines in included files.
 * if p_ic && (compl_cont_status & CONT_SOL) then ptr must be in lowercase.
 */
/*ARGSUSED*/
    void
find_pattern_in_path(ptr, dir, len, whole, skip_comments,
				    type, count, action, start_lnum, end_lnum)
    char_u	*ptr;		/* pointer to search pattern */
    int		dir;		/* direction of expansion */
    int		len;		/* length of search pattern */
    int		whole;		/* match whole words only */
    int		skip_comments;	/* don't match inside comments */
    int		type;		/* Type of search; are we looking for a type?
				   a macro? */
    long	count;
    int		action;		/* What to do when we find it */
    linenr_T	start_lnum;	/* first line to start searching */
    linenr_T	end_lnum;	/* last line for searching */
{
    SearchedFile *files;		/* Stack of included files */
    SearchedFile *bigger;		/* When we need more space */
    int		max_path_depth = 50;
    long	match_count = 1;

    char_u	*pat;
    char_u	*new_fname;
    char_u	*curr_fname = curbuf->b_fname;
    char_u	*prev_fname = NULL;
    linenr_T	lnum;
    int		depth;
    int		depth_displayed;	/* For type==CHECK_PATH */
    int		old_files;
    int		already_searched;
    char_u	*file_line;
    char_u	*line;
    char_u	*p;
    char_u	save_char;
    int		define_matched;
    regmatch_T	regmatch;
    regmatch_T	incl_regmatch;
    regmatch_T	def_regmatch;
    int		matched = FALSE;
    int		did_show = FALSE;
    int		found = FALSE;
    int		i;
    char_u	*already = NULL;
    char_u	*startp = NULL;
    char_u	*inc_opt = NULL;
#ifdef RISCOS
    int		previous_munging = __riscosify_control;
#endif
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
    win_T	*curwin_save = NULL;
#endif

    regmatch.regprog = NULL;
    incl_regmatch.regprog = NULL;
    def_regmatch.regprog = NULL;

    file_line = alloc(LSIZE);
    if (file_line == NULL)
	return;

#ifdef RISCOS
    /* UnixLib knows best how to munge c file names - turn munging back on. */
    int __riscosify_control = 0;
#endif

    if (type != CHECK_PATH && type != FIND_DEFINE
#ifdef FEAT_INS_EXPAND
	/* when CONT_SOL is set compare "ptr" with the beginning of the line
	 * is faster than quote_meta/regcomp/regexec "ptr" -- Acevedo */
	    && !(compl_cont_status & CONT_SOL)
#endif
       )
    {
	pat = alloc(len + 5);
	if (pat == NULL)
	    goto fpip_end;
	sprintf((char *)pat, whole ? "\\<%.*s\\>" : "%.*s", len, ptr);
	/* ignore case according to p_ic, p_scs and pat */
	regmatch.rm_ic = ignorecase(pat);
	regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
	vim_free(pat);
	if (regmatch.regprog == NULL)
	    goto fpip_end;
    }
    inc_opt = (*curbuf->b_p_inc == NUL) ? p_inc : curbuf->b_p_inc;
    if (*inc_opt != NUL)
    {
	incl_regmatch.regprog = vim_regcomp(inc_opt, p_magic ? RE_MAGIC : 0);
	if (incl_regmatch.regprog == NULL)
	    goto fpip_end;
	incl_regmatch.rm_ic = FALSE;	/* don't ignore case in incl. pat. */
    }
    if (type == FIND_DEFINE && (*curbuf->b_p_def != NUL || *p_def != NUL))
    {
	def_regmatch.regprog = vim_regcomp(*curbuf->b_p_def == NUL
			   ? p_def : curbuf->b_p_def, p_magic ? RE_MAGIC : 0);
	if (def_regmatch.regprog == NULL)
	    goto fpip_end;
	def_regmatch.rm_ic = FALSE;	/* don't ignore case in define pat. */
    }
    files = (SearchedFile *)lalloc_clear((long_u)
			       (max_path_depth * sizeof(SearchedFile)), TRUE);
    if (files == NULL)
	goto fpip_end;
    old_files = max_path_depth;
    depth = depth_displayed = -1;

    lnum = start_lnum;
    if (end_lnum > curbuf->b_ml.ml_line_count)
	end_lnum = curbuf->b_ml.ml_line_count;
    if (lnum > end_lnum)		/* do at least one line */
	lnum = end_lnum;
    line = ml_get(lnum);

    for (;;)
    {
	if (incl_regmatch.regprog != NULL
		&& vim_regexec(&incl_regmatch, line, (colnr_T)0))
	{
	    char_u *p_fname = (curr_fname == curbuf->b_fname)
					      ? curbuf->b_ffname : curr_fname;

	    if (inc_opt != NULL && strstr((char *)inc_opt, "\\zs") != NULL)
		/* Use text from '\zs' to '\ze' (or end) of 'include'. */
		new_fname = find_file_name_in_path(incl_regmatch.startp[0],
			      (int)(incl_regmatch.endp[0] - incl_regmatch.startp[0]),
				 FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname);
	    else
		/* Use text after match with 'include'. */
		new_fname = file_name_in_line(incl_regmatch.endp[0], 0,
			     FNAME_EXP|FNAME_INCL|FNAME_REL, 1L, p_fname, NULL);
	    already_searched = FALSE;
	    if (new_fname != NULL)
	    {
		/* Check whether we have already searched in this file */
		for (i = 0;; i++)
		{
		    if (i == depth + 1)
			i = old_files;
		    if (i == max_path_depth)
			break;
		    if (fullpathcmp(new_fname, files[i].name, TRUE) & FPC_SAME)
		    {
			if (type != CHECK_PATH &&
				action == ACTION_SHOW_ALL && files[i].matched)
			{
			    msg_putchar('\n');	    /* cursor below last one */
			    if (!got_int)	    /* don't display if 'q'
						       typed at "--more--"
						       mesage */
			    {
				msg_home_replace_hl(new_fname);
				MSG_PUTS(_(" (includes previously listed match)"));
				prev_fname = NULL;
			    }
			}
			vim_free(new_fname);
			new_fname = NULL;
			already_searched = TRUE;
			break;
		    }
		}
	    }

	    if (type == CHECK_PATH && (action == ACTION_SHOW_ALL
				 || (new_fname == NULL && !already_searched)))
	    {
		if (did_show)
		    msg_putchar('\n');	    /* cursor below last one */
		else
		{
		    gotocmdline(TRUE);	    /* cursor at status line */
		    MSG_PUTS_TITLE(_("--- Included files "));
		    if (action != ACTION_SHOW_ALL)
			MSG_PUTS_TITLE(_("not found "));
		    MSG_PUTS_TITLE(_("in path ---\n"));
		}
		did_show = TRUE;
		while (depth_displayed < depth && !got_int)
		{
		    ++depth_displayed;
		    for (i = 0; i < depth_displayed; i++)
			MSG_PUTS("  ");
		    msg_home_replace(files[depth_displayed].name);
		    MSG_PUTS(" -->\n");
		}
		if (!got_int)		    /* don't display if 'q' typed
					       for "--more--" message */
		{
		    for (i = 0; i <= depth_displayed; i++)
			MSG_PUTS("  ");
		    if (new_fname != NULL)
		    {
			/* using "new_fname" is more reliable, e.g., when
			 * 'includeexpr' is set. */
			msg_outtrans_attr(new_fname, hl_attr(HLF_D));
		    }
		    else
		    {
			/*
			 * Isolate the file name.
			 * Include the surrounding "" or <> if present.
			 */
			for (p = incl_regmatch.endp[0]; !vim_isfilec(*p); p++)
			    ;
			for (i = 0; vim_isfilec(p[i]); i++)
			    ;
			if (i == 0)
			{
			    /* Nothing found, use the rest of the line. */
			    p = incl_regmatch.endp[0];
			    i = (int)STRLEN(p);
			}
			else
			{
			    if (p[-1] == '"' || p[-1] == '<')
			    {
				--p;
				++i;
			    }
			    if (p[i] == '"' || p[i] == '>')
				++i;
			}
			save_char = p[i];
			p[i] = NUL;
			msg_outtrans_attr(p, hl_attr(HLF_D));
			p[i] = save_char;
		    }

		    if (new_fname == NULL && action == ACTION_SHOW_ALL)
		    {
			if (already_searched)
			    MSG_PUTS(_("  (Already listed)"));
			else
			    MSG_PUTS(_("  NOT FOUND"));
		    }
		}
		out_flush();	    /* output each line directly */
	    }

	    if (new_fname != NULL)
	    {
		/* Push the new file onto the file stack */
		if (depth + 1 == old_files)
		{
		    bigger = (SearchedFile *)lalloc((long_u)(
			    max_path_depth * 2 * sizeof(SearchedFile)), TRUE);
		    if (bigger != NULL)
		    {
			for (i = 0; i <= depth; i++)
			    bigger[i] = files[i];
			for (i = depth + 1; i < old_files + max_path_depth; i++)
			{
			    bigger[i].fp = NULL;
			    bigger[i].name = NULL;
			    bigger[i].lnum = 0;
			    bigger[i].matched = FALSE;
			}
			for (i = old_files; i < max_path_depth; i++)
			    bigger[i + max_path_depth] = files[i];
			old_files += max_path_depth;
			max_path_depth *= 2;
			vim_free(files);
			files = bigger;
		    }
		}
		if ((files[depth + 1].fp = mch_fopen((char *)new_fname, "r"))
								    == NULL)
		    vim_free(new_fname);
		else
		{
		    if (++depth == old_files)
		    {
			/*
			 * lalloc() for 'bigger' must have failed above.  We
			 * will forget one of our already visited files now.
			 */
			vim_free(files[old_files].name);
			++old_files;
		    }
		    files[depth].name = curr_fname = new_fname;
		    files[depth].lnum = 0;
		    files[depth].matched = FALSE;
#ifdef FEAT_INS_EXPAND
		    if (action == ACTION_EXPAND)
		    {
			msg_hist_off = TRUE;	/* reset in msg_trunc_attr() */
			vim_snprintf((char*)IObuff, IOSIZE,
				_("Scanning included file: %s"),
				(char *)new_fname);
			msg_trunc_attr(IObuff, TRUE, hl_attr(HLF_R));
		    }
		    else
#endif
			 if (p_verbose >= 5)
		    {
			verbose_enter();
			smsg((char_u *)_("Searching included file %s"),
							   (char *)new_fname);
			verbose_leave();
		    }

		}
	    }
	}
	else
	{
	    /*
	     * Check if the line is a define (type == FIND_DEFINE)
	     */
	    p = line;
search_line:
	    define_matched = FALSE;
	    if (def_regmatch.regprog != NULL
			      && vim_regexec(&def_regmatch, line, (colnr_T)0))
	    {
		/*
		 * Pattern must be first identifier after 'define', so skip
		 * to that position before checking for match of pattern.  Also
		 * don't let it match beyond the end of this identifier.
		 */
		p = def_regmatch.endp[0];
		while (*p && !vim_iswordc(*p))
		    p++;
		define_matched = TRUE;
	    }

	    /*
	     * Look for a match.  Don't do this if we are looking for a
	     * define and this line didn't match define_prog above.
	     */
	    if (def_regmatch.regprog == NULL || define_matched)
	    {
		if (define_matched
#ifdef FEAT_INS_EXPAND
			|| (compl_cont_status & CONT_SOL)
#endif
		    )
		{
		    /* compare the first "len" chars from "ptr" */
		    startp = skipwhite(p);
		    if (p_ic)
			matched = !MB_STRNICMP(startp, ptr, len);
		    else
			matched = !STRNCMP(startp, ptr, len);
		    if (matched && define_matched && whole
						  && vim_iswordc(startp[len]))
			matched = FALSE;
		}
		else if (regmatch.regprog != NULL
			 && vim_regexec(&regmatch, line, (colnr_T)(p - line)))
		{
		    matched = TRUE;
		    startp = regmatch.startp[0];
		    /*
		     * Check if the line is not a comment line (unless we are
		     * looking for a define).  A line starting with "# define"
		     * is not considered to be a comment line.
		     */
		    if (!define_matched && skip_comments)
		    {
#ifdef FEAT_COMMENTS
			if ((*line != '#' ||
				STRNCMP(skipwhite(line + 1), "define", 6) != 0)
				&& get_leader_len(line, NULL, FALSE))
			    matched = FALSE;

			/*
			 * Also check for a "/ *" or "/ /" before the match.
			 * Skips lines like "int backwards;  / * normal index
			 * * /" when looking for "normal".
			 * Note: Doesn't skip "/ *" in comments.
			 */
			p = skipwhite(line);
			if (matched
				|| (p[0] == '/' && p[1] == '*') || p[0] == '*')
#endif
			    for (p = line; *p && p < startp; ++p)
			    {
				if (matched
					&& p[0] == '/'
					&& (p[1] == '*' || p[1] == '/'))
				{
				    matched = FALSE;
				    /* After "//" all text is comment */
				    if (p[1] == '/')
					break;
				    ++p;
				}
				else if (!matched && p[0] == '*' && p[1] == '/')
				{
				    /* Can find match after "* /". */
				    matched = TRUE;
				    ++p;
				}
			    }
		    }
		}
	    }
	}
	if (matched)
	{
#ifdef FEAT_INS_EXPAND
	    if (action == ACTION_EXPAND)
	    {
		int	reuse = 0;
		int	add_r;
		char_u	*aux;

		if (depth == -1 && lnum == curwin->w_cursor.lnum)
		    break;
		found = TRUE;
		aux = p = startp;
		if (compl_cont_status & CONT_ADDING)
		{
		    p += compl_length;
		    if (vim_iswordp(p))
			goto exit_matched;
		    p = find_word_start(p);
		}
		p = find_word_end(p);
		i = (int)(p - aux);

		if ((compl_cont_status & CONT_ADDING) && i == compl_length)
		{
		    /* IOSIZE > compl_length, so the STRNCPY works */
		    STRNCPY(IObuff, aux, i);

		    /* Get the next line: when "depth" < 0  from the current
		     * buffer, otherwise from the included file.  Jump to
		     * exit_matched when past the last line. */
		    if (depth < 0)
		    {
			if (lnum >= end_lnum)
			    goto exit_matched;
			line = ml_get(++lnum);
		    }
		    else if (vim_fgets(line = file_line,
						      LSIZE, files[depth].fp))
			goto exit_matched;

		    /* we read a line, set "already" to check this "line" later
		     * if depth >= 0 we'll increase files[depth].lnum far
		     * bellow  -- Acevedo */
		    already = aux = p = skipwhite(line);
		    p = find_word_start(p);
		    p = find_word_end(p);
		    if (p > aux)
		    {
			if (*aux != ')' && IObuff[i-1] != TAB)
			{
			    if (IObuff[i-1] != ' ')
				IObuff[i++] = ' ';
			    /* IObuf =~ "\(\k\|\i\).* ", thus i >= 2*/
			    if (p_js
				&& (IObuff[i-2] == '.'
				    || (vim_strchr(p_cpo, CPO_JOINSP) == NULL
					&& (IObuff[i-2] == '?'
					    || IObuff[i-2] == '!'))))
				IObuff[i++] = ' ';
			}
			/* copy as much as posible of the new word */
			if (p - aux >= IOSIZE - i)
			    p = aux + IOSIZE - i - 1;
			STRNCPY(IObuff + i, aux, p - aux);
			i += (int)(p - aux);
			reuse |= CONT_S_IPOS;
		    }
		    IObuff[i] = NUL;
		    aux = IObuff;

		    if (i == compl_length)
			goto exit_matched;
		}

		add_r = ins_compl_add_infercase(aux, i, p_ic,
			curr_fname == curbuf->b_fname ? NULL : curr_fname,
			dir, reuse);
		if (add_r == OK)
		    /* if dir was BACKWARD then honor it just once */
		    dir = FORWARD;
		else if (add_r == FAIL)
		    break;
	    }
	    else
#endif
		 if (action == ACTION_SHOW_ALL)
	    {
		found = TRUE;
		if (!did_show)
		    gotocmdline(TRUE);		/* cursor at status line */
		if (curr_fname != prev_fname)
		{
		    if (did_show)
			msg_putchar('\n');	/* cursor below last one */
		    if (!got_int)		/* don't display if 'q' typed
						    at "--more--" mesage */
			msg_home_replace_hl(curr_fname);
		    prev_fname = curr_fname;
		}
		did_show = TRUE;
		if (!got_int)
		    show_pat_in_path(line, type, TRUE, action,
			    (depth == -1) ? NULL : files[depth].fp,
			    (depth == -1) ? &lnum : &files[depth].lnum,
			    match_count++);

		/* Set matched flag for this file and all the ones that
		 * include it */
		for (i = 0; i <= depth; ++i)
		    files[i].matched = TRUE;
	    }
	    else if (--count <= 0)
	    {
		found = TRUE;
		if (depth == -1 && lnum == curwin->w_cursor.lnum
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
						      && g_do_tagpreview == 0
#endif
						      )
		    EMSG(_("E387: Match is on current line"));
		else if (action == ACTION_SHOW)
		{
		    show_pat_in_path(line, type, did_show, action,
			(depth == -1) ? NULL : files[depth].fp,
			(depth == -1) ? &lnum : &files[depth].lnum, 1L);
		    did_show = TRUE;
		}
		else
		{
#ifdef FEAT_GUI
		    need_mouse_correct = TRUE;
#endif
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
		    /* ":psearch" uses the preview window */
		    if (g_do_tagpreview != 0)
		    {
			curwin_save = curwin;
			prepare_tagpreview(TRUE);
		    }
#endif
		    if (action == ACTION_SPLIT)
		    {
#ifdef FEAT_WINDOWS
			if (win_split(0, 0) == FAIL)
#endif
			    break;
#ifdef FEAT_SCROLLBIND
			curwin->w_p_scb = FALSE;
#endif
		    }
		    if (depth == -1)
		    {
			/* match in current file */
#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
			if (g_do_tagpreview != 0)
			{
			    if (getfile(0, curwin_save->w_buffer->b_fname,
						 NULL, TRUE, lnum, FALSE) > 0)
				break;	/* failed to jump to file */
			}
			else
#endif
			    setpcmark();
			curwin->w_cursor.lnum = lnum;
		    }
		    else
		    {
			if (getfile(0, files[depth].name, NULL, TRUE,
						files[depth].lnum, FALSE) > 0)
			    break;	/* failed to jump to file */
			/* autocommands may have changed the lnum, we don't
			 * want that here */
			curwin->w_cursor.lnum = files[depth].lnum;
		    }
		}
		if (action != ACTION_SHOW)
		{
		    curwin->w_cursor.col = (colnr_T) (startp - line);
		    curwin->w_set_curswant = TRUE;
		}

#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
		if (g_do_tagpreview != 0
			   && curwin != curwin_save && win_valid(curwin_save))
		{
		    /* Return cursor to where we were */
		    validate_cursor();
		    redraw_later(VALID);
		    win_enter(curwin_save, TRUE);
		}
#endif
		break;
	    }
#ifdef FEAT_INS_EXPAND
exit_matched:
#endif
	    matched = FALSE;
	    /* look for other matches in the rest of the line if we
	     * are not at the end of it already */
	    if (def_regmatch.regprog == NULL
#ifdef FEAT_INS_EXPAND
		    && action == ACTION_EXPAND
		    && !(compl_cont_status & CONT_SOL)
#endif
		    && *(p = startp + 1))
		goto search_line;
	}
	line_breakcheck();
#ifdef FEAT_INS_EXPAND
	if (action == ACTION_EXPAND)
	    ins_compl_check_keys(30);
	if (got_int || compl_interrupted)
#else
	if (got_int)
#endif
	    break;

	/*
	 * Read the next line.  When reading an included file and encountering
	 * end-of-file, close the file and continue in the file that included
	 * it.
	 */
	while (depth >= 0 && !already
		&& vim_fgets(line = file_line, LSIZE, files[depth].fp))
	{
	    fclose(files[depth].fp);
	    --old_files;
	    files[old_files].name = files[depth].name;
	    files[old_files].matched = files[depth].matched;
	    --depth;
	    curr_fname = (depth == -1) ? curbuf->b_fname
				       : files[depth].name;
	    if (depth < depth_displayed)
		depth_displayed = depth;
	}
	if (depth >= 0)		/* we could read the line */
	    files[depth].lnum++;
	else if (!already)
	{
	    if (++lnum > end_lnum)
		break;
	    line = ml_get(lnum);
	}
	already = NULL;
    }
    /* End of big for (;;) loop. */

    /* Close any files that are still open. */
    for (i = 0; i <= depth; i++)
    {
	fclose(files[i].fp);
	vim_free(files[i].name);
    }
    for (i = old_files; i < max_path_depth; i++)
	vim_free(files[i].name);
    vim_free(files);

    if (type == CHECK_PATH)
    {
	if (!did_show)
	{
	    if (action != ACTION_SHOW_ALL)
		MSG(_("All included files were found"));
	    else
		MSG(_("No included files"));
	}
    }
    else if (!found
#ifdef FEAT_INS_EXPAND
		    && action != ACTION_EXPAND
#endif
						)
    {
#ifdef FEAT_INS_EXPAND
	if (got_int || compl_interrupted)
#else
	if (got_int)
#endif
	    EMSG(_(e_interr));
	else if (type == FIND_DEFINE)
	    EMSG(_("E388: Couldn't find definition"));
	else
	    EMSG(_("E389: Couldn't find pattern"));
    }
    if (action == ACTION_SHOW || action == ACTION_SHOW_ALL)
	msg_end();

fpip_end:
    vim_free(file_line);
    vim_free(regmatch.regprog);
    vim_free(incl_regmatch.regprog);
    vim_free(def_regmatch.regprog);

#ifdef RISCOS
   /* Restore previous file munging state. */
    __riscosify_control = previous_munging;
#endif
}

    static void
show_pat_in_path(line, type, did_show, action, fp, lnum, count)
    char_u  *line;
    int	    type;
    int	    did_show;
    int	    action;
    FILE    *fp;
    linenr_T *lnum;
    long    count;
{
    char_u  *p;

    if (did_show)
	msg_putchar('\n');	/* cursor below last one */
    else if (!msg_silent)
	gotocmdline(TRUE);	/* cursor at status line */
    if (got_int)		/* 'q' typed at "--more--" message */
	return;
    for (;;)
    {
	p = line + STRLEN(line) - 1;
	if (fp != NULL)
	{
	    /* We used fgets(), so get rid of newline at end */
	    if (p >= line && *p == '\n')
		--p;
	    if (p >= line && *p == '\r')
		--p;
	    *(p + 1) = NUL;
	}
	if (action == ACTION_SHOW_ALL)
	{
	    sprintf((char *)IObuff, "%3ld: ", count);	/* show match nr */
	    msg_puts(IObuff);
	    sprintf((char *)IObuff, "%4ld", *lnum);	/* show line nr */
						/* Highlight line numbers */
	    msg_puts_attr(IObuff, hl_attr(HLF_N));
	    MSG_PUTS(" ");
	}
	msg_prt_line(line, FALSE);
	out_flush();			/* show one line at a time */

	/* Definition continues until line that doesn't end with '\' */
	if (got_int || type != FIND_DEFINE || p < line || *p != '\\')
	    break;

	if (fp != NULL)
	{
	    if (vim_fgets(line, LSIZE, fp)) /* end of file */
		break;
	    ++*lnum;
	}
	else
	{
	    if (++*lnum > curbuf->b_ml.ml_line_count)
		break;
	    line = ml_get(*lnum);
	}
	msg_putchar('\n');
    }
}
#endif

#ifdef FEAT_VIMINFO
    int
read_viminfo_search_pattern(virp, force)
    vir_T	*virp;
    int		force;
{
    char_u	*lp;
    int		idx = -1;
    int		magic = FALSE;
    int		no_scs = FALSE;
    int		off_line = FALSE;
    int		off_end = 0;
    long	off = 0;
    int		setlast = FALSE;
#ifdef FEAT_SEARCH_EXTRA
    static int	hlsearch_on = FALSE;
#endif
    char_u	*val;

    /*
     * Old line types:
     * "/pat", "&pat": search/subst. pat
     * "~/pat", "~&pat": last used search/subst. pat
     * New line types:
     * "~h", "~H": hlsearch highlighting off/on
     * "~<magic><smartcase><line><end><off><last><which>pat"
     * <magic>: 'm' off, 'M' on
     * <smartcase>: 's' off, 'S' on
     * <line>: 'L' line offset, 'l' char offset
     * <end>: 'E' from end, 'e' from start
     * <off>: decimal, offset
     * <last>: '~' last used pattern
     * <which>: '/' search pat, '&' subst. pat
     */
    lp = virp->vir_line;
    if (lp[0] == '~' && (lp[1] == 'm' || lp[1] == 'M'))	/* new line type */
    {
	if (lp[1] == 'M')		/* magic on */
	    magic = TRUE;
	if (lp[2] == 's')
	    no_scs = TRUE;
	if (lp[3] == 'L')
	    off_line = TRUE;
	if (lp[4] == 'E')
	    off_end = SEARCH_END;
	lp += 5;
	off = getdigits(&lp);
    }
    if (lp[0] == '~')		/* use this pattern for last-used pattern */
    {
	setlast = TRUE;
	lp++;
    }
    if (lp[0] == '/')
	idx = RE_SEARCH;
    else if (lp[0] == '&')
	idx = RE_SUBST;
#ifdef FEAT_SEARCH_EXTRA
    else if (lp[0] == 'h')	/* ~h: 'hlsearch' highlighting off */
	hlsearch_on = FALSE;
    else if (lp[0] == 'H')	/* ~H: 'hlsearch' highlighting on */
	hlsearch_on = TRUE;
#endif
    if (idx >= 0)
    {
	if (force || spats[idx].pat == NULL)
	{
	    val = viminfo_readstring(virp, (int)(lp - virp->vir_line + 1),
									TRUE);
	    if (val != NULL)
	    {
		set_last_search_pat(val, idx, magic, setlast);
		vim_free(val);
		spats[idx].no_scs = no_scs;
		spats[idx].off.line = off_line;
		spats[idx].off.end = off_end;
		spats[idx].off.off = off;
#ifdef FEAT_SEARCH_EXTRA
		if (setlast)
		    no_hlsearch = !hlsearch_on;
#endif
	    }
	}
    }
    return viminfo_readline(virp);
}

    void
write_viminfo_search_pattern(fp)
    FILE	*fp;
{
    if (get_viminfo_parameter('/') != 0)
    {
#ifdef FEAT_SEARCH_EXTRA
	fprintf(fp, "\n# hlsearch on (H) or off (h):\n~%c",
	    (no_hlsearch || find_viminfo_parameter('h') != NULL) ? 'h' : 'H');
#endif
	wvsp_one(fp, RE_SEARCH, "", '/');
	wvsp_one(fp, RE_SUBST, "Substitute ", '&');
    }
}

    static void
wvsp_one(fp, idx, s, sc)
    FILE	*fp;	/* file to write to */
    int		idx;	/* spats[] index */
    char	*s;	/* search pat */
    int		sc;	/* dir char */
{
    if (spats[idx].pat != NULL)
    {
	fprintf(fp, _("\n# Last %sSearch Pattern:\n~"), s);
	/* off.dir is not stored, it's reset to forward */
	fprintf(fp, "%c%c%c%c%ld%s%c",
		spats[idx].magic    ? 'M' : 'm',	/* magic */
		spats[idx].no_scs   ? 's' : 'S',	/* smartcase */
		spats[idx].off.line ? 'L' : 'l',	/* line offset */
		spats[idx].off.end  ? 'E' : 'e',	/* offset from end */
		spats[idx].off.off,			/* offset */
		last_idx == idx	    ? "~" : "",		/* last used pat */
		sc);
	viminfo_writestring(fp, spats[idx].pat);
    }
}
#endif /* FEAT_VIMINFO */
