Mercurial > vim
comparison src/ex_getln.c @ 95:a2081e6febb8
updated for version 7.0037
author | vimboss |
---|---|
date | Tue, 11 Jan 2005 21:29:04 +0000 |
parents | 388f285bda1b |
children | 6df0106fc595 |
comparison
equal
deleted
inserted
replaced
94:0c2e08de4a75 | 95:a2081e6febb8 |
---|---|
78 static void correct_cmdspos __ARGS((int idx, int cells)); | 78 static void correct_cmdspos __ARGS((int idx, int cells)); |
79 #endif | 79 #endif |
80 static void alloc_cmdbuff __ARGS((int len)); | 80 static void alloc_cmdbuff __ARGS((int len)); |
81 static int realloc_cmdbuff __ARGS((int len)); | 81 static int realloc_cmdbuff __ARGS((int len)); |
82 static void draw_cmdline __ARGS((int start, int len)); | 82 static void draw_cmdline __ARGS((int start, int len)); |
83 static void save_cmdline __ARGS((struct cmdline_info *ccp)); | |
84 static void restore_cmdline __ARGS((struct cmdline_info *ccp)); | |
83 static int cmdline_paste __ARGS((int regname, int literally)); | 85 static int cmdline_paste __ARGS((int regname, int literally)); |
84 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | 86 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
85 static void redrawcmd_preedit __ARGS((void)); | 87 static void redrawcmd_preedit __ARGS((void)); |
86 #endif | 88 #endif |
87 #ifdef FEAT_WILDMENU | 89 #ifdef FEAT_WILDMENU |
591 c = Ctrl_BSL; | 593 c = Ctrl_BSL; |
592 } | 594 } |
593 #ifdef FEAT_EVAL | 595 #ifdef FEAT_EVAL |
594 else if (c == 'e') | 596 else if (c == 'e') |
595 { | 597 { |
596 struct cmdline_info save_ccline; | 598 struct cmdline_info save_ccline; |
597 char_u *p; | 599 char_u *p = NULL; |
598 | 600 |
599 /* | 601 /* |
600 * Replace the command line with the result of an expression. | 602 * Replace the command line with the result of an expression. |
601 * Need to save the current command line, to be able to enter | 603 * Need to save the current command line, to be able to enter |
602 * a new one... | 604 * a new one... |
603 */ | 605 */ |
604 if (ccline.cmdpos == ccline.cmdlen) | 606 if (ccline.cmdpos == ccline.cmdlen) |
605 new_cmdpos = 99999; /* keep it at the end */ | 607 new_cmdpos = 99999; /* keep it at the end */ |
606 else | 608 else |
607 new_cmdpos = ccline.cmdpos; | 609 new_cmdpos = ccline.cmdpos; |
608 save_ccline = ccline; | 610 |
609 ccline.cmdbuff = NULL; | 611 save_cmdline(&save_ccline); |
610 ccline.cmdprompt = NULL; | |
611 c = get_expr_register(); | 612 c = get_expr_register(); |
612 ccline = save_ccline; | 613 restore_cmdline(&save_ccline); |
613 if (c == '=') | 614 if (c == '=') |
614 { | 615 { |
616 save_cmdline(&save_ccline); | |
615 p = get_expr_line(); | 617 p = get_expr_line(); |
616 if (p != NULL | 618 restore_cmdline(&save_ccline); |
617 && realloc_cmdbuff((int)STRLEN(p) + 1) == OK) | 619 |
620 if (p != NULL && realloc_cmdbuff((int)STRLEN(p) + 1) == OK) | |
618 { | 621 { |
619 ccline.cmdlen = STRLEN(p); | 622 ccline.cmdlen = STRLEN(p); |
620 STRCPY(ccline.cmdbuff, p); | 623 STRCPY(ccline.cmdbuff, p); |
621 vim_free(p); | 624 vim_free(p); |
622 | 625 |
1029 beep_flush(); | 1032 beep_flush(); |
1030 c = ESC; | 1033 c = ESC; |
1031 } | 1034 } |
1032 else | 1035 else |
1033 { | 1036 { |
1034 save_ccline = ccline; | 1037 save_cmdline(&save_ccline); |
1035 ccline.cmdbuff = NULL; | |
1036 ccline.cmdprompt = NULL; | |
1037 c = get_expr_register(); | 1038 c = get_expr_register(); |
1038 ccline = save_ccline; | 1039 restore_cmdline(&save_ccline); |
1039 } | 1040 } |
1040 } | 1041 } |
1041 #endif | 1042 #endif |
1042 if (c != ESC) /* use ESC to cancel inserting register */ | 1043 if (c != ESC) /* use ESC to cancel inserting register */ |
1043 { | 1044 { |
1725 #endif | 1726 #endif |
1726 #ifdef CURSOR_SHAPE | 1727 #ifdef CURSOR_SHAPE |
1727 ui_cursor_shape(); /* may show different cursor shape */ | 1728 ui_cursor_shape(); /* may show different cursor shape */ |
1728 #endif | 1729 #endif |
1729 | 1730 |
1730 return ccline.cmdbuff; | 1731 { |
1732 char_u *p = ccline.cmdbuff; | |
1733 | |
1734 /* Make ccline empty, getcmdline() may try to use it. */ | |
1735 ccline.cmdbuff = NULL; | |
1736 return p; | |
1737 } | |
1731 } | 1738 } |
1732 | 1739 |
1733 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | 1740 #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) |
1734 /* | 1741 /* |
1735 * Get a command line with a prompt. | 1742 * Get a command line with a prompt. |
1745 { | 1752 { |
1746 char_u *s; | 1753 char_u *s; |
1747 struct cmdline_info save_ccline; | 1754 struct cmdline_info save_ccline; |
1748 int msg_col_save = msg_col; | 1755 int msg_col_save = msg_col; |
1749 | 1756 |
1750 save_ccline = ccline; | 1757 save_cmdline(&save_ccline); |
1751 ccline.cmdbuff = NULL; | |
1752 ccline.cmdprompt = prompt; | 1758 ccline.cmdprompt = prompt; |
1753 ccline.cmdattr = attr; | 1759 ccline.cmdattr = attr; |
1754 s = getcmdline(firstc, 1L, 0); | 1760 s = getcmdline(firstc, 1L, 0); |
1755 ccline = save_ccline; | 1761 restore_cmdline(&save_ccline); |
1756 /* Restore msg_col, the prompt from input() may have changed it. */ | 1762 /* Restore msg_col, the prompt from input() may have changed it. */ |
1757 msg_col = msg_col_save; | 1763 msg_col = msg_col_save; |
1758 | 1764 |
1759 return s; | 1765 return s; |
1760 } | 1766 } |
2536 if (redraw) | 2542 if (redraw) |
2537 msg_check(); | 2543 msg_check(); |
2538 return retval; | 2544 return retval; |
2539 } | 2545 } |
2540 | 2546 |
2547 static struct cmdline_info prev_ccline; | |
2548 static int prev_ccline_used = FALSE; | |
2549 | |
2550 /* | |
2551 * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
2552 * and overwrite it. But get_cmdline_str() may need it, thus make it | |
2553 * available globally in prev_ccline. | |
2554 */ | |
2555 static void | |
2556 save_cmdline(ccp) | |
2557 struct cmdline_info *ccp; | |
2558 { | |
2559 if (!prev_ccline_used) | |
2560 { | |
2561 vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
2562 prev_ccline_used = TRUE; | |
2563 } | |
2564 *ccp = prev_ccline; | |
2565 prev_ccline = ccline; | |
2566 ccline.cmdbuff = NULL; | |
2567 ccline.cmdprompt = NULL; | |
2568 } | |
2569 | |
2570 /* | |
2571 * Resture ccline after it has been saved with save_cmdline(). | |
2572 */ | |
2573 static void | |
2574 restore_cmdline(ccp) | |
2575 struct cmdline_info *ccp; | |
2576 { | |
2577 ccline = prev_ccline; | |
2578 prev_ccline = *ccp; | |
2579 } | |
2580 | |
2541 /* | 2581 /* |
2542 * paste a yank register into the command line. | 2582 * paste a yank register into the command line. |
2543 * used by CTRL-R command in command-line mode | 2583 * used by CTRL-R command in command-line mode |
2544 * insert_reg() can't be used here, because special characters from the | 2584 * insert_reg() can't be used here, because special characters from the |
2545 * register contents will be interpreted as commands. | 2585 * register contents will be interpreted as commands. |
2570 | 2610 |
2571 #ifdef FEAT_CLIPBOARD | 2611 #ifdef FEAT_CLIPBOARD |
2572 regname = may_get_selection(regname); | 2612 regname = may_get_selection(regname); |
2573 #endif | 2613 #endif |
2574 | 2614 |
2575 /* Need to save and restore ccline, because obtaining the "=" register may | 2615 /* Need to save and restore ccline. */ |
2576 * execute "normal :cmd" and overwrite it. */ | 2616 save_cmdline(&save_ccline); |
2577 save_ccline = ccline; | |
2578 ccline.cmdbuff = NULL; | |
2579 ccline.cmdprompt = NULL; | |
2580 i = get_spec_reg(regname, &arg, &allocated, TRUE); | 2617 i = get_spec_reg(regname, &arg, &allocated, TRUE); |
2581 ccline = save_ccline; | 2618 restore_cmdline(&save_ccline); |
2582 | 2619 |
2583 if (i) | 2620 if (i) |
2584 { | 2621 { |
2585 /* Got the value of a special register in "arg". */ | 2622 /* Got the value of a special register in "arg". */ |
2586 if (arg == NULL) | 2623 if (arg == NULL) |
4532 return -1; | 4569 return -1; |
4533 | 4570 |
4534 return history[histype][hisidx[histype]].hisnum; | 4571 return history[histype][hisidx[histype]].hisnum; |
4535 } | 4572 } |
4536 | 4573 |
4574 static struct cmdline_info *get_ccline_ptr __ARGS((void)); | |
4575 | |
4576 /* | |
4577 * Get pointer to the command line info to use. cmdline_paste() may clear | |
4578 * ccline and put the previous value in prev_ccline. | |
4579 */ | |
4580 static struct cmdline_info * | |
4581 get_ccline_ptr() | |
4582 { | |
4583 if ((State & CMDLINE) == 0) | |
4584 return NULL; | |
4585 if (ccline.cmdbuff != NULL) | |
4586 return &ccline; | |
4587 if (prev_ccline_used && prev_ccline.cmdbuff != NULL) | |
4588 return &prev_ccline; | |
4589 return NULL; | |
4590 } | |
4591 | |
4537 /* | 4592 /* |
4538 * Get the current command line in allocated memory. | 4593 * Get the current command line in allocated memory. |
4539 * Only works when the command line is being edited. | 4594 * Only works when the command line is being edited. |
4540 * Returns NULL when something is wrong. | 4595 * Returns NULL when something is wrong. |
4541 */ | 4596 */ |
4542 char_u * | 4597 char_u * |
4543 get_cmdline_str() | 4598 get_cmdline_str() |
4544 { | 4599 { |
4545 if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0) | 4600 struct cmdline_info *p = get_ccline_ptr(); |
4601 | |
4602 if (p == NULL) | |
4546 return NULL; | 4603 return NULL; |
4547 return vim_strnsave(ccline.cmdbuff, ccline.cmdlen); | 4604 return vim_strnsave(p->cmdbuff, p->cmdlen); |
4548 } | 4605 } |
4549 | 4606 |
4550 /* | 4607 /* |
4551 * Get the current command line position, counted in bytes. | 4608 * Get the current command line position, counted in bytes. |
4552 * Zero is the first position. | 4609 * Zero is the first position. |
4554 * Returns -1 when something is wrong. | 4611 * Returns -1 when something is wrong. |
4555 */ | 4612 */ |
4556 int | 4613 int |
4557 get_cmdline_pos() | 4614 get_cmdline_pos() |
4558 { | 4615 { |
4559 if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0) | 4616 struct cmdline_info *p = get_ccline_ptr(); |
4617 | |
4618 if (p == NULL) | |
4560 return -1; | 4619 return -1; |
4561 return ccline.cmdpos; | 4620 return p->cmdpos; |
4562 } | 4621 } |
4563 | 4622 |
4564 /* | 4623 /* |
4565 * Set the command line byte position to "pos". Zero is the first position. | 4624 * Set the command line byte position to "pos". Zero is the first position. |
4566 * Only works when the command line is being edited. | 4625 * Only works when the command line is being edited. |
4568 */ | 4627 */ |
4569 int | 4628 int |
4570 set_cmdline_pos(pos) | 4629 set_cmdline_pos(pos) |
4571 int pos; | 4630 int pos; |
4572 { | 4631 { |
4573 if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0) | 4632 struct cmdline_info *p = get_ccline_ptr(); |
4633 | |
4634 if (p == NULL) | |
4574 return 1; | 4635 return 1; |
4575 | 4636 |
4576 /* The position is not set directly but after CTRL-\ e or CTRL-R = has | 4637 /* The position is not set directly but after CTRL-\ e or CTRL-R = has |
4577 * changed the command line. */ | 4638 * changed the command line. */ |
4578 if (pos < 0) | 4639 if (pos < 0) |