📄 misc2.c
字号:
bit = name_to_mod_mask(*bp);
if (bit == 0x0)
break; /* Illegal modifier name */
modifiers |= bit;
}
}
/*
* Legal modifier name.
*/
if (bp >= last_dash)
{
/*
* Modifier with single letter, or special key name.
*/
if (modifiers != 0 && last_dash[2] == '>')
key = last_dash[1];
else
key = get_special_key_code(last_dash + 1);
/*
* get_special_key_code() may return NUL for invalid
* special key name.
*/
if (key != NUL)
{
/*
* Only use a modifier when there is no special key code that
* includes the modifier.
*/
key = simplify_key(key, &modifiers);
if (!keycode)
{
/* don't want keycode, use single byte code */
if (key == K_BS)
key = BS;
else if (key == K_DEL)
key = DEL;
}
/*
* Normal Key with modifier: Try to make a single byte code.
*/
if (!IS_SPECIAL(key))
{
if ((modifiers & MOD_MASK_SHIFT) && isalpha(key))
{
key = TO_UPPER(key);
modifiers &= ~MOD_MASK_SHIFT;
}
if ((modifiers & MOD_MASK_CTRL)
&& ((key >= '?' && key <= '_') || isalpha(key)))
{
if (key == '?')
key = DEL;
else
key &= 0x1f;
modifiers &= ~MOD_MASK_CTRL;
}
if ((modifiers & MOD_MASK_ALT) && key < 0x80)
{
key |= 0x80;
modifiers &= ~MOD_MASK_ALT;
}
}
*modp = modifiers;
*srcp = end_of_name;
return key;
}
}
}
return 0;
}
/*
* Try to find key "c" in the special key table.
* Return the index when found, -1 when not found.
*/
int
find_special_key_in_table(c)
int c;
{
int i;
for (i = 0; key_names_table[i].name != NULL; i++)
if (c == key_names_table[i].key)
break;
if (key_names_table[i].name == NULL)
i = -1;
return i;
}
/*
* Find the special key with the given name (the given string does not have to
* end with NUL, the name is assumed to end before the first non-idchar).
* If the name starts with "t_" the next two characters are interpreted as a
* termcap name.
* Return the key code, or 0 if not found.
*/
int
get_special_key_code(name)
char_u *name;
{
char_u *table_name;
char_u string[3];
int i, j;
/*
* If it's <t_xx> we get the code for xx from the termcap
*/
if (name[0] == 't' && name[1] == '_' && name[2] != NUL && name[3] != NUL)
{
string[0] = name[2];
string[1] = name[3];
string[2] = NUL;
if (add_termcap_entry(string, FALSE) == OK)
return TERMCAP2KEY(name[2], name[3]);
}
else
for (i = 0; key_names_table[i].name != NULL; i++)
{
table_name = key_names_table[i].name;
for (j = 0; vim_isIDc(name[j]) && table_name[j] != NUL; j++)
if (TO_LOWER(table_name[j]) != TO_LOWER(name[j]))
break;
if (!vim_isIDc(name[j]) && table_name[j] == NUL)
return key_names_table[i].key;
}
return 0;
}
char_u *
get_key_name(i)
int i;
{
if (i >= KEY_NAMES_TABLE_LEN)
return NULL;
return key_names_table[i].name;
}
#ifdef USE_MOUSE
/*
* Look up the given mouse code to return the relevant information in the other
* arguments. Return which button is down or was released.
*/
int
get_mouse_button(code, is_click, is_drag)
int code;
int *is_click;
int *is_drag;
{
int i;
for (i = 0; mouse_table[i].pseudo_code; i++)
if (code == mouse_table[i].pseudo_code)
{
*is_click = mouse_table[i].is_click;
*is_drag = mouse_table[i].is_drag;
return mouse_table[i].button;
}
return 0; /* Shouldn't get here */
}
/*
* Return the appropriate pseudo mouse event token (KE_LEFTMOUSE etc) based on
* the given information about which mouse button is down, and whether the
* mouse was clicked, dragged or released.
*/
int
get_pseudo_mouse_code(button, is_click, is_drag)
int button; /* eg MOUSE_LEFT */
int is_click;
int is_drag;
{
int i;
for (i = 0; mouse_table[i].pseudo_code; i++)
if (button == mouse_table[i].button
&& is_click == mouse_table[i].is_click
&& is_drag == mouse_table[i].is_drag)
{
return mouse_table[i].pseudo_code;
}
return (int)KE_IGNORE; /* not recongnized, ignore it */
}
#endif /* USE_MOUSE */
/*
* Return the current end-of-line type: EOL_DOS, EOL_UNIX or EOL_MAC.
*/
int
get_fileformat(buf)
BUF *buf;
{
int c = *buf->b_p_ff;
if (buf->b_p_bin || c == 'u')
return EOL_UNIX;
if (c == 'm')
return EOL_MAC;
return EOL_DOS;
}
/*
* Set the current end-of-line type to EOL_DOS, EOL_UNIX or EOL_MAC.
* Sets both 'textmode' and 'fileformat'.
*/
void
set_fileformat(t)
int t;
{
switch (t)
{
case EOL_DOS:
set_string_option_direct((char_u *)"ff", -1, (char_u *)FF_DOS, TRUE);
curbuf->b_p_tx = TRUE;
break;
case EOL_UNIX:
set_string_option_direct((char_u *)"ff", -1, (char_u *)FF_UNIX, TRUE);
curbuf->b_p_tx = FALSE;
break;
case EOL_MAC:
set_string_option_direct((char_u *)"ff", -1, (char_u *)FF_MAC, TRUE);
curbuf->b_p_tx = FALSE;
break;
}
check_status(curbuf);
}
/*
* Return the default fileformat from 'fileformats'.
*/
int
default_fileformat()
{
switch (*p_ffs)
{
case 'm': return EOL_MAC;
case 'd': return EOL_DOS;
}
return EOL_UNIX;
}
/*
* Call shell. Calls mch_call_shell, with 'shellxquote' added.
*/
int
call_shell(cmd, opt)
char_u *cmd;
int opt;
{
char_u *ncmd;
#ifdef USE_GUI_WIN32
/* Don't hide the pointer while executing a shell command. */
gui_mch_mousehide(FALSE);
#endif
if (cmd == NULL || *p_sxq == NUL)
call_shell_retval = mch_call_shell(cmd, opt);
else
{
ncmd = alloc((unsigned)(STRLEN(cmd) + STRLEN(p_sxq) * 2 + 1));
if (ncmd != NULL)
{
STRCPY(ncmd, p_sxq);
STRCAT(ncmd, cmd);
STRCAT(ncmd, p_sxq);
call_shell_retval = mch_call_shell(ncmd, opt);
vim_free(ncmd);
}
else
call_shell_retval = -1;
}
return call_shell_retval;
}
/*
* VISUAL and OP_PENDING State are never set, they are equal to NORMAL State
* with a condition. This function returns the real State.
*/
int
get_real_state()
{
if ((State & NORMAL))
{
if (VIsual_active)
return VISUAL;
else if (finish_op)
return OP_PENDING;
}
return State;
}
/*
* Change to a file's directory.
*/
int
vim_chdirfile(fname)
char_u *fname;
{
char_u temp_string[MAXPATHL];
char_u *p;
char_u *t;
STRCPY(temp_string, fname);
p = get_past_head(temp_string);
t = gettail(temp_string);
while (t > p && vim_ispathsep(t[-1]))
--t;
*t = NUL; /* chop off end of string */
return mch_chdir((char *)temp_string);
}
#ifdef CURSOR_SHAPE
/*
* Handling of cursor shapes in various modes.
*/
struct cursor_entry cursor_table[SHAPE_COUNT] =
{
/* The values will be filled in from the guicursor' default when the GUI
* starts. */
{0, 0, 700L, 400L, 250L, 0, "n"},
{0, 0, 700L, 400L, 250L, 0, "v"},
{0, 0, 700L, 400L, 250L, 0, "i"},
{0, 0, 700L, 400L, 250L, 0, "r"},
{0, 0, 700L, 400L, 250L, 0, "c"},
{0, 0, 700L, 400L, 250L, 0, "ci"},
{0, 0, 700L, 400L, 250L, 0, "cr"},
{0, 0, 100L, 100L, 100L, 0, "sm"},
{0, 0, 700L, 400L, 250L, 0, "o"},
{0, 0, 700L, 400L, 250L, 0, "ve"}
};
/*
* Parse the 'guicursor' option.
* Returns error message for an illegal option, NULL otherwise.
*/
char_u *
parse_guicursor()
{
char_u *modep;
char_u *colonp;
char_u *commap;
char_u *p, *endp;
int idx = 0; /* init for GCC */
int all_idx;
int len;
int i;
long n;
int found_ve = FALSE; /* found "ve" flag */
/*
* Repeat for all comma separated parts.
*/
modep = p_guicursor;
while (*modep)
{
colonp = vim_strchr(modep, ':');
if (colonp == NULL)
return (char_u *)"Missing colon";
commap = vim_strchr(modep, ',');
/*
* Repeat for all mode's before the colon.
* For the 'a' mode, we loop to handle all the modes.
*/
all_idx = -1;
while (modep < colonp || all_idx >= 0)
{
if (all_idx < 0)
{
/* Find the mode. */
if (modep[1] == '-' || modep[1] == ':')
len = 1;
else
len = 2;
if (len == 1 && TO_LOWER(modep[0]) == 'a')
all_idx = SHAPE_COUNT - 1;
else
{
for (idx = 0; idx < SHAPE_COUNT; ++idx)
if (STRNICMP(modep, cursor_table[idx].name, len) == 0)
break;
if (idx == SHAPE_COUNT)
return (char_u *)"Illegal mode";
if (len == 2 && modep[0] == 'v' && modep[1] == 'e')
found_ve = TRUE;
}
modep += len + 1;
}
if (all_idx >= 0)
idx = all_idx--;
else
{
/* Set the defaults, for the missing parts */
cursor_table[idx].shape = SHAPE_BLOCK;
cursor_table[idx].blinkwait = 700L;
cursor_table[idx].blinkon = 400L;
cursor_table[idx].blinkoff = 250L;
}
/* Parse the part after the colon */
for (p = colonp + 1; *p && *p != ','; )
{
/*
* First handle the ones with a number argument.
*/
i = *p;
len = 0;
if (STRNICMP(p, "ver", 3) == 0)
len = 3;
else if (STRNICMP(p, "hor", 3) == 0)
len = 3;
else if (STRNICMP(p, "blinkwait", 9) == 0)
len = 9;
else if (STRNICMP(p, "blinkon", 7) == 0)
len = 7;
else if (STRNICMP(p, "blinkoff", 8) == 0)
len = 8;
if (len)
{
p += len;
if (!isdigit(*p))
return (char_u *)"digit expected";
n = getdigits(&p);
if (len == 3) /* "ver" or "hor" */
{
if (n == 0)
return (char_u *)"Illegal percentage";
if (TO_LOWER(i) == 'v')
cursor_table[idx].shape = SHAPE_VER;
else
cursor_table[idx].shape = SHAPE_HOR;
cursor_table[idx].percentage = n;
}
else if (len == 9)
cursor_table[idx].blinkwait = n;
else if (len == 7)
cursor_table[idx].blinkon = n;
else
cursor_table[idx].blinkoff = n;
}
else if (STRNICMP(p, "block", 5) == 0)
{
cursor_table[idx].shape = SHAPE_BLOCK;
p += 5;
}
else /* must be a highlight group name then */
{
endp = vim_strchr(p, '-');
if (commap == NULL) /* last part */
{
if (endp == NULL)
endp = p + STRLEN(p); /* find end of part */
}
else if (endp > commap || endp == NULL)
endp = commap;
cursor_table[idx].id = syn_check_group(p, (int)(endp - p));
p = endp;
}
if (*p == '-')
++p;
}
}
modep = p;
if (*modep == ',')
++modep;
}
/* If the 's' flag is not given, use the 'v' cursor for 's' */
if (!found_ve)
{
cursor_table[SHAPE_VE].shape = cursor_table[SHAPE_V].shape;
cursor_table[SHAPE_VE].percentage = cursor_table[SHAPE_V].percentage;
cursor_table[SHAPE_VE].blinkwait = cursor_table[SHAPE_V].blinkwait;
cursor_table[SHAPE_VE].blinkon = cursor_table[SHAPE_V].blinkon;
cursor_table[SHAPE_VE].blinkoff = cursor_table[SHAPE_V].blinkoff;
cursor_table[SHAPE_VE].id = cursor_table[SHAPE_V].id;
}
return NULL;
}
/*
* Return the index into cursor_table[] for the current mode.
*/
int
get_cursor_idx()
{
if (State == SHOWMATCH)
return SHAPE_SM;
if (State == INSERT)
return SHAPE_I;
if (State == REPLACE)
return SHAPE_R;
if (State == CMDLINE)
{
if (cmdline_at_end())
return SHAPE_C;
if (cmdline_overstrike())
return SHAPE_CR;
return SHAPE_CI;
}
if (finish_op)
return SHAPE_O;
if (VIsual_active)
{
if (*p_sel == 'e')
return SHAPE_VE;
else
return SHAPE_V;
}
return SHAPE_N;
}
#endif /* CURSOR_SHAPE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -