comparison src/ex_cmds.c @ 1868:954947a70580 v7.2.166

updated for version 7.2-166
author vimboss
date Wed, 29 Apr 2009 16:47:23 +0000
parents cfccbe492612
children 720a59d79bcd
comparison
equal deleted inserted replaced
1867:5ea1f7516c2c 1868:954947a70580
6541 static int last_sign_typenr = MAX_TYPENR; /* is decremented */ 6541 static int last_sign_typenr = MAX_TYPENR; /* is decremented */
6542 6542
6543 static void sign_list_defined __ARGS((sign_T *sp)); 6543 static void sign_list_defined __ARGS((sign_T *sp));
6544 static void sign_undefine __ARGS((sign_T *sp, sign_T *sp_prev)); 6544 static void sign_undefine __ARGS((sign_T *sp, sign_T *sp_prev));
6545 6545
6546 /* 6546 static char *cmds[] = {
6547 * ":sign" command
6548 */
6549 void
6550 ex_sign(eap)
6551 exarg_T *eap;
6552 {
6553 char_u *arg = eap->arg;
6554 char_u *p;
6555 int idx;
6556 sign_T *sp;
6557 sign_T *sp_prev;
6558 buf_T *buf;
6559 static char *cmds[] = {
6560 "define", 6547 "define",
6561 #define SIGNCMD_DEFINE 0 6548 #define SIGNCMD_DEFINE 0
6562 "undefine", 6549 "undefine",
6563 #define SIGNCMD_UNDEFINE 1 6550 #define SIGNCMD_UNDEFINE 1
6564 "list", 6551 "list",
6567 #define SIGNCMD_PLACE 3 6554 #define SIGNCMD_PLACE 3
6568 "unplace", 6555 "unplace",
6569 #define SIGNCMD_UNPLACE 4 6556 #define SIGNCMD_UNPLACE 4
6570 "jump", 6557 "jump",
6571 #define SIGNCMD_JUMP 5 6558 #define SIGNCMD_JUMP 5
6559 NULL
6572 #define SIGNCMD_LAST 6 6560 #define SIGNCMD_LAST 6
6573 }; 6561 };
6562
6563 /*
6564 * Find index of a ":sign" subcmd from its name.
6565 * "*end_cmd" must be writable.
6566 */
6567 static int
6568 sign_cmd_idx(begin_cmd, end_cmd)
6569 char *begin_cmd; /* begin of sign subcmd */
6570 char *end_cmd; /* just after sign subcmd */
6571 {
6572 int idx;
6573 char save = *end_cmd;
6574
6575 *end_cmd = NUL;
6576 for (idx = 0; ; ++idx)
6577 if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0)
6578 break;
6579 *end_cmd = save;
6580 return idx;
6581 }
6582
6583 /*
6584 * ":sign" command
6585 */
6586 void
6587 ex_sign(eap)
6588 exarg_T *eap;
6589 {
6590 char_u *arg = eap->arg;
6591 char_u *p;
6592 int idx;
6593 sign_T *sp;
6594 sign_T *sp_prev;
6595 buf_T *buf;
6574 6596
6575 /* Parse the subcommand. */ 6597 /* Parse the subcommand. */
6576 p = skiptowhite(arg); 6598 p = skiptowhite(arg);
6577 if (*p != NUL) 6599 idx = sign_cmd_idx(arg, p);
6578 *p++ = NUL; 6600 if (idx == SIGNCMD_LAST)
6579 for (idx = 0; ; ++idx) 6601 {
6580 { 6602 EMSG2(_("E160: Unknown sign command: %s"), arg);
6581 if (idx == SIGNCMD_LAST) 6603 return;
6582 {
6583 EMSG2(_("E160: Unknown sign command: %s"), arg);
6584 return;
6585 }
6586 if (STRCMP(arg, cmds[idx]) == 0)
6587 break;
6588 } 6604 }
6589 arg = skipwhite(p); 6605 arg = skipwhite(p);
6590 6606
6591 if (idx <= SIGNCMD_LIST) 6607 if (idx <= SIGNCMD_LIST)
6592 { 6608 {
7108 while (first_sign != NULL) 7124 while (first_sign != NULL)
7109 sign_undefine(first_sign, NULL); 7125 sign_undefine(first_sign, NULL);
7110 } 7126 }
7111 #endif 7127 #endif
7112 7128
7129 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
7130 static enum
7131 {
7132 EXP_SUBCMD, /* expand :sign sub-commands */
7133 EXP_DEFINE, /* expand :sign define {name} args */
7134 EXP_PLACE, /* expand :sign place {id} args */
7135 EXP_UNPLACE, /* expand :sign unplace" */
7136 EXP_SIGN_NAMES /* expand with name of placed signs */
7137 } expand_what;
7138
7139 /*
7140 * Function given to ExpandGeneric() to obtain the sign command
7141 * expansion.
7142 */
7143 /*ARGSUSED*/
7144 char_u *
7145 get_sign_name(xp, idx)
7146 expand_T *xp;
7147 int idx;
7148 {
7149 sign_T *sp;
7150 int current_idx;
7151
7152 switch (expand_what)
7153 {
7154 case EXP_SUBCMD:
7155 return (char_u *)cmds[idx];
7156 case EXP_DEFINE:
7157 {
7158 char *define_arg[] =
7159 {
7160 "icon=", "linehl=", "text=", "texthl=", NULL
7161 };
7162 return (char_u *)define_arg[idx];
7163 }
7164 case EXP_PLACE:
7165 {
7166 char *place_arg[] =
7167 {
7168 "line=", "name=", "file=", "buffer=", NULL
7169 };
7170 return (char_u *)place_arg[idx];
7171 }
7172 case EXP_UNPLACE:
7173 {
7174 char *unplace_arg[] = { "file=", "buffer=", NULL };
7175 return (char_u *)unplace_arg[idx];
7176 }
7177 case EXP_SIGN_NAMES:
7178 /* Complete with name of signs already defined */
7179 current_idx = 0;
7180 for (sp = first_sign; sp != NULL; sp = sp->sn_next)
7181 if (current_idx++ == idx)
7182 return sp->sn_name;
7183 return NULL;
7184 default:
7185 return NULL;
7186 }
7187 }
7188
7189 /*
7190 * Handle command line completion for :sign command.
7191 */
7192 void
7193 set_context_in_sign_cmd(xp, arg)
7194 expand_T *xp;
7195 char_u *arg;
7196 {
7197 char_u *p;
7198 char_u *end_subcmd;
7199 char_u *last;
7200 int cmd_idx;
7201 char_u *begin_subcmd_args;
7202
7203 /* Default: expand subcommands. */
7204 xp->xp_context = EXPAND_SIGN;
7205 expand_what = EXP_SUBCMD;
7206 xp->xp_pattern = arg;
7207
7208 end_subcmd = skiptowhite(arg);
7209 if (*end_subcmd == NUL)
7210 /* expand subcmd name
7211 * :sign {subcmd}<CTRL-D>*/
7212 return;
7213
7214 cmd_idx = sign_cmd_idx(arg, end_subcmd);
7215
7216 /* :sign {subcmd} {subcmd_args}
7217 * |
7218 * begin_subcmd_args */
7219 begin_subcmd_args = skipwhite(end_subcmd);
7220 p = skiptowhite(begin_subcmd_args);
7221 if (*p == NUL)
7222 {
7223 /*
7224 * Expand first argument of subcmd when possible.
7225 * For ":jump {id}" and ":unplace {id}", we could
7226 * possibly expand the ids of all signs already placed.
7227 */
7228 xp->xp_pattern = begin_subcmd_args;
7229 switch (cmd_idx)
7230 {
7231 case SIGNCMD_LIST:
7232 case SIGNCMD_UNDEFINE:
7233 /* :sign list <CTRL-D>
7234 * :sign undefine <CTRL-D> */
7235 expand_what = EXP_SIGN_NAMES;
7236 break;
7237 default:
7238 xp->xp_context = EXPAND_NOTHING;
7239 }
7240 return;
7241 }
7242
7243 /* expand last argument of subcmd */
7244
7245 /* :sign define {name} {args}...
7246 * |
7247 * p */
7248
7249 /* Loop until reaching last argument. */
7250 do
7251 {
7252 p = skipwhite(p);
7253 last = p;
7254 p = skiptowhite(p);
7255 } while (*p != NUL);
7256
7257 p = vim_strchr(last, '=');
7258
7259 /* :sign define {name} {args}... {last}=
7260 * | |
7261 * last p */
7262 if (p == NUL)
7263 {
7264 /* Expand last argument name (before equal sign). */
7265 xp->xp_pattern = last;
7266 switch (cmd_idx)
7267 {
7268 case SIGNCMD_DEFINE:
7269 expand_what = EXP_DEFINE;
7270 break;
7271 case SIGNCMD_PLACE:
7272 expand_what = EXP_PLACE;
7273 break;
7274 case SIGNCMD_JUMP:
7275 case SIGNCMD_UNPLACE:
7276 expand_what = EXP_UNPLACE;
7277 break;
7278 default:
7279 xp->xp_context = EXPAND_NOTHING;
7280 }
7281 }
7282 else
7283 {
7284 /* Expand last argument value (after equal sign). */
7285 xp->xp_pattern = p + 1;
7286 switch (cmd_idx)
7287 {
7288 case SIGNCMD_DEFINE:
7289 if (STRNCMP(last, "texthl", p - last) == 0 ||
7290 STRNCMP(last, "linehl", p - last) == 0)
7291 xp->xp_context = EXPAND_HIGHLIGHT;
7292 else if (STRNCMP(last, "icon", p - last) == 0)
7293 xp->xp_context = EXPAND_FILES;
7294 else
7295 xp->xp_context = EXPAND_NOTHING;
7296 break;
7297 case SIGNCMD_PLACE:
7298 if (STRNCMP(last, "name", p - last) == 0)
7299 expand_what = EXP_SIGN_NAMES;
7300 else
7301 xp->xp_context = EXPAND_NOTHING;
7302 break;
7303 default:
7304 xp->xp_context = EXPAND_NOTHING;
7305 }
7306 }
7307 }
7308 #endif
7113 #endif 7309 #endif
7114 7310
7115 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO) 7311 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO)
7116 /* 7312 /*
7117 * ":drop" 7313 * ":drop"