comparison src/ex_getln.c @ 2557:029ace8dff7d vim73

Now really fix using expressions in the command line (hopefully).
author Bram Moolenaar <bram@vim.org>
date Fri, 13 Aug 2010 19:12:07 +0200
parents e065501c703a
children 7850c8c12347
comparison
equal deleted inserted replaced
2556:e065501c703a 2557:029ace8dff7d
660 c = Ctrl_BSL; 660 c = Ctrl_BSL;
661 } 661 }
662 #ifdef FEAT_EVAL 662 #ifdef FEAT_EVAL
663 else if (c == 'e') 663 else if (c == 'e')
664 { 664 {
665 char_u *p = NULL; 665 char_u *p = NULL;
666 int len;
666 667
667 /* 668 /*
668 * Replace the command line with the result of an expression. 669 * Replace the command line with the result of an expression.
669 * Need to save and restore the current command line, to be 670 * Need to save and restore the current command line, to be
670 * able to enter a new one... 671 * able to enter a new one...
685 save_cmdline(&save_ccline); 686 save_cmdline(&save_ccline);
686 ++textlock; 687 ++textlock;
687 p = get_expr_line(); 688 p = get_expr_line();
688 --textlock; 689 --textlock;
689 restore_cmdline(&save_ccline); 690 restore_cmdline(&save_ccline);
690 691 len = (int)STRLEN(p);
691 if (p != NULL && realloc_cmdbuff((int)STRLEN(p) + 1) == OK) 692
693 if (p != NULL && realloc_cmdbuff(len + 1) == OK)
692 { 694 {
693 ccline.cmdlen = (int)STRLEN(p); 695 ccline.cmdlen = len;
694 STRCPY(ccline.cmdbuff, p); 696 STRCPY(ccline.cmdbuff, p);
695 vim_free(p); 697 vim_free(p);
696 698
697 /* Restore the cursor or use the position set with 699 /* Restore the cursor or use the position set with
698 * set_cmdline_pos(). */ 700 * set_cmdline_pos(). */
2518 realloc_cmdbuff(len) 2520 realloc_cmdbuff(len)
2519 int len; 2521 int len;
2520 { 2522 {
2521 char_u *p; 2523 char_u *p;
2522 2524
2525 if (len < ccline.cmdbufflen)
2526 return OK; /* no need to resize */
2527
2523 p = ccline.cmdbuff; 2528 p = ccline.cmdbuff;
2524 alloc_cmdbuff(len); /* will get some more */ 2529 alloc_cmdbuff(len); /* will get some more */
2525 if (ccline.cmdbuff == NULL) /* out of memory */ 2530 if (ccline.cmdbuff == NULL) /* out of memory */
2526 { 2531 {
2527 ccline.cmdbuff = p; /* keep the old one */ 2532 ccline.cmdbuff = p; /* keep the old one */
2742 if (len < 0) 2747 if (len < 0)
2743 len = (int)STRLEN(str); 2748 len = (int)STRLEN(str);
2744 2749
2745 /* Check if ccline.cmdbuff needs to be longer */ 2750 /* Check if ccline.cmdbuff needs to be longer */
2746 if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen) 2751 if (ccline.cmdlen + len + 1 >= ccline.cmdbufflen)
2747 retval = realloc_cmdbuff(ccline.cmdlen + len); 2752 retval = realloc_cmdbuff(ccline.cmdlen + len + 1);
2748 else 2753 else
2749 retval = OK; 2754 retval = OK;
2750 if (retval == OK) 2755 if (retval == OK)
2751 { 2756 {
2752 if (!ccline.overstrike) 2757 if (!ccline.overstrike)
3333 } 3338 }
3334 3339
3335 if (p2 != NULL && !got_int) 3340 if (p2 != NULL && !got_int)
3336 { 3341 {
3337 difflen = (int)STRLEN(p2) - xp->xp_pattern_len; 3342 difflen = (int)STRLEN(p2) - xp->xp_pattern_len;
3338 if (ccline.cmdlen + difflen > ccline.cmdbufflen - 4) 3343 if (ccline.cmdlen + difflen + 4 > ccline.cmdbufflen)
3339 { 3344 {
3340 v = realloc_cmdbuff(ccline.cmdlen + difflen); 3345 v = realloc_cmdbuff(ccline.cmdlen + difflen + 4);
3341 xp->xp_pattern = ccline.cmdbuff + i; 3346 xp->xp_pattern = ccline.cmdbuff + i;
3342 } 3347 }
3343 else 3348 else
3344 v = OK; 3349 v = OK;
3345 if (v == OK) 3350 if (v == OK)