Mercurial > vim
comparison src/eval.c @ 673:513866ffe6af v7.0200
updated for version 7.0200
author | vimboss |
---|---|
date | Fri, 17 Feb 2006 21:53:23 +0000 |
parents | 83a006f81bac |
children | 4b8583e82cb8 |
comparison
equal
deleted
inserted
replaced
672:db58b9066b21 | 673:513866ffe6af |
---|---|
17256 int c; | 17256 int c; |
17257 int saved_did_emsg; | 17257 int saved_did_emsg; |
17258 char_u *name = NULL; | 17258 char_u *name = NULL; |
17259 char_u *p; | 17259 char_u *p; |
17260 char_u *arg; | 17260 char_u *arg; |
17261 char_u *line_arg = NULL; | |
17261 garray_T newargs; | 17262 garray_T newargs; |
17262 garray_T newlines; | 17263 garray_T newlines; |
17263 int varargs = FALSE; | 17264 int varargs = FALSE; |
17264 int mustend = FALSE; | 17265 int mustend = FALSE; |
17265 int flags = 0; | 17266 int flags = 0; |
17529 } | 17530 } |
17530 else | 17531 else |
17531 break; | 17532 break; |
17532 } | 17533 } |
17533 | 17534 |
17534 if (*p != NUL && *p != '"' && *p != '\n' && !eap->skip && !did_emsg) | 17535 /* When there is a line break use what follows for the function body. |
17536 * Makes 'exe "func Test()\n...\nendfunc"' work. */ | |
17537 if (*p == '\n') | |
17538 line_arg = p + 1; | |
17539 else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg) | |
17535 EMSG(_(e_trailing)); | 17540 EMSG(_(e_trailing)); |
17536 | 17541 |
17537 /* | 17542 /* |
17538 * Read the body of the function, until ":endfunction" is found. | 17543 * Read the body of the function, until ":endfunction" is found. |
17539 */ | 17544 */ |
17561 nesting = 0; | 17566 nesting = 0; |
17562 for (;;) | 17567 for (;;) |
17563 { | 17568 { |
17564 msg_scroll = TRUE; | 17569 msg_scroll = TRUE; |
17565 need_wait_return = FALSE; | 17570 need_wait_return = FALSE; |
17566 if (eap->getline == NULL) | 17571 if (line_arg != NULL) |
17572 { | |
17573 /* Use eap->arg, split up in parts by line breaks. */ | |
17574 theline = line_arg; | |
17575 p = vim_strchr(theline, '\n'); | |
17576 if (p == NULL) | |
17577 line_arg += STRLEN(line_arg); | |
17578 else | |
17579 { | |
17580 *p = NUL; | |
17581 line_arg = p + 1; | |
17582 } | |
17583 } | |
17584 else if (eap->getline == NULL) | |
17567 theline = getcmdline(':', 0L, indent); | 17585 theline = getcmdline(':', 0L, indent); |
17568 else | 17586 else |
17569 theline = eap->getline(':', eap->cookie, indent); | 17587 theline = eap->getline(':', eap->cookie, indent); |
17570 if (KeyTyped) | 17588 if (KeyTyped) |
17571 lines_left = Rows - 1; | 17589 lines_left = Rows - 1; |
17592 ; | 17610 ; |
17593 | 17611 |
17594 /* Check for "endfunction". */ | 17612 /* Check for "endfunction". */ |
17595 if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) | 17613 if (checkforcmd(&p, "endfunction", 4) && nesting-- == 0) |
17596 { | 17614 { |
17597 vim_free(theline); | 17615 if (line_arg == NULL) |
17616 vim_free(theline); | |
17598 break; | 17617 break; |
17599 } | 17618 } |
17600 | 17619 |
17601 /* Increase indent inside "if", "while", "for" and "try", decrease | 17620 /* Increase indent inside "if", "while", "for" and "try", decrease |
17602 * at "end". */ | 17621 * at "end". */ |
17658 } | 17677 } |
17659 | 17678 |
17660 /* Add the line to the function. */ | 17679 /* Add the line to the function. */ |
17661 if (ga_grow(&newlines, 1) == FAIL) | 17680 if (ga_grow(&newlines, 1) == FAIL) |
17662 { | 17681 { |
17663 vim_free(theline); | 17682 if (line_arg == NULL) |
17683 vim_free(theline); | |
17664 goto erret; | 17684 goto erret; |
17665 } | 17685 } |
17666 | 17686 |
17667 /* Copy the line to newly allocated memory. get_one_sourceline() | 17687 /* Copy the line to newly allocated memory. get_one_sourceline() |
17668 * allocates 250 bytes per line, this saves 80% on average. The cost | 17688 * allocates 250 bytes per line, this saves 80% on average. The cost |
17669 * is an extra alloc/free. */ | 17689 * is an extra alloc/free. */ |
17670 p = vim_strsave(theline); | 17690 p = vim_strsave(theline); |
17671 if (p != NULL) | 17691 if (p != NULL) |
17672 { | 17692 { |
17673 vim_free(theline); | 17693 if (line_arg == NULL) |
17694 vim_free(theline); | |
17674 theline = p; | 17695 theline = p; |
17675 } | 17696 } |
17676 | 17697 |
17677 ((char_u **)(newlines.ga_data))[newlines.ga_len] = theline; | 17698 ((char_u **)(newlines.ga_data))[newlines.ga_len] = theline; |
17678 newlines.ga_len++; | 17699 newlines.ga_len++; |
17700 | |
17701 /* Check for end of eap->arg. */ | |
17702 if (line_arg != NULL && *line_arg == NUL) | |
17703 line_arg = NULL; | |
17679 } | 17704 } |
17680 | 17705 |
17681 /* Don't define the function when skipping commands or when an error was | 17706 /* Don't define the function when skipping commands or when an error was |
17682 * detected. */ | 17707 * detected. */ |
17683 if (eap->skip || did_emsg) | 17708 if (eap->skip || did_emsg) |