2016-08-29 22:49:24 +02:00
|
|
|
/* vi:set ts=8 sts=4 sw=4 noet:
|
2004-06-13 20:20:40 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_getln.c: Functions for entering and editing an Ex command line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "vim.h"
|
|
|
|
|
2018-08-14 22:08:25 +02:00
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(x,y) ((x) > (y) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Variables shared between getcmdline(), redrawcmdline() and others.
|
|
|
|
* These need to be saved when using CTRL-R |, that's why they are in a
|
|
|
|
* structure.
|
|
|
|
*/
|
|
|
|
struct cmdline_info
|
|
|
|
{
|
|
|
|
char_u *cmdbuff; /* pointer to command line buffer */
|
|
|
|
int cmdbufflen; /* length of cmdbuff */
|
|
|
|
int cmdlen; /* number of chars in command line */
|
|
|
|
int cmdpos; /* current cursor position */
|
|
|
|
int cmdspos; /* cursor column on screen */
|
2012-04-30 18:48:53 +02:00
|
|
|
int cmdfirstc; /* ':', '/', '?', '=', '>' or NUL */
|
2004-06-13 20:20:40 +00:00
|
|
|
int cmdindent; /* number of spaces before cmdline */
|
|
|
|
char_u *cmdprompt; /* message in front of cmdline */
|
|
|
|
int cmdattr; /* attributes for prompt */
|
|
|
|
int overstrike; /* Typing mode on the command line. Shared by
|
|
|
|
getcmdline() and put_on_cmdline(). */
|
2008-09-14 12:42:29 +00:00
|
|
|
expand_T *xpc; /* struct being used for expansion, xp_pattern
|
|
|
|
may point into cmdbuff */
|
2005-09-20 23:22:24 +00:00
|
|
|
int xp_context; /* type of expansion */
|
|
|
|
# ifdef FEAT_EVAL
|
|
|
|
char_u *xp_arg; /* user-defined expansion arg */
|
2006-11-21 10:29:45 +00:00
|
|
|
int input_fn; /* when TRUE Invoked for input() function */
|
2005-09-20 23:22:24 +00:00
|
|
|
# endif
|
2004-06-13 20:20:40 +00:00
|
|
|
};
|
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
// The current cmdline_info. It is initialized in getcmdline() and after that
|
|
|
|
// used by other functions. When invoking getcmdline() recursively it needs
|
|
|
|
// to be saved with save_cmdline() and restored with restore_cmdline().
|
2008-09-14 12:42:29 +00:00
|
|
|
static struct cmdline_info ccline;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
static int cmd_showtail; /* Only show path tail in lists ? */
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
static int new_cmdpos; /* position set by set_cmdline_pos() */
|
|
|
|
#endif
|
|
|
|
|
2017-07-15 15:21:38 +02:00
|
|
|
static int extra_char = NUL; /* extra character to display when redrawing
|
|
|
|
* the command line */
|
2017-07-16 15:24:01 +02:00
|
|
|
static int extra_char_shift;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
static int cmd_hkmap = 0; /* Hebrew mapping during command line */
|
|
|
|
#endif
|
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
static char_u *getcmdline_int(int firstc, long count, int indent, int init_ccline);
|
2016-01-29 22:13:30 +01:00
|
|
|
static int cmdline_charsize(int idx);
|
|
|
|
static void set_cmdspos(void);
|
|
|
|
static void set_cmdspos_cursor(void);
|
|
|
|
static void correct_cmdspos(int idx, int cells);
|
|
|
|
static void alloc_cmdbuff(int len);
|
|
|
|
static int realloc_cmdbuff(int len);
|
|
|
|
static void draw_cmdline(int start, int len);
|
|
|
|
static void save_cmdline(struct cmdline_info *ccp);
|
|
|
|
static void restore_cmdline(struct cmdline_info *ccp);
|
|
|
|
static int cmdline_paste(int regname, int literally, int remcr);
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_WILDMENU
|
2016-01-29 22:13:30 +01:00
|
|
|
static void cmdline_del(int from);
|
|
|
|
#endif
|
|
|
|
static void redrawcmdprompt(void);
|
|
|
|
static void cursorcmd(void);
|
|
|
|
static int ccheck_abbr(int);
|
|
|
|
static int nextwild(expand_T *xp, int type, int options, int escape);
|
|
|
|
static void escape_fname(char_u **pp);
|
|
|
|
static int showmatches(expand_T *xp, int wildmenu);
|
|
|
|
static void set_expand_context(expand_T *xp);
|
|
|
|
static int ExpandFromContext(expand_T *xp, char_u *, int *, char_u ***, int);
|
|
|
|
static int expand_showtail(expand_T *xp);
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_CMDL_COMPL
|
2016-01-29 22:13:30 +01:00
|
|
|
static int expand_shellcmd(char_u *filepat, int *num_file, char_u ***file, int flagsarg);
|
2016-03-13 13:24:45 +01:00
|
|
|
static int ExpandRTDir(char_u *pat, int flags, int *num_file, char_u ***file, char *dirname[]);
|
2016-03-05 17:41:49 +01:00
|
|
|
static int ExpandPackAddDir(char_u *pat, int *num_file, char_u ***file);
|
2019-04-27 13:04:13 +02:00
|
|
|
# if defined(FEAT_EVAL)
|
2016-01-29 22:13:30 +01:00
|
|
|
static int ExpandUserDefined(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file);
|
|
|
|
static int ExpandUserList(expand_T *xp, int *num_file, char_u ***file);
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FEAT_CMDWIN
|
2017-04-07 15:42:25 +02:00
|
|
|
static int open_cmdwin(void);
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
2011-10-26 22:02:15 +02:00
|
|
|
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
2019-05-09 15:12:55 +02:00
|
|
|
static int sort_func_compare(const void *s1, const void *s2);
|
2016-08-26 19:13:46 +02:00
|
|
|
#endif
|
2011-10-26 22:02:15 +02:00
|
|
|
|
2017-10-19 18:35:51 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
trigger_cmd_autocmd(int typechar, int evt)
|
|
|
|
{
|
|
|
|
char_u typestr[2];
|
|
|
|
|
|
|
|
typestr[0] = typechar;
|
|
|
|
typestr[1] = NUL;
|
|
|
|
apply_autocmds(evt, typestr, typestr, FALSE, curbuf);
|
|
|
|
}
|
|
|
|
|
2017-10-22 14:44:17 +02:00
|
|
|
/*
|
|
|
|
* Abandon the command line.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
abandon_cmdline(void)
|
|
|
|
{
|
2018-02-10 18:45:26 +01:00
|
|
|
VIM_CLEAR(ccline.cmdbuff);
|
2017-10-22 14:44:17 +02:00
|
|
|
if (msg_scrolled == 0)
|
|
|
|
compute_cmdrow();
|
2019-01-19 17:43:09 +01:00
|
|
|
msg("");
|
2017-10-22 14:44:17 +02:00
|
|
|
redraw_cmdline = TRUE;
|
|
|
|
}
|
|
|
|
|
2017-12-17 14:55:01 +01:00
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
2017-12-16 16:33:44 +01:00
|
|
|
/*
|
|
|
|
* Guess that the pattern matches everything. Only finds specific cases, such
|
|
|
|
* as a trailing \|, which can happen while typing a pattern.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
empty_pattern(char_u *p)
|
|
|
|
{
|
2018-01-02 15:37:46 +01:00
|
|
|
size_t n = STRLEN(p);
|
2017-12-16 16:33:44 +01:00
|
|
|
|
|
|
|
/* remove trailing \v and the like */
|
|
|
|
while (n >= 2 && p[n - 2] == '\\'
|
|
|
|
&& vim_strchr((char_u *)"mMvVcCZ", p[n - 1]) != NULL)
|
|
|
|
n -= 2;
|
|
|
|
return n == 0 || (n >= 2 && p[n - 2] == '\\' && p[n - 1] == '|');
|
|
|
|
}
|
|
|
|
|
2018-08-10 22:07:32 +02:00
|
|
|
// Struct to store the viewstate during 'incsearch' highlighting.
|
2018-04-28 13:56:09 +02:00
|
|
|
typedef struct {
|
|
|
|
colnr_T vs_curswant;
|
|
|
|
colnr_T vs_leftcol;
|
|
|
|
linenr_T vs_topline;
|
|
|
|
# ifdef FEAT_DIFF
|
|
|
|
int vs_topfill;
|
|
|
|
# endif
|
|
|
|
linenr_T vs_botline;
|
|
|
|
linenr_T vs_empty_rows;
|
|
|
|
} viewstate_T;
|
|
|
|
|
|
|
|
static void
|
|
|
|
save_viewstate(viewstate_T *vs)
|
|
|
|
{
|
|
|
|
vs->vs_curswant = curwin->w_curswant;
|
|
|
|
vs->vs_leftcol = curwin->w_leftcol;
|
|
|
|
vs->vs_topline = curwin->w_topline;
|
|
|
|
# ifdef FEAT_DIFF
|
|
|
|
vs->vs_topfill = curwin->w_topfill;
|
|
|
|
# endif
|
|
|
|
vs->vs_botline = curwin->w_botline;
|
|
|
|
vs->vs_empty_rows = curwin->w_empty_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
restore_viewstate(viewstate_T *vs)
|
|
|
|
{
|
|
|
|
curwin->w_curswant = vs->vs_curswant;
|
|
|
|
curwin->w_leftcol = vs->vs_leftcol;
|
|
|
|
curwin->w_topline = vs->vs_topline;
|
|
|
|
# ifdef FEAT_DIFF
|
|
|
|
curwin->w_topfill = vs->vs_topfill;
|
|
|
|
# endif
|
|
|
|
curwin->w_botline = vs->vs_botline;
|
|
|
|
curwin->w_empty_rows = vs->vs_empty_rows;
|
|
|
|
}
|
2018-08-10 22:07:32 +02:00
|
|
|
|
|
|
|
// Struct to store the state of 'incsearch' highlighting.
|
|
|
|
typedef struct {
|
|
|
|
pos_T search_start; // where 'incsearch' starts searching
|
|
|
|
pos_T save_cursor;
|
|
|
|
viewstate_T init_viewstate;
|
|
|
|
viewstate_T old_viewstate;
|
|
|
|
pos_T match_start;
|
|
|
|
pos_T match_end;
|
|
|
|
int did_incsearch;
|
|
|
|
int incsearch_postponed;
|
2018-08-14 21:32:21 +02:00
|
|
|
int magic_save;
|
2018-08-10 22:07:32 +02:00
|
|
|
} incsearch_state_T;
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_incsearch_state(incsearch_state_T *is_state)
|
|
|
|
{
|
|
|
|
is_state->match_start = curwin->w_cursor;
|
|
|
|
is_state->did_incsearch = FALSE;
|
|
|
|
is_state->incsearch_postponed = FALSE;
|
2018-08-14 21:32:21 +02:00
|
|
|
is_state->magic_save = p_magic;
|
2018-08-10 22:07:32 +02:00
|
|
|
CLEAR_POS(&is_state->match_end);
|
|
|
|
is_state->save_cursor = curwin->w_cursor; // may be restored later
|
|
|
|
is_state->search_start = curwin->w_cursor;
|
|
|
|
save_viewstate(&is_state->init_viewstate);
|
|
|
|
save_viewstate(&is_state->old_viewstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First move cursor to end of match, then to the start. This
|
|
|
|
* moves the whole match onto the screen when 'nowrap' is set.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_search_match(pos_T *t)
|
|
|
|
{
|
|
|
|
t->lnum += search_match_lines;
|
|
|
|
t->col = search_match_endcol;
|
|
|
|
if (t->lnum > curbuf->b_ml.ml_line_count)
|
|
|
|
{
|
|
|
|
t->lnum = curbuf->b_ml.ml_line_count;
|
|
|
|
coladvance((colnr_T)MAXCOL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return TRUE when 'incsearch' highlighting is to be done.
|
2018-08-11 16:40:43 +02:00
|
|
|
* Sets search_first_line and search_last_line to the address range.
|
2018-09-06 21:44:17 +02:00
|
|
|
* May change the last search pattern.
|
2018-08-10 22:07:32 +02:00
|
|
|
*/
|
|
|
|
static int
|
2018-08-11 16:40:43 +02:00
|
|
|
do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
|
|
|
|
int *skiplen, int *patlen)
|
2018-08-10 22:07:32 +02:00
|
|
|
{
|
2018-08-18 21:23:05 +02:00
|
|
|
char_u *cmd;
|
|
|
|
cmdmod_T save_cmdmod = cmdmod;
|
|
|
|
char_u *p;
|
|
|
|
int delim_optional = FALSE;
|
|
|
|
int delim;
|
|
|
|
char_u *end;
|
2019-01-13 23:38:42 +01:00
|
|
|
char *dummy;
|
2018-08-18 21:23:05 +02:00
|
|
|
exarg_T ea;
|
|
|
|
pos_T save_cursor;
|
2018-08-22 23:05:44 +02:00
|
|
|
int use_last_pat;
|
2018-08-18 21:23:05 +02:00
|
|
|
|
2018-08-11 16:40:43 +02:00
|
|
|
*skiplen = 0;
|
|
|
|
*patlen = ccline.cmdlen;
|
|
|
|
|
2018-08-18 21:23:05 +02:00
|
|
|
if (!p_is || cmd_silent)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// by default search all lines
|
|
|
|
search_first_line = 0;
|
|
|
|
search_last_line = MAXLNUM;
|
|
|
|
|
|
|
|
if (firstc == '/' || firstc == '?')
|
|
|
|
return TRUE;
|
|
|
|
if (firstc != ':')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
vim_memset(&ea, 0, sizeof(ea));
|
|
|
|
ea.line1 = 1;
|
|
|
|
ea.line2 = 1;
|
|
|
|
ea.cmd = ccline.cmdbuff;
|
|
|
|
ea.addr_type = ADDR_LINES;
|
|
|
|
|
|
|
|
parse_command_modifiers(&ea, &dummy, TRUE);
|
|
|
|
cmdmod = save_cmdmod;
|
|
|
|
|
|
|
|
cmd = skip_range(ea.cmd, NULL);
|
|
|
|
if (vim_strchr((char_u *)"sgvl", *cmd) == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
// Skip over "substitute" to find the pattern separator.
|
|
|
|
for (p = cmd; ASCII_ISALPHA(*p); ++p)
|
|
|
|
;
|
|
|
|
if (*skipwhite(p) == NUL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (STRNCMP(cmd, "substitute", p - cmd) == 0
|
|
|
|
|| STRNCMP(cmd, "smagic", p - cmd) == 0
|
|
|
|
|| STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0
|
|
|
|
|| STRNCMP(cmd, "vglobal", p - cmd) == 0)
|
|
|
|
{
|
|
|
|
if (*cmd == 's' && cmd[1] == 'm')
|
|
|
|
p_magic = TRUE;
|
|
|
|
else if (*cmd == 's' && cmd[1] == 'n')
|
|
|
|
p_magic = FALSE;
|
|
|
|
}
|
|
|
|
else if (STRNCMP(cmd, "sort", MAX(p - cmd, 3)) == 0)
|
|
|
|
{
|
|
|
|
// skip over flags
|
|
|
|
while (ASCII_ISALPHA(*(p = skipwhite(p))))
|
|
|
|
++p;
|
|
|
|
if (*p == NUL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0
|
|
|
|
|| STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0
|
|
|
|
|| STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0
|
|
|
|
|| STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0
|
|
|
|
|| STRNCMP(cmd, "global", p - cmd) == 0)
|
2018-08-11 16:40:43 +02:00
|
|
|
{
|
2018-08-18 21:23:05 +02:00
|
|
|
// skip over "!"
|
|
|
|
if (*p == '!')
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
if (*skipwhite(p) == NUL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (*cmd != 'g')
|
|
|
|
delim_optional = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
p = skipwhite(p);
|
|
|
|
delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
|
|
|
|
end = skip_regexp(p, delim, p_magic, NULL);
|
|
|
|
|
2018-08-22 23:05:44 +02:00
|
|
|
use_last_pat = end == p && *end == delim;
|
|
|
|
|
|
|
|
if (end == p && !use_last_pat)
|
2018-08-18 21:23:05 +02:00
|
|
|
return FALSE;
|
2018-08-11 16:40:43 +02:00
|
|
|
|
2018-08-22 23:05:44 +02:00
|
|
|
// Don't do 'hlsearch' highlighting if the pattern matches everything.
|
|
|
|
if (!use_last_pat)
|
|
|
|
{
|
|
|
|
char c = *end;
|
|
|
|
int empty;
|
|
|
|
|
|
|
|
*end = NUL;
|
|
|
|
empty = empty_pattern(p);
|
|
|
|
*end = c;
|
|
|
|
if (empty)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// found a non-empty pattern or //
|
2018-08-18 21:23:05 +02:00
|
|
|
*skiplen = (int)(p - ccline.cmdbuff);
|
|
|
|
*patlen = (int)(end - p);
|
|
|
|
|
|
|
|
// parse the address range
|
|
|
|
save_cursor = curwin->w_cursor;
|
|
|
|
curwin->w_cursor = is_state->search_start;
|
2018-09-15 15:42:40 +02:00
|
|
|
parse_cmd_address(&ea, &dummy, TRUE);
|
2018-08-18 21:23:05 +02:00
|
|
|
if (ea.addr_count > 0)
|
|
|
|
{
|
|
|
|
// Allow for reverse match.
|
|
|
|
if (ea.line2 < ea.line1)
|
2018-08-11 16:40:43 +02:00
|
|
|
{
|
2018-08-18 21:23:05 +02:00
|
|
|
search_first_line = ea.line2;
|
|
|
|
search_last_line = ea.line1;
|
2018-08-11 16:40:43 +02:00
|
|
|
}
|
2018-08-18 21:23:05 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
search_first_line = ea.line1;
|
|
|
|
search_last_line = ea.line2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmd[0] == 's' && cmd[1] != 'o')
|
|
|
|
{
|
|
|
|
// :s defaults to the current line
|
|
|
|
search_first_line = curwin->w_cursor.lnum;
|
|
|
|
search_last_line = curwin->w_cursor.lnum;
|
2018-08-11 16:40:43 +02:00
|
|
|
}
|
|
|
|
|
2018-08-18 21:23:05 +02:00
|
|
|
curwin->w_cursor = save_cursor;
|
|
|
|
return TRUE;
|
2018-08-10 22:07:32 +02:00
|
|
|
}
|
|
|
|
|
2018-08-12 17:39:14 +02:00
|
|
|
static void
|
|
|
|
finish_incsearch_highlighting(
|
|
|
|
int gotesc,
|
|
|
|
incsearch_state_T *is_state,
|
|
|
|
int call_update_screen)
|
|
|
|
{
|
|
|
|
if (is_state->did_incsearch)
|
|
|
|
{
|
|
|
|
is_state->did_incsearch = FALSE;
|
|
|
|
if (gotesc)
|
|
|
|
curwin->w_cursor = is_state->save_cursor;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!EQUAL_POS(is_state->save_cursor, is_state->search_start))
|
|
|
|
{
|
|
|
|
// put the '" mark at the original position
|
|
|
|
curwin->w_cursor = is_state->save_cursor;
|
|
|
|
setpcmark();
|
|
|
|
}
|
|
|
|
curwin->w_cursor = is_state->search_start;
|
|
|
|
}
|
|
|
|
restore_viewstate(&is_state->old_viewstate);
|
|
|
|
highlight_match = FALSE;
|
2018-08-31 22:09:54 +02:00
|
|
|
|
|
|
|
// by default search all lines
|
|
|
|
search_first_line = 0;
|
|
|
|
search_last_line = MAXLNUM;
|
|
|
|
|
|
|
|
p_magic = is_state->magic_save;
|
|
|
|
|
2018-08-12 17:39:14 +02:00
|
|
|
validate_cursor(); /* needed for TAB */
|
2018-09-16 17:08:04 +02:00
|
|
|
redraw_all_later(SOME_VALID);
|
2018-08-12 17:39:14 +02:00
|
|
|
if (call_update_screen)
|
|
|
|
update_screen(SOME_VALID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 22:07:32 +02:00
|
|
|
/*
|
|
|
|
* Do 'incsearch' highlighting if desired.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
may_do_incsearch_highlighting(
|
|
|
|
int firstc,
|
|
|
|
long count,
|
|
|
|
incsearch_state_T *is_state)
|
|
|
|
{
|
2018-08-11 16:40:43 +02:00
|
|
|
int skiplen, patlen;
|
2018-09-09 15:54:14 +02:00
|
|
|
int found; // do_search() result
|
2018-08-10 22:07:32 +02:00
|
|
|
pos_T end_pos;
|
|
|
|
#ifdef FEAT_RELTIME
|
|
|
|
proftime_T tm;
|
|
|
|
#endif
|
2018-08-12 17:39:14 +02:00
|
|
|
int next_char;
|
|
|
|
int use_last_pat;
|
2019-06-21 02:30:38 +02:00
|
|
|
int did_do_incsearch = is_state->did_incsearch;
|
2018-08-10 22:07:32 +02:00
|
|
|
|
2018-09-06 21:44:17 +02:00
|
|
|
// Parsing range may already set the last search pattern.
|
2018-11-30 21:57:55 +01:00
|
|
|
// NOTE: must call restore_last_search_pattern() before returning!
|
2018-09-06 21:44:17 +02:00
|
|
|
save_last_search_pattern();
|
|
|
|
|
2018-08-11 16:40:43 +02:00
|
|
|
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
|
2018-08-12 17:39:14 +02:00
|
|
|
{
|
2018-09-06 21:44:17 +02:00
|
|
|
restore_last_search_pattern();
|
2018-08-12 17:39:14 +02:00
|
|
|
finish_incsearch_highlighting(FALSE, is_state, TRUE);
|
2019-06-21 02:30:38 +02:00
|
|
|
if (did_do_incsearch && vpeekc() == NUL)
|
|
|
|
// may have skipped a redraw, do it now
|
|
|
|
redrawcmd();
|
2018-08-10 22:07:32 +02:00
|
|
|
return;
|
2018-08-12 17:39:14 +02:00
|
|
|
}
|
2018-08-10 22:07:32 +02:00
|
|
|
|
|
|
|
// If there is a character waiting, search and redraw later.
|
|
|
|
if (char_avail())
|
|
|
|
{
|
2018-09-06 21:44:17 +02:00
|
|
|
restore_last_search_pattern();
|
2018-08-10 22:07:32 +02:00
|
|
|
is_state->incsearch_postponed = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
is_state->incsearch_postponed = FALSE;
|
|
|
|
|
2018-08-11 16:40:43 +02:00
|
|
|
if (search_first_line == 0)
|
|
|
|
// start at the original cursor position
|
|
|
|
curwin->w_cursor = is_state->search_start;
|
2018-10-28 14:36:09 +01:00
|
|
|
else if (search_first_line > curbuf->b_ml.ml_line_count)
|
|
|
|
{
|
|
|
|
// start after the last line
|
|
|
|
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
|
|
curwin->w_cursor.col = MAXCOL;
|
|
|
|
}
|
2018-08-11 16:40:43 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// start at the first line in the range
|
|
|
|
curwin->w_cursor.lnum = search_first_line;
|
|
|
|
curwin->w_cursor.col = 0;
|
|
|
|
}
|
2018-08-10 22:07:32 +02:00
|
|
|
|
2018-08-12 17:39:14 +02:00
|
|
|
// Use the previous pattern for ":s//".
|
|
|
|
next_char = ccline.cmdbuff[skiplen + patlen];
|
|
|
|
use_last_pat = patlen == 0 && skiplen > 0
|
|
|
|
&& ccline.cmdbuff[skiplen - 1] == next_char;
|
|
|
|
|
|
|
|
// If there is no pattern, don't do anything.
|
|
|
|
if (patlen == 0 && !use_last_pat)
|
2018-08-10 22:07:32 +02:00
|
|
|
{
|
2018-09-09 15:54:14 +02:00
|
|
|
found = 0;
|
2018-08-10 22:07:32 +02:00
|
|
|
set_no_hlsearch(TRUE); // turn off previous highlight
|
|
|
|
redraw_all_later(SOME_VALID);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK;
|
|
|
|
|
|
|
|
cursor_off(); // so the user knows we're busy
|
|
|
|
out_flush();
|
|
|
|
++emsg_off; // so it doesn't beep if bad expr
|
|
|
|
#ifdef FEAT_RELTIME
|
|
|
|
// Set the time limit to half a second.
|
|
|
|
profile_setlimit(500L, &tm);
|
|
|
|
#endif
|
|
|
|
if (!p_hls)
|
|
|
|
search_flags += SEARCH_KEEP;
|
2018-08-12 15:49:47 +02:00
|
|
|
if (search_first_line != 0)
|
|
|
|
search_flags += SEARCH_START;
|
2018-08-11 16:40:43 +02:00
|
|
|
ccline.cmdbuff[skiplen + patlen] = NUL;
|
2018-09-09 15:54:14 +02:00
|
|
|
found = do_search(NULL, firstc == ':' ? '/' : firstc,
|
2018-08-11 16:40:43 +02:00
|
|
|
ccline.cmdbuff + skiplen, count, search_flags,
|
2018-08-10 22:07:32 +02:00
|
|
|
#ifdef FEAT_RELTIME
|
|
|
|
&tm, NULL
|
|
|
|
#else
|
|
|
|
NULL, NULL
|
|
|
|
#endif
|
|
|
|
);
|
2018-08-12 17:39:14 +02:00
|
|
|
ccline.cmdbuff[skiplen + patlen] = next_char;
|
2018-08-10 22:07:32 +02:00
|
|
|
--emsg_off;
|
|
|
|
|
2018-08-11 16:40:43 +02:00
|
|
|
if (curwin->w_cursor.lnum < search_first_line
|
|
|
|
|| curwin->w_cursor.lnum > search_last_line)
|
2018-08-14 18:16:52 +02:00
|
|
|
{
|
2018-08-11 16:40:43 +02:00
|
|
|
// match outside of address range
|
2018-09-09 15:54:14 +02:00
|
|
|
found = 0;
|
2018-08-14 18:16:52 +02:00
|
|
|
curwin->w_cursor = is_state->search_start;
|
|
|
|
}
|
2018-08-11 16:40:43 +02:00
|
|
|
|
2018-08-10 22:07:32 +02:00
|
|
|
// if interrupted while searching, behave like it failed
|
|
|
|
if (got_int)
|
|
|
|
{
|
|
|
|
(void)vpeekc(); // remove <C-C> from input stream
|
|
|
|
got_int = FALSE; // don't abandon the command line
|
2018-09-09 15:54:14 +02:00
|
|
|
found = 0;
|
2018-08-10 22:07:32 +02:00
|
|
|
}
|
|
|
|
else if (char_avail())
|
|
|
|
// cancelled searching because a char was typed
|
|
|
|
is_state->incsearch_postponed = TRUE;
|
|
|
|
}
|
2018-09-09 15:54:14 +02:00
|
|
|
if (found != 0)
|
2018-08-10 22:07:32 +02:00
|
|
|
highlight_match = TRUE; // highlight position
|
|
|
|
else
|
|
|
|
highlight_match = FALSE; // remove highlight
|
|
|
|
|
|
|
|
// First restore the old curwin values, so the screen is positioned in the
|
|
|
|
// same way as the actual search command.
|
|
|
|
restore_viewstate(&is_state->old_viewstate);
|
|
|
|
changed_cline_bef_curs();
|
|
|
|
update_topline();
|
|
|
|
|
2018-09-09 15:54:14 +02:00
|
|
|
if (found != 0)
|
2018-08-10 22:07:32 +02:00
|
|
|
{
|
|
|
|
pos_T save_pos = curwin->w_cursor;
|
|
|
|
|
|
|
|
is_state->match_start = curwin->w_cursor;
|
|
|
|
set_search_match(&curwin->w_cursor);
|
|
|
|
validate_cursor();
|
|
|
|
end_pos = curwin->w_cursor;
|
|
|
|
is_state->match_end = end_pos;
|
|
|
|
curwin->w_cursor = save_pos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
end_pos = curwin->w_cursor; // shutup gcc 4
|
|
|
|
|
2018-08-23 20:55:45 +02:00
|
|
|
// Disable 'hlsearch' highlighting if the pattern matches everything.
|
|
|
|
// Avoids a flash when typing "foo\|".
|
|
|
|
if (!use_last_pat)
|
|
|
|
{
|
|
|
|
next_char = ccline.cmdbuff[skiplen + patlen];
|
|
|
|
ccline.cmdbuff[skiplen + patlen] = NUL;
|
2018-09-16 17:08:04 +02:00
|
|
|
if (empty_pattern(ccline.cmdbuff) && !no_hlsearch)
|
|
|
|
{
|
|
|
|
redraw_all_later(SOME_VALID);
|
2018-08-23 20:55:45 +02:00
|
|
|
set_no_hlsearch(TRUE);
|
2018-09-16 17:08:04 +02:00
|
|
|
}
|
2018-08-23 20:55:45 +02:00
|
|
|
ccline.cmdbuff[skiplen + patlen] = next_char;
|
|
|
|
}
|
|
|
|
|
2018-08-10 22:07:32 +02:00
|
|
|
validate_cursor();
|
|
|
|
// May redraw the status line to show the cursor position.
|
|
|
|
if (p_ru && curwin->w_status_height > 0)
|
|
|
|
curwin->w_redr_status = TRUE;
|
|
|
|
|
|
|
|
update_screen(SOME_VALID);
|
|
|
|
restore_last_search_pattern();
|
|
|
|
|
2018-09-09 15:54:14 +02:00
|
|
|
// Leave it at the end to make CTRL-R CTRL-W work. But not when beyond the
|
|
|
|
// end of the pattern, e.g. for ":s/pat/".
|
|
|
|
if (ccline.cmdbuff[skiplen + patlen] != NUL)
|
|
|
|
curwin->w_cursor = is_state->search_start;
|
|
|
|
else if (found != 0)
|
2018-08-10 22:07:32 +02:00
|
|
|
curwin->w_cursor = end_pos;
|
|
|
|
|
|
|
|
msg_starthere();
|
|
|
|
redrawcmdline();
|
|
|
|
is_state->did_incsearch = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* May adjust 'incsearch' highlighting for typing CTRL-G and CTRL-T, go to next
|
|
|
|
* or previous match.
|
|
|
|
* Returns FAIL when jumping to cmdline_not_changed;
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
may_adjust_incsearch_highlighting(
|
2018-08-11 16:40:43 +02:00
|
|
|
int firstc,
|
|
|
|
long count,
|
2018-08-10 22:07:32 +02:00
|
|
|
incsearch_state_T *is_state,
|
2018-08-11 16:40:43 +02:00
|
|
|
int c)
|
2018-08-10 22:07:32 +02:00
|
|
|
{
|
2018-08-11 16:40:43 +02:00
|
|
|
int skiplen, patlen;
|
2018-08-10 22:07:32 +02:00
|
|
|
pos_T t;
|
|
|
|
char_u *pat;
|
|
|
|
int search_flags = SEARCH_NOOF;
|
|
|
|
int i;
|
2018-08-11 16:40:43 +02:00
|
|
|
int save;
|
2018-08-10 22:07:32 +02:00
|
|
|
|
2018-09-06 21:44:17 +02:00
|
|
|
// Parsing range may already set the last search pattern.
|
2018-11-30 21:57:55 +01:00
|
|
|
// NOTE: must call restore_last_search_pattern() before returning!
|
2018-09-06 21:44:17 +02:00
|
|
|
save_last_search_pattern();
|
|
|
|
|
2018-08-11 16:40:43 +02:00
|
|
|
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
|
2018-09-06 21:44:17 +02:00
|
|
|
{
|
|
|
|
restore_last_search_pattern();
|
2018-08-10 22:07:32 +02:00
|
|
|
return OK;
|
2018-09-06 21:44:17 +02:00
|
|
|
}
|
2018-08-11 16:40:43 +02:00
|
|
|
if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL)
|
2018-09-06 21:44:17 +02:00
|
|
|
{
|
|
|
|
restore_last_search_pattern();
|
2018-08-10 22:07:32 +02:00
|
|
|
return FAIL;
|
2018-09-06 21:44:17 +02:00
|
|
|
}
|
2018-08-10 22:07:32 +02:00
|
|
|
|
2018-08-11 16:40:43 +02:00
|
|
|
if (firstc == ccline.cmdbuff[skiplen])
|
2018-08-11 19:02:22 +02:00
|
|
|
{
|
2018-08-10 22:07:32 +02:00
|
|
|
pat = last_search_pattern();
|
2018-08-11 19:02:22 +02:00
|
|
|
skiplen = 0;
|
2018-08-14 20:18:26 +02:00
|
|
|
patlen = (int)STRLEN(pat);
|
2018-08-11 19:02:22 +02:00
|
|
|
}
|
2018-08-10 22:07:32 +02:00
|
|
|
else
|
2018-08-11 16:40:43 +02:00
|
|
|
pat = ccline.cmdbuff + skiplen;
|
2018-08-10 22:07:32 +02:00
|
|
|
|
|
|
|
cursor_off();
|
|
|
|
out_flush();
|
|
|
|
if (c == Ctrl_G)
|
|
|
|
{
|
|
|
|
t = is_state->match_end;
|
|
|
|
if (LT_POS(is_state->match_start, is_state->match_end))
|
|
|
|
// Start searching at the end of the match not at the beginning of
|
|
|
|
// the next column.
|
|
|
|
(void)decl(&t);
|
|
|
|
search_flags += SEARCH_COL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
t = is_state->match_start;
|
|
|
|
if (!p_hls)
|
|
|
|
search_flags += SEARCH_KEEP;
|
|
|
|
++emsg_off;
|
2018-08-11 16:40:43 +02:00
|
|
|
save = pat[patlen];
|
|
|
|
pat[patlen] = NUL;
|
2018-12-23 19:10:09 +01:00
|
|
|
i = searchit(curwin, curbuf, &t, NULL,
|
2018-08-10 22:07:32 +02:00
|
|
|
c == Ctrl_G ? FORWARD : BACKWARD,
|
|
|
|
pat, count, search_flags,
|
|
|
|
RE_SEARCH, 0, NULL, NULL);
|
|
|
|
--emsg_off;
|
2018-08-11 16:40:43 +02:00
|
|
|
pat[patlen] = save;
|
2018-08-10 22:07:32 +02:00
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
is_state->search_start = is_state->match_start;
|
|
|
|
is_state->match_end = t;
|
|
|
|
is_state->match_start = t;
|
2018-08-11 16:40:43 +02:00
|
|
|
if (c == Ctrl_T && firstc != '?')
|
2018-08-10 22:07:32 +02:00
|
|
|
{
|
|
|
|
// Move just before the current match, so that when nv_search
|
|
|
|
// finishes the cursor will be put back on the match.
|
|
|
|
is_state->search_start = t;
|
|
|
|
(void)decl(&is_state->search_start);
|
|
|
|
}
|
|
|
|
else if (c == Ctrl_G && firstc == '?')
|
|
|
|
{
|
|
|
|
// Move just after the current match, so that when nv_search
|
|
|
|
// finishes the cursor will be put back on the match.
|
|
|
|
is_state->search_start = t;
|
|
|
|
(void)incl(&is_state->search_start);
|
|
|
|
}
|
|
|
|
if (LT_POS(t, is_state->search_start) && c == Ctrl_G)
|
|
|
|
{
|
|
|
|
// wrap around
|
|
|
|
is_state->search_start = t;
|
|
|
|
if (firstc == '?')
|
|
|
|
(void)incl(&is_state->search_start);
|
|
|
|
else
|
|
|
|
(void)decl(&is_state->search_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_search_match(&is_state->match_end);
|
|
|
|
curwin->w_cursor = is_state->match_start;
|
|
|
|
changed_cline_bef_curs();
|
|
|
|
update_topline();
|
|
|
|
validate_cursor();
|
|
|
|
highlight_match = TRUE;
|
|
|
|
save_viewstate(&is_state->old_viewstate);
|
|
|
|
update_screen(NOT_VALID);
|
|
|
|
redrawcmdline();
|
2019-07-16 21:38:51 +02:00
|
|
|
curwin->w_cursor = is_state->match_end;
|
2018-08-10 22:07:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
vim_beep(BO_ERROR);
|
|
|
|
restore_last_search_pattern();
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When CTRL-L typed: add character from the match to the pattern.
|
|
|
|
* May set "*c" to the added character.
|
|
|
|
* Return OK when jumping to cmdline_not_changed.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
may_add_char_to_search(int firstc, int *c, incsearch_state_T *is_state)
|
|
|
|
{
|
2018-08-11 16:40:43 +02:00
|
|
|
int skiplen, patlen;
|
|
|
|
|
2018-09-06 21:44:17 +02:00
|
|
|
// Parsing range may already set the last search pattern.
|
2018-11-30 21:57:55 +01:00
|
|
|
// NOTE: must call restore_last_search_pattern() before returning!
|
2018-09-06 21:44:17 +02:00
|
|
|
save_last_search_pattern();
|
|
|
|
|
2018-08-11 16:40:43 +02:00
|
|
|
if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
|
2018-09-06 21:44:17 +02:00
|
|
|
{
|
|
|
|
restore_last_search_pattern();
|
2018-08-10 22:07:32 +02:00
|
|
|
return FAIL;
|
2018-09-06 21:44:17 +02:00
|
|
|
}
|
2018-11-30 21:57:55 +01:00
|
|
|
restore_last_search_pattern();
|
2018-08-10 22:07:32 +02:00
|
|
|
|
|
|
|
// Add a character from under the cursor for 'incsearch'.
|
|
|
|
if (is_state->did_incsearch)
|
|
|
|
{
|
|
|
|
curwin->w_cursor = is_state->match_end;
|
2019-04-11 13:45:57 +02:00
|
|
|
*c = gchar_cursor();
|
|
|
|
if (*c != NUL)
|
2018-08-10 22:07:32 +02:00
|
|
|
{
|
|
|
|
// If 'ignorecase' and 'smartcase' are set and the
|
|
|
|
// command line has no uppercase characters, convert
|
|
|
|
// the character to lowercase.
|
2018-08-11 16:40:43 +02:00
|
|
|
if (p_ic && p_scs && !pat_has_uppercase(ccline.cmdbuff + skiplen))
|
2018-08-10 22:07:32 +02:00
|
|
|
*c = MB_TOLOWER(*c);
|
2019-04-11 13:45:57 +02:00
|
|
|
if (*c == firstc || vim_strchr((char_u *)(
|
|
|
|
p_magic ? "\\~^$.*[" : "\\^$"), *c) != NULL)
|
|
|
|
{
|
|
|
|
// put a backslash before special characters
|
|
|
|
stuffcharReadbuff(*c);
|
|
|
|
*c = '\\';
|
|
|
|
}
|
|
|
|
// add any composing characters
|
|
|
|
if (mb_char2len(*c) != mb_ptr2len(ml_get_cursor()))
|
2018-08-10 22:07:32 +02:00
|
|
|
{
|
2019-04-11 13:45:57 +02:00
|
|
|
int save_c = *c;
|
|
|
|
|
|
|
|
while (mb_char2len(*c) != mb_ptr2len(ml_get_cursor()))
|
2018-08-10 22:07:32 +02:00
|
|
|
{
|
2019-04-11 13:45:57 +02:00
|
|
|
curwin->w_cursor.col += mb_char2len(*c);
|
|
|
|
*c = gchar_cursor();
|
2018-08-10 22:07:32 +02:00
|
|
|
stuffcharReadbuff(*c);
|
2018-12-13 22:20:09 +01:00
|
|
|
}
|
2019-04-11 13:45:57 +02:00
|
|
|
*c = save_c;
|
2018-08-10 22:07:32 +02:00
|
|
|
}
|
2019-04-11 13:45:57 +02:00
|
|
|
return FAIL;
|
2018-08-10 22:07:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
2019-06-21 02:30:38 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FEAT_ARABIC
|
|
|
|
/*
|
|
|
|
* Return TRUE if the command line has an Arabic character at or after "start"
|
|
|
|
* for "len" bytes.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cmdline_has_arabic(int start, int len)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
int mb_l;
|
|
|
|
int u8c;
|
|
|
|
char_u *p;
|
|
|
|
int u8cc[MAX_MCO];
|
|
|
|
|
|
|
|
if (!enc_utf8)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (j = start; j < start + len; j += mb_l)
|
|
|
|
{
|
|
|
|
p = ccline.cmdbuff + j;
|
|
|
|
u8c = utfc_ptr2char_len(p, u8cc, start + len - j);
|
|
|
|
mb_l = utfc_ptr2len_len(p, start + len - j);
|
|
|
|
if (ARABIC_CHAR(u8c))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-04-28 13:56:09 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-30 17:45:30 +02:00
|
|
|
void
|
|
|
|
cmdline_init(void)
|
|
|
|
{
|
|
|
|
vim_memset(&ccline, 0, sizeof(struct cmdline_info));
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* getcmdline() - accept a command line starting with firstc.
|
|
|
|
*
|
|
|
|
* firstc == ':' get ":" command line.
|
|
|
|
* firstc == '/' or '?' get search pattern
|
|
|
|
* firstc == '=' get expression
|
|
|
|
* firstc == '@' get text for input() function
|
|
|
|
* firstc == '>' get text for debug mode
|
|
|
|
* firstc == NUL get text for :insert command
|
|
|
|
* firstc == -1 like NUL, and break on CTRL-C
|
|
|
|
*
|
|
|
|
* The line is collected in ccline.cmdbuff, which is reallocated to fit the
|
|
|
|
* command line.
|
|
|
|
*
|
|
|
|
* Careful: getcmdline() can be called recursively!
|
|
|
|
*
|
|
|
|
* Return pointer to allocated string if there is a commandline, NULL
|
|
|
|
* otherwise.
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
getcmdline(
|
|
|
|
int firstc,
|
2018-09-30 17:11:48 +02:00
|
|
|
long count, // only used for incremental search
|
2019-06-25 04:12:16 +02:00
|
|
|
int indent, // indent for inside conditionals
|
|
|
|
int do_concat UNUSED)
|
2018-09-30 17:11:48 +02:00
|
|
|
{
|
|
|
|
return getcmdline_int(firstc, count, indent, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char_u *
|
|
|
|
getcmdline_int(
|
|
|
|
int firstc,
|
|
|
|
long count UNUSED, // only used for incremental search
|
|
|
|
int indent, // indent for inside conditionals
|
|
|
|
int init_ccline) // clear ccline first
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
int gotesc = FALSE; /* TRUE when <ESC> just typed */
|
|
|
|
int do_abbr; /* when TRUE check for abbr. */
|
|
|
|
char_u *lookfor = NULL; /* string to match */
|
|
|
|
int hiscnt; /* current history line in use */
|
|
|
|
int histype; /* history type to be used */
|
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
2018-08-10 22:07:32 +02:00
|
|
|
incsearch_state_T is_state;
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
int did_wild_list = FALSE; /* did wild_list() recently */
|
|
|
|
int wim_index = 0; /* index in wim_flags[] */
|
|
|
|
int res;
|
|
|
|
int save_msg_scroll = msg_scroll;
|
|
|
|
int save_State = State; /* remember State when called */
|
|
|
|
int some_key_typed = FALSE; /* one of the keys was typed */
|
|
|
|
#ifdef FEAT_MOUSE
|
|
|
|
/* mouse drag and release events are ignored, unless they are
|
|
|
|
* preceded with a mouse down event */
|
|
|
|
int ignore_drag_release = TRUE;
|
|
|
|
#endif
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
int break_ctrl_c = FALSE;
|
|
|
|
#endif
|
|
|
|
expand_T xpc;
|
|
|
|
long *b_im_ptr = NULL;
|
2005-03-08 22:40:03 +00:00
|
|
|
struct cmdline_info save_ccline;
|
2018-09-30 17:11:48 +02:00
|
|
|
int did_save_ccline = FALSE;
|
2017-10-19 18:35:51 +02:00
|
|
|
int cmdline_type;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
if (ccline.cmdbuff != NULL)
|
|
|
|
{
|
|
|
|
// Being called recursively. Since ccline is global, we need to save
|
|
|
|
// the current buffer and restore it when returning.
|
|
|
|
save_cmdline(&save_ccline);
|
|
|
|
did_save_ccline = TRUE;
|
|
|
|
}
|
|
|
|
if (init_ccline)
|
|
|
|
vim_memset(&ccline, 0, sizeof(struct cmdline_info));
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
if (firstc == -1)
|
|
|
|
{
|
|
|
|
firstc = NUL;
|
|
|
|
break_ctrl_c = TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
/* start without Hebrew mapping for a command line */
|
|
|
|
if (firstc == ':' || firstc == '=' || firstc == '>')
|
|
|
|
cmd_hkmap = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ccline.overstrike = FALSE; /* always start in insert mode */
|
2018-08-10 22:07:32 +02:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
2018-08-10 22:07:32 +02:00
|
|
|
init_incsearch_state(&is_state);
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set some variables for redrawcmd()
|
|
|
|
*/
|
|
|
|
ccline.cmdfirstc = (firstc == '@' ? 0 : firstc);
|
2005-02-12 14:29:27 +00:00
|
|
|
ccline.cmdindent = (firstc > 0 ? indent : 0);
|
|
|
|
|
|
|
|
/* alloc initial ccline.cmdbuff */
|
|
|
|
alloc_cmdbuff(exmode_active ? 250 : indent + 1);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (ccline.cmdbuff == NULL)
|
2018-09-30 17:11:48 +02:00
|
|
|
goto theend; // out of memory
|
2004-06-13 20:20:40 +00:00
|
|
|
ccline.cmdlen = ccline.cmdpos = 0;
|
|
|
|
ccline.cmdbuff[0] = NUL;
|
2017-03-16 19:58:25 +01:00
|
|
|
sb_text_start_cmdline();
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2005-02-12 14:29:27 +00:00
|
|
|
/* autoindent for :insert and :append */
|
|
|
|
if (firstc <= 0)
|
|
|
|
{
|
2015-07-17 13:22:51 +02:00
|
|
|
vim_memset(ccline.cmdbuff, ' ', indent);
|
2005-02-12 14:29:27 +00:00
|
|
|
ccline.cmdbuff[indent] = NUL;
|
|
|
|
ccline.cmdpos = indent;
|
|
|
|
ccline.cmdspos = indent;
|
|
|
|
ccline.cmdlen = indent;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
ExpandInit(&xpc);
|
2008-09-14 12:42:29 +00:00
|
|
|
ccline.xpc = &xpc;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
if (curwin->w_p_rl && *curwin->w_p_rlc == 's'
|
|
|
|
&& (firstc == '/' || firstc == '?'))
|
|
|
|
cmdmsg_rl = TRUE;
|
|
|
|
else
|
|
|
|
cmdmsg_rl = FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
redir_off = TRUE; /* don't redirect the typed command */
|
|
|
|
if (!cmd_silent)
|
|
|
|
{
|
|
|
|
i = msg_scrolled;
|
|
|
|
msg_scrolled = 0; /* avoid wait_return message */
|
|
|
|
gotocmdline(TRUE);
|
|
|
|
msg_scrolled += i;
|
|
|
|
redrawcmdprompt(); /* draw prompt or indent */
|
|
|
|
set_cmdspos();
|
|
|
|
}
|
|
|
|
xpc.xp_context = EXPAND_NOTHING;
|
|
|
|
xpc.xp_backslash = XP_BS_NONE;
|
2006-01-19 22:16:24 +00:00
|
|
|
#ifndef BACKSLASH_IN_FILENAME
|
|
|
|
xpc.xp_shell = FALSE;
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2005-09-20 23:22:24 +00:00
|
|
|
#if defined(FEAT_EVAL)
|
|
|
|
if (ccline.input_fn)
|
|
|
|
{
|
|
|
|
xpc.xp_context = ccline.xp_context;
|
|
|
|
xpc.xp_pattern = ccline.cmdbuff;
|
2019-04-27 13:04:13 +02:00
|
|
|
# if defined(FEAT_CMDL_COMPL)
|
2005-09-20 23:22:24 +00:00
|
|
|
xpc.xp_arg = ccline.xp_arg;
|
2007-07-24 12:34:30 +00:00
|
|
|
# endif
|
2005-09-20 23:22:24 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Avoid scrolling when called by a recursive do_cmdline(), e.g. when
|
|
|
|
* doing ":@0" when register 0 doesn't contain a CR.
|
|
|
|
*/
|
|
|
|
msg_scroll = FALSE;
|
|
|
|
|
|
|
|
State = CMDLINE;
|
|
|
|
|
|
|
|
if (firstc == '/' || firstc == '?' || firstc == '@')
|
|
|
|
{
|
|
|
|
/* Use ":lmap" mappings for search pattern and input(). */
|
|
|
|
if (curbuf->b_p_imsearch == B_IMODE_USE_INSERT)
|
|
|
|
b_im_ptr = &curbuf->b_p_iminsert;
|
|
|
|
else
|
|
|
|
b_im_ptr = &curbuf->b_p_imsearch;
|
|
|
|
if (*b_im_ptr == B_IMODE_LMAP)
|
|
|
|
State |= LANGMAP;
|
2018-03-04 18:08:14 +01:00
|
|
|
#ifdef HAVE_INPUT_METHOD
|
2004-06-13 20:20:40 +00:00
|
|
|
im_set_active(*b_im_ptr == B_IMODE_IM);
|
|
|
|
#endif
|
|
|
|
}
|
2018-03-04 18:08:14 +01:00
|
|
|
#ifdef HAVE_INPUT_METHOD
|
2004-06-13 20:20:40 +00:00
|
|
|
else if (p_imcmdline)
|
|
|
|
im_set_active(TRUE);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FEAT_MOUSE
|
|
|
|
setmouse();
|
|
|
|
#endif
|
|
|
|
#ifdef CURSOR_SHAPE
|
|
|
|
ui_cursor_shape(); /* may show different cursor shape */
|
|
|
|
#endif
|
|
|
|
|
2005-12-02 00:46:37 +00:00
|
|
|
/* When inside an autocommand for writing "exiting" may be set and
|
|
|
|
* terminal mode set to cooked. Need to set raw mode here then. */
|
|
|
|
settmode(TMODE_RAW);
|
|
|
|
|
2017-10-19 18:35:51 +02:00
|
|
|
/* Trigger CmdlineEnter autocommands. */
|
|
|
|
cmdline_type = firstc == NUL ? '-' : firstc;
|
|
|
|
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINEENTER);
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
init_history();
|
2019-08-06 21:59:57 +02:00
|
|
|
hiscnt = get_hislen(); /* set hiscnt to impossible history value */
|
2004-06-13 20:20:40 +00:00
|
|
|
histype = hist_char2type(firstc);
|
|
|
|
|
|
|
|
#ifdef FEAT_DIGRAPHS
|
2009-04-29 16:47:23 +00:00
|
|
|
do_digraph(-1); /* init digraph typeahead */
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
2014-06-25 12:26:46 +02:00
|
|
|
/* If something above caused an error, reset the flags, we do want to type
|
|
|
|
* and execute commands. Display may be messed up a bit. */
|
|
|
|
if (did_emsg)
|
|
|
|
redrawcmd();
|
|
|
|
did_emsg = FALSE;
|
|
|
|
got_int = FALSE;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Collect the command string, handling editing keys.
|
|
|
|
*/
|
|
|
|
for (;;)
|
|
|
|
{
|
2006-09-10 19:07:28 +00:00
|
|
|
redir_off = TRUE; /* Don't redirect the typed command.
|
|
|
|
Repeated, because a ":redir" inside
|
|
|
|
completion may switch it on. */
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef USE_ON_FLY_SCROLL
|
|
|
|
dont_scroll = FALSE; /* allow scrolling here */
|
|
|
|
#endif
|
|
|
|
quit_more = FALSE; /* reset after CTRL-D which had a more-prompt */
|
|
|
|
|
2018-04-07 19:09:09 +02:00
|
|
|
did_emsg = FALSE; /* There can't really be a reason why an error
|
|
|
|
that occurs while typing a command should
|
|
|
|
cause the command not to be executed. */
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
cursorcmd(); /* set the cursor on the right spot */
|
2008-01-02 20:55:27 +00:00
|
|
|
|
2017-11-28 20:47:40 +01:00
|
|
|
/* Get a character. Ignore K_IGNORE and K_NOP, they should not do
|
|
|
|
* anything, such as stop completion. */
|
2008-01-02 20:55:27 +00:00
|
|
|
do
|
|
|
|
c = safe_vgetc();
|
2019-03-30 18:47:01 +01:00
|
|
|
while (c == K_IGNORE || c == K_NOP);
|
2008-01-02 20:55:27 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
if (KeyTyped)
|
|
|
|
{
|
|
|
|
some_key_typed = TRUE;
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
if (cmd_hkmap)
|
|
|
|
c = hkmap(c);
|
|
|
|
if (cmdmsg_rl && !KeyStuffed)
|
|
|
|
{
|
|
|
|
/* Invert horizontal movements and operations. Only when
|
|
|
|
* typed by the user directly, not when the result of a
|
|
|
|
* mapping. */
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case K_RIGHT: c = K_LEFT; break;
|
|
|
|
case K_S_RIGHT: c = K_S_LEFT; break;
|
|
|
|
case K_C_RIGHT: c = K_C_LEFT; break;
|
|
|
|
case K_LEFT: c = K_RIGHT; break;
|
|
|
|
case K_S_LEFT: c = K_S_RIGHT; break;
|
|
|
|
case K_C_LEFT: c = K_C_RIGHT; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ignore got_int when CTRL-C was typed here.
|
|
|
|
* Don't ignore it in :global, we really need to break then, e.g., for
|
|
|
|
* ":g/pat/normal /pat" (without the <CR>).
|
|
|
|
* Don't ignore it for the input() function.
|
|
|
|
*/
|
|
|
|
if ((c == Ctrl_C
|
|
|
|
#ifdef UNIX
|
|
|
|
|| c == intr_char
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
#if defined(FEAT_EVAL) || defined(FEAT_CRYPT)
|
|
|
|
&& firstc != '@'
|
|
|
|
#endif
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
&& !break_ctrl_c
|
|
|
|
#endif
|
|
|
|
&& !global_busy)
|
|
|
|
got_int = FALSE;
|
|
|
|
|
2019-08-06 21:59:57 +02:00
|
|
|
// free old command line when finished moving around in the history
|
|
|
|
// list
|
2004-06-13 20:20:40 +00:00
|
|
|
if (lookfor != NULL
|
2005-03-06 23:38:09 +00:00
|
|
|
&& c != K_S_DOWN && c != K_S_UP
|
2005-03-25 21:53:48 +00:00
|
|
|
&& c != K_DOWN && c != K_UP
|
2004-06-13 20:20:40 +00:00
|
|
|
&& c != K_PAGEDOWN && c != K_PAGEUP
|
|
|
|
&& c != K_KPAGEDOWN && c != K_KPAGEUP
|
2005-03-25 21:53:48 +00:00
|
|
|
&& c != K_LEFT && c != K_RIGHT
|
2004-06-13 20:20:40 +00:00
|
|
|
&& (xpc.xp_numfiles > 0 || (c != Ctrl_P && c != Ctrl_N)))
|
2018-02-10 18:45:26 +01:00
|
|
|
VIM_CLEAR(lookfor);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/*
|
2008-09-14 12:42:29 +00:00
|
|
|
* When there are matching completions to select <S-Tab> works like
|
|
|
|
* CTRL-P (unless 'wc' is <S-Tab>).
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
2008-09-14 12:42:29 +00:00
|
|
|
if (c != p_wc && c == K_S_TAB && xpc.xp_numfiles > 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
c = Ctrl_P;
|
|
|
|
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
/* Special translations for 'wildmenu' */
|
|
|
|
if (did_wild_list && p_wmnu)
|
|
|
|
{
|
2005-03-25 21:53:48 +00:00
|
|
|
if (c == K_LEFT)
|
2004-06-13 20:20:40 +00:00
|
|
|
c = Ctrl_P;
|
2005-03-25 21:53:48 +00:00
|
|
|
else if (c == K_RIGHT)
|
2004-06-13 20:20:40 +00:00
|
|
|
c = Ctrl_N;
|
|
|
|
}
|
|
|
|
/* Hitting CR after "emenu Name.": complete submenu */
|
|
|
|
if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu
|
|
|
|
&& ccline.cmdpos > 1
|
|
|
|
&& ccline.cmdbuff[ccline.cmdpos - 1] == '.'
|
|
|
|
&& ccline.cmdbuff[ccline.cmdpos - 2] != '\\'
|
|
|
|
&& (c == '\n' || c == '\r' || c == K_KENTER))
|
|
|
|
c = K_DOWN;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* free expanded names when finished walking through matches */
|
|
|
|
if (xpc.xp_numfiles != -1
|
|
|
|
&& !(c == p_wc && KeyTyped) && c != p_wcm
|
|
|
|
&& c != Ctrl_N && c != Ctrl_P && c != Ctrl_A
|
|
|
|
&& c != Ctrl_L)
|
|
|
|
{
|
|
|
|
(void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE);
|
|
|
|
did_wild_list = FALSE;
|
|
|
|
#ifdef FEAT_WILDMENU
|
2005-03-25 21:53:48 +00:00
|
|
|
if (!p_wmnu || (c != K_UP && c != K_DOWN))
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
xpc.xp_context = EXPAND_NOTHING;
|
|
|
|
wim_index = 0;
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
if (p_wmnu && wild_menu_showing != 0)
|
|
|
|
{
|
|
|
|
int skt = KeyTyped;
|
2005-09-25 22:16:38 +00:00
|
|
|
int old_RedrawingDisabled = RedrawingDisabled;
|
2005-09-20 23:22:24 +00:00
|
|
|
|
|
|
|
if (ccline.input_fn)
|
|
|
|
RedrawingDisabled = 0;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (wild_menu_showing == WM_SCROLLED)
|
|
|
|
{
|
|
|
|
/* Entered command line, move it up */
|
|
|
|
cmdline_row--;
|
|
|
|
redrawcmd();
|
|
|
|
}
|
|
|
|
else if (save_p_ls != -1)
|
|
|
|
{
|
|
|
|
/* restore 'laststatus' and 'winminheight' */
|
|
|
|
p_ls = save_p_ls;
|
|
|
|
p_wmh = save_p_wmh;
|
|
|
|
last_status(FALSE);
|
|
|
|
update_screen(VALID); /* redraw the screen NOW */
|
|
|
|
redrawcmd();
|
|
|
|
save_p_ls = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
win_redraw_last_status(topframe);
|
|
|
|
redraw_statuslines();
|
|
|
|
}
|
|
|
|
KeyTyped = skt;
|
|
|
|
wild_menu_showing = 0;
|
2005-09-25 22:16:38 +00:00
|
|
|
if (ccline.input_fn)
|
|
|
|
RedrawingDisabled = old_RedrawingDisabled;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
/* Special translations for 'wildmenu' */
|
|
|
|
if (xpc.xp_context == EXPAND_MENUNAMES && p_wmnu)
|
|
|
|
{
|
|
|
|
/* Hitting <Down> after "emenu Name.": complete submenu */
|
2007-07-17 16:15:36 +00:00
|
|
|
if (c == K_DOWN && ccline.cmdpos > 0
|
|
|
|
&& ccline.cmdbuff[ccline.cmdpos - 1] == '.')
|
2004-06-13 20:20:40 +00:00
|
|
|
c = p_wc;
|
2005-03-25 21:53:48 +00:00
|
|
|
else if (c == K_UP)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* Hitting <Up>: Remove one submenu name in front of the
|
|
|
|
* cursor */
|
|
|
|
int found = FALSE;
|
|
|
|
|
|
|
|
j = (int)(xpc.xp_pattern - ccline.cmdbuff);
|
|
|
|
i = 0;
|
|
|
|
while (--j > 0)
|
|
|
|
{
|
|
|
|
/* check for start of menu name */
|
|
|
|
if (ccline.cmdbuff[j] == ' '
|
|
|
|
&& ccline.cmdbuff[j - 1] != '\\')
|
|
|
|
{
|
|
|
|
i = j + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* check for start of submenu name */
|
|
|
|
if (ccline.cmdbuff[j] == '.'
|
|
|
|
&& ccline.cmdbuff[j - 1] != '\\')
|
|
|
|
{
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
i = j + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i > 0)
|
|
|
|
cmdline_del(i);
|
|
|
|
c = p_wc;
|
|
|
|
xpc.xp_context = EXPAND_NOTHING;
|
|
|
|
}
|
|
|
|
}
|
2006-03-06 23:29:24 +00:00
|
|
|
if ((xpc.xp_context == EXPAND_FILES
|
2008-06-24 21:56:24 +00:00
|
|
|
|| xpc.xp_context == EXPAND_DIRECTORIES
|
2006-03-06 23:29:24 +00:00
|
|
|
|| xpc.xp_context == EXPAND_SHELLCMD) && p_wmnu)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u upseg[5];
|
|
|
|
|
|
|
|
upseg[0] = PATHSEP;
|
|
|
|
upseg[1] = '.';
|
|
|
|
upseg[2] = '.';
|
|
|
|
upseg[3] = PATHSEP;
|
|
|
|
upseg[4] = NUL;
|
|
|
|
|
2007-07-17 16:15:36 +00:00
|
|
|
if (c == K_DOWN
|
|
|
|
&& ccline.cmdpos > 0
|
|
|
|
&& ccline.cmdbuff[ccline.cmdpos - 1] == PATHSEP
|
|
|
|
&& (ccline.cmdpos < 3
|
|
|
|
|| ccline.cmdbuff[ccline.cmdpos - 2] != '.'
|
2004-06-13 20:20:40 +00:00
|
|
|
|| ccline.cmdbuff[ccline.cmdpos - 3] != '.'))
|
|
|
|
{
|
|
|
|
/* go down a directory */
|
|
|
|
c = p_wc;
|
|
|
|
}
|
2005-03-25 21:53:48 +00:00
|
|
|
else if (STRNCMP(xpc.xp_pattern, upseg + 1, 3) == 0 && c == K_DOWN)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* If in a direct ancestor, strip off one ../ to go down */
|
|
|
|
int found = FALSE;
|
|
|
|
|
|
|
|
j = ccline.cmdpos;
|
|
|
|
i = (int)(xpc.xp_pattern - ccline.cmdbuff);
|
|
|
|
while (--j > i)
|
|
|
|
{
|
2004-12-19 22:46:22 +00:00
|
|
|
if (has_mbyte)
|
|
|
|
j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (vim_ispathsep(ccline.cmdbuff[j]))
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found
|
|
|
|
&& ccline.cmdbuff[j - 1] == '.'
|
|
|
|
&& ccline.cmdbuff[j - 2] == '.'
|
|
|
|
&& (vim_ispathsep(ccline.cmdbuff[j - 3]) || j == i + 2))
|
|
|
|
{
|
|
|
|
cmdline_del(j - 2);
|
|
|
|
c = p_wc;
|
|
|
|
}
|
|
|
|
}
|
2005-03-25 21:53:48 +00:00
|
|
|
else if (c == K_UP)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* go up a directory */
|
|
|
|
int found = FALSE;
|
|
|
|
|
|
|
|
j = ccline.cmdpos - 1;
|
|
|
|
i = (int)(xpc.xp_pattern - ccline.cmdbuff);
|
|
|
|
while (--j > i)
|
|
|
|
{
|
|
|
|
if (has_mbyte)
|
|
|
|
j -= (*mb_head_off)(ccline.cmdbuff, ccline.cmdbuff + j);
|
|
|
|
if (vim_ispathsep(ccline.cmdbuff[j])
|
|
|
|
#ifdef BACKSLASH_IN_FILENAME
|
2016-02-16 15:06:59 +01:00
|
|
|
&& vim_strchr((char_u *)" *?[{`$%#",
|
|
|
|
ccline.cmdbuff[j + 1]) == NULL
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
i = j + 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
j = i;
|
|
|
|
else if (STRNCMP(ccline.cmdbuff + j, upseg, 4) == 0)
|
|
|
|
j += 4;
|
|
|
|
else if (STRNCMP(ccline.cmdbuff + j, upseg + 1, 3) == 0
|
|
|
|
&& j == i)
|
|
|
|
j += 3;
|
|
|
|
else
|
|
|
|
j = 0;
|
|
|
|
if (j > 0)
|
|
|
|
{
|
|
|
|
/* TODO this is only for DOS/UNIX systems - need to put in
|
|
|
|
* machine-specific stuff here and in upseg init */
|
|
|
|
cmdline_del(j);
|
|
|
|
put_on_cmdline(upseg + 1, 3, FALSE);
|
|
|
|
}
|
|
|
|
else if (ccline.cmdpos > i)
|
|
|
|
cmdline_del(i);
|
2011-12-08 18:44:51 +01:00
|
|
|
|
|
|
|
/* Now complete in the new directory. Set KeyTyped in case the
|
|
|
|
* Up key came from a mapping. */
|
2004-06-13 20:20:40 +00:00
|
|
|
c = p_wc;
|
2011-12-08 18:44:51 +01:00
|
|
|
KeyTyped = TRUE;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* FEAT_WILDMENU */
|
|
|
|
|
|
|
|
/* CTRL-\ CTRL-N goes to Normal mode, CTRL-\ CTRL-G goes to Insert
|
|
|
|
* mode when 'insertmode' is set, CTRL-\ e prompts for an expression. */
|
|
|
|
if (c == Ctrl_BSL)
|
|
|
|
{
|
|
|
|
++no_mapping;
|
|
|
|
++allow_keys;
|
2007-09-13 16:26:47 +00:00
|
|
|
c = plain_vgetc();
|
2004-06-13 20:20:40 +00:00
|
|
|
--no_mapping;
|
|
|
|
--allow_keys;
|
2012-10-11 04:04:37 +02:00
|
|
|
/* CTRL-\ e doesn't work when obtaining an expression, unless it
|
|
|
|
* is in a mapping. */
|
|
|
|
if (c != Ctrl_N && c != Ctrl_G && (c != 'e'
|
2018-09-25 20:48:57 +02:00
|
|
|
|| (ccline.cmdfirstc == '=' && KeyTyped)
|
|
|
|
#ifdef FEAT_EVAL
|
2018-09-25 22:27:35 +02:00
|
|
|
|| cmdline_star > 0
|
2018-09-25 20:48:57 +02:00
|
|
|
#endif
|
|
|
|
))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
vungetc(c);
|
|
|
|
c = Ctrl_BSL;
|
|
|
|
}
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
else if (c == 'e')
|
|
|
|
{
|
2010-08-13 19:12:07 +02:00
|
|
|
char_u *p = NULL;
|
|
|
|
int len;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Replace the command line with the result of an expression.
|
2006-01-12 23:22:24 +00:00
|
|
|
* Need to save and restore the current command line, to be
|
|
|
|
* able to enter a new one...
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
if (ccline.cmdpos == ccline.cmdlen)
|
|
|
|
new_cmdpos = 99999; /* keep it at the end */
|
|
|
|
else
|
|
|
|
new_cmdpos = ccline.cmdpos;
|
2005-01-11 21:29:04 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
c = get_expr_register();
|
|
|
|
if (c == '=')
|
|
|
|
{
|
2006-01-20 23:10:18 +00:00
|
|
|
/* Need to save and restore ccline. And set "textlock"
|
2006-01-19 22:16:24 +00:00
|
|
|
* to avoid nasty things like going to another buffer when
|
|
|
|
* evaluating an expression. */
|
2006-01-20 23:10:18 +00:00
|
|
|
++textlock;
|
2004-06-13 20:20:40 +00:00
|
|
|
p = get_expr_line();
|
2006-01-20 23:10:18 +00:00
|
|
|
--textlock;
|
2005-01-11 21:29:04 +00:00
|
|
|
|
2010-10-27 12:58:23 +02:00
|
|
|
if (p != NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2010-10-27 12:58:23 +02:00
|
|
|
len = (int)STRLEN(p);
|
|
|
|
if (realloc_cmdbuff(len + 1) == OK)
|
|
|
|
{
|
|
|
|
ccline.cmdlen = len;
|
|
|
|
STRCPY(ccline.cmdbuff, p);
|
|
|
|
vim_free(p);
|
|
|
|
|
|
|
|
/* Restore the cursor or use the position set with
|
|
|
|
* set_cmdline_pos(). */
|
|
|
|
if (new_cmdpos > ccline.cmdlen)
|
|
|
|
ccline.cmdpos = ccline.cmdlen;
|
|
|
|
else
|
|
|
|
ccline.cmdpos = new_cmdpos;
|
|
|
|
|
|
|
|
KeyTyped = FALSE; /* Don't do p_wc completion. */
|
|
|
|
redrawcmd();
|
|
|
|
goto cmdline_changed;
|
|
|
|
}
|
2018-11-24 14:27:44 +01:00
|
|
|
vim_free(p);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
beep_flush();
|
2010-11-16 14:06:08 +01:00
|
|
|
got_int = FALSE; /* don't abandon the command line */
|
|
|
|
did_emsg = FALSE;
|
|
|
|
emsg_on_display = FALSE;
|
|
|
|
redrawcmd();
|
|
|
|
goto cmdline_not_changed;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (c == Ctrl_G && p_im && restart_edit == 0)
|
|
|
|
restart_edit = 'a';
|
|
|
|
gotesc = TRUE; /* will free ccline.cmdbuff after putting it
|
|
|
|
in history */
|
|
|
|
goto returncmd; /* back to Normal mode */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FEAT_CMDWIN
|
|
|
|
if (c == cedit_key || c == K_CMDWIN)
|
|
|
|
{
|
2014-09-09 18:45:49 +02:00
|
|
|
if (ex_normal_busy == 0 && got_int == FALSE)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Open a window to edit the command line (and history).
|
|
|
|
*/
|
2017-04-07 15:42:25 +02:00
|
|
|
c = open_cmdwin();
|
2014-09-09 18:45:49 +02:00
|
|
|
some_key_typed = TRUE;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
# ifdef FEAT_DIGRAPHS
|
|
|
|
else
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
#ifdef FEAT_DIGRAPHS
|
|
|
|
c = do_digraph(c);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC
|
|
|
|
&& (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL)))
|
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
/* In Ex mode a backslash escapes a newline. */
|
|
|
|
if (exmode_active
|
|
|
|
&& c != ESC
|
|
|
|
&& ccline.cmdpos == ccline.cmdlen
|
2007-07-17 16:15:36 +00:00
|
|
|
&& ccline.cmdpos > 0
|
2005-02-22 08:49:11 +00:00
|
|
|
&& ccline.cmdbuff[ccline.cmdpos - 1] == '\\')
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
if (c == K_KENTER)
|
|
|
|
c = '\n';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gotesc = FALSE; /* Might have typed ESC previously, don't
|
|
|
|
truncate the cmdline now. */
|
|
|
|
if (ccheck_abbr(c + ABBR_OFF))
|
|
|
|
goto cmdline_changed;
|
|
|
|
if (!cmd_silent)
|
|
|
|
{
|
|
|
|
windgoto(msg_row, 0);
|
|
|
|
out_flush();
|
|
|
|
}
|
|
|
|
break;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Completion for 'wildchar' or 'wildcharm' key.
|
|
|
|
* - hitting <ESC> twice means: abandon command line.
|
|
|
|
* - wildcard expansion is only done when the 'wildchar' key is really
|
|
|
|
* typed, not when it comes from a macro
|
|
|
|
*/
|
|
|
|
if ((c == p_wc && !gotesc && KeyTyped) || c == p_wcm)
|
|
|
|
{
|
|
|
|
if (xpc.xp_numfiles > 0) /* typed p_wc at least twice */
|
|
|
|
{
|
|
|
|
/* if 'wildmode' contains "list" may still need to list */
|
|
|
|
if (xpc.xp_numfiles > 1
|
|
|
|
&& !did_wild_list
|
|
|
|
&& (wim_flags[wim_index] & WIM_LIST))
|
|
|
|
{
|
|
|
|
(void)showmatches(&xpc, FALSE);
|
|
|
|
redrawcmd();
|
|
|
|
did_wild_list = TRUE;
|
|
|
|
}
|
|
|
|
if (wim_flags[wim_index] & WIM_LONGEST)
|
2012-11-28 16:49:58 +01:00
|
|
|
res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP,
|
|
|
|
firstc != '@');
|
2004-06-13 20:20:40 +00:00
|
|
|
else if (wim_flags[wim_index] & WIM_FULL)
|
2012-11-28 16:49:58 +01:00
|
|
|
res = nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP,
|
|
|
|
firstc != '@');
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
res = OK; /* don't insert 'wildchar' now */
|
|
|
|
}
|
|
|
|
else /* typed p_wc first time */
|
|
|
|
{
|
|
|
|
wim_index = 0;
|
|
|
|
j = ccline.cmdpos;
|
|
|
|
/* if 'wildmode' first contains "longest", get longest
|
|
|
|
* common part */
|
|
|
|
if (wim_flags[0] & WIM_LONGEST)
|
2012-11-28 16:49:58 +01:00
|
|
|
res = nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP,
|
|
|
|
firstc != '@');
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
2012-11-28 16:49:58 +01:00
|
|
|
res = nextwild(&xpc, WILD_EXPAND_KEEP, WILD_NO_BEEP,
|
|
|
|
firstc != '@');
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* if interrupted while completing, behave like it failed */
|
|
|
|
if (got_int)
|
|
|
|
{
|
|
|
|
(void)vpeekc(); /* remove <C-C> from input stream */
|
|
|
|
got_int = FALSE; /* don't abandon the command line */
|
|
|
|
(void)ExpandOne(&xpc, NULL, NULL, 0, WILD_FREE);
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
xpc.xp_context = EXPAND_NOTHING;
|
|
|
|
#endif
|
|
|
|
goto cmdline_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* when more than one match, and 'wildmode' first contains
|
|
|
|
* "list", or no change and 'wildmode' contains "longest,list",
|
|
|
|
* list all matches */
|
|
|
|
if (res == OK && xpc.xp_numfiles > 1)
|
|
|
|
{
|
|
|
|
/* a "longest" that didn't do anything is skipped (but not
|
|
|
|
* "list:longest") */
|
|
|
|
if (wim_flags[0] == WIM_LONGEST && ccline.cmdpos == j)
|
|
|
|
wim_index = 1;
|
|
|
|
if ((wim_flags[wim_index] & WIM_LIST)
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
|| (p_wmnu && (wim_flags[wim_index] & WIM_FULL) != 0)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (!(wim_flags[0] & WIM_LONGEST))
|
|
|
|
{
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
int p_wmnu_save = p_wmnu;
|
|
|
|
p_wmnu = 0;
|
|
|
|
#endif
|
2012-11-28 16:49:58 +01:00
|
|
|
/* remove match */
|
|
|
|
nextwild(&xpc, WILD_PREV, 0, firstc != '@');
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
p_wmnu = p_wmnu_save;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
(void)showmatches(&xpc, p_wmnu
|
|
|
|
&& ((wim_flags[wim_index] & WIM_LIST) == 0));
|
|
|
|
#else
|
|
|
|
(void)showmatches(&xpc, FALSE);
|
|
|
|
#endif
|
|
|
|
redrawcmd();
|
|
|
|
did_wild_list = TRUE;
|
|
|
|
if (wim_flags[wim_index] & WIM_LONGEST)
|
2012-11-28 16:49:58 +01:00
|
|
|
nextwild(&xpc, WILD_LONGEST, WILD_NO_BEEP,
|
|
|
|
firstc != '@');
|
2004-06-13 20:20:40 +00:00
|
|
|
else if (wim_flags[wim_index] & WIM_FULL)
|
2012-11-28 16:49:58 +01:00
|
|
|
nextwild(&xpc, WILD_NEXT, WILD_NO_BEEP,
|
|
|
|
firstc != '@');
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else
|
2015-07-21 17:53:25 +02:00
|
|
|
vim_beep(BO_WILD);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
else if (xpc.xp_numfiles == -1)
|
|
|
|
xpc.xp_context = EXPAND_NOTHING;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (wim_index < 3)
|
|
|
|
++wim_index;
|
|
|
|
if (c == ESC)
|
|
|
|
gotesc = TRUE;
|
|
|
|
if (res == OK)
|
|
|
|
goto cmdline_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
gotesc = FALSE;
|
|
|
|
|
|
|
|
/* <S-Tab> goes to last match, in a clumsy way */
|
|
|
|
if (c == K_S_TAB && KeyTyped)
|
|
|
|
{
|
2012-11-28 16:49:58 +01:00
|
|
|
if (nextwild(&xpc, WILD_EXPAND_KEEP, 0, firstc != '@') == OK
|
|
|
|
&& nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK
|
|
|
|
&& nextwild(&xpc, WILD_PREV, 0, firstc != '@') == OK)
|
2004-06-13 20:20:40 +00:00
|
|
|
goto cmdline_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == NUL || c == K_ZERO) /* NUL is stored as NL */
|
|
|
|
c = NL;
|
|
|
|
|
|
|
|
do_abbr = TRUE; /* default: check for abbreviation */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Big switch for a typed command line character.
|
|
|
|
*/
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case K_BS:
|
|
|
|
case Ctrl_H:
|
|
|
|
case K_DEL:
|
|
|
|
case K_KDEL:
|
|
|
|
case Ctrl_W:
|
|
|
|
if (c == K_KDEL)
|
|
|
|
c = K_DEL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* delete current character is the same as backspace on next
|
|
|
|
* character, except at end of line
|
|
|
|
*/
|
|
|
|
if (c == K_DEL && ccline.cmdpos != ccline.cmdlen)
|
|
|
|
++ccline.cmdpos;
|
|
|
|
if (has_mbyte && c == K_DEL)
|
|
|
|
ccline.cmdpos += mb_off_next(ccline.cmdbuff,
|
|
|
|
ccline.cmdbuff + ccline.cmdpos);
|
|
|
|
if (ccline.cmdpos > 0)
|
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
|
|
|
|
j = ccline.cmdpos;
|
|
|
|
p = ccline.cmdbuff + j;
|
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
p = mb_prevptr(ccline.cmdbuff, p);
|
|
|
|
if (c == Ctrl_W)
|
|
|
|
{
|
|
|
|
while (p > ccline.cmdbuff && vim_isspace(*p))
|
|
|
|
p = mb_prevptr(ccline.cmdbuff, p);
|
|
|
|
i = mb_get_class(p);
|
|
|
|
while (p > ccline.cmdbuff && mb_get_class(p) == i)
|
|
|
|
p = mb_prevptr(ccline.cmdbuff, p);
|
|
|
|
if (mb_get_class(p) != i)
|
2005-08-10 21:07:57 +00:00
|
|
|
p += (*mb_ptr2len)(p);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-24 15:04:48 +01:00
|
|
|
else if (c == Ctrl_W)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
while (p > ccline.cmdbuff && vim_isspace(p[-1]))
|
|
|
|
--p;
|
|
|
|
i = vim_iswordc(p[-1]);
|
|
|
|
while (p > ccline.cmdbuff && !vim_isspace(p[-1])
|
|
|
|
&& vim_iswordc(p[-1]) == i)
|
|
|
|
--p;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
--p;
|
|
|
|
ccline.cmdpos = (int)(p - ccline.cmdbuff);
|
|
|
|
ccline.cmdlen -= j - ccline.cmdpos;
|
|
|
|
i = ccline.cmdpos;
|
|
|
|
while (i < ccline.cmdlen)
|
|
|
|
ccline.cmdbuff[i++] = ccline.cmdbuff[j++];
|
|
|
|
|
|
|
|
/* Truncate at the end, required for multi-byte chars. */
|
|
|
|
ccline.cmdbuff[ccline.cmdlen] = NUL;
|
2016-08-26 19:13:46 +02:00
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
|
|
|
if (ccline.cmdlen == 0)
|
|
|
|
{
|
2018-08-10 22:07:32 +02:00
|
|
|
is_state.search_start = is_state.save_cursor;
|
2016-09-03 21:04:58 +02:00
|
|
|
/* save view settings, so that the screen
|
|
|
|
* won't be restored at the wrong position */
|
2018-08-10 22:07:32 +02:00
|
|
|
is_state.old_viewstate = is_state.init_viewstate;
|
2016-08-26 19:13:46 +02:00
|
|
|
}
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
redrawcmd();
|
|
|
|
}
|
|
|
|
else if (ccline.cmdlen == 0 && c != Ctrl_W
|
|
|
|
&& ccline.cmdprompt == NULL && indent == 0)
|
|
|
|
{
|
|
|
|
/* In ex and debug mode it doesn't make sense to return. */
|
|
|
|
if (exmode_active
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
|| ccline.cmdfirstc == '>'
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
2018-02-10 18:45:26 +01:00
|
|
|
VIM_CLEAR(ccline.cmdbuff); /* no commandline to return */
|
2004-06-13 20:20:40 +00:00
|
|
|
if (!cmd_silent)
|
|
|
|
{
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
if (cmdmsg_rl)
|
|
|
|
msg_col = Columns;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
msg_col = 0;
|
|
|
|
msg_putchar(' '); /* delete ':' */
|
|
|
|
}
|
2016-08-26 19:13:46 +02:00
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
|
|
|
if (ccline.cmdlen == 0)
|
2018-08-10 22:07:32 +02:00
|
|
|
is_state.search_start = is_state.save_cursor;
|
2016-08-26 19:13:46 +02:00
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
redraw_cmdline = TRUE;
|
|
|
|
goto returncmd; /* back to cmd mode */
|
|
|
|
}
|
|
|
|
goto cmdline_changed;
|
|
|
|
|
|
|
|
case K_INS:
|
|
|
|
case K_KINS:
|
|
|
|
ccline.overstrike = !ccline.overstrike;
|
|
|
|
#ifdef CURSOR_SHAPE
|
|
|
|
ui_cursor_shape(); /* may show different cursor shape */
|
|
|
|
#endif
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
case Ctrl_HAT:
|
2006-03-18 21:40:56 +00:00
|
|
|
if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* ":lmap" mappings exists, toggle use of mappings. */
|
|
|
|
State ^= LANGMAP;
|
2018-03-04 18:08:14 +01:00
|
|
|
#ifdef HAVE_INPUT_METHOD
|
2004-06-13 20:20:40 +00:00
|
|
|
im_set_active(FALSE); /* Disable input method */
|
|
|
|
#endif
|
|
|
|
if (b_im_ptr != NULL)
|
|
|
|
{
|
|
|
|
if (State & LANGMAP)
|
|
|
|
*b_im_ptr = B_IMODE_LMAP;
|
|
|
|
else
|
|
|
|
*b_im_ptr = B_IMODE_NONE;
|
|
|
|
}
|
|
|
|
}
|
2018-03-04 18:08:14 +01:00
|
|
|
#ifdef HAVE_INPUT_METHOD
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* There are no ":lmap" mappings, toggle IM. When
|
|
|
|
* 'imdisable' is set don't try getting the status, it's
|
|
|
|
* always off. */
|
|
|
|
if ((p_imdisable && b_im_ptr != NULL)
|
|
|
|
? *b_im_ptr == B_IMODE_IM : im_get_status())
|
|
|
|
{
|
|
|
|
im_set_active(FALSE); /* Disable input method */
|
|
|
|
if (b_im_ptr != NULL)
|
|
|
|
*b_im_ptr = B_IMODE_NONE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
im_set_active(TRUE); /* Enable input method */
|
|
|
|
if (b_im_ptr != NULL)
|
|
|
|
*b_im_ptr = B_IMODE_IM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (b_im_ptr != NULL)
|
|
|
|
{
|
|
|
|
if (b_im_ptr == &curbuf->b_p_iminsert)
|
|
|
|
set_iminsert_global();
|
|
|
|
else
|
|
|
|
set_imsearch_global();
|
|
|
|
}
|
|
|
|
#ifdef CURSOR_SHAPE
|
|
|
|
ui_cursor_shape(); /* may show different cursor shape */
|
|
|
|
#endif
|
2017-09-16 20:54:51 +02:00
|
|
|
#if defined(FEAT_KEYMAP)
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Show/unshow value of 'keymap' in status lines later. */
|
|
|
|
status_redraw_curbuf();
|
|
|
|
#endif
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
/* case '@': only in very old vi */
|
|
|
|
case Ctrl_U:
|
|
|
|
/* delete all characters left of the cursor */
|
|
|
|
j = ccline.cmdpos;
|
|
|
|
ccline.cmdlen -= j;
|
|
|
|
i = ccline.cmdpos = 0;
|
|
|
|
while (i < ccline.cmdlen)
|
|
|
|
ccline.cmdbuff[i++] = ccline.cmdbuff[j++];
|
|
|
|
/* Truncate at the end, required for multi-byte chars. */
|
|
|
|
ccline.cmdbuff[ccline.cmdlen] = NUL;
|
2016-08-26 19:13:46 +02:00
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
|
|
|
if (ccline.cmdlen == 0)
|
2018-08-10 22:07:32 +02:00
|
|
|
is_state.search_start = is_state.save_cursor;
|
2016-08-26 19:13:46 +02:00
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
redrawcmd();
|
|
|
|
goto cmdline_changed;
|
|
|
|
|
|
|
|
#ifdef FEAT_CLIPBOARD
|
|
|
|
case Ctrl_Y:
|
|
|
|
/* Copy the modeless selection, if there is one. */
|
|
|
|
if (clip_star.state != SELECT_CLEARED)
|
|
|
|
{
|
|
|
|
if (clip_star.state == SELECT_DONE)
|
|
|
|
clip_copy_modeless_selection(TRUE);
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case ESC: /* get here if p_wc != ESC or when ESC typed twice */
|
|
|
|
case Ctrl_C:
|
2005-12-02 00:46:37 +00:00
|
|
|
/* In exmode it doesn't make sense to return. Except when
|
2005-02-07 22:01:03 +00:00
|
|
|
* ":normal" runs out of characters. */
|
|
|
|
if (exmode_active
|
2016-01-31 14:55:40 +01:00
|
|
|
&& (ex_normal_busy == 0 || typebuf.tb_len > 0))
|
2004-06-13 20:20:40 +00:00
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
gotesc = TRUE; /* will free ccline.cmdbuff after
|
|
|
|
putting it in history */
|
|
|
|
goto returncmd; /* back to cmd mode */
|
|
|
|
|
|
|
|
case Ctrl_R: /* insert register */
|
|
|
|
#ifdef USE_ON_FLY_SCROLL
|
|
|
|
dont_scroll = TRUE; /* disallow scrolling here */
|
|
|
|
#endif
|
|
|
|
putcmdline('"', TRUE);
|
|
|
|
++no_mapping;
|
2007-09-13 16:26:47 +00:00
|
|
|
i = c = plain_vgetc(); /* CTRL-R <char> */
|
2004-06-13 20:20:40 +00:00
|
|
|
if (i == Ctrl_O)
|
|
|
|
i = Ctrl_R; /* CTRL-R CTRL-O == CTRL-R CTRL-R */
|
|
|
|
if (i == Ctrl_R)
|
2007-09-13 16:26:47 +00:00
|
|
|
c = plain_vgetc(); /* CTRL-R CTRL-R <char> */
|
2017-07-15 15:21:38 +02:00
|
|
|
extra_char = NUL;
|
2004-06-13 20:20:40 +00:00
|
|
|
--no_mapping;
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
/*
|
|
|
|
* Insert the result of an expression.
|
|
|
|
* Need to save the current command line, to be able to enter
|
|
|
|
* a new one...
|
|
|
|
*/
|
|
|
|
new_cmdpos = -1;
|
|
|
|
if (c == '=')
|
|
|
|
{
|
2018-09-25 22:27:35 +02:00
|
|
|
if (ccline.cmdfirstc == '=' // can't do this recursively
|
|
|
|
|| cmdline_star > 0) // or when typing a password
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
beep_flush();
|
|
|
|
c = ESC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
c = get_expr_register();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (c != ESC) /* use ESC to cancel inserting register */
|
|
|
|
{
|
2006-10-17 14:25:24 +00:00
|
|
|
cmdline_paste(c, i == Ctrl_R, FALSE);
|
2005-12-17 22:06:52 +00:00
|
|
|
|
2005-12-19 22:14:58 +00:00
|
|
|
#ifdef FEAT_EVAL
|
2005-12-17 22:06:52 +00:00
|
|
|
/* When there was a serious error abort getting the
|
|
|
|
* command line. */
|
|
|
|
if (aborting())
|
|
|
|
{
|
|
|
|
gotesc = TRUE; /* will free ccline.cmdbuff after
|
|
|
|
putting it in history */
|
|
|
|
goto returncmd; /* back to cmd mode */
|
|
|
|
}
|
2005-12-19 22:14:58 +00:00
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
KeyTyped = FALSE; /* Don't do p_wc completion. */
|
|
|
|
#ifdef FEAT_EVAL
|
|
|
|
if (new_cmdpos >= 0)
|
|
|
|
{
|
|
|
|
/* set_cmdline_pos() was used */
|
|
|
|
if (new_cmdpos > ccline.cmdlen)
|
|
|
|
ccline.cmdpos = ccline.cmdlen;
|
|
|
|
else
|
|
|
|
ccline.cmdpos = new_cmdpos;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
redrawcmd();
|
|
|
|
goto cmdline_changed;
|
|
|
|
|
|
|
|
case Ctrl_D:
|
|
|
|
if (showmatches(&xpc, FALSE) == EXPAND_NOTHING)
|
|
|
|
break; /* Use ^D as normal char instead */
|
|
|
|
|
|
|
|
redrawcmd();
|
|
|
|
continue; /* don't do incremental search now */
|
|
|
|
|
|
|
|
case K_RIGHT:
|
|
|
|
case K_S_RIGHT:
|
|
|
|
case K_C_RIGHT:
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (ccline.cmdpos >= ccline.cmdlen)
|
|
|
|
break;
|
|
|
|
i = cmdline_charsize(ccline.cmdpos);
|
|
|
|
if (KeyTyped && ccline.cmdspos + i >= Columns * Rows)
|
|
|
|
break;
|
|
|
|
ccline.cmdspos += i;
|
|
|
|
if (has_mbyte)
|
2005-08-10 21:07:57 +00:00
|
|
|
ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff
|
2004-06-13 20:20:40 +00:00
|
|
|
+ ccline.cmdpos);
|
|
|
|
else
|
|
|
|
++ccline.cmdpos;
|
|
|
|
}
|
2005-03-06 23:38:09 +00:00
|
|
|
while ((c == K_S_RIGHT || c == K_C_RIGHT
|
|
|
|
|| (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)))
|
2004-06-13 20:20:40 +00:00
|
|
|
&& ccline.cmdbuff[ccline.cmdpos] != ' ');
|
|
|
|
if (has_mbyte)
|
|
|
|
set_cmdspos_cursor();
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
case K_LEFT:
|
|
|
|
case K_S_LEFT:
|
|
|
|
case K_C_LEFT:
|
2007-12-07 19:28:58 +00:00
|
|
|
if (ccline.cmdpos == 0)
|
|
|
|
goto cmdline_not_changed;
|
2004-06-13 20:20:40 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
--ccline.cmdpos;
|
|
|
|
if (has_mbyte) /* move to first byte of char */
|
|
|
|
ccline.cmdpos -= (*mb_head_off)(ccline.cmdbuff,
|
|
|
|
ccline.cmdbuff + ccline.cmdpos);
|
|
|
|
ccline.cmdspos -= cmdline_charsize(ccline.cmdpos);
|
|
|
|
}
|
2007-12-07 19:28:58 +00:00
|
|
|
while (ccline.cmdpos > 0
|
|
|
|
&& (c == K_S_LEFT || c == K_C_LEFT
|
2005-03-06 23:38:09 +00:00
|
|
|
|| (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)))
|
2004-06-13 20:20:40 +00:00
|
|
|
&& ccline.cmdbuff[ccline.cmdpos - 1] != ' ');
|
|
|
|
if (has_mbyte)
|
|
|
|
set_cmdspos_cursor();
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
case K_IGNORE:
|
2017-04-07 15:42:25 +02:00
|
|
|
/* Ignore mouse event or open_cmdwin() result. */
|
2008-01-02 20:55:27 +00:00
|
|
|
goto cmdline_not_changed;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2019-02-17 17:44:42 +01:00
|
|
|
#ifdef FEAT_GUI_MSWIN
|
|
|
|
/* On MS-Windows ignore <M-F4>, we get it when closing the window
|
|
|
|
* was cancelled. */
|
2006-01-12 23:22:24 +00:00
|
|
|
case K_F4:
|
|
|
|
if (mod_mask == MOD_MASK_ALT)
|
|
|
|
{
|
|
|
|
redrawcmd(); /* somehow the cmdline is cleared */
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_MOUSE
|
|
|
|
case K_MIDDLEDRAG:
|
|
|
|
case K_MIDDLERELEASE:
|
|
|
|
goto cmdline_not_changed; /* Ignore mouse */
|
|
|
|
|
|
|
|
case K_MIDDLEMOUSE:
|
|
|
|
# ifdef FEAT_GUI
|
|
|
|
/* When GUI is active, also paste when 'mouse' is empty */
|
|
|
|
if (!gui.in_use)
|
|
|
|
# endif
|
|
|
|
if (!mouse_has(MOUSE_COMMAND))
|
|
|
|
goto cmdline_not_changed; /* Ignore mouse */
|
2006-02-27 00:08:02 +00:00
|
|
|
# ifdef FEAT_CLIPBOARD
|
2004-06-13 20:20:40 +00:00
|
|
|
if (clip_star.available)
|
2006-10-17 14:25:24 +00:00
|
|
|
cmdline_paste('*', TRUE, TRUE);
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
2006-02-27 00:08:02 +00:00
|
|
|
# endif
|
2006-10-17 14:25:24 +00:00
|
|
|
cmdline_paste(0, TRUE, TRUE);
|
2004-06-13 20:20:40 +00:00
|
|
|
redrawcmd();
|
|
|
|
goto cmdline_changed;
|
|
|
|
|
2006-02-27 00:08:02 +00:00
|
|
|
# ifdef FEAT_DND
|
2004-06-13 20:20:40 +00:00
|
|
|
case K_DROP:
|
2006-10-17 14:25:24 +00:00
|
|
|
cmdline_paste('~', TRUE, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
redrawcmd();
|
|
|
|
goto cmdline_changed;
|
2006-02-27 00:08:02 +00:00
|
|
|
# endif
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
case K_LEFTDRAG:
|
|
|
|
case K_LEFTRELEASE:
|
|
|
|
case K_RIGHTDRAG:
|
|
|
|
case K_RIGHTRELEASE:
|
|
|
|
/* Ignore drag and release events when the button-down wasn't
|
|
|
|
* seen before. */
|
|
|
|
if (ignore_drag_release)
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case K_LEFTMOUSE:
|
|
|
|
case K_RIGHTMOUSE:
|
|
|
|
if (c == K_LEFTRELEASE || c == K_RIGHTRELEASE)
|
|
|
|
ignore_drag_release = TRUE;
|
|
|
|
else
|
|
|
|
ignore_drag_release = FALSE;
|
|
|
|
# ifdef FEAT_GUI
|
|
|
|
/* When GUI is active, also move when 'mouse' is empty */
|
|
|
|
if (!gui.in_use)
|
|
|
|
# endif
|
|
|
|
if (!mouse_has(MOUSE_COMMAND))
|
|
|
|
goto cmdline_not_changed; /* Ignore mouse */
|
|
|
|
# ifdef FEAT_CLIPBOARD
|
|
|
|
if (mouse_row < cmdline_row && clip_star.available)
|
|
|
|
{
|
|
|
|
int button, is_click, is_drag;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle modeless selection.
|
|
|
|
*/
|
|
|
|
button = get_mouse_button(KEY2TERMCAP1(c),
|
|
|
|
&is_click, &is_drag);
|
|
|
|
if (mouse_model_popup() && button == MOUSE_LEFT
|
|
|
|
&& (mod_mask & MOD_MASK_SHIFT))
|
|
|
|
{
|
|
|
|
/* Translate shift-left to right button. */
|
|
|
|
button = MOUSE_RIGHT;
|
|
|
|
mod_mask &= ~MOD_MASK_SHIFT;
|
|
|
|
}
|
|
|
|
clip_modeless(button, is_click, is_drag);
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
set_cmdspos();
|
|
|
|
for (ccline.cmdpos = 0; ccline.cmdpos < ccline.cmdlen;
|
|
|
|
++ccline.cmdpos)
|
|
|
|
{
|
|
|
|
i = cmdline_charsize(ccline.cmdpos);
|
|
|
|
if (mouse_row <= cmdline_row + ccline.cmdspos / Columns
|
|
|
|
&& mouse_col < ccline.cmdspos % Columns + i)
|
|
|
|
break;
|
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
/* Count ">" for double-wide char that doesn't fit. */
|
|
|
|
correct_cmdspos(ccline.cmdpos, i);
|
2005-08-10 21:07:57 +00:00
|
|
|
ccline.cmdpos += (*mb_ptr2len)(ccline.cmdbuff
|
2004-06-13 20:20:40 +00:00
|
|
|
+ ccline.cmdpos) - 1;
|
|
|
|
}
|
|
|
|
ccline.cmdspos += i;
|
|
|
|
}
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
/* Mouse scroll wheel: ignored here */
|
|
|
|
case K_MOUSEDOWN:
|
|
|
|
case K_MOUSEUP:
|
2010-07-25 15:49:07 +02:00
|
|
|
case K_MOUSELEFT:
|
|
|
|
case K_MOUSERIGHT:
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Alternate buttons ignored here */
|
|
|
|
case K_X1MOUSE:
|
|
|
|
case K_X1DRAG:
|
|
|
|
case K_X1RELEASE:
|
|
|
|
case K_X2MOUSE:
|
|
|
|
case K_X2DRAG:
|
|
|
|
case K_X2RELEASE:
|
2017-11-18 18:52:04 +01:00
|
|
|
case K_MOUSEMOVE:
|
2004-06-13 20:20:40 +00:00
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
#endif /* FEAT_MOUSE */
|
|
|
|
|
|
|
|
#ifdef FEAT_GUI
|
|
|
|
case K_LEFTMOUSE_NM: /* mousefocus click, ignored */
|
|
|
|
case K_LEFTRELEASE_NM:
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
case K_VER_SCROLLBAR:
|
2005-10-03 22:02:18 +00:00
|
|
|
if (msg_scrolled == 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
gui_do_scroll();
|
|
|
|
redrawcmd();
|
|
|
|
}
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
case K_HOR_SCROLLBAR:
|
2005-10-03 22:02:18 +00:00
|
|
|
if (msg_scrolled == 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2010-07-25 15:49:07 +02:00
|
|
|
gui_do_horiz_scroll(scrollbar_value, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
redrawcmd();
|
|
|
|
}
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
#endif
|
2006-02-27 00:08:02 +00:00
|
|
|
#ifdef FEAT_GUI_TABLINE
|
|
|
|
case K_TABLINE:
|
|
|
|
case K_TABMENU:
|
|
|
|
/* Don't want to change any tabs here. Make sure the same tab
|
|
|
|
* is still selected. */
|
|
|
|
if (gui_use_tabline())
|
|
|
|
gui_mch_set_curtab(tabpage_index(curtab));
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
case K_SELECT: /* end of Select mode mapping - ignore */
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
case Ctrl_B: /* begin of command line */
|
|
|
|
case K_HOME:
|
|
|
|
case K_KHOME:
|
|
|
|
case K_S_HOME:
|
|
|
|
case K_C_HOME:
|
|
|
|
ccline.cmdpos = 0;
|
|
|
|
set_cmdspos();
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
case Ctrl_E: /* end of command line */
|
|
|
|
case K_END:
|
|
|
|
case K_KEND:
|
|
|
|
case K_S_END:
|
|
|
|
case K_C_END:
|
|
|
|
ccline.cmdpos = ccline.cmdlen;
|
|
|
|
set_cmdspos_cursor();
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
case Ctrl_A: /* all matches */
|
2012-11-28 16:49:58 +01:00
|
|
|
if (nextwild(&xpc, WILD_ALL, 0, firstc != '@') == FAIL)
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
goto cmdline_changed;
|
|
|
|
|
2006-03-16 21:41:35 +00:00
|
|
|
case Ctrl_L:
|
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
2018-08-10 22:07:32 +02:00
|
|
|
if (may_add_char_to_search(firstc, &c, &is_state) == OK)
|
2006-03-16 21:41:35 +00:00
|
|
|
goto cmdline_not_changed;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* completion: longest common part */
|
2012-11-28 16:49:58 +01:00
|
|
|
if (nextwild(&xpc, WILD_LONGEST, 0, firstc != '@') == FAIL)
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
goto cmdline_changed;
|
|
|
|
|
|
|
|
case Ctrl_N: /* next match */
|
|
|
|
case Ctrl_P: /* previous match */
|
2016-08-26 19:56:00 +02:00
|
|
|
if (xpc.xp_numfiles > 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2012-11-28 16:49:58 +01:00
|
|
|
if (nextwild(&xpc, (c == Ctrl_P) ? WILD_PREV : WILD_NEXT,
|
|
|
|
0, firstc != '@') == FAIL)
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
2016-08-27 16:26:56 +02:00
|
|
|
goto cmdline_not_changed;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2017-10-24 21:49:36 +02:00
|
|
|
/* FALLTHROUGH */
|
2004-06-13 20:20:40 +00:00
|
|
|
case K_UP:
|
|
|
|
case K_DOWN:
|
|
|
|
case K_S_UP:
|
|
|
|
case K_S_DOWN:
|
|
|
|
case K_PAGEUP:
|
|
|
|
case K_KPAGEUP:
|
|
|
|
case K_PAGEDOWN:
|
|
|
|
case K_KPAGEDOWN:
|
2019-08-06 21:59:57 +02:00
|
|
|
if (get_hislen() == 0 || firstc == NUL) /* no history */
|
2004-06-13 20:20:40 +00:00
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
|
|
|
i = hiscnt;
|
|
|
|
|
|
|
|
/* save current command string so it can be restored later */
|
|
|
|
if (lookfor == NULL)
|
|
|
|
{
|
|
|
|
if ((lookfor = vim_strsave(ccline.cmdbuff)) == NULL)
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
lookfor[ccline.cmdpos] = NUL;
|
|
|
|
}
|
|
|
|
|
|
|
|
j = (int)STRLEN(lookfor);
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* one step backwards */
|
2005-03-25 21:53:48 +00:00
|
|
|
if (c == K_UP|| c == K_S_UP || c == Ctrl_P
|
2005-03-06 23:38:09 +00:00
|
|
|
|| c == K_PAGEUP || c == K_KPAGEUP)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2019-08-06 21:59:57 +02:00
|
|
|
if (hiscnt == get_hislen()) /* first time */
|
|
|
|
hiscnt = *get_hisidx(histype);
|
|
|
|
else if (hiscnt == 0 && *get_hisidx(histype) != get_hislen() - 1)
|
|
|
|
hiscnt = get_hislen() - 1;
|
|
|
|
else if (hiscnt != *get_hisidx(histype) + 1)
|
2004-06-13 20:20:40 +00:00
|
|
|
--hiscnt;
|
|
|
|
else /* at top of list */
|
|
|
|
{
|
|
|
|
hiscnt = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* one step forwards */
|
|
|
|
{
|
|
|
|
/* on last entry, clear the line */
|
2019-08-06 21:59:57 +02:00
|
|
|
if (hiscnt == *get_hisidx(histype))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2019-08-06 21:59:57 +02:00
|
|
|
hiscnt = get_hislen();
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not on a history line, nothing to do */
|
2019-08-06 21:59:57 +02:00
|
|
|
if (hiscnt == get_hislen())
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
2019-08-06 21:59:57 +02:00
|
|
|
if (hiscnt == get_hislen() - 1) /* wrap around */
|
2004-06-13 20:20:40 +00:00
|
|
|
hiscnt = 0;
|
|
|
|
else
|
|
|
|
++hiscnt;
|
|
|
|
}
|
2019-08-06 21:59:57 +02:00
|
|
|
if (hiscnt < 0 || get_histentry(histype)[hiscnt].hisstr == NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
hiscnt = i;
|
|
|
|
break;
|
|
|
|
}
|
2005-03-25 21:53:48 +00:00
|
|
|
if ((c != K_UP && c != K_DOWN)
|
2005-03-06 23:38:09 +00:00
|
|
|
|| hiscnt == i
|
2019-08-06 21:59:57 +02:00
|
|
|
|| STRNCMP(get_histentry(histype)[hiscnt].hisstr,
|
2004-06-13 20:20:40 +00:00
|
|
|
lookfor, (size_t)j) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hiscnt != i) /* jumped to other entry */
|
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
int len;
|
|
|
|
int old_firstc;
|
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
VIM_CLEAR(ccline.cmdbuff);
|
2008-09-14 12:42:29 +00:00
|
|
|
xpc.xp_context = EXPAND_NOTHING;
|
2019-08-06 21:59:57 +02:00
|
|
|
if (hiscnt == get_hislen())
|
2004-06-13 20:20:40 +00:00
|
|
|
p = lookfor; /* back to the old one */
|
|
|
|
else
|
2019-08-06 21:59:57 +02:00
|
|
|
p = get_histentry(histype)[hiscnt].hisstr;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (histype == HIST_SEARCH
|
|
|
|
&& p != lookfor
|
|
|
|
&& (old_firstc = p[STRLEN(p) + 1]) != firstc)
|
|
|
|
{
|
|
|
|
/* Correct for the separator character used when
|
|
|
|
* adding the history entry vs the one used now.
|
|
|
|
* First loop: count length.
|
|
|
|
* Second loop: copy the characters. */
|
|
|
|
for (i = 0; i <= 1; ++i)
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
for (j = 0; p[j] != NUL; ++j)
|
|
|
|
{
|
|
|
|
/* Replace old sep with new sep, unless it is
|
|
|
|
* escaped. */
|
|
|
|
if (p[j] == old_firstc
|
|
|
|
&& (j == 0 || p[j - 1] != '\\'))
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
ccline.cmdbuff[len] = firstc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Escape new sep, unless it is already
|
|
|
|
* escaped. */
|
|
|
|
if (p[j] == firstc
|
|
|
|
&& (j == 0 || p[j - 1] != '\\'))
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
ccline.cmdbuff[len] = '\\';
|
|
|
|
++len;
|
|
|
|
}
|
|
|
|
if (i > 0)
|
|
|
|
ccline.cmdbuff[len] = p[j];
|
|
|
|
}
|
|
|
|
++len;
|
|
|
|
}
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
alloc_cmdbuff(len);
|
|
|
|
if (ccline.cmdbuff == NULL)
|
|
|
|
goto returncmd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ccline.cmdbuff[len] = NUL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
alloc_cmdbuff((int)STRLEN(p));
|
|
|
|
if (ccline.cmdbuff == NULL)
|
|
|
|
goto returncmd;
|
|
|
|
STRCPY(ccline.cmdbuff, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
|
|
|
|
redrawcmd();
|
|
|
|
goto cmdline_changed;
|
|
|
|
}
|
|
|
|
beep_flush();
|
2016-08-27 16:26:56 +02:00
|
|
|
goto cmdline_not_changed;
|
|
|
|
|
2016-09-03 20:04:34 +02:00
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
2016-08-27 16:26:56 +02:00
|
|
|
case Ctrl_G: /* next match */
|
|
|
|
case Ctrl_T: /* previous match */
|
2018-08-10 22:07:32 +02:00
|
|
|
if (may_adjust_incsearch_highlighting(
|
|
|
|
firstc, count, &is_state, c) == FAIL)
|
2016-09-03 20:04:34 +02:00
|
|
|
goto cmdline_not_changed;
|
|
|
|
break;
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
case Ctrl_V:
|
|
|
|
case Ctrl_Q:
|
|
|
|
#ifdef FEAT_MOUSE
|
|
|
|
ignore_drag_release = TRUE;
|
|
|
|
#endif
|
|
|
|
putcmdline('^', TRUE);
|
|
|
|
c = get_literal(); /* get next (two) character(s) */
|
|
|
|
do_abbr = FALSE; /* don't do abbreviation now */
|
2017-07-15 15:21:38 +02:00
|
|
|
extra_char = NUL;
|
2004-06-13 20:20:40 +00:00
|
|
|
/* may need to remove ^ when composing char was typed */
|
|
|
|
if (enc_utf8 && utf_iscomposing(c) && !cmd_silent)
|
|
|
|
{
|
|
|
|
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
|
|
|
msg_putchar(' ');
|
|
|
|
cursorcmd();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef FEAT_DIGRAPHS
|
|
|
|
case Ctrl_K:
|
|
|
|
#ifdef FEAT_MOUSE
|
|
|
|
ignore_drag_release = TRUE;
|
|
|
|
#endif
|
|
|
|
putcmdline('?', TRUE);
|
|
|
|
#ifdef USE_ON_FLY_SCROLL
|
|
|
|
dont_scroll = TRUE; /* disallow scrolling here */
|
|
|
|
#endif
|
|
|
|
c = get_digraph(TRUE);
|
2017-07-15 15:21:38 +02:00
|
|
|
extra_char = NUL;
|
2004-06-13 20:20:40 +00:00
|
|
|
if (c != NUL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
redrawcmd();
|
|
|
|
goto cmdline_not_changed;
|
|
|
|
#endif /* FEAT_DIGRAPHS */
|
|
|
|
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
case Ctrl__: /* CTRL-_: switch language mode */
|
|
|
|
if (!p_ari)
|
|
|
|
break;
|
2019-02-16 15:10:30 +01:00
|
|
|
cmd_hkmap = !cmd_hkmap;
|
2004-06-13 20:20:40 +00:00
|
|
|
goto cmdline_not_changed;
|
|
|
|
#endif
|
|
|
|
|
2017-01-24 15:57:55 +01:00
|
|
|
case K_PS:
|
|
|
|
bracketed_paste(PASTE_CMDLINE, FALSE, NULL);
|
|
|
|
goto cmdline_changed;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
default:
|
|
|
|
#ifdef UNIX
|
|
|
|
if (c == intr_char)
|
|
|
|
{
|
|
|
|
gotesc = TRUE; /* will free ccline.cmdbuff after
|
|
|
|
putting it in history */
|
|
|
|
goto returncmd; /* back to Normal mode */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Normal character with no special meaning. Just set mod_mask
|
|
|
|
* to 0x0 so that typing Shift-Space in the GUI doesn't enter
|
|
|
|
* the string <S-Space>. This should only happen after ^V.
|
|
|
|
*/
|
|
|
|
if (!IS_SPECIAL(c))
|
|
|
|
mod_mask = 0x0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* End of switch on command line character.
|
|
|
|
* We come here if we have a normal character.
|
|
|
|
*/
|
|
|
|
|
2019-01-24 15:04:48 +01:00
|
|
|
if (do_abbr && (IS_SPECIAL(c) || !vim_iswordc(c))
|
|
|
|
&& (ccheck_abbr(
|
|
|
|
// Add ABBR_OFF for characters above 0x100, this is
|
|
|
|
// what check_abbr() expects.
|
|
|
|
(has_mbyte && c >= 0x100) ? (c + ABBR_OFF) : c)
|
|
|
|
|| c == Ctrl_RSB))
|
2004-06-13 20:20:40 +00:00
|
|
|
goto cmdline_changed;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* put the character in the command line
|
|
|
|
*/
|
|
|
|
if (IS_SPECIAL(c) || mod_mask != 0)
|
|
|
|
put_on_cmdline(get_special_key_name(c, mod_mask), -1, TRUE);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
j = (*mb_char2bytes)(c, IObuff);
|
|
|
|
IObuff[j] = NUL; /* exclude composing chars */
|
|
|
|
put_on_cmdline(IObuff, j, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IObuff[0] = c;
|
|
|
|
put_on_cmdline(IObuff, 1, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto cmdline_changed;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This part implements incremental searches for "/" and "?"
|
|
|
|
* Jump to cmdline_not_changed when a character has been read but the command
|
|
|
|
* line did not change. Then we only search and redraw if something changed in
|
|
|
|
* the past.
|
|
|
|
* Jump to cmdline_changed when the command line did change.
|
|
|
|
* (Sorry for the goto's, I know it is ugly).
|
|
|
|
*/
|
|
|
|
cmdline_not_changed:
|
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
2018-08-10 22:07:32 +02:00
|
|
|
if (!is_state.incsearch_postponed)
|
2004-06-13 20:20:40 +00:00
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cmdline_changed:
|
2018-01-31 15:48:32 +01:00
|
|
|
/* Trigger CmdlineChanged autocommands. */
|
|
|
|
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINECHANGED);
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
2018-08-10 22:07:32 +02:00
|
|
|
may_do_incsearch_highlighting(firstc, count, &is_state);
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
if (cmdmsg_rl
|
|
|
|
# ifdef FEAT_ARABIC
|
2019-06-21 02:30:38 +02:00
|
|
|
|| (p_arshape && !p_tbidi
|
|
|
|
&& cmdline_has_arabic(0, ccline.cmdlen))
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
)
|
|
|
|
/* Always redraw the whole command line to fix shaping and
|
2012-02-22 17:58:04 +01:00
|
|
|
* right-left typing. Not efficient, but it works.
|
|
|
|
* Do it only when there are no characters left to read
|
|
|
|
* to avoid useless intermediate redraws. */
|
|
|
|
if (vpeekc() == NUL)
|
|
|
|
redrawcmd();
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
returncmd:
|
|
|
|
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
cmdmsg_rl = FALSE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ExpandCleanup(&xpc);
|
2008-09-14 12:42:29 +00:00
|
|
|
ccline.xpc = NULL;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
#ifdef FEAT_SEARCH_EXTRA
|
2018-08-12 17:39:14 +02:00
|
|
|
finish_incsearch_highlighting(gotesc, &is_state, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (ccline.cmdbuff != NULL)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Put line in history buffer (":" and "=" only when it was typed).
|
|
|
|
*/
|
|
|
|
if (ccline.cmdlen && firstc != NUL
|
|
|
|
&& (some_key_typed || histype == HIST_SEARCH))
|
|
|
|
{
|
|
|
|
add_to_history(histype, ccline.cmdbuff, TRUE,
|
|
|
|
histype == HIST_SEARCH ? firstc : NUL);
|
|
|
|
if (firstc == ':')
|
|
|
|
{
|
|
|
|
vim_free(new_last_cmdline);
|
|
|
|
new_last_cmdline = vim_strsave(ccline.cmdbuff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-22 14:44:17 +02:00
|
|
|
if (gotesc)
|
|
|
|
abandon_cmdline();
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the screen was shifted up, redraw the whole screen (later).
|
|
|
|
* If the line is too long, clear it, so ruler and shown command do
|
|
|
|
* not get printed in the middle of it.
|
|
|
|
*/
|
|
|
|
msg_check();
|
|
|
|
msg_scroll = save_msg_scroll;
|
|
|
|
redir_off = FALSE;
|
|
|
|
|
|
|
|
/* When the command line was typed, no need for a wait-return prompt. */
|
|
|
|
if (some_key_typed)
|
|
|
|
need_wait_return = FALSE;
|
|
|
|
|
2017-10-19 18:35:51 +02:00
|
|
|
/* Trigger CmdlineLeave autocommands. */
|
|
|
|
trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVE);
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
State = save_State;
|
2018-03-04 18:08:14 +01:00
|
|
|
#ifdef HAVE_INPUT_METHOD
|
2004-06-13 20:20:40 +00:00
|
|
|
if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP)
|
|
|
|
im_save_status(b_im_ptr);
|
|
|
|
im_set_active(FALSE);
|
|
|
|
#endif
|
|
|
|
#ifdef FEAT_MOUSE
|
|
|
|
setmouse();
|
|
|
|
#endif
|
|
|
|
#ifdef CURSOR_SHAPE
|
|
|
|
ui_cursor_shape(); /* may show different cursor shape */
|
|
|
|
#endif
|
2017-03-16 19:58:25 +01:00
|
|
|
sb_text_end_cmdline();
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
theend:
|
2005-01-11 21:29:04 +00:00
|
|
|
{
|
|
|
|
char_u *p = ccline.cmdbuff;
|
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
if (did_save_ccline)
|
|
|
|
restore_cmdline(&save_ccline);
|
|
|
|
else
|
|
|
|
ccline.cmdbuff = NULL;
|
2005-01-11 21:29:04 +00:00
|
|
|
return p;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* Get a command line with a prompt.
|
|
|
|
* This is prepared to be called recursively from getcmdline() (e.g. by
|
|
|
|
* f_input() when evaluating an expression from CTRL-R =).
|
|
|
|
* Returns the command line in allocated memory, or NULL.
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
getcmdline_prompt(
|
|
|
|
int firstc,
|
|
|
|
char_u *prompt, /* command line prompt */
|
|
|
|
int attr, /* attributes for prompt */
|
|
|
|
int xp_context, /* type of expansion */
|
|
|
|
char_u *xp_arg) /* user-defined expansion argument */
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *s;
|
|
|
|
struct cmdline_info save_ccline;
|
2018-09-30 17:11:48 +02:00
|
|
|
int did_save_ccline = FALSE;
|
2004-06-13 20:20:40 +00:00
|
|
|
int msg_col_save = msg_col;
|
2016-03-22 20:31:13 +01:00
|
|
|
int msg_silent_save = msg_silent;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
if (ccline.cmdbuff != NULL)
|
|
|
|
{
|
|
|
|
// Save the values of the current cmdline and restore them below.
|
|
|
|
save_cmdline(&save_ccline);
|
|
|
|
did_save_ccline = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
vim_memset(&ccline, 0, sizeof(struct cmdline_info));
|
2004-06-13 20:20:40 +00:00
|
|
|
ccline.cmdprompt = prompt;
|
|
|
|
ccline.cmdattr = attr;
|
2005-09-20 23:22:24 +00:00
|
|
|
# ifdef FEAT_EVAL
|
|
|
|
ccline.xp_context = xp_context;
|
|
|
|
ccline.xp_arg = xp_arg;
|
|
|
|
ccline.input_fn = (firstc == '@');
|
|
|
|
# endif
|
2016-03-22 20:31:13 +01:00
|
|
|
msg_silent = 0;
|
2018-09-30 17:11:48 +02:00
|
|
|
s = getcmdline_int(firstc, 1L, 0, FALSE);
|
|
|
|
|
|
|
|
if (did_save_ccline)
|
|
|
|
restore_cmdline(&save_ccline);
|
|
|
|
|
2016-03-22 20:31:13 +01:00
|
|
|
msg_silent = msg_silent_save;
|
2011-08-17 16:25:48 +02:00
|
|
|
/* Restore msg_col, the prompt from input() may have changed it.
|
|
|
|
* But only if called recursively and the commandline is therefore being
|
|
|
|
* restored to an old one; if not, the input() prompt stays on the screen,
|
|
|
|
* so we need its modified msg_col left intact. */
|
|
|
|
if (ccline.cmdbuff != NULL)
|
|
|
|
msg_col = msg_col_save;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-19 22:16:24 +00:00
|
|
|
/*
|
2006-01-20 23:10:18 +00:00
|
|
|
* Return TRUE when the text must not be changed and we can't switch to
|
|
|
|
* another window or buffer. Used when editing the command line, evaluating
|
|
|
|
* 'balloonexpr', etc.
|
2006-01-19 22:16:24 +00:00
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
text_locked(void)
|
2006-01-19 22:16:24 +00:00
|
|
|
{
|
|
|
|
#ifdef FEAT_CMDWIN
|
|
|
|
if (cmdwin_type != 0)
|
|
|
|
return TRUE;
|
|
|
|
#endif
|
2006-01-20 23:10:18 +00:00
|
|
|
return textlock != 0;
|
2006-01-19 22:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give an error message for a command that isn't allowed while the cmdline
|
|
|
|
* window is open or editing the cmdline in another way.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
text_locked_msg(void)
|
2016-09-03 16:29:04 +02:00
|
|
|
{
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_(get_text_locked_msg()));
|
2016-09-03 16:29:04 +02:00
|
|
|
}
|
|
|
|
|
2019-01-13 23:38:42 +01:00
|
|
|
char *
|
2016-09-03 16:29:04 +02:00
|
|
|
get_text_locked_msg(void)
|
2006-01-19 22:16:24 +00:00
|
|
|
{
|
|
|
|
#ifdef FEAT_CMDWIN
|
|
|
|
if (cmdwin_type != 0)
|
2016-09-03 16:29:04 +02:00
|
|
|
return e_cmdwin;
|
2006-01-19 22:16:24 +00:00
|
|
|
#endif
|
2016-09-03 16:29:04 +02:00
|
|
|
return e_secure;
|
2006-01-19 22:16:24 +00:00
|
|
|
}
|
|
|
|
|
2006-04-05 20:41:53 +00:00
|
|
|
/*
|
2009-03-05 02:15:53 +00:00
|
|
|
* Check if "curbuf_lock" or "allbuf_lock" is set and return TRUE when it is
|
|
|
|
* and give an error message.
|
2006-04-05 20:41:53 +00:00
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
curbuf_locked(void)
|
2006-04-05 20:41:53 +00:00
|
|
|
{
|
|
|
|
if (curbuf_lock > 0)
|
|
|
|
{
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_("E788: Not allowed to edit another buffer now"));
|
2006-04-05 20:41:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-03-05 02:15:53 +00:00
|
|
|
return allbuf_locked();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if "allbuf_lock" is set and return TRUE when it is and give an error
|
|
|
|
* message.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
allbuf_locked(void)
|
2009-03-05 02:15:53 +00:00
|
|
|
{
|
|
|
|
if (allbuf_lock > 0)
|
|
|
|
{
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_("E811: Not allowed to change buffer information now"));
|
2009-03-05 02:15:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2006-04-05 20:41:53 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
cmdline_charsize(int idx)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
#if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
|
|
|
|
if (cmdline_star > 0) /* showing '*', always 1 position */
|
|
|
|
return 1;
|
|
|
|
#endif
|
|
|
|
return ptr2cells(ccline.cmdbuff + idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the offset of the cursor on the command line for the prompt and
|
|
|
|
* indent.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
set_cmdspos(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-09-20 23:22:24 +00:00
|
|
|
if (ccline.cmdfirstc != NUL)
|
2004-06-13 20:20:40 +00:00
|
|
|
ccline.cmdspos = 1 + ccline.cmdindent;
|
|
|
|
else
|
|
|
|
ccline.cmdspos = 0 + ccline.cmdindent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the screen position for the cursor on the command line.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
set_cmdspos_cursor(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i, m, c;
|
|
|
|
|
|
|
|
set_cmdspos();
|
|
|
|
if (KeyTyped)
|
2005-09-29 18:26:07 +00:00
|
|
|
{
|
2004-06-13 20:20:40 +00:00
|
|
|
m = Columns * Rows;
|
2005-09-29 18:26:07 +00:00
|
|
|
if (m < 0) /* overflow, Columns or Rows at weird value */
|
|
|
|
m = MAXCOL;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
m = MAXCOL;
|
|
|
|
for (i = 0; i < ccline.cmdlen && i < ccline.cmdpos; ++i)
|
|
|
|
{
|
|
|
|
c = cmdline_charsize(i);
|
|
|
|
/* Count ">" for double-wide multi-byte char that doesn't fit. */
|
|
|
|
if (has_mbyte)
|
|
|
|
correct_cmdspos(i, c);
|
2008-06-20 16:31:07 +00:00
|
|
|
/* If the cmdline doesn't fit, show cursor on last visible char.
|
|
|
|
* Don't move the cursor itself, so we can still append. */
|
2004-06-13 20:20:40 +00:00
|
|
|
if ((ccline.cmdspos += c) >= m)
|
|
|
|
{
|
|
|
|
ccline.cmdspos -= c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (has_mbyte)
|
2005-08-10 21:07:57 +00:00
|
|
|
i += (*mb_ptr2len)(ccline.cmdbuff + i) - 1;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the character at "idx", which is "cells" wide, is a multi-byte
|
|
|
|
* character that doesn't fit, so that a ">" must be displayed.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
correct_cmdspos(int idx, int cells)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-08-10 21:07:57 +00:00
|
|
|
if ((*mb_ptr2len)(ccline.cmdbuff + idx) > 1
|
2004-06-13 20:20:40 +00:00
|
|
|
&& (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1
|
|
|
|
&& ccline.cmdspos % Columns + cells > Columns)
|
|
|
|
ccline.cmdspos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get an Ex command line for the ":" command.
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
getexline(
|
|
|
|
int c, /* normally ':', NUL for ":append" */
|
|
|
|
void *cookie UNUSED,
|
2019-06-25 04:12:16 +02:00
|
|
|
int indent, /* indent for inside conditionals */
|
|
|
|
int do_concat)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* When executing a register, remove ':' that's in front of each line. */
|
|
|
|
if (exec_from_reg && vpeekc() == ':')
|
|
|
|
(void)vgetc();
|
2019-06-25 04:12:16 +02:00
|
|
|
return getcmdline(c, 1L, indent, do_concat);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get an Ex command line for Ex mode.
|
|
|
|
* In Ex mode we only use the OS supplied line editing features and no
|
|
|
|
* mappings or abbreviations.
|
2005-02-22 08:49:11 +00:00
|
|
|
* Returns a string in allocated memory or NULL.
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
getexmodeline(
|
|
|
|
int promptc, /* normally ':', NUL for ":append" and '?' for
|
2005-02-22 08:49:11 +00:00
|
|
|
:s prompt */
|
2016-01-30 15:52:46 +01:00
|
|
|
void *cookie UNUSED,
|
2019-06-25 04:12:16 +02:00
|
|
|
int indent, /* indent for inside conditionals */
|
|
|
|
int do_concat UNUSED)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
garray_T line_ga;
|
|
|
|
char_u *pend;
|
|
|
|
int startcol = 0;
|
2007-07-28 12:21:47 +00:00
|
|
|
int c1 = 0;
|
2005-02-22 08:49:11 +00:00
|
|
|
int escaped = FALSE; /* CTRL-V typed */
|
|
|
|
int vcol = 0;
|
|
|
|
char_u *p;
|
2007-07-28 12:21:47 +00:00
|
|
|
int prev_char;
|
2014-06-12 19:44:48 +02:00
|
|
|
int len;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Switch cursor on now. This avoids that it happens after the "\n", which
|
|
|
|
* confuses the system function that computes tabstops. */
|
|
|
|
cursor_on();
|
|
|
|
|
|
|
|
/* always start in column 0; write a newline if necessary */
|
|
|
|
compute_cmdrow();
|
2005-02-22 08:49:11 +00:00
|
|
|
if ((msg_col || msg_didout) && promptc != '?')
|
2004-06-13 20:20:40 +00:00
|
|
|
msg_putchar('\n');
|
2005-02-22 08:49:11 +00:00
|
|
|
if (promptc == ':')
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-02-12 14:29:27 +00:00
|
|
|
/* indent that is only displayed, not in the line itself */
|
2005-02-22 08:49:11 +00:00
|
|
|
if (p_prompt)
|
|
|
|
msg_putchar(':');
|
2004-06-13 20:20:40 +00:00
|
|
|
while (indent-- > 0)
|
|
|
|
msg_putchar(' ');
|
|
|
|
startcol = msg_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
ga_init2(&line_ga, 1, 30);
|
|
|
|
|
2005-02-12 14:29:27 +00:00
|
|
|
/* autoindent for :insert and :append is in the line itself */
|
2005-02-22 08:49:11 +00:00
|
|
|
if (promptc <= 0)
|
2005-02-12 14:29:27 +00:00
|
|
|
{
|
|
|
|
vcol = indent;
|
|
|
|
while (indent >= 8)
|
|
|
|
{
|
|
|
|
ga_append(&line_ga, TAB);
|
2019-01-19 17:43:09 +01:00
|
|
|
msg_puts(" ");
|
2005-02-12 14:29:27 +00:00
|
|
|
indent -= 8;
|
|
|
|
}
|
|
|
|
while (indent-- > 0)
|
|
|
|
{
|
|
|
|
ga_append(&line_ga, ' ');
|
|
|
|
msg_putchar(' ');
|
|
|
|
}
|
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
++no_mapping;
|
|
|
|
++allow_keys;
|
2005-02-12 14:29:27 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Get the line, one character at a time.
|
|
|
|
*/
|
|
|
|
got_int = FALSE;
|
2005-02-22 08:49:11 +00:00
|
|
|
while (!got_int)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2015-04-03 17:11:45 +02:00
|
|
|
long sw;
|
|
|
|
char_u *s;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
if (ga_grow(&line_ga, 40) == FAIL)
|
|
|
|
break;
|
|
|
|
|
2017-02-26 14:00:07 +01:00
|
|
|
/*
|
|
|
|
* Get one character at a time.
|
|
|
|
*/
|
2007-07-28 12:21:47 +00:00
|
|
|
prev_char = c1;
|
2017-02-26 14:00:07 +01:00
|
|
|
|
|
|
|
/* Check for a ":normal" command and no more characters left. */
|
|
|
|
if (ex_normal_busy > 0 && typebuf.tb_len == 0)
|
|
|
|
c1 = '\n';
|
|
|
|
else
|
|
|
|
c1 = vgetc();
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/*
|
2005-02-22 08:49:11 +00:00
|
|
|
* Handle line editing.
|
|
|
|
* Previously this was left to the system, putting the terminal in
|
|
|
|
* cooked mode, but then CTRL-D and CTRL-T can't be used properly.
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
2005-02-22 08:49:11 +00:00
|
|
|
if (got_int)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
msg_putchar('\n');
|
|
|
|
break;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2017-01-24 15:57:55 +01:00
|
|
|
if (c1 == K_PS)
|
|
|
|
{
|
|
|
|
bracketed_paste(PASTE_EX, FALSE, &line_ga);
|
|
|
|
goto redraw;
|
|
|
|
}
|
|
|
|
|
2005-02-22 08:49:11 +00:00
|
|
|
if (!escaped)
|
|
|
|
{
|
|
|
|
/* CR typed means "enter", which is NL */
|
|
|
|
if (c1 == '\r')
|
|
|
|
c1 = '\n';
|
|
|
|
|
|
|
|
if (c1 == BS || c1 == K_BS
|
|
|
|
|| c1 == DEL || c1 == K_DEL || c1 == K_KDEL)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
if (line_ga.ga_len > 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2014-06-12 19:44:48 +02:00
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
p = (char_u *)line_ga.ga_data;
|
|
|
|
p[line_ga.ga_len] = NUL;
|
|
|
|
len = (*mb_head_off)(p, p + line_ga.ga_len - 1) + 1;
|
|
|
|
line_ga.ga_len -= len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
--line_ga.ga_len;
|
2005-02-22 08:49:11 +00:00
|
|
|
goto redraw;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2005-02-22 08:49:11 +00:00
|
|
|
if (c1 == Ctrl_U)
|
|
|
|
{
|
|
|
|
msg_col = startcol;
|
|
|
|
msg_clr_eos();
|
|
|
|
line_ga.ga_len = 0;
|
2015-04-03 17:11:45 +02:00
|
|
|
goto redraw;
|
2005-02-22 08:49:11 +00:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2005-02-22 08:49:11 +00:00
|
|
|
if (c1 == Ctrl_T)
|
|
|
|
{
|
2015-04-03 17:11:45 +02:00
|
|
|
sw = get_sw_value(curbuf);
|
2005-02-22 08:49:11 +00:00
|
|
|
p = (char_u *)line_ga.ga_data;
|
|
|
|
p[line_ga.ga_len] = NUL;
|
2014-06-25 14:39:50 +02:00
|
|
|
indent = get_indent_str(p, 8, FALSE);
|
2012-08-08 18:01:05 +02:00
|
|
|
indent += sw - indent % sw;
|
2005-02-22 08:49:11 +00:00
|
|
|
add_indent:
|
2014-06-25 14:39:50 +02:00
|
|
|
while (get_indent_str(p, 8, FALSE) < indent)
|
2005-02-22 08:49:11 +00:00
|
|
|
{
|
2015-08-11 19:14:00 +02:00
|
|
|
(void)ga_grow(&line_ga, 2); /* one more for the NUL */
|
2015-04-03 17:11:45 +02:00
|
|
|
p = (char_u *)line_ga.ga_data;
|
|
|
|
s = skipwhite(p);
|
2005-02-22 08:49:11 +00:00
|
|
|
mch_memmove(s + 1, s, line_ga.ga_len - (s - p) + 1);
|
|
|
|
*s = ' ';
|
|
|
|
++line_ga.ga_len;
|
|
|
|
}
|
|
|
|
redraw:
|
|
|
|
/* redraw the line */
|
|
|
|
msg_col = startcol;
|
|
|
|
vcol = 0;
|
2014-06-12 19:44:48 +02:00
|
|
|
p = (char_u *)line_ga.ga_data;
|
|
|
|
p[line_ga.ga_len] = NUL;
|
|
|
|
while (p < (char_u *)line_ga.ga_data + line_ga.ga_len)
|
2005-02-22 08:49:11 +00:00
|
|
|
{
|
|
|
|
if (*p == TAB)
|
2005-02-12 14:29:27 +00:00
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
do
|
|
|
|
msg_putchar(' ');
|
2019-03-30 18:47:01 +01:00
|
|
|
while (++vcol % 8);
|
2014-06-12 19:44:48 +02:00
|
|
|
++p;
|
2005-02-12 14:29:27 +00:00
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
else
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2014-06-12 19:44:48 +02:00
|
|
|
len = MB_PTR2LEN(p);
|
|
|
|
msg_outtrans_len(p, len);
|
|
|
|
vcol += ptr2cells(p);
|
|
|
|
p += len;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
msg_clr_eos();
|
2007-07-28 12:21:47 +00:00
|
|
|
windgoto(msg_row, msg_col);
|
2005-02-22 08:49:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2005-02-22 08:49:11 +00:00
|
|
|
if (c1 == Ctrl_D)
|
|
|
|
{
|
|
|
|
/* Delete one shiftwidth. */
|
|
|
|
p = (char_u *)line_ga.ga_data;
|
|
|
|
if (prev_char == '0' || prev_char == '^')
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
if (prev_char == '^')
|
|
|
|
ex_keep_indent = TRUE;
|
|
|
|
indent = 0;
|
|
|
|
p[--line_ga.ga_len] = NUL;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
p[line_ga.ga_len] = NUL;
|
2014-06-25 14:39:50 +02:00
|
|
|
indent = get_indent_str(p, 8, FALSE);
|
2015-04-03 17:11:45 +02:00
|
|
|
if (indent > 0)
|
|
|
|
{
|
|
|
|
--indent;
|
|
|
|
indent -= indent % get_sw_value(curbuf);
|
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
}
|
2014-06-25 14:39:50 +02:00
|
|
|
while (get_indent_str(p, 8, FALSE) > indent)
|
2005-02-22 08:49:11 +00:00
|
|
|
{
|
2015-04-03 17:11:45 +02:00
|
|
|
s = skipwhite(p);
|
2005-02-22 08:49:11 +00:00
|
|
|
mch_memmove(s - 1, s, line_ga.ga_len - (s - p) + 1);
|
|
|
|
--line_ga.ga_len;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
goto add_indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c1 == Ctrl_V || c1 == Ctrl_Q)
|
|
|
|
{
|
|
|
|
escaped = TRUE;
|
|
|
|
continue;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
|
|
|
|
/* Ignore special key codes: mouse movement, K_IGNORE, etc. */
|
|
|
|
if (IS_SPECIAL(c1))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_SPECIAL(c1))
|
|
|
|
c1 = '?';
|
2014-06-12 19:44:48 +02:00
|
|
|
if (has_mbyte)
|
|
|
|
len = (*mb_char2bytes)(c1,
|
|
|
|
(char_u *)line_ga.ga_data + line_ga.ga_len);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = 1;
|
|
|
|
((char_u *)line_ga.ga_data)[line_ga.ga_len] = c1;
|
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
if (c1 == '\n')
|
|
|
|
msg_putchar('\n');
|
|
|
|
else if (c1 == TAB)
|
|
|
|
{
|
|
|
|
/* Don't use chartabsize(), 'ts' can be different */
|
|
|
|
do
|
|
|
|
msg_putchar(' ');
|
2019-03-30 18:47:01 +01:00
|
|
|
while (++vcol % 8);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
msg_outtrans_len(
|
2014-06-12 19:44:48 +02:00
|
|
|
((char_u *)line_ga.ga_data) + line_ga.ga_len, len);
|
2005-02-22 08:49:11 +00:00
|
|
|
vcol += char2cells(c1);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2014-06-12 19:44:48 +02:00
|
|
|
line_ga.ga_len += len;
|
2005-02-22 08:49:11 +00:00
|
|
|
escaped = FALSE;
|
|
|
|
|
|
|
|
windgoto(msg_row, msg_col);
|
2005-02-12 14:29:27 +00:00
|
|
|
pend = (char_u *)(line_ga.ga_data) + line_ga.ga_len;
|
2005-02-22 08:49:11 +00:00
|
|
|
|
2010-09-29 15:50:30 +02:00
|
|
|
/* We are done when a NL is entered, but not when it comes after an
|
|
|
|
* odd number of backslashes, that results in a NUL. */
|
|
|
|
if (line_ga.ga_len > 0 && pend[-1] == '\n')
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2010-09-29 15:50:30 +02:00
|
|
|
int bcount = 0;
|
|
|
|
|
|
|
|
while (line_ga.ga_len - 2 >= bcount && pend[-2 - bcount] == '\\')
|
|
|
|
++bcount;
|
|
|
|
|
|
|
|
if (bcount > 0)
|
|
|
|
{
|
|
|
|
/* Halve the number of backslashes: "\NL" -> "NUL", "\\NL" ->
|
|
|
|
* "\NL", etc. */
|
|
|
|
line_ga.ga_len -= (bcount + 1) / 2;
|
|
|
|
pend -= (bcount + 1) / 2;
|
|
|
|
pend[-1] = '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((bcount & 1) == 0)
|
|
|
|
{
|
|
|
|
--line_ga.ga_len;
|
|
|
|
--pend;
|
|
|
|
*pend = NUL;
|
|
|
|
break;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-22 08:49:11 +00:00
|
|
|
--no_mapping;
|
|
|
|
--allow_keys;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* make following messages go to the next line */
|
|
|
|
msg_didout = FALSE;
|
|
|
|
msg_col = 0;
|
|
|
|
if (msg_row < Rows - 1)
|
|
|
|
++msg_row;
|
|
|
|
emsg_on_display = FALSE; /* don't want ui_delay() */
|
|
|
|
|
|
|
|
if (got_int)
|
|
|
|
ga_clear(&line_ga);
|
|
|
|
|
|
|
|
return (char_u *)line_ga.ga_data;
|
|
|
|
}
|
|
|
|
|
2005-09-01 20:46:49 +00:00
|
|
|
# if defined(MCH_CURSOR_SHAPE) || defined(FEAT_GUI) \
|
|
|
|
|| defined(FEAT_MOUSESHAPE) || defined(PROTO)
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Return TRUE if ccline.overstrike is on.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
cmdline_overstrike(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
return ccline.overstrike;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return TRUE if the cursor is at the end of the cmdline.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
cmdline_at_end(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
return (ccline.cmdpos >= ccline.cmdlen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-12-06 19:59:18 +00:00
|
|
|
#if (defined(FEAT_XIM) && (defined(FEAT_GUI_GTK))) || defined(PROTO)
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Return the virtual column number at the current cursor position.
|
|
|
|
* This is used by the IM code to obtain the start of the preedit string.
|
|
|
|
*/
|
|
|
|
colnr_T
|
2016-01-30 15:52:46 +01:00
|
|
|
cmdline_getvcol_cursor(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen)
|
|
|
|
return MAXCOL;
|
|
|
|
|
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
colnr_T col;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (col = 0; i < ccline.cmdpos; ++col)
|
2005-08-10 21:07:57 +00:00
|
|
|
i += (*mb_ptr2len)(ccline.cmdbuff + i);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ccline.cmdpos;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
|
|
|
|
/*
|
|
|
|
* If part of the command line is an IM preedit string, redraw it with
|
|
|
|
* IM feedback attributes. The cursor position is restored after drawing.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
redrawcmd_preedit(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if ((State & CMDLINE)
|
|
|
|
&& xic != NULL
|
2006-09-14 08:25:49 +00:00
|
|
|
/* && im_get_status() doesn't work when using SCIM */
|
2004-06-13 20:20:40 +00:00
|
|
|
&& !p_imdisable
|
|
|
|
&& im_is_preediting())
|
|
|
|
{
|
|
|
|
int cmdpos = 0;
|
|
|
|
int cmdspos;
|
|
|
|
int old_row;
|
|
|
|
int old_col;
|
|
|
|
colnr_T col;
|
|
|
|
|
|
|
|
old_row = msg_row;
|
|
|
|
old_col = msg_col;
|
2005-09-20 23:22:24 +00:00
|
|
|
cmdspos = ((ccline.cmdfirstc != NUL) ? 1 : 0) + ccline.cmdindent;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
for (col = 0; col < preedit_start_col
|
|
|
|
&& cmdpos < ccline.cmdlen; ++col)
|
|
|
|
{
|
|
|
|
cmdspos += (*mb_ptr2cells)(ccline.cmdbuff + cmdpos);
|
2005-08-10 21:07:57 +00:00
|
|
|
cmdpos += (*mb_ptr2len)(ccline.cmdbuff + cmdpos);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmdspos += preedit_start_col;
|
|
|
|
cmdpos += preedit_start_col;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_row = cmdline_row + (cmdspos / (int)Columns);
|
|
|
|
msg_col = cmdspos % (int)Columns;
|
|
|
|
if (msg_row >= Rows)
|
|
|
|
msg_row = Rows - 1;
|
|
|
|
|
|
|
|
for (col = 0; cmdpos < ccline.cmdlen; ++col)
|
|
|
|
{
|
|
|
|
int char_len;
|
|
|
|
int char_attr;
|
|
|
|
|
|
|
|
char_attr = im_get_feedback_attr(col);
|
|
|
|
if (char_attr < 0)
|
|
|
|
break; /* end of preedit string */
|
|
|
|
|
|
|
|
if (has_mbyte)
|
2005-08-10 21:07:57 +00:00
|
|
|
char_len = (*mb_ptr2len)(ccline.cmdbuff + cmdpos);
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
char_len = 1;
|
|
|
|
|
|
|
|
msg_outtrans_len_attr(ccline.cmdbuff + cmdpos, char_len, char_attr);
|
|
|
|
cmdpos += char_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_row = old_row;
|
|
|
|
msg_col = old_col;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* FEAT_XIM && FEAT_GUI_GTK */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new command line buffer.
|
|
|
|
* Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
alloc_cmdbuff(int len)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* give some extra space to avoid having to allocate all the time
|
|
|
|
*/
|
|
|
|
if (len < 80)
|
|
|
|
len = 100;
|
|
|
|
else
|
|
|
|
len += 20;
|
|
|
|
|
|
|
|
ccline.cmdbuff = alloc(len); /* caller should check for out-of-memory */
|
|
|
|
ccline.cmdbufflen = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-allocate the command line to length len + something extra.
|
|
|
|
* return FAIL for failure, OK otherwise
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
realloc_cmdbuff(int len)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
|
2010-08-13 19:12:07 +02:00
|
|
|
if (len < ccline.cmdbufflen)
|
|
|
|
return OK; /* no need to resize */
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
p = ccline.cmdbuff;
|
|
|
|
alloc_cmdbuff(len); /* will get some more */
|
|
|
|
if (ccline.cmdbuff == NULL) /* out of memory */
|
|
|
|
{
|
|
|
|
ccline.cmdbuff = p; /* keep the old one */
|
|
|
|
return FAIL;
|
|
|
|
}
|
2010-08-13 16:51:26 +02:00
|
|
|
/* There isn't always a NUL after the command, but it may need to be
|
|
|
|
* there, thus copy up to the NUL and add a NUL. */
|
|
|
|
mch_memmove(ccline.cmdbuff, p, (size_t)ccline.cmdlen);
|
|
|
|
ccline.cmdbuff[ccline.cmdlen] = NUL;
|
2004-06-13 20:20:40 +00:00
|
|
|
vim_free(p);
|
2008-09-14 12:42:29 +00:00
|
|
|
|
|
|
|
if (ccline.xpc != NULL
|
|
|
|
&& ccline.xpc->xp_pattern != NULL
|
|
|
|
&& ccline.xpc->xp_context != EXPAND_NOTHING
|
|
|
|
&& ccline.xpc->xp_context != EXPAND_UNSUCCESSFUL)
|
|
|
|
{
|
2008-11-28 10:01:10 +00:00
|
|
|
int i = (int)(ccline.xpc->xp_pattern - p);
|
2008-09-14 12:42:29 +00:00
|
|
|
|
|
|
|
/* If xp_pattern points inside the old cmdbuff it needs to be adjusted
|
|
|
|
* to point into the newly allocated memory. */
|
|
|
|
if (i >= 0 && i <= ccline.cmdlen)
|
|
|
|
ccline.xpc->xp_pattern = ccline.cmdbuff + i;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-06-25 23:04:51 +00:00
|
|
|
#if defined(FEAT_ARABIC) || defined(PROTO)
|
|
|
|
static char_u *arshape_buf = NULL;
|
|
|
|
|
|
|
|
# if defined(EXITFREE) || defined(PROTO)
|
|
|
|
void
|
2019-07-04 20:26:21 +02:00
|
|
|
free_arshape_buf(void)
|
2005-06-25 23:04:51 +00:00
|
|
|
{
|
|
|
|
vim_free(arshape_buf);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Draw part of the cmdline at the current cursor position. But draw stars
|
|
|
|
* when cmdline_star is TRUE.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
draw_cmdline(int start, int len)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
#if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (cmdline_star > 0)
|
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
{
|
|
|
|
msg_putchar('*');
|
|
|
|
if (has_mbyte)
|
2005-08-10 21:07:57 +00:00
|
|
|
i += (*mb_ptr2len)(ccline.cmdbuff + start + i) - 1;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef FEAT_ARABIC
|
2019-06-21 02:30:38 +02:00
|
|
|
if (p_arshape && !p_tbidi && cmdline_has_arabic(start, len))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
static int buflen = 0;
|
|
|
|
char_u *p;
|
|
|
|
int j;
|
|
|
|
int newlen = 0;
|
|
|
|
int mb_l;
|
2006-03-09 22:32:39 +00:00
|
|
|
int pc, pc1 = 0;
|
2004-06-13 20:20:40 +00:00
|
|
|
int prev_c = 0;
|
|
|
|
int prev_c1 = 0;
|
2006-03-06 23:29:24 +00:00
|
|
|
int u8c;
|
|
|
|
int u8cc[MAX_MCO];
|
2004-06-13 20:20:40 +00:00
|
|
|
int nc = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do arabic shaping into a temporary buffer. This is very
|
|
|
|
* inefficient!
|
|
|
|
*/
|
2005-09-06 19:25:11 +00:00
|
|
|
if (len * 2 + 2 > buflen)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* Re-allocate the buffer. We keep it around to avoid a lot of
|
|
|
|
* alloc()/free() calls. */
|
2005-06-25 23:04:51 +00:00
|
|
|
vim_free(arshape_buf);
|
2005-09-06 19:25:11 +00:00
|
|
|
buflen = len * 2 + 2;
|
2005-06-25 23:04:51 +00:00
|
|
|
arshape_buf = alloc(buflen);
|
|
|
|
if (arshape_buf == NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
return; /* out of memory */
|
|
|
|
}
|
|
|
|
|
2005-09-06 19:25:11 +00:00
|
|
|
if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start)))
|
|
|
|
{
|
|
|
|
/* Prepend a space to draw the leading composing char on. */
|
|
|
|
arshape_buf[0] = ' ';
|
|
|
|
newlen = 1;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
for (j = start; j < start + len; j += mb_l)
|
|
|
|
{
|
|
|
|
p = ccline.cmdbuff + j;
|
2006-03-06 23:29:24 +00:00
|
|
|
u8c = utfc_ptr2char_len(p, u8cc, start + len - j);
|
2005-08-10 21:07:57 +00:00
|
|
|
mb_l = utfc_ptr2len_len(p, start + len - j);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (ARABIC_CHAR(u8c))
|
|
|
|
{
|
|
|
|
/* Do Arabic shaping. */
|
|
|
|
if (cmdmsg_rl)
|
|
|
|
{
|
|
|
|
/* displaying from right to left */
|
|
|
|
pc = prev_c;
|
|
|
|
pc1 = prev_c1;
|
2006-03-06 23:29:24 +00:00
|
|
|
prev_c1 = u8cc[0];
|
2004-06-13 20:20:40 +00:00
|
|
|
if (j + mb_l >= start + len)
|
|
|
|
nc = NUL;
|
|
|
|
else
|
|
|
|
nc = utf_ptr2char(p + mb_l);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* displaying from left to right */
|
|
|
|
if (j + mb_l >= start + len)
|
|
|
|
pc = NUL;
|
|
|
|
else
|
2006-03-06 23:29:24 +00:00
|
|
|
{
|
|
|
|
int pcc[MAX_MCO];
|
|
|
|
|
|
|
|
pc = utfc_ptr2char_len(p + mb_l, pcc,
|
2004-06-13 20:20:40 +00:00
|
|
|
start + len - j - mb_l);
|
2006-03-06 23:29:24 +00:00
|
|
|
pc1 = pcc[0];
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
nc = prev_c;
|
|
|
|
}
|
|
|
|
prev_c = u8c;
|
|
|
|
|
2006-03-06 23:29:24 +00:00
|
|
|
u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2005-06-25 23:04:51 +00:00
|
|
|
newlen += (*mb_char2bytes)(u8c, arshape_buf + newlen);
|
2006-03-06 23:29:24 +00:00
|
|
|
if (u8cc[0] != 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2006-03-06 23:29:24 +00:00
|
|
|
newlen += (*mb_char2bytes)(u8cc[0], arshape_buf + newlen);
|
|
|
|
if (u8cc[1] != 0)
|
|
|
|
newlen += (*mb_char2bytes)(u8cc[1],
|
2005-06-25 23:04:51 +00:00
|
|
|
arshape_buf + newlen);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev_c = u8c;
|
2005-06-25 23:04:51 +00:00
|
|
|
mch_memmove(arshape_buf + newlen, p, mb_l);
|
2004-06-13 20:20:40 +00:00
|
|
|
newlen += mb_l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-25 23:04:51 +00:00
|
|
|
msg_outtrans_len(arshape_buf, newlen);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
msg_outtrans_len(ccline.cmdbuff + start, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put a character on the command line. Shifts the following text to the
|
|
|
|
* right when "shift" is TRUE. Used for CTRL-V, CTRL-K, etc.
|
|
|
|
* "c" must be printable (fit in one display cell)!
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
putcmdline(int c, int shift)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (cmd_silent)
|
|
|
|
return;
|
|
|
|
msg_no_more = TRUE;
|
|
|
|
msg_putchar(c);
|
|
|
|
if (shift)
|
|
|
|
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
|
|
|
msg_no_more = FALSE;
|
|
|
|
cursorcmd();
|
2017-07-16 15:24:01 +02:00
|
|
|
extra_char = c;
|
|
|
|
extra_char_shift = shift;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Undo a putcmdline(c, FALSE).
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
unputcmdline(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (cmd_silent)
|
|
|
|
return;
|
|
|
|
msg_no_more = TRUE;
|
|
|
|
if (ccline.cmdlen == ccline.cmdpos)
|
|
|
|
msg_putchar(' ');
|
2012-06-06 12:03:06 +02:00
|
|
|
else if (has_mbyte)
|
|
|
|
draw_cmdline(ccline.cmdpos,
|
|
|
|
(*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos));
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
draw_cmdline(ccline.cmdpos, 1);
|
|
|
|
msg_no_more = FALSE;
|
|
|
|
cursorcmd();
|
2017-07-16 15:24:01 +02:00
|
|
|
extra_char = NUL;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put the given string, of the given length, onto the command line.
|
|
|
|
* If len is -1, then STRLEN() is used to calculate the length.
|
|
|
|
* If 'redraw' is TRUE then the new part of the command line, and the remaining
|
|
|
|
* part will be redrawn, otherwise it will not. If this function is called
|
|
|
|
* twice in a row, then 'redraw' should be FALSE and redrawcmd() should be
|
|
|
|
* called afterwards.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
put_on_cmdline(char_u *str, int len, int redraw)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
int i;
|
|
|
|
int m;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
len = (int)STRLEN(str);
|
|
|
|
|
|
|
|
/* Check if ccline.cmdbuff needs to be longer */
|
|
|
|
if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen)
|
2010-08-13 19:12:07 +02:00
|
|
|
retval = realloc_cmdbuff(ccline.cmdlen + len + 1);
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
retval = OK;
|
|
|
|
if (retval == OK)
|
|
|
|
{
|
|
|
|
if (!ccline.overstrike)
|
|
|
|
{
|
|
|
|
mch_memmove(ccline.cmdbuff + ccline.cmdpos + len,
|
|
|
|
ccline.cmdbuff + ccline.cmdpos,
|
|
|
|
(size_t)(ccline.cmdlen - ccline.cmdpos));
|
|
|
|
ccline.cmdlen += len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
/* Count nr of characters in the new string. */
|
|
|
|
m = 0;
|
2005-08-10 21:07:57 +00:00
|
|
|
for (i = 0; i < len; i += (*mb_ptr2len)(str + i))
|
2004-06-13 20:20:40 +00:00
|
|
|
++m;
|
|
|
|
/* Count nr of bytes in cmdline that are overwritten by these
|
|
|
|
* characters. */
|
|
|
|
for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0;
|
2005-08-10 21:07:57 +00:00
|
|
|
i += (*mb_ptr2len)(ccline.cmdbuff + i))
|
2004-06-13 20:20:40 +00:00
|
|
|
--m;
|
|
|
|
if (i < ccline.cmdlen)
|
|
|
|
{
|
|
|
|
mch_memmove(ccline.cmdbuff + ccline.cmdpos + len,
|
|
|
|
ccline.cmdbuff + i, (size_t)(ccline.cmdlen - i));
|
|
|
|
ccline.cmdlen += ccline.cmdpos + len - i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ccline.cmdlen = ccline.cmdpos + len;
|
|
|
|
}
|
2019-01-24 15:04:48 +01:00
|
|
|
else if (ccline.cmdpos + len > ccline.cmdlen)
|
2004-06-13 20:20:40 +00:00
|
|
|
ccline.cmdlen = ccline.cmdpos + len;
|
|
|
|
}
|
|
|
|
mch_memmove(ccline.cmdbuff + ccline.cmdpos, str, (size_t)len);
|
|
|
|
ccline.cmdbuff[ccline.cmdlen] = NUL;
|
|
|
|
|
|
|
|
if (enc_utf8)
|
|
|
|
{
|
|
|
|
/* When the inserted text starts with a composing character,
|
|
|
|
* backup to the character before it. There could be two of them.
|
|
|
|
*/
|
|
|
|
i = 0;
|
|
|
|
c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
|
|
|
|
while (ccline.cmdpos > 0 && utf_iscomposing(c))
|
|
|
|
{
|
|
|
|
i = (*mb_head_off)(ccline.cmdbuff,
|
|
|
|
ccline.cmdbuff + ccline.cmdpos - 1) + 1;
|
|
|
|
ccline.cmdpos -= i;
|
|
|
|
len += i;
|
|
|
|
c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos);
|
|
|
|
}
|
2019-01-24 15:04:48 +01:00
|
|
|
#ifdef FEAT_ARABIC
|
2004-06-13 20:20:40 +00:00
|
|
|
if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c))
|
|
|
|
{
|
|
|
|
/* Check the previous character for Arabic combining pair. */
|
|
|
|
i = (*mb_head_off)(ccline.cmdbuff,
|
|
|
|
ccline.cmdbuff + ccline.cmdpos - 1) + 1;
|
|
|
|
if (arabic_combine(utf_ptr2char(ccline.cmdbuff
|
|
|
|
+ ccline.cmdpos - i), c))
|
|
|
|
{
|
|
|
|
ccline.cmdpos -= i;
|
|
|
|
len += i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
}
|
2019-01-24 15:04:48 +01:00
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
if (i != 0)
|
|
|
|
{
|
|
|
|
/* Also backup the cursor position. */
|
|
|
|
i = ptr2cells(ccline.cmdbuff + ccline.cmdpos);
|
|
|
|
ccline.cmdspos -= i;
|
|
|
|
msg_col -= i;
|
|
|
|
if (msg_col < 0)
|
|
|
|
{
|
|
|
|
msg_col += Columns;
|
|
|
|
--msg_row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (redraw && !cmd_silent)
|
|
|
|
{
|
|
|
|
msg_no_more = TRUE;
|
|
|
|
i = cmdline_row;
|
2011-09-30 17:46:21 +02:00
|
|
|
cursorcmd();
|
2004-06-13 20:20:40 +00:00
|
|
|
draw_cmdline(ccline.cmdpos, ccline.cmdlen - ccline.cmdpos);
|
|
|
|
/* Avoid clearing the rest of the line too often. */
|
|
|
|
if (cmdline_row != i || ccline.overstrike)
|
|
|
|
msg_clr_eos();
|
|
|
|
msg_no_more = FALSE;
|
|
|
|
}
|
2019-02-16 15:10:30 +01:00
|
|
|
if (KeyTyped)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2019-02-16 15:10:30 +01:00
|
|
|
m = Columns * Rows;
|
|
|
|
if (m < 0) /* overflow, Columns or Rows at weird value */
|
2004-06-13 20:20:40 +00:00
|
|
|
m = MAXCOL;
|
2019-02-16 15:10:30 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
m = MAXCOL;
|
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
{
|
|
|
|
c = cmdline_charsize(ccline.cmdpos);
|
|
|
|
/* count ">" for a double-wide char that doesn't fit. */
|
|
|
|
if (has_mbyte)
|
|
|
|
correct_cmdspos(ccline.cmdpos, c);
|
|
|
|
/* Stop cursor at the end of the screen, but do increment the
|
|
|
|
* insert position, so that entering a very long command
|
|
|
|
* works, even though you can't see it. */
|
|
|
|
if (ccline.cmdspos + c < m)
|
|
|
|
ccline.cmdspos += c;
|
2019-01-24 15:04:48 +01:00
|
|
|
|
2019-02-16 15:10:30 +01:00
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
c = (*mb_ptr2len)(ccline.cmdbuff + ccline.cmdpos) - 1;
|
|
|
|
if (c > len - i - 1)
|
|
|
|
c = len - i - 1;
|
|
|
|
ccline.cmdpos += c;
|
|
|
|
i += c;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
2019-02-16 15:10:30 +01:00
|
|
|
++ccline.cmdpos;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (redraw)
|
|
|
|
msg_check();
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2005-01-11 21:29:04 +00:00
|
|
|
static struct cmdline_info prev_ccline;
|
|
|
|
static int prev_ccline_used = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save ccline, because obtaining the "=" register may execute "normal :cmd"
|
|
|
|
* and overwrite it. But get_cmdline_str() may need it, thus make it
|
|
|
|
* available globally in prev_ccline.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
save_cmdline(struct cmdline_info *ccp)
|
2005-01-11 21:29:04 +00:00
|
|
|
{
|
|
|
|
if (!prev_ccline_used)
|
|
|
|
{
|
|
|
|
vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info));
|
|
|
|
prev_ccline_used = TRUE;
|
|
|
|
}
|
|
|
|
*ccp = prev_ccline;
|
|
|
|
prev_ccline = ccline;
|
2018-09-30 17:11:48 +02:00
|
|
|
ccline.cmdbuff = NULL; // signal that ccline is not in use
|
2005-01-11 21:29:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-05-10 18:25:20 +00:00
|
|
|
* Restore ccline after it has been saved with save_cmdline().
|
2005-01-11 21:29:04 +00:00
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
restore_cmdline(struct cmdline_info *ccp)
|
2005-01-11 21:29:04 +00:00
|
|
|
{
|
|
|
|
ccline = prev_ccline;
|
|
|
|
prev_ccline = *ccp;
|
|
|
|
}
|
|
|
|
|
2004-07-10 09:47:34 +00:00
|
|
|
/*
|
2015-12-17 14:04:24 +01:00
|
|
|
* Paste a yank register into the command line.
|
|
|
|
* Used by CTRL-R command in command-line mode.
|
2004-07-10 09:47:34 +00:00
|
|
|
* insert_reg() can't be used here, because special characters from the
|
|
|
|
* register contents will be interpreted as commands.
|
|
|
|
*
|
2015-12-17 14:04:24 +01:00
|
|
|
* Return FAIL for failure, OK otherwise.
|
2004-07-10 09:47:34 +00:00
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
cmdline_paste(
|
|
|
|
int regname,
|
|
|
|
int literally, /* Insert text literally instead of "as typed" */
|
|
|
|
int remcr) /* remove trailing CR */
|
2004-07-10 09:47:34 +00:00
|
|
|
{
|
|
|
|
long i;
|
|
|
|
char_u *arg;
|
2006-03-16 21:41:35 +00:00
|
|
|
char_u *p;
|
2004-07-10 09:47:34 +00:00
|
|
|
int allocated;
|
|
|
|
|
|
|
|
/* check for valid regname; also accept special characters for CTRL-R in
|
|
|
|
* the command line */
|
|
|
|
if (regname != Ctrl_F && regname != Ctrl_P && regname != Ctrl_W
|
2018-05-01 19:24:03 +02:00
|
|
|
&& regname != Ctrl_A && regname != Ctrl_L
|
|
|
|
&& !valid_yank_reg(regname, FALSE))
|
2004-07-10 09:47:34 +00:00
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
/* A register containing CTRL-R can cause an endless loop. Allow using
|
|
|
|
* CTRL-C to break the loop. */
|
|
|
|
line_breakcheck();
|
|
|
|
if (got_int)
|
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
#ifdef FEAT_CLIPBOARD
|
|
|
|
regname = may_get_selection(regname);
|
|
|
|
#endif
|
|
|
|
|
2018-09-30 17:11:48 +02:00
|
|
|
// Need to set "textlock" to avoid nasty things like going to another
|
|
|
|
// buffer when evaluating an expression.
|
2006-01-20 23:10:18 +00:00
|
|
|
++textlock;
|
2004-07-10 09:47:34 +00:00
|
|
|
i = get_spec_reg(regname, &arg, &allocated, TRUE);
|
2006-01-20 23:10:18 +00:00
|
|
|
--textlock;
|
2004-07-10 09:47:34 +00:00
|
|
|
|
|
|
|
if (i)
|
|
|
|
{
|
|
|
|
/* Got the value of a special register in "arg". */
|
|
|
|
if (arg == NULL)
|
|
|
|
return FAIL;
|
2006-03-16 21:41:35 +00:00
|
|
|
|
|
|
|
/* When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate
|
|
|
|
* part of the word. */
|
|
|
|
p = arg;
|
|
|
|
if (p_is && regname == Ctrl_W)
|
|
|
|
{
|
|
|
|
char_u *w;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* Locate start of last word in the cmd buffer. */
|
2011-07-07 16:44:37 +02:00
|
|
|
for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; )
|
2006-03-16 21:41:35 +00:00
|
|
|
{
|
|
|
|
if (has_mbyte)
|
|
|
|
{
|
|
|
|
len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1;
|
|
|
|
if (!vim_iswordc(mb_ptr2char(w - len)))
|
|
|
|
break;
|
|
|
|
w -= len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!vim_iswordc(w[-1]))
|
|
|
|
break;
|
|
|
|
--w;
|
|
|
|
}
|
|
|
|
}
|
2011-07-07 16:44:37 +02:00
|
|
|
len = (int)((ccline.cmdbuff + ccline.cmdpos) - w);
|
2006-03-16 21:41:35 +00:00
|
|
|
if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0)
|
|
|
|
p += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdline_paste_str(p, literally);
|
2004-07-10 09:47:34 +00:00
|
|
|
if (allocated)
|
|
|
|
vim_free(arg);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2006-10-17 14:25:24 +00:00
|
|
|
return cmdline_paste_reg(regname, literally, remcr);
|
2004-07-10 09:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put a string on the command line.
|
|
|
|
* When "literally" is TRUE, insert literally.
|
|
|
|
* When "literally" is FALSE, insert as typed, but don't leave the command
|
|
|
|
* line.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
cmdline_paste_str(char_u *s, int literally)
|
2004-07-10 09:47:34 +00:00
|
|
|
{
|
|
|
|
int c, cv;
|
|
|
|
|
|
|
|
if (literally)
|
|
|
|
put_on_cmdline(s, -1, TRUE);
|
|
|
|
else
|
|
|
|
while (*s != NUL)
|
|
|
|
{
|
|
|
|
cv = *s;
|
|
|
|
if (cv == Ctrl_V && s[1])
|
|
|
|
++s;
|
|
|
|
if (has_mbyte)
|
2008-06-20 10:56:16 +00:00
|
|
|
c = mb_cptr2char_adv(&s);
|
2004-07-10 09:47:34 +00:00
|
|
|
else
|
|
|
|
c = *s++;
|
2012-06-29 13:44:41 +02:00
|
|
|
if (cv == Ctrl_V || c == ESC || c == Ctrl_C
|
|
|
|
|| c == CAR || c == NL || c == Ctrl_L
|
2004-07-10 09:47:34 +00:00
|
|
|
#ifdef UNIX
|
|
|
|
|| c == intr_char
|
|
|
|
#endif
|
|
|
|
|| (c == Ctrl_BSL && *s == Ctrl_N))
|
|
|
|
stuffcharReadbuff(Ctrl_V);
|
|
|
|
stuffcharReadbuff(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
/*
|
|
|
|
* Delete characters on the command line, from "from" to the current
|
|
|
|
* position.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
cmdline_del(int from)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
mch_memmove(ccline.cmdbuff + from, ccline.cmdbuff + ccline.cmdpos,
|
|
|
|
(size_t)(ccline.cmdlen - ccline.cmdpos + 1));
|
|
|
|
ccline.cmdlen -= ccline.cmdpos - from;
|
|
|
|
ccline.cmdpos = from;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2016-05-05 17:18:41 +02:00
|
|
|
* This function is called when the screen size changes and with incremental
|
|
|
|
* search and in other situations where the command line may have been
|
|
|
|
* overwritten.
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
redrawcmdline(void)
|
2017-04-30 19:39:39 +02:00
|
|
|
{
|
|
|
|
redrawcmdline_ex(TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
redrawcmdline_ex(int do_compute_cmdrow)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (cmd_silent)
|
|
|
|
return;
|
|
|
|
need_wait_return = FALSE;
|
2017-04-30 19:39:39 +02:00
|
|
|
if (do_compute_cmdrow)
|
|
|
|
compute_cmdrow();
|
2004-06-13 20:20:40 +00:00
|
|
|
redrawcmd();
|
|
|
|
cursorcmd();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
redrawcmdprompt(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (cmd_silent)
|
|
|
|
return;
|
2005-09-20 23:22:24 +00:00
|
|
|
if (ccline.cmdfirstc != NUL)
|
2004-06-13 20:20:40 +00:00
|
|
|
msg_putchar(ccline.cmdfirstc);
|
|
|
|
if (ccline.cmdprompt != NULL)
|
|
|
|
{
|
2019-01-19 17:43:09 +01:00
|
|
|
msg_puts_attr((char *)ccline.cmdprompt, ccline.cmdattr);
|
2004-06-13 20:20:40 +00:00
|
|
|
ccline.cmdindent = msg_col + (msg_row - cmdline_row) * Columns;
|
|
|
|
/* do the reverse of set_cmdspos() */
|
2005-09-20 23:22:24 +00:00
|
|
|
if (ccline.cmdfirstc != NUL)
|
2004-06-13 20:20:40 +00:00
|
|
|
--ccline.cmdindent;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (i = ccline.cmdindent; i > 0; --i)
|
|
|
|
msg_putchar(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Redraw what is currently on the command line.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
redrawcmd(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (cmd_silent)
|
|
|
|
return;
|
|
|
|
|
2006-02-23 21:32:16 +00:00
|
|
|
/* when 'incsearch' is set there may be no command line while redrawing */
|
|
|
|
if (ccline.cmdbuff == NULL)
|
|
|
|
{
|
|
|
|
windgoto(cmdline_row, 0);
|
|
|
|
msg_clr_eos();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
msg_start();
|
|
|
|
redrawcmdprompt();
|
|
|
|
|
|
|
|
/* Don't use more prompt, truncate the cmdline if it doesn't fit. */
|
|
|
|
msg_no_more = TRUE;
|
|
|
|
draw_cmdline(0, ccline.cmdlen);
|
|
|
|
msg_clr_eos();
|
|
|
|
msg_no_more = FALSE;
|
|
|
|
|
|
|
|
set_cmdspos_cursor();
|
2017-07-15 15:21:38 +02:00
|
|
|
if (extra_char != NUL)
|
2017-07-16 15:24:01 +02:00
|
|
|
putcmdline(extra_char, extra_char_shift);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* An emsg() before may have set msg_scroll. This is used in normal mode,
|
|
|
|
* in cmdline mode we can reset them now.
|
|
|
|
*/
|
|
|
|
msg_scroll = FALSE; /* next message overwrites cmdline */
|
|
|
|
|
|
|
|
/* Typing ':' at the more prompt may set skip_redraw. We don't want this
|
|
|
|
* in cmdline mode */
|
|
|
|
skip_redraw = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
compute_cmdrow(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-10-03 22:02:18 +00:00
|
|
|
if (exmode_active || msg_scrolled != 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
cmdline_row = Rows - 1;
|
|
|
|
else
|
|
|
|
cmdline_row = W_WINROW(lastwin) + lastwin->w_height
|
2017-09-24 16:24:34 +02:00
|
|
|
+ lastwin->w_status_height;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
cursorcmd(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (cmd_silent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
if (cmdmsg_rl)
|
|
|
|
{
|
|
|
|
msg_row = cmdline_row + (ccline.cmdspos / (int)(Columns - 1));
|
|
|
|
msg_col = (int)Columns - (ccline.cmdspos % (int)(Columns - 1)) - 1;
|
|
|
|
if (msg_row <= 0)
|
|
|
|
msg_row = Rows - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
msg_row = cmdline_row + (ccline.cmdspos / (int)Columns);
|
|
|
|
msg_col = ccline.cmdspos % (int)Columns;
|
|
|
|
if (msg_row >= Rows)
|
|
|
|
msg_row = Rows - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
windgoto(msg_row, msg_col);
|
|
|
|
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
|
2017-08-30 22:00:20 +02:00
|
|
|
if (p_imst == IM_ON_THE_SPOT)
|
|
|
|
redrawcmd_preedit();
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MCH_CURSOR_SHAPE
|
|
|
|
mch_update_cursor();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
gotocmdline(int clr)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
msg_start();
|
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
if (cmdmsg_rl)
|
|
|
|
msg_col = Columns - 1;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
msg_col = 0; /* always start in column 0 */
|
|
|
|
if (clr) /* clear the bottom line(s) */
|
|
|
|
msg_clr_eos(); /* will reset clear_cmdline */
|
|
|
|
windgoto(cmdline_row, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the word in front of the cursor for an abbreviation.
|
|
|
|
* Called when the non-id character "c" has been entered.
|
|
|
|
* When an abbreviation is recognized it is removed from the text with
|
|
|
|
* backspaces and the replacement string is inserted, followed by "c".
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
ccheck_abbr(int c)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2018-05-13 18:36:27 +02:00
|
|
|
int spos = 0;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
if (p_paste || no_abbr) /* no abbreviations or in paste mode */
|
|
|
|
return FALSE;
|
|
|
|
|
2018-05-13 18:36:27 +02:00
|
|
|
/* Do not consider '<,'> be part of the mapping, skip leading whitespace.
|
|
|
|
* Actually accepts any mark. */
|
|
|
|
while (VIM_ISWHITE(ccline.cmdbuff[spos]) && spos < ccline.cmdlen)
|
|
|
|
spos++;
|
|
|
|
if (ccline.cmdlen - spos > 5
|
|
|
|
&& ccline.cmdbuff[spos] == '\''
|
|
|
|
&& ccline.cmdbuff[spos + 2] == ','
|
|
|
|
&& ccline.cmdbuff[spos + 3] == '\'')
|
|
|
|
spos += 5;
|
|
|
|
else
|
|
|
|
/* check abbreviation from the beginning of the commandline */
|
|
|
|
spos = 0;
|
|
|
|
|
|
|
|
return check_abbr(c, ccline.cmdbuff, ccline.cmdpos, spos);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
2011-10-26 22:02:15 +02:00
|
|
|
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
sort_func_compare(const void *s1, const void *s2)
|
2011-10-26 22:02:15 +02:00
|
|
|
{
|
|
|
|
char_u *p1 = *(char_u **)s1;
|
|
|
|
char_u *p2 = *(char_u **)s2;
|
|
|
|
|
|
|
|
if (*p1 != '<' && *p2 == '<') return -1;
|
|
|
|
if (*p1 == '<' && *p2 != '<') return 1;
|
|
|
|
return STRCMP(p1, p2);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Return FAIL if this is not an appropriate context in which to do
|
|
|
|
* completion of anything, return OK if it is (even if there are no matches).
|
|
|
|
* For the caller, this means that the character is just passed through like a
|
|
|
|
* normal character (instead of being expanded). This allows :s/^I^D etc.
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
nextwild(
|
|
|
|
expand_T *xp,
|
|
|
|
int type,
|
|
|
|
int options, /* extra options for ExpandOne() */
|
|
|
|
int escape) /* if TRUE, escape the returned matches */
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
char_u *p1;
|
|
|
|
char_u *p2;
|
|
|
|
int difflen;
|
|
|
|
int v;
|
|
|
|
|
|
|
|
if (xp->xp_numfiles == -1)
|
|
|
|
{
|
|
|
|
set_expand_context(xp);
|
|
|
|
cmd_showtail = expand_showtail(xp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xp->xp_context == EXPAND_UNSUCCESSFUL)
|
|
|
|
{
|
|
|
|
beep_flush();
|
|
|
|
return OK; /* Something illegal on command line */
|
|
|
|
}
|
|
|
|
if (xp->xp_context == EXPAND_NOTHING)
|
|
|
|
{
|
|
|
|
/* Caller can use the character as a normal char instead */
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
|
2019-01-19 17:43:09 +01:00
|
|
|
msg_puts("..."); /* show that we are busy */
|
2004-06-13 20:20:40 +00:00
|
|
|
out_flush();
|
|
|
|
|
|
|
|
i = (int)(xp->xp_pattern - ccline.cmdbuff);
|
2009-09-18 15:25:52 +00:00
|
|
|
xp->xp_pattern_len = ccline.cmdpos - i;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (type == WILD_NEXT || type == WILD_PREV)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Get next/previous match for a previous expanded pattern.
|
|
|
|
*/
|
|
|
|
p2 = ExpandOne(xp, NULL, NULL, 0, type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Translate string into pattern and expand it.
|
|
|
|
*/
|
2009-09-18 15:25:52 +00:00
|
|
|
if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len,
|
|
|
|
xp->xp_context)) == NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
p2 = NULL;
|
|
|
|
else
|
|
|
|
{
|
2010-12-02 16:01:29 +01:00
|
|
|
int use_options = options |
|
2012-11-28 16:49:58 +01:00
|
|
|
WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT;
|
|
|
|
if (escape)
|
|
|
|
use_options |= WILD_ESCAPE;
|
2010-12-02 16:01:29 +01:00
|
|
|
|
|
|
|
if (p_wic)
|
|
|
|
use_options += WILD_ICASE;
|
2009-09-18 15:25:52 +00:00
|
|
|
p2 = ExpandOne(xp, p1,
|
|
|
|
vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len),
|
2010-12-02 16:01:29 +01:00
|
|
|
use_options, type);
|
2004-06-13 20:20:40 +00:00
|
|
|
vim_free(p1);
|
2010-01-19 14:59:56 +01:00
|
|
|
/* longest match: make sure it is not shorter, happens with :help */
|
2004-06-13 20:20:40 +00:00
|
|
|
if (p2 != NULL && type == WILD_LONGEST)
|
|
|
|
{
|
2009-09-18 15:25:52 +00:00
|
|
|
for (j = 0; j < xp->xp_pattern_len; ++j)
|
2004-06-13 20:20:40 +00:00
|
|
|
if (ccline.cmdbuff[i + j] == '*'
|
|
|
|
|| ccline.cmdbuff[i + j] == '?')
|
|
|
|
break;
|
|
|
|
if ((int)STRLEN(p2) < j)
|
2018-02-10 18:45:26 +01:00
|
|
|
VIM_CLEAR(p2);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p2 != NULL && !got_int)
|
|
|
|
{
|
2009-09-18 15:25:52 +00:00
|
|
|
difflen = (int)STRLEN(p2) - xp->xp_pattern_len;
|
2010-08-13 19:12:07 +02:00
|
|
|
if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2010-08-13 19:12:07 +02:00
|
|
|
v = realloc_cmdbuff(ccline.cmdlen + difflen + 4);
|
2004-06-13 20:20:40 +00:00
|
|
|
xp->xp_pattern = ccline.cmdbuff + i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
v = OK;
|
|
|
|
if (v == OK)
|
|
|
|
{
|
2005-06-13 22:28:56 +00:00
|
|
|
mch_memmove(&ccline.cmdbuff[ccline.cmdpos + difflen],
|
|
|
|
&ccline.cmdbuff[ccline.cmdpos],
|
|
|
|
(size_t)(ccline.cmdlen - ccline.cmdpos + 1));
|
|
|
|
mch_memmove(&ccline.cmdbuff[i], p2, STRLEN(p2));
|
2004-06-13 20:20:40 +00:00
|
|
|
ccline.cmdlen += difflen;
|
|
|
|
ccline.cmdpos += difflen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vim_free(p2);
|
|
|
|
|
|
|
|
redrawcmd();
|
2004-10-24 19:18:58 +00:00
|
|
|
cursorcmd();
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* When expanding a ":map" command and no matches are found, assume that
|
|
|
|
* the key is supposed to be inserted literally */
|
|
|
|
if (xp->xp_context == EXPAND_MAPPINGS && p2 == NULL)
|
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
if (xp->xp_numfiles <= 0 && p2 == NULL)
|
|
|
|
beep_flush();
|
|
|
|
else if (xp->xp_numfiles == 1)
|
|
|
|
/* free expanded pattern */
|
|
|
|
(void)ExpandOne(xp, NULL, NULL, 0, WILD_FREE);
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do wildcard expansion on the string 'str'.
|
|
|
|
* Chars that should not be expanded must be preceded with a backslash.
|
2008-06-20 16:31:07 +00:00
|
|
|
* Return a pointer to allocated memory containing the new string.
|
2004-06-13 20:20:40 +00:00
|
|
|
* Return NULL for failure.
|
|
|
|
*
|
2007-09-30 20:11:26 +00:00
|
|
|
* "orig" is the originally expanded string, copied to allocated memory. It
|
|
|
|
* should either be kept in orig_save or freed. When "mode" is WILD_NEXT or
|
|
|
|
* WILD_PREV "orig" should be NULL.
|
|
|
|
*
|
2006-04-20 22:17:20 +00:00
|
|
|
* Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode"
|
|
|
|
* is WILD_EXPAND_FREE or WILD_ALL.
|
2004-06-13 20:20:40 +00:00
|
|
|
*
|
|
|
|
* mode = WILD_FREE: just free previously expanded matches
|
|
|
|
* mode = WILD_EXPAND_FREE: normal expansion, do not keep matches
|
|
|
|
* mode = WILD_EXPAND_KEEP: normal expansion, keep matches
|
|
|
|
* mode = WILD_NEXT: use next match in multiple match, wrap to first
|
|
|
|
* mode = WILD_PREV: use previous match in multiple match, wrap to first
|
|
|
|
* mode = WILD_ALL: return all matches concatenated
|
|
|
|
* mode = WILD_LONGEST: return longest matched part
|
2012-03-07 19:18:23 +01:00
|
|
|
* mode = WILD_ALL_KEEP: get all matches, keep matches
|
2004-06-13 20:20:40 +00:00
|
|
|
*
|
|
|
|
* options = WILD_LIST_NOTFOUND: list entries without a match
|
|
|
|
* options = WILD_HOME_REPLACE: do home_replace() for buffer names
|
|
|
|
* options = WILD_USE_NL: Use '\n' for WILD_ALL
|
|
|
|
* options = WILD_NO_BEEP: Don't beep for multiple matches
|
|
|
|
* options = WILD_ADD_SLASH: add a slash after directory names
|
|
|
|
* options = WILD_KEEP_ALL: don't remove 'wildignore' entries
|
|
|
|
* options = WILD_SILENT: don't print warning messages
|
|
|
|
* options = WILD_ESCAPE: put backslash before special chars
|
2010-12-02 16:01:29 +01:00
|
|
|
* options = WILD_ICASE: ignore case for files
|
2004-06-13 20:20:40 +00:00
|
|
|
*
|
|
|
|
* The variables xp->xp_context and xp->xp_backslash must have been set!
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandOne(
|
|
|
|
expand_T *xp,
|
|
|
|
char_u *str,
|
|
|
|
char_u *orig, /* allocated copy of original of expanded string */
|
|
|
|
int options,
|
|
|
|
int mode)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *ss = NULL;
|
|
|
|
static int findex;
|
|
|
|
static char_u *orig_save = NULL; /* kept value of orig */
|
2007-10-30 16:37:15 +00:00
|
|
|
int orig_saved = FALSE;
|
2004-06-13 20:20:40 +00:00
|
|
|
int i;
|
|
|
|
long_u len;
|
|
|
|
int non_suf_match; /* number without matching suffix */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* first handle the case of using an old match
|
|
|
|
*/
|
|
|
|
if (mode == WILD_NEXT || mode == WILD_PREV)
|
|
|
|
{
|
|
|
|
if (xp->xp_numfiles > 0)
|
|
|
|
{
|
|
|
|
if (mode == WILD_PREV)
|
|
|
|
{
|
|
|
|
if (findex == -1)
|
|
|
|
findex = xp->xp_numfiles;
|
|
|
|
--findex;
|
|
|
|
}
|
|
|
|
else /* mode == WILD_NEXT */
|
|
|
|
++findex;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When wrapping around, return the original string, set findex to
|
|
|
|
* -1.
|
|
|
|
*/
|
|
|
|
if (findex < 0)
|
|
|
|
{
|
|
|
|
if (orig_save == NULL)
|
|
|
|
findex = xp->xp_numfiles - 1;
|
|
|
|
else
|
|
|
|
findex = -1;
|
|
|
|
}
|
|
|
|
if (findex >= xp->xp_numfiles)
|
|
|
|
{
|
|
|
|
if (orig_save == NULL)
|
|
|
|
findex = 0;
|
|
|
|
else
|
|
|
|
findex = -1;
|
|
|
|
}
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
if (p_wmnu)
|
|
|
|
win_redr_status_matches(xp, xp->xp_numfiles, xp->xp_files,
|
|
|
|
findex, cmd_showtail);
|
|
|
|
#endif
|
|
|
|
if (findex == -1)
|
|
|
|
return vim_strsave(orig_save);
|
|
|
|
return vim_strsave(xp->xp_files[findex]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-30 20:11:26 +00:00
|
|
|
/* free old names */
|
2004-06-13 20:20:40 +00:00
|
|
|
if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST)
|
|
|
|
{
|
|
|
|
FreeWild(xp->xp_numfiles, xp->xp_files);
|
|
|
|
xp->xp_numfiles = -1;
|
2018-02-10 18:45:26 +01:00
|
|
|
VIM_CLEAR(orig_save);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
findex = 0;
|
|
|
|
|
|
|
|
if (mode == WILD_FREE) /* only release file name */
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (xp->xp_numfiles == -1)
|
|
|
|
{
|
|
|
|
vim_free(orig_save);
|
|
|
|
orig_save = orig;
|
2007-10-30 16:37:15 +00:00
|
|
|
orig_saved = TRUE;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the expansion.
|
|
|
|
*/
|
|
|
|
if (ExpandFromContext(xp, str, &xp->xp_numfiles, &xp->xp_files,
|
|
|
|
options) == FAIL)
|
|
|
|
{
|
|
|
|
#ifdef FNAME_ILLEGAL
|
|
|
|
/* Illegal file name has been silently skipped. But when there
|
|
|
|
* are wildcards, the real problem is that there was no match,
|
|
|
|
* causing the pattern to be added, which has illegal characters.
|
|
|
|
*/
|
|
|
|
if (!(options & WILD_SILENT) && (options & WILD_LIST_NOTFOUND))
|
2019-01-13 23:38:42 +01:00
|
|
|
semsg(_(e_nomatch2), str);
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (xp->xp_numfiles == 0)
|
|
|
|
{
|
|
|
|
if (!(options & WILD_SILENT))
|
2019-01-13 23:38:42 +01:00
|
|
|
semsg(_(e_nomatch2), str);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Escape the matches for use on the command line. */
|
|
|
|
ExpandEscape(xp, str, xp->xp_numfiles, xp->xp_files, options);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for matching suffixes in file names.
|
|
|
|
*/
|
2012-03-07 19:18:23 +01:00
|
|
|
if (mode != WILD_ALL && mode != WILD_ALL_KEEP
|
|
|
|
&& mode != WILD_LONGEST)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (xp->xp_numfiles)
|
|
|
|
non_suf_match = xp->xp_numfiles;
|
|
|
|
else
|
|
|
|
non_suf_match = 1;
|
|
|
|
if ((xp->xp_context == EXPAND_FILES
|
|
|
|
|| xp->xp_context == EXPAND_DIRECTORIES)
|
|
|
|
&& xp->xp_numfiles > 1)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* More than one match; check suffix.
|
|
|
|
* The files will have been sorted on matching suffix in
|
|
|
|
* expand_wildcards, only need to check the first two.
|
|
|
|
*/
|
|
|
|
non_suf_match = 0;
|
|
|
|
for (i = 0; i < 2; ++i)
|
|
|
|
if (match_suffix(xp->xp_files[i]))
|
|
|
|
++non_suf_match;
|
|
|
|
}
|
|
|
|
if (non_suf_match != 1)
|
|
|
|
{
|
|
|
|
/* Can we ever get here unless it's while expanding
|
|
|
|
* interactively? If not, we can get rid of this all
|
|
|
|
* together. Don't really want to wait for this message
|
|
|
|
* (and possibly have to hit return to continue!).
|
|
|
|
*/
|
|
|
|
if (!(options & WILD_SILENT))
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_(e_toomany));
|
2004-06-13 20:20:40 +00:00
|
|
|
else if (!(options & WILD_NO_BEEP))
|
|
|
|
beep_flush();
|
|
|
|
}
|
|
|
|
if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE))
|
|
|
|
ss = vim_strsave(xp->xp_files[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find longest common part */
|
|
|
|
if (mode == WILD_LONGEST && xp->xp_numfiles > 0)
|
|
|
|
{
|
2015-11-19 19:00:05 +01:00
|
|
|
int mb_len = 1;
|
|
|
|
int c0, ci;
|
|
|
|
|
|
|
|
for (len = 0; xp->xp_files[0][len]; len += mb_len)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2015-11-19 19:00:05 +01:00
|
|
|
if (has_mbyte)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2015-11-19 19:00:05 +01:00
|
|
|
mb_len = (*mb_ptr2len)(&xp->xp_files[0][len]);
|
|
|
|
c0 =(* mb_ptr2char)(&xp->xp_files[0][len]);
|
|
|
|
}
|
|
|
|
else
|
2015-11-21 16:28:50 +01:00
|
|
|
c0 = xp->xp_files[0][len];
|
2015-11-19 19:00:05 +01:00
|
|
|
for (i = 1; i < xp->xp_numfiles; ++i)
|
|
|
|
{
|
|
|
|
if (has_mbyte)
|
|
|
|
ci =(* mb_ptr2char)(&xp->xp_files[i][len]);
|
|
|
|
else
|
|
|
|
ci = xp->xp_files[i][len];
|
2013-03-19 16:49:16 +01:00
|
|
|
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
|
2004-06-13 20:20:40 +00:00
|
|
|
|| xp->xp_context == EXPAND_FILES
|
2006-03-06 23:29:24 +00:00
|
|
|
|| xp->xp_context == EXPAND_SHELLCMD
|
2013-03-19 16:49:16 +01:00
|
|
|
|| xp->xp_context == EXPAND_BUFFERS))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2015-11-19 19:00:05 +01:00
|
|
|
if (MB_TOLOWER(c0) != MB_TOLOWER(ci))
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-11-19 19:00:05 +01:00
|
|
|
else if (c0 != ci)
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i < xp->xp_numfiles)
|
|
|
|
{
|
|
|
|
if (!(options & WILD_NO_BEEP))
|
2015-07-21 17:53:25 +02:00
|
|
|
vim_beep(BO_WILD);
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-19 19:00:05 +01:00
|
|
|
|
2019-05-24 18:54:09 +02:00
|
|
|
ss = alloc(len + 1);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (ss)
|
2005-07-18 21:58:11 +00:00
|
|
|
vim_strncpy(ss, xp->xp_files[0], (size_t)len);
|
2004-06-13 20:20:40 +00:00
|
|
|
findex = -1; /* next p_wc gets first one */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Concatenate all matching names */
|
|
|
|
if (mode == WILD_ALL && xp->xp_numfiles > 0)
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
for (i = 0; i < xp->xp_numfiles; ++i)
|
|
|
|
len += (long_u)STRLEN(xp->xp_files[i]) + 1;
|
2019-05-24 19:39:03 +02:00
|
|
|
ss = alloc(len);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (ss != NULL)
|
|
|
|
{
|
|
|
|
*ss = NUL;
|
|
|
|
for (i = 0; i < xp->xp_numfiles; ++i)
|
|
|
|
{
|
|
|
|
STRCAT(ss, xp->xp_files[i]);
|
|
|
|
if (i != xp->xp_numfiles - 1)
|
|
|
|
STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == WILD_EXPAND_FREE || mode == WILD_ALL)
|
|
|
|
ExpandCleanup(xp);
|
|
|
|
|
2007-09-30 20:11:26 +00:00
|
|
|
/* Free "orig" if it wasn't stored in "orig_save". */
|
2007-10-30 16:37:15 +00:00
|
|
|
if (!orig_saved)
|
2007-09-30 20:11:26 +00:00
|
|
|
vim_free(orig);
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare an expand structure for use.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandInit(expand_T *xp)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2008-09-14 12:42:29 +00:00
|
|
|
xp->xp_pattern = NULL;
|
2009-09-18 15:25:52 +00:00
|
|
|
xp->xp_pattern_len = 0;
|
2004-06-13 20:20:40 +00:00
|
|
|
xp->xp_backslash = XP_BS_NONE;
|
2006-01-19 22:16:24 +00:00
|
|
|
#ifndef BACKSLASH_IN_FILENAME
|
|
|
|
xp->xp_shell = FALSE;
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
xp->xp_numfiles = -1;
|
|
|
|
xp->xp_files = NULL;
|
2019-04-27 13:04:13 +02:00
|
|
|
#if defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
|
2006-01-19 22:16:24 +00:00
|
|
|
xp->xp_arg = NULL;
|
|
|
|
#endif
|
2013-06-29 12:58:33 +02:00
|
|
|
xp->xp_line = NULL;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup an expand structure after use.
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandCleanup(expand_T *xp)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (xp->xp_numfiles >= 0)
|
|
|
|
{
|
|
|
|
FreeWild(xp->xp_numfiles, xp->xp_files);
|
|
|
|
xp->xp_numfiles = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandEscape(
|
|
|
|
expand_T *xp,
|
|
|
|
char_u *str,
|
|
|
|
int numfiles,
|
|
|
|
char_u **files,
|
|
|
|
int options)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char_u *p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* May change home directory back to "~"
|
|
|
|
*/
|
|
|
|
if (options & WILD_HOME_REPLACE)
|
|
|
|
tilde_replace(str, numfiles, files);
|
|
|
|
|
|
|
|
if (options & WILD_ESCAPE)
|
|
|
|
{
|
|
|
|
if (xp->xp_context == EXPAND_FILES
|
2011-04-28 17:21:53 +02:00
|
|
|
|| xp->xp_context == EXPAND_FILES_IN_PATH
|
2006-03-06 23:29:24 +00:00
|
|
|
|| xp->xp_context == EXPAND_SHELLCMD
|
2004-06-13 20:20:40 +00:00
|
|
|
|| xp->xp_context == EXPAND_BUFFERS
|
|
|
|
|| xp->xp_context == EXPAND_DIRECTORIES)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Insert a backslash into a file name before a space, \, %, #
|
|
|
|
* and wildmatch characters, except '~'.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < numfiles; ++i)
|
|
|
|
{
|
|
|
|
/* for ":set path=" we need to escape spaces twice */
|
|
|
|
if (xp->xp_backslash == XP_BS_THREE)
|
|
|
|
{
|
|
|
|
p = vim_strsave_escaped(files[i], (char_u *)" ");
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
vim_free(files[i]);
|
|
|
|
files[i] = p;
|
2006-03-09 22:32:39 +00:00
|
|
|
#if defined(BACKSLASH_IN_FILENAME)
|
2004-06-13 20:20:40 +00:00
|
|
|
p = vim_strsave_escaped(files[i], (char_u *)" ");
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
vim_free(files[i]);
|
|
|
|
files[i] = p;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2008-05-28 20:02:48 +00:00
|
|
|
#ifdef BACKSLASH_IN_FILENAME
|
|
|
|
p = vim_strsave_fnameescape(files[i], FALSE);
|
|
|
|
#else
|
2008-05-28 14:49:58 +00:00
|
|
|
p = vim_strsave_fnameescape(files[i], xp->xp_shell);
|
2008-05-28 20:02:48 +00:00
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
vim_free(files[i]);
|
|
|
|
files[i] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If 'str' starts with "\~", replace "~" at start of
|
|
|
|
* files[i] with "\~". */
|
|
|
|
if (str[0] == '\\' && str[1] == '~' && files[i][0] == '~')
|
2005-07-21 21:08:21 +00:00
|
|
|
escape_fname(&files[i]);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
xp->xp_backslash = XP_BS_NONE;
|
2005-07-21 21:08:21 +00:00
|
|
|
|
|
|
|
/* If the first file starts with a '+' escape it. Otherwise it
|
|
|
|
* could be seen as "+cmd". */
|
|
|
|
if (*files[0] == '+')
|
|
|
|
escape_fname(&files[0]);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else if (xp->xp_context == EXPAND_TAGS)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Insert a backslash before characters in a tag name that
|
|
|
|
* would terminate the ":tag" command.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < numfiles; ++i)
|
|
|
|
{
|
|
|
|
p = vim_strsave_escaped(files[i], (char_u *)"\\|\"");
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
vim_free(files[i]);
|
|
|
|
files[i] = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-28 14:49:58 +00:00
|
|
|
/*
|
|
|
|
* Escape special characters in "fname" for when used as a file name argument
|
|
|
|
* after a Vim command, or, when "shell" is non-zero, a shell command.
|
|
|
|
* Returns the result in allocated memory.
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
vim_strsave_fnameescape(char_u *fname, int shell)
|
2008-05-28 14:49:58 +00:00
|
|
|
{
|
2008-07-24 18:29:37 +00:00
|
|
|
char_u *p;
|
2008-05-28 14:49:58 +00:00
|
|
|
#ifdef BACKSLASH_IN_FILENAME
|
|
|
|
char_u buf[20];
|
|
|
|
int j = 0;
|
|
|
|
|
2013-11-12 05:28:26 +01:00
|
|
|
/* Don't escape '[', '{' and '!' if they are in 'isfname'. */
|
2008-05-28 14:49:58 +00:00
|
|
|
for (p = PATH_ESC_CHARS; *p != NUL; ++p)
|
2013-11-12 05:28:26 +01:00
|
|
|
if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p))
|
2008-05-28 14:49:58 +00:00
|
|
|
buf[j++] = *p;
|
|
|
|
buf[j] = NUL;
|
2008-08-08 10:59:17 +00:00
|
|
|
p = vim_strsave_escaped(fname, buf);
|
2008-05-28 14:49:58 +00:00
|
|
|
#else
|
2008-07-24 18:29:37 +00:00
|
|
|
p = vim_strsave_escaped(fname, shell ? SHELL_ESC_CHARS : PATH_ESC_CHARS);
|
|
|
|
if (shell && csh_like_shell() && p != NULL)
|
|
|
|
{
|
|
|
|
char_u *s;
|
|
|
|
|
|
|
|
/* For csh and similar shells need to put two backslashes before '!'.
|
|
|
|
* One is taken by Vim, one by the shell. */
|
|
|
|
s = vim_strsave_escaped(p, (char_u *)"!");
|
|
|
|
vim_free(p);
|
|
|
|
p = s;
|
|
|
|
}
|
2008-05-28 14:49:58 +00:00
|
|
|
#endif
|
2008-08-08 10:59:17 +00:00
|
|
|
|
|
|
|
/* '>' and '+' are special at the start of some commands, e.g. ":edit" and
|
|
|
|
* ":write". "cd -" has a special meaning. */
|
2010-07-31 16:44:19 +02:00
|
|
|
if (p != NULL && (*p == '>' || *p == '+' || (*p == '-' && p[1] == NUL)))
|
2008-08-08 10:59:17 +00:00
|
|
|
escape_fname(&p);
|
|
|
|
|
|
|
|
return p;
|
2008-05-28 14:49:58 +00:00
|
|
|
}
|
|
|
|
|
2005-07-21 21:08:21 +00:00
|
|
|
/*
|
|
|
|
* Put a backslash before the file name in "pp", which is in allocated memory.
|
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
escape_fname(char_u **pp)
|
2005-07-21 21:08:21 +00:00
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
|
2019-05-24 18:54:09 +02:00
|
|
|
p = alloc(STRLEN(*pp) + 2);
|
2005-07-21 21:08:21 +00:00
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
p[0] = '\\';
|
|
|
|
STRCPY(p + 1, *pp);
|
|
|
|
vim_free(*pp);
|
|
|
|
*pp = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* For each file name in files[num_files]:
|
|
|
|
* If 'orig_pat' starts with "~/", replace the home directory with "~".
|
|
|
|
*/
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
tilde_replace(
|
|
|
|
char_u *orig_pat,
|
|
|
|
int num_files,
|
|
|
|
char_u **files)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char_u *p;
|
|
|
|
|
|
|
|
if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1]))
|
|
|
|
{
|
|
|
|
for (i = 0; i < num_files; ++i)
|
|
|
|
{
|
|
|
|
p = home_replace_save(NULL, files[i]);
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
|
|
|
vim_free(files[i]);
|
|
|
|
files[i] = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Show all matches for completion on the command line.
|
|
|
|
* Returns EXPAND_NOTHING when the character that triggered expansion should
|
|
|
|
* be inserted like a normal character.
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
showmatches(expand_T *xp, int wildmenu UNUSED)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
#define L_SHOWFILE(m) (showtail ? sm_gettail(files_found[m]) : files_found[m])
|
|
|
|
int num_files;
|
|
|
|
char_u **files_found;
|
|
|
|
int i, j, k;
|
|
|
|
int maxlen;
|
|
|
|
int lines;
|
|
|
|
int columns;
|
|
|
|
char_u *p;
|
|
|
|
int lastlen;
|
|
|
|
int attr;
|
|
|
|
int showtail;
|
|
|
|
|
|
|
|
if (xp->xp_numfiles == -1)
|
|
|
|
{
|
|
|
|
set_expand_context(xp);
|
|
|
|
i = expand_cmdline(xp, ccline.cmdbuff, ccline.cmdpos,
|
|
|
|
&num_files, &files_found);
|
|
|
|
showtail = expand_showtail(xp);
|
|
|
|
if (i != EXPAND_OK)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
num_files = xp->xp_numfiles;
|
|
|
|
files_found = xp->xp_files;
|
|
|
|
showtail = cmd_showtail;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
if (!wildmenu)
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
msg_didany = FALSE; /* lines_left will be set */
|
|
|
|
msg_start(); /* prepare for paging */
|
|
|
|
msg_putchar('\n');
|
|
|
|
out_flush();
|
|
|
|
cmdline_row = msg_row;
|
|
|
|
msg_didany = FALSE; /* lines_left will be set again */
|
|
|
|
msg_start(); /* prepare for paging */
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (got_int)
|
|
|
|
got_int = FALSE; /* only int. the completion, not the cmd line */
|
|
|
|
#ifdef FEAT_WILDMENU
|
|
|
|
else if (wildmenu)
|
2017-03-30 22:04:55 +02:00
|
|
|
win_redr_status_matches(xp, num_files, files_found, -1, showtail);
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* find the length of the longest file name */
|
|
|
|
maxlen = 0;
|
|
|
|
for (i = 0; i < num_files; ++i)
|
|
|
|
{
|
|
|
|
if (!showtail && (xp->xp_context == EXPAND_FILES
|
2006-03-06 23:29:24 +00:00
|
|
|
|| xp->xp_context == EXPAND_SHELLCMD
|
2004-06-13 20:20:40 +00:00
|
|
|
|| xp->xp_context == EXPAND_BUFFERS))
|
|
|
|
{
|
|
|
|
home_replace(NULL, files_found[i], NameBuff, MAXPATHL, TRUE);
|
|
|
|
j = vim_strsize(NameBuff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
j = vim_strsize(L_SHOWFILE(i));
|
|
|
|
if (j > maxlen)
|
|
|
|
maxlen = j;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xp->xp_context == EXPAND_TAGS_LISTFILES)
|
|
|
|
lines = num_files;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* compute the number of columns and lines for the listing */
|
|
|
|
maxlen += 2; /* two spaces between file names */
|
|
|
|
columns = ((int)Columns + 2) / maxlen;
|
|
|
|
if (columns < 1)
|
|
|
|
columns = 1;
|
|
|
|
lines = (num_files + columns - 1) / columns;
|
|
|
|
}
|
|
|
|
|
2017-03-16 17:23:31 +01:00
|
|
|
attr = HL_ATTR(HLF_D); /* find out highlighting for directories */
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (xp->xp_context == EXPAND_TAGS_LISTFILES)
|
|
|
|
{
|
2019-01-19 17:43:09 +01:00
|
|
|
msg_puts_attr(_("tagname"), HL_ATTR(HLF_T));
|
2004-06-13 20:20:40 +00:00
|
|
|
msg_clr_eos();
|
|
|
|
msg_advance(maxlen - 3);
|
2019-01-19 17:43:09 +01:00
|
|
|
msg_puts_attr(_(" kind file\n"), HL_ATTR(HLF_T));
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* list the files line by line */
|
|
|
|
for (i = 0; i < lines; ++i)
|
|
|
|
{
|
|
|
|
lastlen = 999;
|
|
|
|
for (k = i; k < num_files; k += lines)
|
|
|
|
{
|
|
|
|
if (xp->xp_context == EXPAND_TAGS_LISTFILES)
|
|
|
|
{
|
2017-03-16 17:23:31 +01:00
|
|
|
msg_outtrans_attr(files_found[k], HL_ATTR(HLF_D));
|
2004-06-13 20:20:40 +00:00
|
|
|
p = files_found[k] + STRLEN(files_found[k]) + 1;
|
|
|
|
msg_advance(maxlen + 1);
|
2019-01-19 17:43:09 +01:00
|
|
|
msg_puts((char *)p);
|
2004-06-13 20:20:40 +00:00
|
|
|
msg_advance(maxlen + 3);
|
2019-01-19 17:43:09 +01:00
|
|
|
msg_outtrans_long_attr(p + 2, HL_ATTR(HLF_D));
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (j = maxlen - lastlen; --j >= 0; )
|
|
|
|
msg_putchar(' ');
|
|
|
|
if (xp->xp_context == EXPAND_FILES
|
2006-03-06 23:29:24 +00:00
|
|
|
|| xp->xp_context == EXPAND_SHELLCMD
|
2004-06-13 20:20:40 +00:00
|
|
|
|| xp->xp_context == EXPAND_BUFFERS)
|
|
|
|
{
|
2010-03-17 19:13:27 +01:00
|
|
|
/* highlight directories */
|
2010-03-23 18:06:52 +01:00
|
|
|
if (xp->xp_numfiles != -1)
|
|
|
|
{
|
|
|
|
char_u *halved_slash;
|
|
|
|
char_u *exp_path;
|
|
|
|
|
|
|
|
/* Expansion was done before and special characters
|
|
|
|
* were escaped, need to halve backslashes. Also
|
|
|
|
* $HOME has been replaced with ~/. */
|
|
|
|
exp_path = expand_env_save_opt(files_found[k], TRUE);
|
|
|
|
halved_slash = backslash_halve_save(
|
|
|
|
exp_path != NULL ? exp_path : files_found[k]);
|
|
|
|
j = mch_isdir(halved_slash != NULL ? halved_slash
|
|
|
|
: files_found[k]);
|
|
|
|
vim_free(exp_path);
|
|
|
|
vim_free(halved_slash);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Expansion was done here, file names are literal. */
|
|
|
|
j = mch_isdir(files_found[k]);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (showtail)
|
|
|
|
p = L_SHOWFILE(k);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
home_replace(NULL, files_found[k], NameBuff, MAXPATHL,
|
|
|
|
TRUE);
|
|
|
|
p = NameBuff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
j = FALSE;
|
|
|
|
p = L_SHOWFILE(k);
|
|
|
|
}
|
|
|
|
lastlen = msg_outtrans_attr(p, j ? attr : 0);
|
|
|
|
}
|
|
|
|
if (msg_col > 0) /* when not wrapped around */
|
|
|
|
{
|
|
|
|
msg_clr_eos();
|
|
|
|
msg_putchar('\n');
|
|
|
|
}
|
|
|
|
out_flush(); /* show one line at a time */
|
|
|
|
if (got_int)
|
|
|
|
{
|
|
|
|
got_int = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we redraw the command below the lines that we have just listed
|
|
|
|
* This is a bit tricky, but it saves a lot of screen updating.
|
|
|
|
*/
|
|
|
|
cmdline_row = msg_row; /* will put it back later */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xp->xp_numfiles == -1)
|
|
|
|
FreeWild(num_files, files_found);
|
|
|
|
|
|
|
|
return EXPAND_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private gettail for showmatches() (and win_redr_status_matches()):
|
|
|
|
* Find tail of file name path, but ignore trailing "/".
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
sm_gettail(char_u *s)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *p;
|
|
|
|
char_u *t = s;
|
|
|
|
int had_sep = FALSE;
|
|
|
|
|
|
|
|
for (p = s; *p != NUL; )
|
|
|
|
{
|
|
|
|
if (vim_ispathsep(*p)
|
|
|
|
#ifdef BACKSLASH_IN_FILENAME
|
|
|
|
&& !rem_backslash(p)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
had_sep = TRUE;
|
|
|
|
else if (had_sep)
|
|
|
|
{
|
|
|
|
t = p;
|
|
|
|
had_sep = FALSE;
|
|
|
|
}
|
2017-03-12 19:22:36 +01:00
|
|
|
MB_PTR_ADV(p);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return TRUE if we only need to show the tail of completion matches.
|
|
|
|
* When not completing file names or there is a wildcard in the path FALSE is
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
expand_showtail(expand_T *xp)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *s;
|
|
|
|
char_u *end;
|
|
|
|
|
|
|
|
/* When not completing file names a "/" may mean something different. */
|
2006-03-06 23:29:24 +00:00
|
|
|
if (xp->xp_context != EXPAND_FILES
|
|
|
|
&& xp->xp_context != EXPAND_SHELLCMD
|
|
|
|
&& xp->xp_context != EXPAND_DIRECTORIES)
|
2004-06-13 20:20:40 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
end = gettail(xp->xp_pattern);
|
|
|
|
if (end == xp->xp_pattern) /* there is no path separator */
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (s = xp->xp_pattern; s < end; s++)
|
|
|
|
{
|
|
|
|
/* Skip escaped wildcards. Only when the backslash is not a path
|
|
|
|
* separator, on DOS the '*' "path\*\file" must not be skipped. */
|
|
|
|
if (rem_backslash(s))
|
|
|
|
++s;
|
|
|
|
else if (vim_strchr((char_u *)"*?[", *s) != NULL)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare a string for expansion.
|
|
|
|
* When expanding file names: The string will be used with expand_wildcards().
|
2013-11-05 07:13:41 +01:00
|
|
|
* Copy "fname[len]" into allocated memory and add a '*' at the end.
|
2004-06-13 20:20:40 +00:00
|
|
|
* When expanding other names: The string will be used with regcomp(). Copy
|
|
|
|
* the name into allocated memory and prepend "^".
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
addstar(
|
|
|
|
char_u *fname,
|
|
|
|
int len,
|
|
|
|
int context) /* EXPAND_FILES etc. */
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *retval;
|
|
|
|
int i, j;
|
|
|
|
int new_len;
|
|
|
|
char_u *tail;
|
2010-06-01 21:57:09 +02:00
|
|
|
int ends_in_star;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2006-03-06 23:29:24 +00:00
|
|
|
if (context != EXPAND_FILES
|
2010-07-14 16:52:17 +02:00
|
|
|
&& context != EXPAND_FILES_IN_PATH
|
2006-03-06 23:29:24 +00:00
|
|
|
&& context != EXPAND_SHELLCMD
|
|
|
|
&& context != EXPAND_DIRECTORIES)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Matching will be done internally (on something other than files).
|
|
|
|
* So we convert the file-matching-type wildcards into our kind for
|
|
|
|
* use with vim_regcomp(). First work out how long it will be:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* For help tags the translation is done in find_help_tags().
|
|
|
|
* For a tag pattern starting with "/" no translation is needed. */
|
|
|
|
if (context == EXPAND_HELP
|
|
|
|
|| context == EXPAND_COLORS
|
|
|
|
|| context == EXPAND_COMPILER
|
2010-07-29 20:59:59 +02:00
|
|
|
|| context == EXPAND_OWNSYNTAX
|
2010-06-21 06:24:34 +02:00
|
|
|
|| context == EXPAND_FILETYPE
|
2016-03-05 17:41:49 +01:00
|
|
|
|| context == EXPAND_PACKADD
|
2017-01-24 21:18:19 +01:00
|
|
|
|| ((context == EXPAND_TAGS_LISTFILES
|
|
|
|
|| context == EXPAND_TAGS)
|
|
|
|
&& fname[0] == '/'))
|
2004-06-13 20:20:40 +00:00
|
|
|
retval = vim_strnsave(fname, len);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_len = len + 2; /* +2 for '^' at start, NUL at end */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
if (fname[i] == '*' || fname[i] == '~')
|
|
|
|
new_len++; /* '*' needs to be replaced by ".*"
|
|
|
|
'~' needs to be replaced by "\~" */
|
|
|
|
|
|
|
|
/* Buffer names are like file names. "." should be literal */
|
|
|
|
if (context == EXPAND_BUFFERS && fname[i] == '.')
|
|
|
|
new_len++; /* "." becomes "\." */
|
|
|
|
|
|
|
|
/* Custom expansion takes care of special things, match
|
|
|
|
* backslashes literally (perhaps also for other types?) */
|
2006-01-20 23:10:18 +00:00
|
|
|
if ((context == EXPAND_USER_DEFINED
|
|
|
|
|| context == EXPAND_USER_LIST) && fname[i] == '\\')
|
2004-06-13 20:20:40 +00:00
|
|
|
new_len++; /* '\' becomes "\\" */
|
|
|
|
}
|
|
|
|
retval = alloc(new_len);
|
|
|
|
if (retval != NULL)
|
|
|
|
{
|
|
|
|
retval[0] = '^';
|
|
|
|
j = 1;
|
|
|
|
for (i = 0; i < len; i++, j++)
|
|
|
|
{
|
|
|
|
/* Skip backslash. But why? At least keep it for custom
|
|
|
|
* expansion. */
|
|
|
|
if (context != EXPAND_USER_DEFINED
|
2005-07-09 21:08:57 +00:00
|
|
|
&& context != EXPAND_USER_LIST
|
|
|
|
&& fname[i] == '\\'
|
|
|
|
&& ++i == len)
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
switch (fname[i])
|
|
|
|
{
|
|
|
|
case '*': retval[j++] = '.';
|
|
|
|
break;
|
|
|
|
case '~': retval[j++] = '\\';
|
|
|
|
break;
|
|
|
|
case '?': retval[j] = '.';
|
|
|
|
continue;
|
|
|
|
case '.': if (context == EXPAND_BUFFERS)
|
|
|
|
retval[j++] = '\\';
|
|
|
|
break;
|
2005-07-09 21:08:57 +00:00
|
|
|
case '\\': if (context == EXPAND_USER_DEFINED
|
|
|
|
|| context == EXPAND_USER_LIST)
|
2004-06-13 20:20:40 +00:00
|
|
|
retval[j++] = '\\';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
retval[j] = fname[i];
|
|
|
|
}
|
|
|
|
retval[j] = NUL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
retval = alloc(len + 4);
|
|
|
|
if (retval != NULL)
|
|
|
|
{
|
2005-07-18 21:58:11 +00:00
|
|
|
vim_strncpy(retval, fname, len);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/*
|
2006-04-15 20:25:09 +00:00
|
|
|
* Don't add a star to *, ~, ~user, $var or `cmd`.
|
|
|
|
* * would become **, which walks the whole tree.
|
2004-06-13 20:20:40 +00:00
|
|
|
* ~ would be at the start of the file name, but not the tail.
|
|
|
|
* $ could be anywhere in the tail.
|
|
|
|
* ` could be anywhere in the file name.
|
2008-01-04 14:17:47 +00:00
|
|
|
* When the name ends in '$' don't add a star, remove the '$'.
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
tail = gettail(retval);
|
2010-06-01 21:57:09 +02:00
|
|
|
ends_in_star = (len > 0 && retval[len - 1] == '*');
|
|
|
|
#ifndef BACKSLASH_IN_FILENAME
|
|
|
|
for (i = len - 2; i >= 0; --i)
|
|
|
|
{
|
|
|
|
if (retval[i] != '\\')
|
|
|
|
break;
|
|
|
|
ends_in_star = !ends_in_star;
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
if ((*retval != '~' || tail != retval)
|
2010-06-01 21:57:09 +02:00
|
|
|
&& !ends_in_star
|
2004-06-13 20:20:40 +00:00
|
|
|
&& vim_strchr(tail, '$') == NULL
|
|
|
|
&& vim_strchr(retval, '`') == NULL)
|
|
|
|
retval[len++] = '*';
|
2008-01-04 14:17:47 +00:00
|
|
|
else if (len > 0 && retval[len - 1] == '$')
|
|
|
|
--len;
|
2004-06-13 20:20:40 +00:00
|
|
|
retval[len] = NUL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must parse the command line so far to work out what context we are in.
|
|
|
|
* Completion can then be done based on that context.
|
|
|
|
* This routine sets the variables:
|
|
|
|
* xp->xp_pattern The start of the pattern to be expanded within
|
|
|
|
* the command line (ends at the cursor).
|
|
|
|
* xp->xp_context The type of thing to expand. Will be one of:
|
|
|
|
*
|
|
|
|
* EXPAND_UNSUCCESSFUL Used sometimes when there is something illegal on
|
|
|
|
* the command line, like an unknown command. Caller
|
|
|
|
* should beep.
|
|
|
|
* EXPAND_NOTHING Unrecognised context for completion, use char like
|
|
|
|
* a normal char, rather than for completion. eg
|
|
|
|
* :s/^I/
|
|
|
|
* EXPAND_COMMANDS Cursor is still touching the command, so complete
|
|
|
|
* it.
|
|
|
|
* EXPAND_BUFFERS Complete file names for :buf and :sbuf commands.
|
2019-07-12 17:58:01 +02:00
|
|
|
* EXPAND_FILES After command with EX_XFILE set, or after setting
|
2004-06-13 20:20:40 +00:00
|
|
|
* with P_EXPAND set. eg :e ^I, :w>>^I
|
|
|
|
* EXPAND_DIRECTORIES In some cases this is used instead of the latter
|
|
|
|
* when we know only directories are of interest. eg
|
|
|
|
* :set dir=^I
|
2006-03-06 23:29:24 +00:00
|
|
|
* EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd".
|
2004-06-13 20:20:40 +00:00
|
|
|
* EXPAND_SETTINGS Complete variable names. eg :set d^I
|
|
|
|
* EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I
|
|
|
|
* EXPAND_TAGS Complete tags from the files in p_tags. eg :ta a^I
|
|
|
|
* EXPAND_TAGS_LISTFILES As above, but list filenames on ^D, after :tselect
|
|
|
|
* EXPAND_HELP Complete tags from the file 'helpfile'/tags
|
|
|
|
* EXPAND_EVENTS Complete event names
|
|
|
|
* EXPAND_SYNTAX Complete :syntax command arguments
|
|
|
|
* EXPAND_HIGHLIGHT Complete highlight (syntax) group names
|
|
|
|
* EXPAND_AUGROUP Complete autocommand group names
|
|
|
|
* EXPAND_USER_VARS Complete user defined variable names, eg :unlet a^I
|
|
|
|
* EXPAND_MAPPINGS Complete mapping and abbreviation names,
|
|
|
|
* eg :unmap a^I , :cunab x^I
|
|
|
|
* EXPAND_FUNCTIONS Complete internal or user defined function names,
|
|
|
|
* eg :call sub^I
|
|
|
|
* EXPAND_USER_FUNC Complete user defined function names, eg :delf F^I
|
|
|
|
* EXPAND_EXPRESSION Complete internal or user defined function/variable
|
|
|
|
* names in expressions, eg :while s^I
|
|
|
|
* EXPAND_ENV_VARS Complete environment variable names
|
2012-08-15 14:05:05 +02:00
|
|
|
* EXPAND_USER Complete user names
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
set_expand_context(expand_T *xp)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-02-22 08:49:11 +00:00
|
|
|
/* only expansion for ':', '>' and '=' command-lines */
|
2004-06-13 20:20:40 +00:00
|
|
|
if (ccline.cmdfirstc != ':'
|
|
|
|
#ifdef FEAT_EVAL
|
2005-02-22 08:49:11 +00:00
|
|
|
&& ccline.cmdfirstc != '>' && ccline.cmdfirstc != '='
|
2005-09-20 23:22:24 +00:00
|
|
|
&& !ccline.input_fn
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
xp->xp_context = EXPAND_NOTHING;
|
|
|
|
return;
|
|
|
|
}
|
2016-09-05 21:51:14 +02:00
|
|
|
set_cmd_context(xp, ccline.cmdbuff, ccline.cmdlen, ccline.cmdpos, TRUE);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
set_cmd_context(
|
|
|
|
expand_T *xp,
|
|
|
|
char_u *str, /* start of command line */
|
|
|
|
int len, /* length of command line (excl. NUL) */
|
2016-09-05 21:51:14 +02:00
|
|
|
int col, /* position of cursor */
|
|
|
|
int use_ccline UNUSED) /* use ccline for info */
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int old_char = NUL;
|
|
|
|
char_u *nextcomm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Avoid a UMR warning from Purify, only save the character if it has been
|
|
|
|
* written before.
|
|
|
|
*/
|
|
|
|
if (col < len)
|
|
|
|
old_char = str[col];
|
|
|
|
str[col] = NUL;
|
|
|
|
nextcomm = str;
|
2005-02-22 08:49:11 +00:00
|
|
|
|
|
|
|
#ifdef FEAT_EVAL
|
2016-09-05 21:51:14 +02:00
|
|
|
if (use_ccline && ccline.cmdfirstc == '=')
|
2007-07-24 12:34:30 +00:00
|
|
|
{
|
|
|
|
# ifdef FEAT_CMDL_COMPL
|
2005-02-22 08:49:11 +00:00
|
|
|
/* pass CMD_SIZE because there is no real command */
|
|
|
|
set_context_for_expression(xp, str, CMD_SIZE);
|
2007-07-24 12:34:30 +00:00
|
|
|
# endif
|
|
|
|
}
|
2016-09-05 21:51:14 +02:00
|
|
|
else if (use_ccline && ccline.input_fn)
|
2005-09-20 23:22:24 +00:00
|
|
|
{
|
|
|
|
xp->xp_context = ccline.xp_context;
|
|
|
|
xp->xp_pattern = ccline.cmdbuff;
|
2019-04-27 13:04:13 +02:00
|
|
|
# if defined(FEAT_CMDL_COMPL)
|
2005-09-20 23:22:24 +00:00
|
|
|
xp->xp_arg = ccline.xp_arg;
|
2007-07-24 12:34:30 +00:00
|
|
|
# endif
|
2005-09-20 23:22:24 +00:00
|
|
|
}
|
2005-02-22 08:49:11 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
while (nextcomm != NULL)
|
|
|
|
nextcomm = set_one_cmd_context(xp, nextcomm);
|
|
|
|
|
2013-06-30 12:21:24 +02:00
|
|
|
/* Store the string here so that call_user_expand_func() can get to them
|
|
|
|
* easily. */
|
|
|
|
xp->xp_line = str;
|
|
|
|
xp->xp_col = col;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
str[col] = old_char;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expand the command line "str" from context "xp".
|
|
|
|
* "xp" must have been set by set_cmd_context().
|
|
|
|
* xp->xp_pattern points into "str", to where the text that is to be expanded
|
|
|
|
* starts.
|
|
|
|
* Returns EXPAND_UNSUCCESSFUL when there is something illegal before the
|
|
|
|
* cursor.
|
|
|
|
* Returns EXPAND_NOTHING when there is nothing to expand, might insert the
|
|
|
|
* key that triggered expansion literally.
|
|
|
|
* Returns EXPAND_OK otherwise.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
expand_cmdline(
|
|
|
|
expand_T *xp,
|
|
|
|
char_u *str, /* start of command line */
|
|
|
|
int col, /* position of cursor */
|
|
|
|
int *matchcount, /* return: nr of matches */
|
|
|
|
char_u ***matches) /* return: array of pointers to matches */
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *file_str = NULL;
|
2010-12-02 16:01:29 +01:00
|
|
|
int options = WILD_ADD_SLASH|WILD_SILENT;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (xp->xp_context == EXPAND_UNSUCCESSFUL)
|
|
|
|
{
|
|
|
|
beep_flush();
|
|
|
|
return EXPAND_UNSUCCESSFUL; /* Something illegal on command line */
|
|
|
|
}
|
|
|
|
if (xp->xp_context == EXPAND_NOTHING)
|
|
|
|
{
|
|
|
|
/* Caller can use the character as a normal char instead */
|
|
|
|
return EXPAND_NOTHING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add star to file name, or convert to regexp if not exp. files. */
|
2009-09-18 15:25:52 +00:00
|
|
|
xp->xp_pattern_len = (int)(str + col - xp->xp_pattern);
|
|
|
|
file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (file_str == NULL)
|
|
|
|
return EXPAND_UNSUCCESSFUL;
|
|
|
|
|
2010-12-02 16:01:29 +01:00
|
|
|
if (p_wic)
|
|
|
|
options += WILD_ICASE;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* find all files that match the description */
|
2010-12-02 16:01:29 +01:00
|
|
|
if (ExpandFromContext(xp, file_str, matchcount, matches, options) == FAIL)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
*matchcount = 0;
|
|
|
|
*matches = NULL;
|
|
|
|
}
|
|
|
|
vim_free(file_str);
|
|
|
|
|
|
|
|
return EXPAND_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FEAT_MULTI_LANG
|
|
|
|
/*
|
2016-03-28 19:59:02 +02:00
|
|
|
* Cleanup matches for help tags:
|
|
|
|
* Remove "@ab" if the top of 'helplang' is "ab" and the language of the first
|
|
|
|
* tag matches it. Otherwise remove "@en" if "en" is the only language.
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
static void
|
2016-01-30 15:52:46 +01:00
|
|
|
cleanup_help_tags(int num_file, char_u **file)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int len;
|
2016-03-28 19:59:02 +02:00
|
|
|
char_u buf[4];
|
|
|
|
char_u *p = buf;
|
|
|
|
|
2016-05-05 17:18:41 +02:00
|
|
|
if (p_hlg[0] != NUL && (p_hlg[0] != 'e' || p_hlg[1] != 'n'))
|
2016-03-28 19:59:02 +02:00
|
|
|
{
|
|
|
|
*p++ = '@';
|
|
|
|
*p++ = p_hlg[0];
|
|
|
|
*p++ = p_hlg[1];
|
|
|
|
}
|
|
|
|
*p = NUL;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_file; ++i)
|
|
|
|
{
|
|
|
|
len = (int)STRLEN(file[i]) - 3;
|
2016-03-28 19:59:02 +02:00
|
|
|
if (len <= 0)
|
|
|
|
continue;
|
2016-05-07 18:36:48 +02:00
|
|
|
if (STRCMP(file[i] + len, "@en") == 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/* Sorting on priority means the same item in another language may
|
|
|
|
* be anywhere. Search all items for a match up to the "@en". */
|
|
|
|
for (j = 0; j < num_file; ++j)
|
2016-05-07 18:36:48 +02:00
|
|
|
if (j != i && (int)STRLEN(file[j]) == len + 3
|
|
|
|
&& STRNCMP(file[i], file[j], len + 1) == 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
if (j == num_file)
|
2016-05-05 17:18:41 +02:00
|
|
|
/* item only exists with @en, remove it */
|
2004-06-13 20:20:40 +00:00
|
|
|
file[i][len] = NUL;
|
|
|
|
}
|
|
|
|
}
|
2016-05-07 18:36:48 +02:00
|
|
|
|
|
|
|
if (*buf != NUL)
|
|
|
|
for (i = 0; i < num_file; ++i)
|
|
|
|
{
|
|
|
|
len = (int)STRLEN(file[i]) - 3;
|
|
|
|
if (len <= 0)
|
|
|
|
continue;
|
|
|
|
if (STRCMP(file[i] + len, buf) == 0)
|
|
|
|
{
|
|
|
|
/* remove the default language */
|
|
|
|
file[i][len] = NUL;
|
|
|
|
}
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the expansion based on xp->xp_context and "pat".
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandFromContext(
|
|
|
|
expand_T *xp,
|
|
|
|
char_u *pat,
|
|
|
|
int *num_file,
|
|
|
|
char_u ***file,
|
2019-08-02 19:52:15 +02:00
|
|
|
int options) // WILD_ flags
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
#ifdef FEAT_CMDL_COMPL
|
|
|
|
regmatch_T regmatch;
|
|
|
|
#endif
|
|
|
|
int ret;
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
flags = EW_DIR; /* include directories */
|
|
|
|
if (options & WILD_LIST_NOTFOUND)
|
|
|
|
flags |= EW_NOTFOUND;
|
|
|
|
if (options & WILD_ADD_SLASH)
|
|
|
|
flags |= EW_ADDSLASH;
|
|
|
|
if (options & WILD_KEEP_ALL)
|
|
|
|
flags |= EW_KEEPALL;
|
|
|
|
if (options & WILD_SILENT)
|
|
|
|
flags |= EW_SILENT;
|
2015-03-05 19:35:25 +01:00
|
|
|
if (options & WILD_ALLLINKS)
|
|
|
|
flags |= EW_ALLLINKS;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2010-07-14 16:52:17 +02:00
|
|
|
if (xp->xp_context == EXPAND_FILES
|
|
|
|
|| xp->xp_context == EXPAND_DIRECTORIES
|
|
|
|
|| xp->xp_context == EXPAND_FILES_IN_PATH)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Expand file or directory names.
|
|
|
|
*/
|
|
|
|
int free_pat = FALSE;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* for ":set path=" and ":set tags=" halve backslashes for escaped
|
|
|
|
* space */
|
|
|
|
if (xp->xp_backslash != XP_BS_NONE)
|
|
|
|
{
|
|
|
|
free_pat = TRUE;
|
|
|
|
pat = vim_strsave(pat);
|
|
|
|
for (i = 0; pat[i]; ++i)
|
|
|
|
if (pat[i] == '\\')
|
|
|
|
{
|
|
|
|
if (xp->xp_backslash == XP_BS_THREE
|
|
|
|
&& pat[i + 1] == '\\'
|
|
|
|
&& pat[i + 2] == '\\'
|
|
|
|
&& pat[i + 3] == ' ')
|
2008-06-24 21:56:24 +00:00
|
|
|
STRMOVE(pat + i, pat + i + 3);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (xp->xp_backslash == XP_BS_ONE
|
|
|
|
&& pat[i + 1] == ' ')
|
2008-06-24 21:56:24 +00:00
|
|
|
STRMOVE(pat + i, pat + i + 1);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xp->xp_context == EXPAND_FILES)
|
|
|
|
flags |= EW_FILE;
|
2010-07-14 16:52:17 +02:00
|
|
|
else if (xp->xp_context == EXPAND_FILES_IN_PATH)
|
|
|
|
flags |= (EW_FILE | EW_PATH);
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
flags = (flags | EW_DIR) & ~EW_FILE;
|
2010-12-02 16:01:29 +01:00
|
|
|
if (options & WILD_ICASE)
|
|
|
|
flags |= EW_ICASE;
|
|
|
|
|
2009-12-02 16:14:36 +00:00
|
|
|
/* Expand wildcards, supporting %:h and the like. */
|
|
|
|
ret = expand_wildcards_eval(&pat, num_file, file, flags);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (free_pat)
|
|
|
|
vim_free(pat);
|
2019-07-28 16:36:39 +02:00
|
|
|
#ifdef BACKSLASH_IN_FILENAME
|
2019-08-02 19:52:15 +02:00
|
|
|
if (p_csl[0] != NUL && (options & WILD_IGNORE_COMPLETESLASH) == 0)
|
2019-07-28 16:36:39 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < *num_file; ++i)
|
|
|
|
{
|
|
|
|
char_u *ptr = (*file)[i];
|
|
|
|
|
|
|
|
while (*ptr != NUL)
|
|
|
|
{
|
|
|
|
if (p_csl[0] == 's' && *ptr == '\\')
|
|
|
|
*ptr = '/';
|
|
|
|
else if (p_csl[0] == 'b' && *ptr == '/')
|
|
|
|
*ptr = '\\';
|
|
|
|
ptr += (*mb_ptr2len)(ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*file = (char_u **)"";
|
|
|
|
*num_file = 0;
|
|
|
|
if (xp->xp_context == EXPAND_HELP)
|
|
|
|
{
|
2008-08-06 13:03:07 +00:00
|
|
|
/* With an empty argument we would get all the help tags, which is
|
|
|
|
* very slow. Get matches for "help" instead. */
|
|
|
|
if (find_help_tags(*pat == NUL ? (char_u *)"help" : pat,
|
|
|
|
num_file, file, FALSE) == OK)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
#ifdef FEAT_MULTI_LANG
|
|
|
|
cleanup_help_tags(*num_file, *file);
|
|
|
|
#endif
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef FEAT_CMDL_COMPL
|
|
|
|
return FAIL;
|
|
|
|
#else
|
2006-03-07 22:38:47 +00:00
|
|
|
if (xp->xp_context == EXPAND_SHELLCMD)
|
|
|
|
return expand_shellcmd(pat, num_file, file, flags);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (xp->xp_context == EXPAND_OLD_SETTING)
|
|
|
|
return ExpandOldSetting(num_file, file);
|
|
|
|
if (xp->xp_context == EXPAND_BUFFERS)
|
|
|
|
return ExpandBufnames(pat, num_file, file, options);
|
|
|
|
if (xp->xp_context == EXPAND_TAGS
|
|
|
|
|| xp->xp_context == EXPAND_TAGS_LISTFILES)
|
|
|
|
return expand_tags(xp->xp_context == EXPAND_TAGS, pat, num_file, file);
|
|
|
|
if (xp->xp_context == EXPAND_COLORS)
|
2011-06-26 19:40:23 +02:00
|
|
|
{
|
|
|
|
char *directories[] = {"colors", NULL};
|
2016-03-13 13:24:45 +01:00
|
|
|
return ExpandRTDir(pat, DIP_START + DIP_OPT, num_file, file,
|
|
|
|
directories);
|
2011-06-26 19:40:23 +02:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
if (xp->xp_context == EXPAND_COMPILER)
|
2011-06-26 19:40:23 +02:00
|
|
|
{
|
2011-09-30 16:23:32 +02:00
|
|
|
char *directories[] = {"compiler", NULL};
|
2016-03-13 13:24:45 +01:00
|
|
|
return ExpandRTDir(pat, 0, num_file, file, directories);
|
2011-06-26 19:40:23 +02:00
|
|
|
}
|
2010-07-29 20:59:59 +02:00
|
|
|
if (xp->xp_context == EXPAND_OWNSYNTAX)
|
2011-06-26 19:40:23 +02:00
|
|
|
{
|
|
|
|
char *directories[] = {"syntax", NULL};
|
2016-03-13 13:24:45 +01:00
|
|
|
return ExpandRTDir(pat, 0, num_file, file, directories);
|
2011-06-26 19:40:23 +02:00
|
|
|
}
|
2010-07-29 20:59:59 +02:00
|
|
|
if (xp->xp_context == EXPAND_FILETYPE)
|
2011-06-26 19:40:23 +02:00
|
|
|
{
|
|
|
|
char *directories[] = {"syntax", "indent", "ftplugin", NULL};
|
2016-03-13 13:24:45 +01:00
|
|
|
return ExpandRTDir(pat, 0, num_file, file, directories);
|
2011-06-26 19:40:23 +02:00
|
|
|
}
|
2019-04-27 13:04:13 +02:00
|
|
|
# if defined(FEAT_EVAL)
|
2005-07-09 21:08:57 +00:00
|
|
|
if (xp->xp_context == EXPAND_USER_LIST)
|
2006-04-30 18:54:39 +00:00
|
|
|
return ExpandUserList(xp, num_file, file);
|
2005-07-09 21:08:57 +00:00
|
|
|
# endif
|
2016-03-05 17:41:49 +01:00
|
|
|
if (xp->xp_context == EXPAND_PACKADD)
|
|
|
|
return ExpandPackAddDir(pat, num_file, file);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
regmatch.regprog = vim_regcomp(pat, p_magic ? RE_MAGIC : 0);
|
|
|
|
if (regmatch.regprog == NULL)
|
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
/* set ignore-case according to p_ic, p_scs and pat */
|
|
|
|
regmatch.rm_ic = ignorecase(pat);
|
|
|
|
|
|
|
|
if (xp->xp_context == EXPAND_SETTINGS
|
|
|
|
|| xp->xp_context == EXPAND_BOOL_SETTINGS)
|
|
|
|
ret = ExpandSettings(xp, ®match, num_file, file);
|
|
|
|
else if (xp->xp_context == EXPAND_MAPPINGS)
|
|
|
|
ret = ExpandMappings(®match, num_file, file);
|
2019-04-27 13:04:13 +02:00
|
|
|
# if defined(FEAT_EVAL)
|
2004-06-13 20:20:40 +00:00
|
|
|
else if (xp->xp_context == EXPAND_USER_DEFINED)
|
|
|
|
ret = ExpandUserDefined(xp, ®match, num_file, file);
|
|
|
|
# endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static struct expgen
|
|
|
|
{
|
|
|
|
int context;
|
2016-01-29 23:20:40 +01:00
|
|
|
char_u *((*func)(expand_T *, int));
|
2004-06-13 20:20:40 +00:00
|
|
|
int ic;
|
2011-05-19 18:26:40 +02:00
|
|
|
int escaped;
|
2004-06-13 20:20:40 +00:00
|
|
|
} tab[] =
|
|
|
|
{
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_COMMANDS, get_command_name, FALSE, TRUE},
|
|
|
|
{EXPAND_BEHAVE, get_behave_arg, TRUE, TRUE},
|
2017-08-06 15:22:15 +02:00
|
|
|
{EXPAND_MAPCLEAR, get_mapclear_arg, TRUE, TRUE},
|
2016-10-15 15:39:39 +02:00
|
|
|
{EXPAND_MESSAGES, get_messages_arg, TRUE, TRUE},
|
2012-04-30 18:48:53 +02:00
|
|
|
{EXPAND_HISTORY, get_history_arg, TRUE, TRUE},
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE},
|
2014-12-08 04:16:44 +01:00
|
|
|
{EXPAND_USER_ADDR_TYPE, get_user_cmd_addr_type, FALSE, TRUE},
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE},
|
|
|
|
{EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE},
|
|
|
|
{EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE},
|
2004-06-13 20:20:40 +00:00
|
|
|
#ifdef FEAT_EVAL
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE},
|
|
|
|
{EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE},
|
|
|
|
{EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE},
|
|
|
|
{EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE},
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FEAT_MENU
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_MENUS, get_menu_name, FALSE, TRUE},
|
|
|
|
{EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE},
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FEAT_SYN_HL
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE},
|
2013-06-08 15:24:48 +02:00
|
|
|
#endif
|
|
|
|
#ifdef FEAT_PROFILE
|
|
|
|
{EXPAND_SYNTIME, get_syntime_arg, TRUE, TRUE},
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE},
|
|
|
|
{EXPAND_EVENTS, get_event_name, TRUE, TRUE},
|
|
|
|
{EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE},
|
2009-03-18 11:52:53 +00:00
|
|
|
#ifdef FEAT_CSCOPE
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE},
|
2009-03-18 11:52:53 +00:00
|
|
|
#endif
|
2009-04-29 16:47:23 +00:00
|
|
|
#ifdef FEAT_SIGNS
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_SIGN, get_sign_name, TRUE, TRUE},
|
2009-04-29 16:47:23 +00:00
|
|
|
#endif
|
2010-02-03 15:14:22 +01:00
|
|
|
#ifdef FEAT_PROFILE
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_PROFILE, get_profile_name, TRUE, TRUE},
|
2010-02-03 15:14:22 +01:00
|
|
|
#endif
|
2019-01-24 15:54:21 +01:00
|
|
|
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE},
|
|
|
|
{EXPAND_LOCALES, get_locales, TRUE, FALSE},
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
2011-05-19 18:26:40 +02:00
|
|
|
{EXPAND_ENV_VARS, get_env_name, TRUE, TRUE},
|
2012-08-15 14:05:05 +02:00
|
|
|
{EXPAND_USER, get_users, TRUE, FALSE},
|
2018-03-29 15:55:38 +02:00
|
|
|
{EXPAND_ARGLIST, get_arglist_name, TRUE, FALSE},
|
2004-06-13 20:20:40 +00:00
|
|
|
};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a context in the table and call the ExpandGeneric() with the
|
|
|
|
* right function to do the expansion.
|
|
|
|
*/
|
|
|
|
ret = FAIL;
|
2009-05-16 15:31:32 +00:00
|
|
|
for (i = 0; i < (int)(sizeof(tab) / sizeof(struct expgen)); ++i)
|
2004-06-13 20:20:40 +00:00
|
|
|
if (xp->xp_context == tab[i].context)
|
|
|
|
{
|
|
|
|
if (tab[i].ic)
|
|
|
|
regmatch.rm_ic = TRUE;
|
2011-05-19 18:26:40 +02:00
|
|
|
ret = ExpandGeneric(xp, ®match, num_file, file,
|
2012-06-29 13:44:41 +02:00
|
|
|
tab[i].func, tab[i].escaped);
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 18:19:48 +02:00
|
|
|
vim_regfree(regmatch.regprog);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
#endif /* FEAT_CMDL_COMPL */
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* Expand a list of names.
|
|
|
|
*
|
|
|
|
* Generic function for command line completion. It calls a function to
|
|
|
|
* obtain strings, one by one. The strings are matched against a regexp
|
|
|
|
* program. Matching strings are copied into an array, which is returned.
|
|
|
|
*
|
|
|
|
* Returns OK when no problems encountered, FAIL for error (out of memory).
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandGeneric(
|
|
|
|
expand_T *xp,
|
|
|
|
regmatch_T *regmatch,
|
|
|
|
int *num_file,
|
|
|
|
char_u ***file,
|
|
|
|
char_u *((*func)(expand_T *, int)),
|
2004-06-13 20:20:40 +00:00
|
|
|
/* returns a string from the list */
|
2016-01-30 15:52:46 +01:00
|
|
|
int escaped)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count = 0;
|
2005-08-12 19:59:19 +00:00
|
|
|
int round;
|
2004-06-13 20:20:40 +00:00
|
|
|
char_u *str;
|
|
|
|
|
|
|
|
/* do this loop twice:
|
2005-08-12 19:59:19 +00:00
|
|
|
* round == 0: count the number of matching names
|
|
|
|
* round == 1: copy the matching names into allocated memory
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
2005-08-12 19:59:19 +00:00
|
|
|
for (round = 0; round <= 1; ++round)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
for (i = 0; ; ++i)
|
|
|
|
{
|
|
|
|
str = (*func)(xp, i);
|
|
|
|
if (str == NULL) /* end of list */
|
|
|
|
break;
|
|
|
|
if (*str == NUL) /* skip empty strings */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (vim_regexec(regmatch, str, (colnr_T)0))
|
|
|
|
{
|
2005-08-12 19:59:19 +00:00
|
|
|
if (round)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2011-05-19 18:26:40 +02:00
|
|
|
if (escaped)
|
|
|
|
str = vim_strsave_escaped(str, (char_u *)" \t\\.");
|
|
|
|
else
|
|
|
|
str = vim_strsave(str);
|
2004-06-13 20:20:40 +00:00
|
|
|
(*file)[count] = str;
|
|
|
|
#ifdef FEAT_MENU
|
|
|
|
if (func == get_menu_names && str != NULL)
|
|
|
|
{
|
|
|
|
/* test for separator added by get_menu_names() */
|
|
|
|
str += STRLEN(str) - 1;
|
|
|
|
if (*str == '\001')
|
|
|
|
*str = '.';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
2005-08-12 19:59:19 +00:00
|
|
|
if (round == 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
if (count == 0)
|
|
|
|
return OK;
|
|
|
|
*num_file = count;
|
2019-05-28 23:08:19 +02:00
|
|
|
*file = ALLOC_MULT(char_u *, count);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (*file == NULL)
|
|
|
|
{
|
|
|
|
*file = (char_u **)"";
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-08-12 19:59:19 +00:00
|
|
|
|
2006-04-13 20:37:35 +00:00
|
|
|
/* Sort the results. Keep menu's in the specified order. */
|
|
|
|
if (xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_MENUS)
|
2011-10-26 22:02:15 +02:00
|
|
|
{
|
|
|
|
if (xp->xp_context == EXPAND_EXPRESSION
|
|
|
|
|| xp->xp_context == EXPAND_FUNCTIONS
|
|
|
|
|| xp->xp_context == EXPAND_USER_FUNC)
|
|
|
|
/* <SNR> functions should be sorted to the end. */
|
|
|
|
qsort((void *)*file, (size_t)*num_file, sizeof(char_u *),
|
|
|
|
sort_func_compare);
|
|
|
|
else
|
|
|
|
sort_strings(*file, *num_file);
|
|
|
|
}
|
2005-08-12 19:59:19 +00:00
|
|
|
|
2007-07-24 12:34:30 +00:00
|
|
|
#ifdef FEAT_CMDL_COMPL
|
|
|
|
/* Reset the variables used for special highlight names expansion, so that
|
|
|
|
* they don't show up when getting normal highlight names by ID. */
|
|
|
|
reset_expand_highlight();
|
|
|
|
#endif
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2006-03-07 22:38:47 +00:00
|
|
|
/*
|
|
|
|
* Complete a shell command.
|
|
|
|
* Returns FAIL or OK;
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
expand_shellcmd(
|
|
|
|
char_u *filepat, /* pattern to match with command names */
|
|
|
|
int *num_file, /* return: number of matches */
|
|
|
|
char_u ***file, /* return: array with matches */
|
|
|
|
int flagsarg) /* EW_ flags */
|
2006-03-07 22:38:47 +00:00
|
|
|
{
|
|
|
|
char_u *pat;
|
|
|
|
int i;
|
2018-05-22 16:58:47 +02:00
|
|
|
char_u *path = NULL;
|
2006-03-07 22:38:47 +00:00
|
|
|
int mustfree = FALSE;
|
|
|
|
garray_T ga;
|
|
|
|
char_u *buf = alloc(MAXPATHL);
|
|
|
|
size_t l;
|
|
|
|
char_u *s, *e;
|
|
|
|
int flags = flagsarg;
|
|
|
|
int ret;
|
2015-03-21 17:32:19 +01:00
|
|
|
int did_curdir = FALSE;
|
2018-05-22 16:58:47 +02:00
|
|
|
hashtab_T found_ht;
|
|
|
|
hashitem_T *hi;
|
|
|
|
hash_T hash;
|
2006-03-07 22:38:47 +00:00
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
/* for ":set path=" and ":set tags=" halve backslashes for escaped
|
|
|
|
* space */
|
|
|
|
pat = vim_strsave(filepat);
|
|
|
|
for (i = 0; pat[i]; ++i)
|
|
|
|
if (pat[i] == '\\' && pat[i + 1] == ' ')
|
2008-06-24 21:56:24 +00:00
|
|
|
STRMOVE(pat + i, pat + i + 1);
|
2006-03-07 22:38:47 +00:00
|
|
|
|
2015-03-21 17:32:19 +01:00
|
|
|
flags |= EW_FILE | EW_EXEC | EW_SHELLCMD;
|
2006-03-07 22:38:47 +00:00
|
|
|
|
2018-05-22 16:58:47 +02:00
|
|
|
if (pat[0] == '.' && (vim_ispathsep(pat[1])
|
|
|
|
|| (pat[1] == '.' && vim_ispathsep(pat[2]))))
|
2006-03-07 22:38:47 +00:00
|
|
|
path = (char_u *)".";
|
|
|
|
else
|
2010-11-10 15:37:05 +01:00
|
|
|
{
|
2018-05-22 16:58:47 +02:00
|
|
|
/* For an absolute name we don't use $PATH. */
|
|
|
|
if (!mch_isFullName(pat))
|
|
|
|
path = vim_getenv((char_u *)"PATH", &mustfree);
|
2010-11-10 15:37:05 +01:00
|
|
|
if (path == NULL)
|
|
|
|
path = (char_u *)"";
|
|
|
|
}
|
2006-03-07 22:38:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Go over all directories in $PATH. Expand matches in that directory and
|
2015-03-21 17:32:19 +01:00
|
|
|
* collect them in "ga". When "." is not in $PATH also expand for the
|
|
|
|
* current directory, to find "subdir/cmd".
|
2006-03-07 22:38:47 +00:00
|
|
|
*/
|
|
|
|
ga_init2(&ga, (int)sizeof(char *), 10);
|
2018-05-22 16:58:47 +02:00
|
|
|
hash_init(&found_ht);
|
2015-03-21 17:32:19 +01:00
|
|
|
for (s = path; ; s = e)
|
2006-03-07 22:38:47 +00:00
|
|
|
{
|
2016-02-23 14:53:34 +01:00
|
|
|
#if defined(MSWIN)
|
2006-03-07 22:38:47 +00:00
|
|
|
e = vim_strchr(s, ';');
|
|
|
|
#else
|
|
|
|
e = vim_strchr(s, ':');
|
|
|
|
#endif
|
|
|
|
if (e == NULL)
|
|
|
|
e = s + STRLEN(s);
|
|
|
|
|
2018-07-28 19:20:13 +02:00
|
|
|
if (*s == NUL)
|
|
|
|
{
|
|
|
|
if (did_curdir)
|
|
|
|
break;
|
|
|
|
// Find directories in the current directory, path is empty.
|
|
|
|
did_curdir = TRUE;
|
|
|
|
flags |= EW_DIR;
|
|
|
|
}
|
|
|
|
else if (STRNCMP(s, ".", (int)(e - s)) == 0)
|
|
|
|
{
|
|
|
|
did_curdir = TRUE;
|
|
|
|
flags |= EW_DIR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// Do not match directories inside a $PATH item.
|
|
|
|
flags &= ~EW_DIR;
|
|
|
|
|
2006-03-07 22:38:47 +00:00
|
|
|
l = e - s;
|
|
|
|
if (l > MAXPATHL - 5)
|
|
|
|
break;
|
|
|
|
vim_strncpy(buf, s, l);
|
|
|
|
add_pathsep(buf);
|
|
|
|
l = STRLEN(buf);
|
|
|
|
vim_strncpy(buf + l, pat, MAXPATHL - 1 - l);
|
|
|
|
|
|
|
|
/* Expand matches in one directory of $PATH. */
|
|
|
|
ret = expand_wildcards(1, &buf, num_file, file, flags);
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
if (ga_grow(&ga, *num_file) == FAIL)
|
|
|
|
FreeWild(*num_file, *file);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < *num_file; ++i)
|
|
|
|
{
|
2018-05-22 16:58:47 +02:00
|
|
|
char_u *name = (*file)[i];
|
|
|
|
|
|
|
|
if (STRLEN(name) > l)
|
2006-03-07 22:38:47 +00:00
|
|
|
{
|
2018-05-22 16:58:47 +02:00
|
|
|
// Check if this name was already found.
|
|
|
|
hash = hash_hash(name + l);
|
|
|
|
hi = hash_lookup(&found_ht, name + l, hash);
|
|
|
|
if (HASHITEM_EMPTY(hi))
|
|
|
|
{
|
|
|
|
// Remove the path that was prepended.
|
|
|
|
STRMOVE(name, name + l);
|
|
|
|
((char_u **)ga.ga_data)[ga.ga_len++] = name;
|
|
|
|
hash_add_item(&found_ht, hi, name, hash);
|
|
|
|
name = NULL;
|
|
|
|
}
|
2006-03-07 22:38:47 +00:00
|
|
|
}
|
2018-05-22 16:58:47 +02:00
|
|
|
vim_free(name);
|
2006-03-07 22:38:47 +00:00
|
|
|
}
|
|
|
|
vim_free(*file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*e != NUL)
|
|
|
|
++e;
|
|
|
|
}
|
|
|
|
*file = ga.ga_data;
|
|
|
|
*num_file = ga.ga_len;
|
|
|
|
|
|
|
|
vim_free(buf);
|
|
|
|
vim_free(pat);
|
|
|
|
if (mustfree)
|
|
|
|
vim_free(path);
|
2018-05-22 16:58:47 +02:00
|
|
|
hash_clear(&found_ht);
|
2006-03-07 22:38:47 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-27 13:04:13 +02:00
|
|
|
# if defined(FEAT_EVAL)
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
2017-02-23 19:03:28 +01:00
|
|
|
* Call "user_expand_func()" to invoke a user defined Vim script function and
|
|
|
|
* return the result (either a string or a List).
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
2005-07-09 21:08:57 +00:00
|
|
|
static void *
|
2016-01-30 15:52:46 +01:00
|
|
|
call_user_expand_func(
|
2018-08-01 19:06:03 +02:00
|
|
|
void *(*user_expand_func)(char_u *, int, typval_T *),
|
2016-01-30 15:52:46 +01:00
|
|
|
expand_T *xp,
|
|
|
|
int *num_file,
|
|
|
|
char_u ***file)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2013-06-30 22:43:27 +02:00
|
|
|
int keep = 0;
|
2018-06-12 22:05:14 +02:00
|
|
|
typval_T args[4];
|
2018-09-10 21:05:02 +02:00
|
|
|
sctx_T save_current_sctx = current_sctx;
|
2018-06-12 22:05:14 +02:00
|
|
|
char_u *pat = NULL;
|
2005-07-09 21:08:57 +00:00
|
|
|
void *ret;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2013-06-29 12:58:33 +02:00
|
|
|
if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL)
|
2005-07-09 21:08:57 +00:00
|
|
|
return NULL;
|
2004-06-13 20:20:40 +00:00
|
|
|
*num_file = 0;
|
|
|
|
*file = NULL;
|
|
|
|
|
2013-06-29 12:58:33 +02:00
|
|
|
if (ccline.cmdbuff != NULL)
|
2008-01-18 12:16:16 +00:00
|
|
|
{
|
|
|
|
keep = ccline.cmdbuff[ccline.cmdlen];
|
|
|
|
ccline.cmdbuff[ccline.cmdlen] = 0;
|
|
|
|
}
|
2013-06-29 12:58:33 +02:00
|
|
|
|
2018-06-12 22:05:14 +02:00
|
|
|
pat = vim_strnsave(xp->xp_pattern, xp->xp_pattern_len);
|
|
|
|
|
|
|
|
args[0].v_type = VAR_STRING;
|
|
|
|
args[0].vval.v_string = pat;
|
|
|
|
args[1].v_type = VAR_STRING;
|
|
|
|
args[1].vval.v_string = xp->xp_line;
|
|
|
|
args[2].v_type = VAR_NUMBER;
|
|
|
|
args[2].vval.v_number = xp->xp_col;
|
|
|
|
args[3].v_type = VAR_UNKNOWN;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2018-09-10 21:05:02 +02:00
|
|
|
current_sctx = xp->xp_script_ctx;
|
2004-07-03 16:05:59 +00:00
|
|
|
|
2018-08-01 19:06:03 +02:00
|
|
|
ret = user_expand_func(xp->xp_arg, 3, args);
|
2004-07-03 16:05:59 +00:00
|
|
|
|
2018-09-10 21:05:02 +02:00
|
|
|
current_sctx = save_current_sctx;
|
2008-01-18 12:16:16 +00:00
|
|
|
if (ccline.cmdbuff != NULL)
|
|
|
|
ccline.cmdbuff[ccline.cmdlen] = keep;
|
2005-07-09 21:08:57 +00:00
|
|
|
|
2018-06-12 22:05:14 +02:00
|
|
|
vim_free(pat);
|
2005-07-09 21:08:57 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expand names with a function defined by the user.
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandUserDefined(
|
|
|
|
expand_T *xp,
|
|
|
|
regmatch_T *regmatch,
|
|
|
|
int *num_file,
|
|
|
|
char_u ***file)
|
2005-07-09 21:08:57 +00:00
|
|
|
{
|
|
|
|
char_u *retstr;
|
|
|
|
char_u *s;
|
|
|
|
char_u *e;
|
2018-02-11 15:20:20 +01:00
|
|
|
int keep;
|
2005-07-09 21:08:57 +00:00
|
|
|
garray_T ga;
|
2018-02-11 15:20:20 +01:00
|
|
|
int skip;
|
2005-07-09 21:08:57 +00:00
|
|
|
|
|
|
|
retstr = call_user_expand_func(call_func_retstr, xp, num_file, file);
|
|
|
|
if (retstr == NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
ga_init2(&ga, (int)sizeof(char *), 3);
|
2005-07-09 21:08:57 +00:00
|
|
|
for (s = retstr; *s != NUL; s = e)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
e = vim_strchr(s, '\n');
|
|
|
|
if (e == NULL)
|
|
|
|
e = s + STRLEN(s);
|
|
|
|
keep = *e;
|
2018-02-11 15:20:20 +01:00
|
|
|
*e = NUL;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2018-02-11 15:20:20 +01:00
|
|
|
skip = xp->xp_pattern[0] && vim_regexec(regmatch, s, (colnr_T)0) == 0;
|
|
|
|
*e = keep;
|
|
|
|
|
|
|
|
if (!skip)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2018-02-11 15:20:20 +01:00
|
|
|
if (ga_grow(&ga, 1) == FAIL)
|
|
|
|
break;
|
|
|
|
((char_u **)ga.ga_data)[ga.ga_len] = vim_strnsave(s, (int)(e - s));
|
|
|
|
++ga.ga_len;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*e != NUL)
|
|
|
|
++e;
|
|
|
|
}
|
2005-07-09 21:08:57 +00:00
|
|
|
vim_free(retstr);
|
|
|
|
*file = ga.ga_data;
|
|
|
|
*num_file = ga.ga_len;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expand names with a list returned by a function defined by the user.
|
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandUserList(
|
|
|
|
expand_T *xp,
|
|
|
|
int *num_file,
|
|
|
|
char_u ***file)
|
2005-07-09 21:08:57 +00:00
|
|
|
{
|
|
|
|
list_T *retlist;
|
|
|
|
listitem_T *li;
|
|
|
|
garray_T ga;
|
|
|
|
|
|
|
|
retlist = call_user_expand_func(call_func_retlist, xp, num_file, file);
|
|
|
|
if (retlist == NULL)
|
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
ga_init2(&ga, (int)sizeof(char *), 3);
|
|
|
|
/* Loop over the items in the list. */
|
|
|
|
for (li = retlist->lv_first; li != NULL; li = li->li_next)
|
|
|
|
{
|
2009-06-24 15:05:00 +00:00
|
|
|
if (li->li_tv.v_type != VAR_STRING || li->li_tv.vval.v_string == NULL)
|
|
|
|
continue; /* Skip non-string items and empty strings */
|
2005-07-09 21:08:57 +00:00
|
|
|
|
|
|
|
if (ga_grow(&ga, 1) == FAIL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
((char_u **)ga.ga_data)[ga.ga_len] =
|
2009-06-24 15:05:00 +00:00
|
|
|
vim_strsave(li->li_tv.vval.v_string);
|
2005-07-09 21:08:57 +00:00
|
|
|
++ga.ga_len;
|
|
|
|
}
|
|
|
|
list_unref(retlist);
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
*file = ga.ga_data;
|
|
|
|
*num_file = ga.ga_len;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2016-03-13 13:24:45 +01:00
|
|
|
* Expand color scheme, compiler or filetype names.
|
|
|
|
* Search from 'runtimepath':
|
|
|
|
* 'runtimepath'/{dirnames}/{pat}.vim
|
|
|
|
* When "flags" has DIP_START: search also from 'start' of 'packpath':
|
|
|
|
* 'packpath'/pack/ * /start/ * /{dirnames}/{pat}.vim
|
|
|
|
* When "flags" has DIP_OPT: search also from 'opt' of 'packpath':
|
|
|
|
* 'packpath'/pack/ * /opt/ * /{dirnames}/{pat}.vim
|
2011-06-26 19:40:23 +02:00
|
|
|
* "dirnames" is an array with one or more directory names.
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
|
|
|
static int
|
2016-01-30 15:52:46 +01:00
|
|
|
ExpandRTDir(
|
|
|
|
char_u *pat,
|
2016-03-13 13:24:45 +01:00
|
|
|
int flags,
|
2016-01-30 15:52:46 +01:00
|
|
|
int *num_file,
|
|
|
|
char_u ***file,
|
|
|
|
char *dirnames[])
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *s;
|
|
|
|
char_u *e;
|
2014-05-07 18:35:30 +02:00
|
|
|
char_u *match;
|
2004-06-13 20:20:40 +00:00
|
|
|
garray_T ga;
|
2011-06-26 19:40:23 +02:00
|
|
|
int i;
|
|
|
|
int pat_len;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
*num_file = 0;
|
|
|
|
*file = NULL;
|
2011-07-07 15:04:52 +02:00
|
|
|
pat_len = (int)STRLEN(pat);
|
2011-06-26 19:40:23 +02:00
|
|
|
ga_init2(&ga, (int)sizeof(char *), 10);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2011-06-26 19:40:23 +02:00
|
|
|
for (i = 0; dirnames[i] != NULL; ++i)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2019-05-24 18:54:09 +02:00
|
|
|
s = alloc(STRLEN(dirnames[i]) + pat_len + 7);
|
2011-06-26 19:40:23 +02:00
|
|
|
if (s == NULL)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2011-06-26 19:40:23 +02:00
|
|
|
ga_clear_strings(&ga);
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
sprintf((char *)s, "%s/%s*.vim", dirnames[i], pat);
|
2014-05-07 18:35:30 +02:00
|
|
|
globpath(p_rtp, s, &ga, 0);
|
2011-06-26 19:40:23 +02:00
|
|
|
vim_free(s);
|
2014-05-07 18:35:30 +02:00
|
|
|
}
|
2011-06-26 19:40:23 +02:00
|
|
|
|
2016-03-13 13:24:45 +01:00
|
|
|
if (flags & DIP_START) {
|
|
|
|
for (i = 0; dirnames[i] != NULL; ++i)
|
|
|
|
{
|
2019-05-24 18:54:09 +02:00
|
|
|
s = alloc(STRLEN(dirnames[i]) + pat_len + 22);
|
2016-03-13 13:24:45 +01:00
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
ga_clear_strings(&ga);
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
sprintf((char *)s, "pack/*/start/*/%s/%s*.vim", dirnames[i], pat);
|
|
|
|
globpath(p_pp, s, &ga, 0);
|
|
|
|
vim_free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DIP_OPT) {
|
|
|
|
for (i = 0; dirnames[i] != NULL; ++i)
|
|
|
|
{
|
2019-05-24 18:54:09 +02:00
|
|
|
s = alloc(STRLEN(dirnames[i]) + pat_len + 20);
|
2016-03-13 13:24:45 +01:00
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
ga_clear_strings(&ga);
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
sprintf((char *)s, "pack/*/opt/*/%s/%s*.vim", dirnames[i], pat);
|
|
|
|
globpath(p_pp, s, &ga, 0);
|
|
|
|
vim_free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-07 18:35:30 +02:00
|
|
|
for (i = 0; i < ga.ga_len; ++i)
|
|
|
|
{
|
|
|
|
match = ((char_u **)ga.ga_data)[i];
|
|
|
|
s = match;
|
|
|
|
e = s + STRLEN(s);
|
|
|
|
if (e - 4 > s && STRNICMP(e - 4, ".vim", 4) == 0)
|
2011-06-26 19:40:23 +02:00
|
|
|
{
|
2014-05-07 18:35:30 +02:00
|
|
|
e -= 4;
|
2017-03-12 19:22:36 +01:00
|
|
|
for (s = e; s > match; MB_PTR_BACK(match, s))
|
2014-05-07 18:35:30 +02:00
|
|
|
if (s < match || vim_ispathsep(*s))
|
|
|
|
break;
|
|
|
|
++s;
|
|
|
|
*e = NUL;
|
|
|
|
mch_memmove(match, s, e - s + 1);
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-07 18:35:30 +02:00
|
|
|
|
2011-06-26 19:40:23 +02:00
|
|
|
if (ga.ga_len == 0)
|
2012-06-29 13:44:41 +02:00
|
|
|
return FAIL;
|
2010-07-29 20:59:59 +02:00
|
|
|
|
|
|
|
/* Sort and remove duplicates which can happen when specifying multiple
|
2011-06-26 19:40:23 +02:00
|
|
|
* directories in dirnames. */
|
2010-07-29 20:59:59 +02:00
|
|
|
remove_duplicates(&ga);
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
*file = ga.ga_data;
|
|
|
|
*num_file = ga.ga_len;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2016-03-05 17:41:49 +01:00
|
|
|
/*
|
|
|
|
* Expand loadplugin names:
|
|
|
|
* 'packpath'/pack/ * /opt/{pat}
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ExpandPackAddDir(
|
|
|
|
char_u *pat,
|
|
|
|
int *num_file,
|
|
|
|
char_u ***file)
|
|
|
|
{
|
|
|
|
char_u *s;
|
|
|
|
char_u *e;
|
|
|
|
char_u *match;
|
|
|
|
garray_T ga;
|
|
|
|
int i;
|
|
|
|
int pat_len;
|
|
|
|
|
|
|
|
*num_file = 0;
|
|
|
|
*file = NULL;
|
|
|
|
pat_len = (int)STRLEN(pat);
|
|
|
|
ga_init2(&ga, (int)sizeof(char *), 10);
|
|
|
|
|
2019-05-24 18:54:09 +02:00
|
|
|
s = alloc(pat_len + 26);
|
2016-03-05 17:41:49 +01:00
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
ga_clear_strings(&ga);
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
sprintf((char *)s, "pack/*/opt/%s*", pat);
|
|
|
|
globpath(p_pp, s, &ga, 0);
|
|
|
|
vim_free(s);
|
|
|
|
|
|
|
|
for (i = 0; i < ga.ga_len; ++i)
|
|
|
|
{
|
|
|
|
match = ((char_u **)ga.ga_data)[i];
|
|
|
|
s = gettail(match);
|
|
|
|
e = s + STRLEN(s);
|
|
|
|
mch_memmove(match, s, e - s + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ga.ga_len == 0)
|
|
|
|
return FAIL;
|
|
|
|
|
|
|
|
/* Sort and remove duplicates which can happen when specifying multiple
|
|
|
|
* directories in dirnames. */
|
|
|
|
remove_duplicates(&ga);
|
|
|
|
|
|
|
|
*file = ga.ga_data;
|
|
|
|
*num_file = ga.ga_len;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(FEAT_CMDL_COMPL) || defined(FEAT_EVAL) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* Expand "file" for all comma-separated directories in "path".
|
2014-05-07 18:35:30 +02:00
|
|
|
* Adds the matches to "ga". Caller must init "ga".
|
2004-06-13 20:20:40 +00:00
|
|
|
*/
|
2014-05-07 18:35:30 +02:00
|
|
|
void
|
2016-01-30 15:52:46 +01:00
|
|
|
globpath(
|
|
|
|
char_u *path,
|
|
|
|
char_u *file,
|
|
|
|
garray_T *ga,
|
|
|
|
int expand_options)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
expand_T xpc;
|
|
|
|
char_u *buf;
|
|
|
|
int i;
|
|
|
|
int num_p;
|
|
|
|
char_u **p;
|
|
|
|
|
|
|
|
buf = alloc(MAXPATHL);
|
|
|
|
if (buf == NULL)
|
2014-05-07 18:35:30 +02:00
|
|
|
return;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2006-01-19 22:16:24 +00:00
|
|
|
ExpandInit(&xpc);
|
2004-06-13 20:20:40 +00:00
|
|
|
xpc.xp_context = EXPAND_FILES;
|
2006-01-19 22:16:24 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Loop over all entries in {path}. */
|
|
|
|
while (*path != NUL)
|
|
|
|
{
|
|
|
|
/* Copy one item of the path to buf[] and concatenate the file name. */
|
|
|
|
copy_option_part(&path, buf, MAXPATHL, ",");
|
|
|
|
if (STRLEN(buf) + STRLEN(file) + 2 < MAXPATHL)
|
|
|
|
{
|
2016-02-23 14:53:34 +01:00
|
|
|
# if defined(MSWIN)
|
2010-08-05 21:40:16 +02:00
|
|
|
/* Using the platform's path separator (\) makes vim incorrectly
|
|
|
|
* treat it as an escape character, use '/' instead. */
|
|
|
|
if (*buf != NUL && !after_pathsep(buf, buf + STRLEN(buf)))
|
|
|
|
STRCAT(buf, "/");
|
|
|
|
# else
|
2004-06-13 20:20:40 +00:00
|
|
|
add_pathsep(buf);
|
2010-08-05 21:40:16 +02:00
|
|
|
# endif
|
2004-06-13 20:20:40 +00:00
|
|
|
STRCAT(buf, file);
|
2008-11-28 10:01:10 +00:00
|
|
|
if (ExpandFromContext(&xpc, buf, &num_p, &p,
|
|
|
|
WILD_SILENT|expand_options) != FAIL && num_p > 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2008-11-28 10:01:10 +00:00
|
|
|
ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT|expand_options);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2014-05-07 18:35:30 +02:00
|
|
|
if (ga_grow(ga, num_p) == OK)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < num_p; ++i)
|
|
|
|
{
|
2014-05-07 18:35:30 +02:00
|
|
|
((char_u **)ga->ga_data)[ga->ga_len] =
|
2014-05-29 14:36:29 +02:00
|
|
|
vim_strnsave(p[i], (int)STRLEN(p[i]));
|
2014-05-07 18:35:30 +02:00
|
|
|
++ga->ga_len;
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-07 18:35:30 +02:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
FreeWild(num_p, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vim_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-03-19 22:50:43 +01:00
|
|
|
#if defined(FEAT_EVAL) || defined(FEAT_CMDWIN) || defined(PROTO)
|
2016-03-19 22:29:49 +01:00
|
|
|
/*
|
2018-09-30 17:11:48 +02:00
|
|
|
* Get pointer to the command line info to use. save_ccline() may clear
|
2016-03-19 22:29:49 +01:00
|
|
|
* ccline and put the previous value in prev_ccline.
|
|
|
|
*/
|
|
|
|
static struct cmdline_info *
|
|
|
|
get_ccline_ptr(void)
|
|
|
|
{
|
|
|
|
if ((State & CMDLINE) == 0)
|
|
|
|
return NULL;
|
|
|
|
if (ccline.cmdbuff != NULL)
|
|
|
|
return &ccline;
|
|
|
|
if (prev_ccline_used && prev_ccline.cmdbuff != NULL)
|
|
|
|
return &prev_ccline;
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-03-19 22:50:43 +01:00
|
|
|
#endif
|
2016-03-19 22:29:49 +01:00
|
|
|
|
2016-03-19 22:50:43 +01:00
|
|
|
#if defined(FEAT_EVAL) || defined(PROTO)
|
2016-03-19 22:29:49 +01:00
|
|
|
/*
|
|
|
|
* Get the current command line in allocated memory.
|
|
|
|
* Only works when the command line is being edited.
|
|
|
|
* Returns NULL when something is wrong.
|
|
|
|
*/
|
|
|
|
char_u *
|
|
|
|
get_cmdline_str(void)
|
|
|
|
{
|
2018-09-25 22:27:35 +02:00
|
|
|
struct cmdline_info *p;
|
2016-03-19 22:29:49 +01:00
|
|
|
|
2018-09-25 22:27:35 +02:00
|
|
|
if (cmdline_star > 0)
|
|
|
|
return NULL;
|
|
|
|
p = get_ccline_ptr();
|
2016-03-19 22:29:49 +01:00
|
|
|
if (p == NULL)
|
|
|
|
return NULL;
|
|
|
|
return vim_strnsave(p->cmdbuff, p->cmdlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current command line position, counted in bytes.
|
|
|
|
* Zero is the first position.
|
|
|
|
* Only works when the command line is being edited.
|
|
|
|
* Returns -1 when something is wrong.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
get_cmdline_pos(void)
|
|
|
|
{
|
|
|
|
struct cmdline_info *p = get_ccline_ptr();
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
return -1;
|
|
|
|
return p->cmdpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the command line byte position to "pos". Zero is the first position.
|
|
|
|
* Only works when the command line is being edited.
|
|
|
|
* Returns 1 when failed, 0 when OK.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
set_cmdline_pos(
|
|
|
|
int pos)
|
|
|
|
{
|
|
|
|
struct cmdline_info *p = get_ccline_ptr();
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* The position is not set directly but after CTRL-\ e or CTRL-R = has
|
|
|
|
* changed the command line. */
|
|
|
|
if (pos < 0)
|
|
|
|
new_cmdpos = 0;
|
|
|
|
else
|
|
|
|
new_cmdpos = pos;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(FEAT_EVAL) || defined(FEAT_CMDWIN) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* Get the current command-line type.
|
|
|
|
* Returns ':' or '/' or '?' or '@' or '>' or '-'
|
|
|
|
* Only works when the command line is being edited.
|
|
|
|
* Returns NUL when something is wrong.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
get_cmdline_type(void)
|
|
|
|
{
|
|
|
|
struct cmdline_info *p = get_ccline_ptr();
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
return NUL;
|
|
|
|
if (p->cmdfirstc == NUL)
|
2016-03-19 22:50:43 +01:00
|
|
|
return
|
|
|
|
# ifdef FEAT_EVAL
|
|
|
|
(p->input_fn) ? '@' :
|
|
|
|
# endif
|
|
|
|
'-';
|
2016-03-19 22:29:49 +01:00
|
|
|
return p->cmdfirstc;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-06 21:59:57 +02:00
|
|
|
/*
|
|
|
|
* Return the first character of the current command line.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
get_cmdline_firstc(void)
|
|
|
|
{
|
|
|
|
return ccline.cmdfirstc;
|
|
|
|
}
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* Get indices "num1,num2" that specify a range within a list (not a range of
|
|
|
|
* text lines in a buffer!) from a string. Used for ":history" and ":clist".
|
|
|
|
* Returns OK if parsed successfully, otherwise FAIL.
|
|
|
|
*/
|
|
|
|
int
|
2016-01-30 15:52:46 +01:00
|
|
|
get_list_range(char_u **str, int *num1, int *num2)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
int first = FALSE;
|
2016-07-01 18:17:26 +02:00
|
|
|
varnumber_T num;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
*str = skipwhite(*str);
|
|
|
|
if (**str == '-' || vim_isdigit(**str)) /* parse "from" part of range */
|
|
|
|
{
|
2019-05-19 19:59:35 +02:00
|
|
|
vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
*str += len;
|
|
|
|
*num1 = (int)num;
|
|
|
|
first = TRUE;
|
|
|
|
}
|
|
|
|
*str = skipwhite(*str);
|
|
|
|
if (**str == ',') /* parse "to" part of range */
|
|
|
|
{
|
|
|
|
*str = skipwhite(*str + 1);
|
2019-05-19 19:59:35 +02:00
|
|
|
vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
*num2 = (int)num;
|
|
|
|
*str = skipwhite(*str + len);
|
|
|
|
}
|
|
|
|
else if (!first) /* no number given at all */
|
|
|
|
return FAIL;
|
|
|
|
}
|
|
|
|
else if (first) /* only one number given */
|
|
|
|
*num2 = *num1;
|
|
|
|
return OK;
|
|
|
|
}
|
2016-06-09 20:24:28 +02:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
#if defined(FEAT_CMDWIN) || defined(PROTO)
|
|
|
|
/*
|
|
|
|
* Open a window on the current command line and history. Allow editing in
|
|
|
|
* the window. Returns when the window is closed.
|
|
|
|
* Returns:
|
|
|
|
* CR if the command is to be executed
|
|
|
|
* Ctrl_C if it is to be abandoned
|
|
|
|
* K_IGNORE if editing continues
|
|
|
|
*/
|
|
|
|
static int
|
2017-04-07 15:42:25 +02:00
|
|
|
open_cmdwin(void)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2016-07-10 22:11:16 +02:00
|
|
|
bufref_T old_curbuf;
|
2004-06-13 20:20:40 +00:00
|
|
|
win_T *old_curwin = curwin;
|
2016-07-10 22:11:16 +02:00
|
|
|
bufref_T bufref;
|
2004-06-13 20:20:40 +00:00
|
|
|
win_T *wp;
|
|
|
|
int i;
|
|
|
|
linenr_T lnum;
|
|
|
|
int histtype;
|
|
|
|
garray_T winsizes;
|
|
|
|
int save_restart_edit = restart_edit;
|
|
|
|
int save_State = State;
|
|
|
|
int save_exmode = exmode_active;
|
2005-09-07 21:18:43 +00:00
|
|
|
#ifdef FEAT_RIGHTLEFT
|
|
|
|
int save_cmdmsg_rl = cmdmsg_rl;
|
|
|
|
#endif
|
2014-08-17 17:24:07 +02:00
|
|
|
#ifdef FEAT_FOLDING
|
|
|
|
int save_KeyTyped;
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Can't do this recursively. Can't do it when typing a password. */
|
|
|
|
if (cmdwin_type != 0
|
|
|
|
# if defined(FEAT_CRYPT) || defined(FEAT_EVAL)
|
|
|
|
|| cmdline_star > 0
|
|
|
|
# endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
beep_flush();
|
|
|
|
return K_IGNORE;
|
|
|
|
}
|
2016-07-10 22:11:16 +02:00
|
|
|
set_bufref(&old_curbuf, curbuf);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Save current window sizes. */
|
|
|
|
win_size_save(&winsizes);
|
|
|
|
|
|
|
|
/* Don't execute autocommands while creating the window. */
|
2007-09-29 12:16:41 +00:00
|
|
|
block_autocmds();
|
2018-03-04 18:08:14 +01:00
|
|
|
|
2019-01-22 22:55:00 +01:00
|
|
|
#if defined(FEAT_INS_EXPAND)
|
2019-01-22 22:08:09 +01:00
|
|
|
// When using completion in Insert mode with <C-R>=<C-F> one can open the
|
|
|
|
// command line window, but we don't want the popup menu then.
|
|
|
|
pum_undisplay();
|
2019-01-22 22:55:00 +01:00
|
|
|
#endif
|
2019-01-22 22:08:09 +01:00
|
|
|
|
2006-02-23 21:32:16 +00:00
|
|
|
/* don't use a new tab page */
|
|
|
|
cmdmod.tab = 0;
|
2017-04-07 15:42:25 +02:00
|
|
|
cmdmod.noswapfile = 1;
|
2006-02-23 21:32:16 +00:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Create a window for the command-line buffer. */
|
|
|
|
if (win_split((int)p_cwh, WSP_BOT) == FAIL)
|
|
|
|
{
|
|
|
|
beep_flush();
|
2007-09-29 12:16:41 +00:00
|
|
|
unblock_autocmds();
|
2004-06-13 20:20:40 +00:00
|
|
|
return K_IGNORE;
|
|
|
|
}
|
2009-03-02 01:12:48 +00:00
|
|
|
cmdwin_type = get_cmdline_type();
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Create the command-line buffer empty. */
|
2008-11-15 13:12:07 +00:00
|
|
|
(void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL);
|
2008-06-24 21:56:24 +00:00
|
|
|
(void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE);
|
2004-06-13 20:20:40 +00:00
|
|
|
set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL);
|
|
|
|
curbuf->b_p_ma = TRUE;
|
2009-04-29 10:05:51 +00:00
|
|
|
#ifdef FEAT_FOLDING
|
|
|
|
curwin->w_p_fen = FALSE;
|
|
|
|
#endif
|
2004-06-13 20:20:40 +00:00
|
|
|
# ifdef FEAT_RIGHTLEFT
|
2005-09-07 21:18:43 +00:00
|
|
|
curwin->w_p_rl = cmdmsg_rl;
|
|
|
|
cmdmsg_rl = FALSE;
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
2010-09-21 16:56:35 +02:00
|
|
|
RESET_BINDING(curwin);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Do execute autocommands for setting the filetype (load syntax). */
|
2007-09-29 12:16:41 +00:00
|
|
|
unblock_autocmds();
|
2017-06-25 21:17:25 +02:00
|
|
|
/* But don't allow switching to another buffer. */
|
|
|
|
++curbuf_lock;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2005-09-07 21:18:43 +00:00
|
|
|
/* Showing the prompt may have set need_wait_return, reset it. */
|
|
|
|
need_wait_return = FALSE;
|
|
|
|
|
2009-03-02 01:12:48 +00:00
|
|
|
histtype = hist_char2type(cmdwin_type);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (histtype == HIST_CMD || histtype == HIST_DEBUG)
|
|
|
|
{
|
|
|
|
if (p_wc == TAB)
|
|
|
|
{
|
|
|
|
add_map((char_u *)"<buffer> <Tab> <C-X><C-V>", INSERT);
|
|
|
|
add_map((char_u *)"<buffer> <Tab> a<C-X><C-V>", NORMAL);
|
|
|
|
}
|
|
|
|
set_option_value((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL);
|
|
|
|
}
|
2017-06-25 21:17:25 +02:00
|
|
|
--curbuf_lock;
|
2004-06-13 20:20:40 +00:00
|
|
|
|
2004-06-24 15:53:16 +00:00
|
|
|
/* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin
|
|
|
|
* sets 'textwidth' to 78). */
|
|
|
|
curbuf->b_p_tw = 0;
|
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Fill the buffer with the history. */
|
|
|
|
init_history();
|
2019-08-06 21:59:57 +02:00
|
|
|
if (get_hislen() > 0)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2019-08-06 21:59:57 +02:00
|
|
|
i = *get_hisidx(histtype);
|
2004-06-13 20:20:40 +00:00
|
|
|
if (i >= 0)
|
|
|
|
{
|
|
|
|
lnum = 0;
|
|
|
|
do
|
|
|
|
{
|
2019-08-06 21:59:57 +02:00
|
|
|
if (++i == get_hislen())
|
2004-06-13 20:20:40 +00:00
|
|
|
i = 0;
|
2019-08-06 21:59:57 +02:00
|
|
|
if (get_histentry(histtype)[i].hisstr != NULL)
|
|
|
|
ml_append(lnum++, get_histentry(histtype)[i].hisstr,
|
2004-06-13 20:20:40 +00:00
|
|
|
(colnr_T)0, FALSE);
|
|
|
|
}
|
2019-08-06 21:59:57 +02:00
|
|
|
while (i != *get_hisidx(histtype));
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replace the empty last line with the current command-line and put the
|
|
|
|
* cursor there. */
|
|
|
|
ml_replace(curbuf->b_ml.ml_line_count, ccline.cmdbuff, TRUE);
|
|
|
|
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
|
|
|
|
curwin->w_cursor.col = ccline.cmdpos;
|
2005-09-07 21:18:43 +00:00
|
|
|
changed_line_abv_curs();
|
|
|
|
invalidate_botline();
|
2006-03-12 22:05:10 +00:00
|
|
|
redraw_later(SOME_VALID);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* No Ex mode here! */
|
|
|
|
exmode_active = 0;
|
|
|
|
|
|
|
|
State = NORMAL;
|
|
|
|
# ifdef FEAT_MOUSE
|
|
|
|
setmouse();
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/* Trigger CmdwinEnter autocommands. */
|
2017-10-19 18:35:51 +02:00
|
|
|
trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER);
|
2006-08-16 14:23:04 +00:00
|
|
|
if (restart_edit != 0) /* autocmd with ":startinsert" */
|
|
|
|
stuffcharReadbuff(K_NOP);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
i = RedrawingDisabled;
|
|
|
|
RedrawingDisabled = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the main loop until <CR> or CTRL-C is typed.
|
|
|
|
*/
|
|
|
|
cmdwin_result = 0;
|
2005-02-22 08:49:11 +00:00
|
|
|
main_loop(TRUE, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
RedrawingDisabled = i;
|
|
|
|
|
2018-03-04 18:08:14 +01:00
|
|
|
# ifdef FEAT_FOLDING
|
2014-08-17 17:24:07 +02:00
|
|
|
save_KeyTyped = KeyTyped;
|
2018-03-04 18:08:14 +01:00
|
|
|
# endif
|
2014-08-17 17:24:07 +02:00
|
|
|
|
2004-06-13 20:20:40 +00:00
|
|
|
/* Trigger CmdwinLeave autocommands. */
|
2017-10-19 18:35:51 +02:00
|
|
|
trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE);
|
2014-08-17 17:24:07 +02:00
|
|
|
|
2018-03-04 18:08:14 +01:00
|
|
|
# ifdef FEAT_FOLDING
|
2014-08-17 17:24:07 +02:00
|
|
|
/* Restore KeyTyped in case it is modified by autocommands */
|
|
|
|
KeyTyped = save_KeyTyped;
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
|
|
|
|
cmdwin_type = 0;
|
|
|
|
exmode_active = save_exmode;
|
|
|
|
|
2008-06-20 16:31:07 +00:00
|
|
|
/* Safety check: The old window or buffer was deleted: It's a bug when
|
2004-06-13 20:20:40 +00:00
|
|
|
* this happens! */
|
2016-07-10 22:11:16 +02:00
|
|
|
if (!win_valid(old_curwin) || !bufref_valid(&old_curbuf))
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
cmdwin_result = Ctrl_C;
|
2019-01-13 23:38:42 +01:00
|
|
|
emsg(_("E199: Active window or buffer deleted"));
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-04 18:08:14 +01:00
|
|
|
# if defined(FEAT_EVAL)
|
2004-06-13 20:20:40 +00:00
|
|
|
/* autocmds may abort script processing */
|
|
|
|
if (aborting() && cmdwin_result != K_IGNORE)
|
|
|
|
cmdwin_result = Ctrl_C;
|
|
|
|
# endif
|
|
|
|
/* Set the new command line from the cmdline buffer. */
|
|
|
|
vim_free(ccline.cmdbuff);
|
2005-09-07 21:18:43 +00:00
|
|
|
if (cmdwin_result == K_XF1 || cmdwin_result == K_XF2) /* :qa[!] typed */
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
2005-09-07 21:18:43 +00:00
|
|
|
char *p = (cmdwin_result == K_XF2) ? "qa" : "qa!";
|
|
|
|
|
|
|
|
if (histtype == HIST_CMD)
|
|
|
|
{
|
|
|
|
/* Execute the command directly. */
|
|
|
|
ccline.cmdbuff = vim_strsave((char_u *)p);
|
|
|
|
cmdwin_result = CAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* First need to cancel what we were doing. */
|
|
|
|
ccline.cmdbuff = NULL;
|
|
|
|
stuffcharReadbuff(':');
|
|
|
|
stuffReadbuff((char_u *)p);
|
|
|
|
stuffcharReadbuff(CAR);
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
else if (cmdwin_result == K_XF2) /* :qa typed */
|
|
|
|
{
|
|
|
|
ccline.cmdbuff = vim_strsave((char_u *)"qa");
|
|
|
|
cmdwin_result = CAR;
|
|
|
|
}
|
2011-05-19 14:50:54 +02:00
|
|
|
else if (cmdwin_result == Ctrl_C)
|
|
|
|
{
|
|
|
|
/* :q or :close, don't execute any command
|
|
|
|
* and don't modify the cmd window. */
|
|
|
|
ccline.cmdbuff = NULL;
|
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
ccline.cmdbuff = vim_strsave(ml_get_curline());
|
|
|
|
if (ccline.cmdbuff == NULL)
|
2017-07-11 15:11:57 +02:00
|
|
|
{
|
|
|
|
ccline.cmdbuff = vim_strsave((char_u *)"");
|
|
|
|
ccline.cmdlen = 0;
|
|
|
|
ccline.cmdbufflen = 1;
|
|
|
|
ccline.cmdpos = 0;
|
2004-06-13 20:20:40 +00:00
|
|
|
cmdwin_result = Ctrl_C;
|
2017-07-11 15:11:57 +02:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
|
|
|
|
ccline.cmdbufflen = ccline.cmdlen + 1;
|
|
|
|
ccline.cmdpos = curwin->w_cursor.col;
|
|
|
|
if (ccline.cmdpos > ccline.cmdlen)
|
|
|
|
ccline.cmdpos = ccline.cmdlen;
|
|
|
|
if (cmdwin_result == K_IGNORE)
|
|
|
|
{
|
|
|
|
set_cmdspos_cursor();
|
|
|
|
redrawcmd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't execute autocommands while deleting the window. */
|
2007-09-29 12:16:41 +00:00
|
|
|
block_autocmds();
|
2015-06-25 18:20:36 +02:00
|
|
|
# ifdef FEAT_CONCEAL
|
|
|
|
/* Avoid command-line window first character being concealed. */
|
|
|
|
curwin->w_p_cole = 0;
|
2004-06-13 20:20:40 +00:00
|
|
|
# endif
|
|
|
|
wp = curwin;
|
2016-07-10 22:11:16 +02:00
|
|
|
set_bufref(&bufref, curbuf);
|
2004-06-13 20:20:40 +00:00
|
|
|
win_goto(old_curwin);
|
|
|
|
win_close(wp, TRUE);
|
2010-03-02 17:23:21 +01:00
|
|
|
|
|
|
|
/* win_close() may have already wiped the buffer when 'bh' is
|
|
|
|
* set to 'wipe' */
|
2016-07-10 22:11:16 +02:00
|
|
|
if (bufref_valid(&bufref))
|
|
|
|
close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
/* Restore window sizes. */
|
|
|
|
win_size_restore(&winsizes);
|
|
|
|
|
2007-09-29 12:16:41 +00:00
|
|
|
unblock_autocmds();
|
2004-06-13 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ga_clear(&winsizes);
|
|
|
|
restart_edit = save_restart_edit;
|
2005-09-07 21:18:43 +00:00
|
|
|
# ifdef FEAT_RIGHTLEFT
|
|
|
|
cmdmsg_rl = save_cmdmsg_rl;
|
|
|
|
# endif
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
State = save_State;
|
|
|
|
# ifdef FEAT_MOUSE
|
|
|
|
setmouse();
|
|
|
|
# endif
|
|
|
|
|
|
|
|
return cmdwin_result;
|
|
|
|
}
|
|
|
|
#endif /* FEAT_CMDWIN */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Used for commands that either take a simple command string argument, or:
|
|
|
|
* cmd << endmarker
|
|
|
|
* {script}
|
|
|
|
* endmarker
|
|
|
|
* Returns a pointer to allocated memory with {script} or NULL.
|
|
|
|
*/
|
|
|
|
char_u *
|
2016-01-30 15:52:46 +01:00
|
|
|
script_get(exarg_T *eap, char_u *cmd)
|
2004-06-13 20:20:40 +00:00
|
|
|
{
|
|
|
|
char_u *theline;
|
|
|
|
char *end_pattern = NULL;
|
|
|
|
char dot[] = ".";
|
|
|
|
garray_T ga;
|
|
|
|
|
|
|
|
if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ga_init2(&ga, 1, 0x400);
|
|
|
|
|
|
|
|
if (cmd[2] != NUL)
|
|
|
|
end_pattern = (char *)skipwhite(cmd + 2);
|
|
|
|
else
|
|
|
|
end_pattern = dot;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
theline = eap->getline(
|
|
|
|
#ifdef FEAT_EVAL
|
2005-01-05 22:16:17 +00:00
|
|
|
eap->cstack->cs_looplevel > 0 ? -1 :
|
2004-06-13 20:20:40 +00:00
|
|
|
#endif
|
2019-06-25 04:12:16 +02:00
|
|
|
NUL, eap->cookie, 0, TRUE);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
if (theline == NULL || STRCMP(end_pattern, theline) == 0)
|
2008-08-06 12:19:26 +00:00
|
|
|
{
|
|
|
|
vim_free(theline);
|
2004-06-13 20:20:40 +00:00
|
|
|
break;
|
2008-08-06 12:19:26 +00:00
|
|
|
}
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
ga_concat(&ga, theline);
|
|
|
|
ga_append(&ga, '\n');
|
|
|
|
vim_free(theline);
|
|
|
|
}
|
2004-07-29 08:43:53 +00:00
|
|
|
ga_append(&ga, NUL);
|
2004-06-13 20:20:40 +00:00
|
|
|
|
|
|
|
return (char_u *)ga.ga_data;
|
|
|
|
}
|