~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to src/nvim/ex_docmd.c

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
381
381
    suppress_errthrow = FALSE;
382
382
  }
383
383
 
384
 
  /*
385
 
   * If requested, store and reset the global values controlling the
386
 
   * exception handling (used when debugging).  Otherwise clear it to avoid
387
 
   * a bogus compiler warning when the optimizer uses inline functions...
388
 
   */
389
 
  if (flags & DOCMD_EXCRESET)
 
384
  // If requested, store and reset the global values controlling the
 
385
  // exception handling (used when debugging).  Otherwise clear it to avoid
 
386
  // a bogus compiler warning when the optimizer uses inline functions...
 
387
  if (flags & DOCMD_EXCRESET) {
390
388
    save_dbg_stuff(&debug_saved);
391
 
  else
392
 
    memset(&debug_saved, 0, 1);
 
389
  } else {
 
390
    memset(&debug_saved, 0, sizeof(debug_saved));
 
391
  }
393
392
 
394
393
  initial_trylevel = trylevel;
395
394
 
1702
1701
    p = vim_strnsave(ea.cmd, p - ea.cmd);
1703
1702
    int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL);
1704
1703
    xfree(p);
1705
 
    if (ret && !aborting()) {
1706
 
      p = find_command(&ea, NULL);
1707
 
    }
 
1704
    // If the autocommands did something and didn't cause an error, try
 
1705
    // finding the command again.
 
1706
    p = (ret && !aborting()) ? find_command(&ea, NULL) : NULL;
1708
1707
  }
1709
1708
 
1710
1709
  if (p == NULL) {
2348
2347
    eap->cmdidx = CMD_k;
2349
2348
    ++p;
2350
2349
  } else if (p[0] == 's'
2351
 
             && ((p[1] == 'c' && p[2] != 's' && p[2] != 'r'
2352
 
                  && p[3] != 'i' && p[4] != 'p')
 
2350
             && ((p[1] == 'c'
 
2351
                  && (p[2] == NUL
 
2352
                      || (p[2] != 's' && p[2] != 'r'
 
2353
                          && (p[3] == NUL
 
2354
                              || (p[3] != 'i' && p[4] != 'p')))))
2353
2355
                 || p[1] == 'g'
2354
2356
                 || (p[1] == 'i' && p[2] != 'm' && p[2] != 'l' && p[2] != 'g')
2355
2357
                 || p[1] == 'I'
2676
2678
    p = cmd + 1;
2677
2679
  } else {
2678
2680
    p = cmd;
2679
 
    while (ASCII_ISALPHA(*p) || *p == '*')        /* Allow * wild card */
2680
 
      ++p;
2681
 
    /* check for non-alpha command */
2682
 
    if (p == cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL)
2683
 
      ++p;
2684
 
    /* for python 3.x: ":py3*" commands completion */
 
2681
    while (ASCII_ISALPHA(*p) || *p == '*') {  // Allow * wild card
 
2682
      p++;
 
2683
    }
 
2684
    // a user command may contain digits
 
2685
    if (ASCII_ISUPPER(cmd[0])) {
 
2686
      while (ASCII_ISALNUM(*p) || *p == '*') {
 
2687
        p++;
 
2688
      }
 
2689
    }
 
2690
    // for python 3.x: ":py3*" commands completion
2685
2691
    if (cmd[0] == 'p' && cmd[1] == 'y' && p == cmd + 2 && *p == '3') {
2686
 
      ++p;
2687
 
      while (ASCII_ISALPHA(*p) || *p == '*')
2688
 
        ++p;
 
2692
      p++;
 
2693
      while (ASCII_ISALPHA(*p) || *p == '*') {
 
2694
        p++;
 
2695
      }
 
2696
    }
 
2697
    // check for non-alpha command
 
2698
    if (p == cmd && vim_strchr((char_u *)"@*!=><&~#", *p) != NULL) {
 
2699
      p++;
2689
2700
    }
2690
2701
    len = (int)(p - cmd);
2691
2702
 
2699
2710
              (size_t)len) == 0)
2700
2711
        break;
2701
2712
 
2702
 
    if (cmd[0] >= 'A' && cmd[0] <= 'Z')
2703
 
      while (ASCII_ISALNUM(*p) || *p == '*')            /* Allow * wild card */
2704
 
        ++p;
 
2713
    if (cmd[0] >= 'A' && cmd[0] <= 'Z') {
 
2714
      while (ASCII_ISALNUM(*p) || *p == '*') {  // Allow * wild card
 
2715
        p++;
 
2716
      }
 
2717
    }
2705
2718
  }
2706
2719
 
2707
2720
  /*
4307
4320
 */
4308
4321
static void ex_mapclear(exarg_T *eap)
4309
4322
{
4310
 
  map_clear(eap->cmd, eap->arg, eap->forceit, FALSE);
 
4323
  map_clear_mode(eap->cmd, eap->arg, eap->forceit, false);
4311
4324
}
4312
4325
 
4313
4326
/*
4315
4328
 */
4316
4329
static void ex_abclear(exarg_T *eap)
4317
4330
{
4318
 
  map_clear(eap->cmd, eap->arg, TRUE, TRUE);
 
4331
  map_clear_mode(eap->cmd, eap->arg, true, true);
4319
4332
}
4320
4333
 
4321
4334
static void ex_autocmd(exarg_T *eap)
6277
6290
  if (eap->cmdidx == CMD_tabedit
6278
6291
      || eap->cmdidx == CMD_tabfind
6279
6292
      || eap->cmdidx == CMD_tabnew) {
6280
 
    if (win_new_tabpage(cmdmod.tab != 0 ? cmdmod.tab
6281
 
            : eap->addr_count == 0 ? 0
6282
 
            : (int)eap->line2 + 1) != FAIL) {
6283
 
      apply_autocmds(EVENT_TABNEW, eap->arg, eap->arg,  FALSE, curbuf); 
 
6293
    if (win_new_tabpage(cmdmod.tab != 0 ? cmdmod.tab : eap->addr_count == 0
 
6294
                        ? 0 : (int)eap->line2 + 1, eap->arg) != FAIL) {
6284
6295
      do_exedit(eap, old_curwin);
6285
6296
      apply_autocmds(EVENT_TABNEWENTERED, NULL, NULL, FALSE, curbuf);
6286
6297
 
8280
8291
          retval[len] = ' ';
8281
8292
        ++len;
8282
8293
      }
8283
 
      for (; *p != NUL; ++p) {
8284
 
        if (*p == ' ' || *p == '\\') {
8285
 
          /* insert a backslash */
8286
 
          if (retval != NULL)
 
8294
      for (; *p != NUL; p++) {
 
8295
        if (*p == ' '
 
8296
#ifndef BACKSLASH_IN_FILENAME
 
8297
            || *p == '\\'
 
8298
#endif
 
8299
            ) {
 
8300
          // insert a backslash
 
8301
          if (retval != NULL) {
8287
8302
            retval[len] = '\\';
8288
 
          ++len;
 
8303
          }
 
8304
          len++;
8289
8305
        }
8290
 
        if (retval != NULL)
 
8306
        if (retval != NULL) {
8291
8307
          retval[len] = *p;
8292
 
        ++len;
 
8308
        }
 
8309
        len++;
8293
8310
      }
8294
8311
    }
8295
8312
 
8765
8782
  return FALSE;
8766
8783
}
8767
8784
 
8768
 
/*
8769
 
 * Return non-zero if window "wp" is to be stored in the Session.
8770
 
 */
 
8785
/// Return non-zero if window "wp" is to be stored in the Session.
8771
8786
static int ses_do_win(win_T *wp)
8772
8787
{
8773
8788
  if (wp->w_buffer->b_fname == NULL
8774
 
      /* When 'buftype' is "nofile" can't restore the window contents. */
8775
 
      || bt_nofile(wp->w_buffer)
8776
 
      )
 
8789
      // When 'buftype' is "nofile" can't restore the window contents.
 
8790
      || (!wp->w_buffer->terminal && bt_nofile(wp->w_buffer))) {
8777
8791
    return ssop_flags & SSOP_BLANK;
8778
 
  if (wp->w_buffer->b_help)
 
8792
  }
 
8793
  if (wp->w_buffer->b_help) {
8779
8794
    return ssop_flags & SSOP_HELP;
8780
 
  return TRUE;
 
8795
  }
 
8796
  return true;
8781
8797
}
8782
8798
 
8783
8799
/*
9213
9229
  return NULL;
9214
9230
}
9215
9231
 
9216
 
static int filetype_detect = FALSE;
9217
 
static int filetype_plugin = FALSE;
9218
 
static int filetype_indent = FALSE;
 
9232
static TriState filetype_detect = kNone;
 
9233
static TriState filetype_plugin = kNone;
 
9234
static TriState filetype_indent = kNone;
9219
9235
 
9220
9236
/*
9221
9237
 * ":filetype [plugin] [indent] {on,off,detect}"
9229
9245
static void ex_filetype(exarg_T *eap)
9230
9246
{
9231
9247
  char_u      *arg = eap->arg;
9232
 
  int plugin = FALSE;
9233
 
  int indent = FALSE;
 
9248
  bool plugin = false;
 
9249
  bool indent = false;
9234
9250
 
9235
9251
  if (*eap->arg == NUL) {
9236
9252
    /* Print current status. */
9237
9253
    smsg("filetype detection:%s  plugin:%s  indent:%s",
9238
 
        filetype_detect ? "ON" : "OFF",
9239
 
        filetype_plugin ? (filetype_detect ? "ON" : "(on)") : "OFF",
9240
 
        filetype_indent ? (filetype_detect ? "ON" : "(on)") : "OFF");
 
9254
         filetype_detect == kTrue ? "ON" : "OFF",
 
9255
         filetype_plugin == kTrue ? (filetype_detect == kTrue ? "ON" : "(on)") : "OFF",   // NOLINT(whitespace/line_length)
 
9256
         filetype_indent == kTrue ? (filetype_detect == kTrue ? "ON" : "(on)") : "OFF");  // NOLINT(whitespace/line_length)
9241
9257
    return;
9242
9258
  }
9243
9259
 
9244
9260
  /* Accept "plugin" and "indent" in any order. */
9245
9261
  for (;; ) {
9246
9262
    if (STRNCMP(arg, "plugin", 6) == 0) {
9247
 
      plugin = TRUE;
 
9263
      plugin = true;
9248
9264
      arg = skipwhite(arg + 6);
9249
9265
      continue;
9250
9266
    }
9251
9267
    if (STRNCMP(arg, "indent", 6) == 0) {
9252
 
      indent = TRUE;
 
9268
      indent = true;
9253
9269
      arg = skipwhite(arg + 6);
9254
9270
      continue;
9255
9271
    }
9257
9273
  }
9258
9274
  if (STRCMP(arg, "on") == 0 || STRCMP(arg, "detect") == 0) {
9259
9275
    if (*arg == 'o' || !filetype_detect) {
9260
 
      source_runtime((char_u *)FILETYPE_FILE, TRUE);
9261
 
      filetype_detect = TRUE;
 
9276
      source_runtime((char_u *)FILETYPE_FILE, true);
 
9277
      filetype_detect = kTrue;
9262
9278
      if (plugin) {
9263
 
        source_runtime((char_u *)FTPLUGIN_FILE, TRUE);
9264
 
        filetype_plugin = TRUE;
 
9279
        source_runtime((char_u *)FTPLUGIN_FILE, true);
 
9280
        filetype_plugin = kTrue;
9265
9281
      }
9266
9282
      if (indent) {
9267
 
        source_runtime((char_u *)INDENT_FILE, TRUE);
9268
 
        filetype_indent = TRUE;
 
9283
        source_runtime((char_u *)INDENT_FILE, true);
 
9284
        filetype_indent = kTrue;
9269
9285
      }
9270
9286
    }
9271
9287
    if (*arg == 'd') {
9275
9291
  } else if (STRCMP(arg, "off") == 0) {
9276
9292
    if (plugin || indent) {
9277
9293
      if (plugin) {
9278
 
        source_runtime((char_u *)FTPLUGOF_FILE, TRUE);
9279
 
        filetype_plugin = FALSE;
 
9294
        source_runtime((char_u *)FTPLUGOF_FILE, true);
 
9295
        filetype_plugin = kFalse;
9280
9296
      }
9281
9297
      if (indent) {
9282
 
        source_runtime((char_u *)INDOFF_FILE, TRUE);
9283
 
        filetype_indent = FALSE;
 
9298
        source_runtime((char_u *)INDOFF_FILE, true);
 
9299
        filetype_indent = kFalse;
9284
9300
      }
9285
9301
    } else {
9286
 
      source_runtime((char_u *)FTOFF_FILE, TRUE);
9287
 
      filetype_detect = FALSE;
 
9302
      source_runtime((char_u *)FTOFF_FILE, true);
 
9303
      filetype_detect = kFalse;
9288
9304
    }
9289
9305
  } else
9290
9306
    EMSG2(_(e_invarg2), arg);
9291
9307
}
9292
9308
 
 
9309
/// Do ":filetype plugin indent on" if user did not already do some
 
9310
/// permutation thereof.
 
9311
void filetype_maybe_enable(void)
 
9312
{
 
9313
  if (filetype_detect == kNone
 
9314
      && filetype_plugin == kNone
 
9315
      && filetype_indent == kNone) {
 
9316
    source_runtime((char_u *)FILETYPE_FILE, true);
 
9317
    filetype_detect = kTrue;
 
9318
    source_runtime((char_u *)FTPLUGIN_FILE, true);
 
9319
    filetype_plugin = kTrue;
 
9320
    source_runtime((char_u *)INDENT_FILE, true);
 
9321
    filetype_indent = kTrue;
 
9322
  }
 
9323
}
 
9324
 
9293
9325
/*
9294
9326
 * ":setfiletype {name}"
9295
9327
 */
9327
9359
  redraw_all_later(SOME_VALID);
9328
9360
}
9329
9361
 
9330
 
/*
9331
 
 * ":[N]match {group} {pattern}"
9332
 
 * Sets nextcmd to the start of the next command, if any.  Also called when
9333
 
 * skipping commands to find the next command.
9334
 
 */
 
9362
// ":[N]match {group} {pattern}"
 
9363
// Sets nextcmd to the start of the next command, if any.  Also called when
 
9364
// skipping commands to find the next command.
9335
9365
static void ex_match(exarg_T *eap)
9336
9366
{
9337
 
  char_u      *p;
9338
 
  char_u      *g = NULL;
9339
 
  char_u      *end;
 
9367
  char_u *p;
 
9368
  char_u *g = NULL;
 
9369
  char_u *end;
9340
9370
  int c;
9341
9371
  int id;
9342
9372
 
9343
 
  if (eap->line2 <= 3)
 
9373
  if (eap->line2 <= 3) {
9344
9374
    id = eap->line2;
9345
 
  else {
 
9375
  } else {
9346
9376
    EMSG(e_invcmd);
9347
9377
    return;
9348
9378
  }
9349
9379
 
9350
 
  /* First clear any old pattern. */
9351
 
  if (!eap->skip)
9352
 
    match_delete(curwin, id, FALSE);
 
9380
  // First clear any old pattern.
 
9381
  if (!eap->skip) {
 
9382
    match_delete(curwin, id, false);
 
9383
  }
9353
9384
 
9354
 
  if (ends_excmd(*eap->arg))
 
9385
  if (ends_excmd(*eap->arg)) {
9355
9386
    end = eap->arg;
9356
 
  else if ((STRNICMP(eap->arg, "none", 4) == 0
9357
 
            && (ascii_iswhite(eap->arg[4]) || ends_excmd(eap->arg[4]))))
 
9387
  } else if ((STRNICMP(eap->arg, "none", 4) == 0
 
9388
              && (ascii_iswhite(eap->arg[4]) || ends_excmd(eap->arg[4])))) {
9358
9389
    end = eap->arg + 4;
9359
 
  else {
 
9390
  } else {
9360
9391
    p = skiptowhite(eap->arg);
9361
 
    if (!eap->skip)
 
9392
    if (!eap->skip) {
9362
9393
      g = vim_strnsave(eap->arg, (int)(p - eap->arg));
 
9394
    }
9363
9395
    p = skipwhite(p);
9364
9396
    if (*p == NUL) {
9365
 
      /* There must be two arguments. */
 
9397
      // There must be two arguments.
 
9398
      xfree(g);
9366
9399
      EMSG2(_(e_invarg2), eap->arg);
9367
9400
      return;
9368
9401
    }
9369
 
    end = skip_regexp(p + 1, *p, TRUE, NULL);
 
9402
    end = skip_regexp(p + 1, *p, true, NULL);
9370
9403
    if (!eap->skip) {
9371
9404
      if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) {
 
9405
        xfree(g);
9372
9406
        eap->errmsg = e_trailing;
9373
9407
        return;
9374
9408
      }
9375
9409
      if (*end != *p) {
 
9410
        xfree(g);
9376
9411
        EMSG2(_(e_invarg2), p);
9377
9412
        return;
9378
9413
      }
9379
9414
 
9380
9415
      c = *end;
9381
9416
      *end = NUL;
9382
 
      match_add(curwin, g, p + 1, 10, id, NULL);
 
9417
      match_add(curwin, g, p + 1, 10, id, NULL, NULL);
9383
9418
      xfree(g);
9384
9419
      *end = c;
9385
9420
    }