comparison src/usercmd.c @ 22703:f2bfee4ac356 v8.2.1900

patch 8.2.1900: Vim9: command modifiers do not work Commit: https://github.com/vim/vim/commit/02194d2bd54eacd0b7b9a017a3fe1702ecb80971 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 24 23:08:38 2020 +0200 patch 8.2.1900: Vim9: command modifiers do not work Problem: Vim9: command modifiers do not work. Solution: Make most command modifiers work.
author Bram Moolenaar <Bram@vim.org>
date Sat, 24 Oct 2020 23:15:04 +0200
parents e82579016863
children 8968ed4ba4ba
comparison
equal deleted inserted replaced
22702:81d7d3860786 22703:f2bfee4ac356
1233 1233
1234 return result; 1234 return result;
1235 } 1235 }
1236 1236
1237 /* 1237 /*
1238 * Add modifiers from "cmdmod.cmod_split" to "buf". Set "multi_mods" when one 1238 * Add modifiers from "cmod->cmod_split" to "buf". Set "multi_mods" when one
1239 * was added. Return the number of bytes added. 1239 * was added. Return the number of bytes added.
1240 */ 1240 */
1241 size_t 1241 size_t
1242 add_win_cmd_modifers(char_u *buf, int *multi_mods) 1242 add_win_cmd_modifers(char_u *buf, cmdmod_T *cmod, int *multi_mods)
1243 { 1243 {
1244 size_t result = 0; 1244 size_t result = 0;
1245 1245
1246 // :aboveleft and :leftabove 1246 // :aboveleft and :leftabove
1247 if (cmdmod.cmod_split & WSP_ABOVE) 1247 if (cmod->cmod_split & WSP_ABOVE)
1248 result += add_cmd_modifier(buf, "aboveleft", multi_mods); 1248 result += add_cmd_modifier(buf, "aboveleft", multi_mods);
1249 // :belowright and :rightbelow 1249 // :belowright and :rightbelow
1250 if (cmdmod.cmod_split & WSP_BELOW) 1250 if (cmod->cmod_split & WSP_BELOW)
1251 result += add_cmd_modifier(buf, "belowright", multi_mods); 1251 result += add_cmd_modifier(buf, "belowright", multi_mods);
1252 // :botright 1252 // :botright
1253 if (cmdmod.cmod_split & WSP_BOT) 1253 if (cmod->cmod_split & WSP_BOT)
1254 result += add_cmd_modifier(buf, "botright", multi_mods); 1254 result += add_cmd_modifier(buf, "botright", multi_mods);
1255 1255
1256 // :tab 1256 // :tab
1257 if (cmdmod.cmod_tab > 0) 1257 if (cmod->cmod_tab > 0)
1258 result += add_cmd_modifier(buf, "tab", multi_mods); 1258 result += add_cmd_modifier(buf, "tab", multi_mods);
1259 // :topleft 1259 // :topleft
1260 if (cmdmod.cmod_split & WSP_TOP) 1260 if (cmod->cmod_split & WSP_TOP)
1261 result += add_cmd_modifier(buf, "topleft", multi_mods); 1261 result += add_cmd_modifier(buf, "topleft", multi_mods);
1262 // :vertical 1262 // :vertical
1263 if (cmdmod.cmod_split & WSP_VERT) 1263 if (cmod->cmod_split & WSP_VERT)
1264 result += add_cmd_modifier(buf, "vertical", multi_mods); 1264 result += add_cmd_modifier(buf, "vertical", multi_mods);
1265 return result;
1266 }
1267
1268 /*
1269 * Generate text for the "cmod" command modifiers.
1270 * If "buf" is NULL just return the length.
1271 */
1272 int
1273 produce_cmdmods(char_u *buf, cmdmod_T *cmod, int quote)
1274 {
1275 int result = 0;
1276 int multi_mods = 0;
1277 int i;
1278 typedef struct {
1279 int flag;
1280 char *name;
1281 } mod_entry_T;
1282 static mod_entry_T mod_entries[] = {
1283 #ifdef FEAT_BROWSE_CMD
1284 {CMOD_BROWSE, "browse"},
1285 #endif
1286 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
1287 {CMOD_CONFIRM, "confirm"},
1288 #endif
1289 {CMOD_HIDE, "hide"},
1290 {CMOD_KEEPALT, "keepalt"},
1291 {CMOD_KEEPJUMPS, "keepjumps"},
1292 {CMOD_KEEPMARKS, "keepmarks"},
1293 {CMOD_KEEPPATTERNS, "keeppatterns"},
1294 {CMOD_LOCKMARKS, "lockmarks"},
1295 {CMOD_NOSWAPFILE, "noswapfile"},
1296 {CMOD_UNSILENT, "unsilent"},
1297 {CMOD_NOAUTOCMD, "noautocmd"},
1298 #ifdef HAVE_SANDBOX
1299 {CMOD_SANDBOX, "sandbox"},
1300 #endif
1301 {0, NULL}
1302 };
1303
1304 result = quote ? 2 : 0;
1305 if (buf != NULL)
1306 {
1307 if (quote)
1308 *buf++ = '"';
1309 *buf = '\0';
1310 }
1311
1312 // the modifiers that are simple flags
1313 for (i = 0; mod_entries[i].name != NULL; ++i)
1314 if (cmod->cmod_flags & mod_entries[i].flag)
1315 result += add_cmd_modifier(buf, mod_entries[i].name, &multi_mods);
1316
1317 // :silent
1318 if (cmod->cmod_flags & CMOD_SILENT)
1319 result += add_cmd_modifier(buf,
1320 (cmod->cmod_flags & CMOD_ERRSILENT) ? "silent!"
1321 : "silent", &multi_mods);
1322 // :verbose
1323 if (p_verbose > 0)
1324 result += add_cmd_modifier(buf, "verbose", &multi_mods);
1325 // flags from cmod->cmod_split
1326 result += add_win_cmd_modifers(buf, cmod, &multi_mods);
1327 if (quote && buf != NULL)
1328 {
1329 buf += result - 2;
1330 *buf = '"';
1331 }
1265 return result; 1332 return result;
1266 } 1333 }
1267 1334
1268 /* 1335 /*
1269 * Check for a <> code in a user command. 1336 * Check for a <> code in a user command.
1450 break; 1517 break;
1451 } 1518 }
1452 1519
1453 case ct_MODS: 1520 case ct_MODS:
1454 { 1521 {
1455 int multi_mods = 0; 1522 result = produce_cmdmods(buf, &cmdmod, quote);
1456 typedef struct {
1457 int flag;
1458 char *name;
1459 } mod_entry_T;
1460 static mod_entry_T mod_entries[] = {
1461 #ifdef FEAT_BROWSE_CMD
1462 {CMOD_BROWSE, "browse"},
1463 #endif
1464 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
1465 {CMOD_CONFIRM, "confirm"},
1466 #endif
1467 {CMOD_HIDE, "hide"},
1468 {CMOD_KEEPALT, "keepalt"},
1469 {CMOD_KEEPJUMPS, "keepjumps"},
1470 {CMOD_KEEPMARKS, "keepmarks"},
1471 {CMOD_KEEPPATTERNS, "keeppatterns"},
1472 {CMOD_LOCKMARKS, "lockmarks"},
1473 {CMOD_NOSWAPFILE, "noswapfile"},
1474 {0, NULL}
1475 };
1476 int i;
1477
1478 result = quote ? 2 : 0;
1479 if (buf != NULL)
1480 {
1481 if (quote)
1482 *buf++ = '"';
1483 *buf = '\0';
1484 }
1485
1486 // the modifiers that are simple flags
1487 for (i = 0; mod_entries[i].name != NULL; ++i)
1488 if (cmdmod.cmod_flags & mod_entries[i].flag)
1489 result += add_cmd_modifier(buf, mod_entries[i].name,
1490 &multi_mods);
1491
1492 // TODO: How to support :noautocmd?
1493 #ifdef HAVE_SANDBOX
1494 // TODO: How to support :sandbox?
1495 #endif
1496 // :silent
1497 if (msg_silent > 0)
1498 result += add_cmd_modifier(buf,
1499 emsg_silent > 0 ? "silent!" : "silent", &multi_mods);
1500 // TODO: How to support :unsilent?
1501 // :verbose
1502 if (p_verbose > 0)
1503 result += add_cmd_modifier(buf, "verbose", &multi_mods);
1504 // flags from cmdmod.cmod_split
1505 result += add_win_cmd_modifers(buf, &multi_mods);
1506 if (quote && buf != NULL)
1507 {
1508 buf += result - 2;
1509 *buf = '"';
1510 }
1511 break; 1523 break;
1512 } 1524 }
1513 1525
1514 case ct_REGISTER: 1526 case ct_REGISTER:
1515 result = eap->regname ? 1 : 0; 1527 result = eap->regname ? 1 : 0;