comparison src/edit.c @ 840:2c885fab04e3 v7.0e06

updated for version 7.0e06
author vimboss
date Sat, 22 Apr 2006 22:33:57 +0000
parents 5a7843c57316
children c2cae213194d
comparison
equal deleted inserted replaced
839:1f3b1021f002 840:2c885fab04e3
176 static void spell_back_to_badword __ARGS((void)); 176 static void spell_back_to_badword __ARGS((void));
177 static int spell_bad_len = 0; /* length of located bad word */ 177 static int spell_bad_len = 0; /* length of located bad word */
178 #endif 178 #endif
179 static void stop_insert __ARGS((pos_T *end_insert_pos, int esc)); 179 static void stop_insert __ARGS((pos_T *end_insert_pos, int esc));
180 static int echeck_abbr __ARGS((int)); 180 static int echeck_abbr __ARGS((int));
181 #if 0
181 static void replace_push_off __ARGS((int c)); 182 static void replace_push_off __ARGS((int c));
183 #endif
182 static int replace_pop __ARGS((void)); 184 static int replace_pop __ARGS((void));
183 static void replace_join __ARGS((int off)); 185 static void replace_join __ARGS((int off));
184 static void replace_pop_ins __ARGS((void)); 186 static void replace_pop_ins __ARGS((void));
185 #ifdef FEAT_MBYTE 187 #ifdef FEAT_MBYTE
186 static void mb_replace_pop_ins __ARGS((int cc)); 188 static void mb_replace_pop_ins __ARGS((int cc));
5821 * start_arrow() is called when an arrow key is used in insert mode. 5823 * start_arrow() is called when an arrow key is used in insert mode.
5822 * For undo/redo it resembles hitting the <ESC> key. 5824 * For undo/redo it resembles hitting the <ESC> key.
5823 */ 5825 */
5824 static void 5826 static void
5825 start_arrow(end_insert_pos) 5827 start_arrow(end_insert_pos)
5826 pos_T *end_insert_pos; 5828 pos_T *end_insert_pos; /* can be NULL */
5827 { 5829 {
5828 if (!arrow_used) /* something has been inserted */ 5830 if (!arrow_used) /* something has been inserted */
5829 { 5831 {
5830 AppendToRedobuff(ESC_STR); 5832 AppendToRedobuff(ESC_STR);
5831 stop_insert(end_insert_pos, FALSE); 5833 stop_insert(end_insert_pos, FALSE);
5910 5912
5911 return (arrow_used || ins_need_undo ? FAIL : OK); 5913 return (arrow_used || ins_need_undo ? FAIL : OK);
5912 } 5914 }
5913 5915
5914 /* 5916 /*
5915 * do a few things to stop inserting 5917 * Do a few things to stop inserting.
5918 * "end_insert_pos" is where insert ended. It is NULL when we already jumped
5919 * to another window/buffer.
5916 */ 5920 */
5917 static void 5921 static void
5918 stop_insert(end_insert_pos, esc) 5922 stop_insert(end_insert_pos, esc)
5919 pos_T *end_insert_pos; /* where insert ended */ 5923 pos_T *end_insert_pos;
5920 int esc; /* called by ins_esc() */ 5924 int esc; /* called by ins_esc() */
5921 { 5925 {
5922 int cc; 5926 int cc;
5923 char_u *ptr; 5927 char_u *ptr;
5924 5928
5939 last_insert_skip = new_insert_skip; 5943 last_insert_skip = new_insert_skip;
5940 } 5944 }
5941 else 5945 else
5942 vim_free(ptr); 5946 vim_free(ptr);
5943 5947
5944 if (!arrow_used) 5948 if (!arrow_used && end_insert_pos != NULL)
5945 { 5949 {
5946 /* Auto-format now. It may seem strange to do this when stopping an 5950 /* Auto-format now. It may seem strange to do this when stopping an
5947 * insertion (or moving the cursor), but it's required when appending 5951 * insertion (or moving the cursor), but it's required when appending
5948 * a line and having it end in a space. But only do it when something 5952 * a line and having it end in a space. But only do it when something
5949 * was actually inserted, otherwise undo won't work. */ 5953 * was actually inserted, otherwise undo won't work. */
5985 5989
5986 /* If we just did an auto-indent, remove the white space from the end 5990 /* If we just did an auto-indent, remove the white space from the end
5987 * of the line, and put the cursor back. 5991 * of the line, and put the cursor back.
5988 * Do this when ESC was used or moving the cursor up/down. */ 5992 * Do this when ESC was used or moving the cursor up/down. */
5989 if (did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL 5993 if (did_ai && (esc || (vim_strchr(p_cpo, CPO_INDENT) == NULL
5990 && curwin->w_cursor.lnum != end_insert_pos->lnum))) 5994 && curwin->w_cursor.lnum != end_insert_pos->lnum)))
5991 { 5995 {
5992 pos_T tpos = curwin->w_cursor; 5996 pos_T tpos = curwin->w_cursor;
5993 5997
5994 curwin->w_cursor = *end_insert_pos; 5998 curwin->w_cursor = *end_insert_pos;
5995 for (;;) 5999 for (;;)
6028 did_si = FALSE; 6032 did_si = FALSE;
6029 can_si = FALSE; 6033 can_si = FALSE;
6030 can_si_back = FALSE; 6034 can_si_back = FALSE;
6031 #endif 6035 #endif
6032 6036
6033 /* set '[ and '] to the inserted text */ 6037 /* Set '[ and '] to the inserted text. When end_insert_pos is NULL we are
6034 curbuf->b_op_start = Insstart; 6038 * now in a different buffer. */
6035 curbuf->b_op_end = *end_insert_pos; 6039 if (end_insert_pos != NULL)
6040 {
6041 curbuf->b_op_start = Insstart;
6042 curbuf->b_op_end = *end_insert_pos;
6043 }
6036 } 6044 }
6037 6045
6038 /* 6046 /*
6039 * Set the last inserted text to a single character. 6047 * Set the last inserted text to a single character.
6040 * Used for the replace command. 6048 * Used for the replace command.
6561 mch_memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u))); 6569 mch_memmove(p + 1, p, (size_t)(replace_offset * sizeof(char_u)));
6562 *p = c; 6570 *p = c;
6563 ++replace_stack_nr; 6571 ++replace_stack_nr;
6564 } 6572 }
6565 6573
6574 #if 0
6566 /* 6575 /*
6567 * call replace_push(c) with replace_offset set to the first NUL. 6576 * call replace_push(c) with replace_offset set to the first NUL.
6568 */ 6577 */
6569 static void 6578 static void
6570 replace_push_off(c) 6579 replace_push_off(c)
6578 if (*--p == NUL) 6587 if (*--p == NUL)
6579 break; 6588 break;
6580 replace_push(c); 6589 replace_push(c);
6581 replace_offset = 0; 6590 replace_offset = 0;
6582 } 6591 }
6592 #endif
6583 6593
6584 /* 6594 /*
6585 * Pop one item from the replace stack. 6595 * Pop one item from the replace stack.
6586 * return -1 if stack empty 6596 * return -1 if stack empty
6587 * return replaced character or NUL otherwise 6597 * return replaced character or NUL otherwise
8021 || arrow_used)))))) 8031 || arrow_used))))))
8022 { 8032 {
8023 int ts; 8033 int ts;
8024 colnr_T vcol; 8034 colnr_T vcol;
8025 colnr_T want_vcol; 8035 colnr_T want_vcol;
8036 #if 0
8026 int extra = 0; 8037 int extra = 0;
8038 #endif
8027 8039
8028 *inserted_space_p = FALSE; 8040 *inserted_space_p = FALSE;
8029 if (p_sta && in_indent) 8041 if (p_sta && in_indent)
8030 ts = curbuf->b_p_sw; 8042 ts = curbuf->b_p_sw;
8031 else 8043 else
8080 ins_char(' '); 8092 ins_char(' ');
8081 else 8093 else
8082 #endif 8094 #endif
8083 { 8095 {
8084 ins_str((char_u *)" "); 8096 ins_str((char_u *)" ");
8085 if ((State & REPLACE_FLAG) && extra <= 1) 8097 if ((State & REPLACE_FLAG) /* && extra <= 1 */)
8086 { 8098 {
8099 #if 0
8087 if (extra) 8100 if (extra)
8088 replace_push_off(NUL); 8101 replace_push_off(NUL);
8089 else 8102 else
8103 #endif
8090 replace_push(NUL); 8104 replace_push(NUL);
8091 } 8105 }
8106 #if 0
8092 if (extra == 2) 8107 if (extra == 2)
8093 extra = 1; 8108 extra = 1;
8109 #endif
8094 } 8110 }
8095 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL); 8111 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
8096 } 8112 }
8097 } 8113 }
8098 8114
8203 static void 8219 static void
8204 ins_mouse(c) 8220 ins_mouse(c)
8205 int c; 8221 int c;
8206 { 8222 {
8207 pos_T tpos; 8223 pos_T tpos;
8224 win_T *old_curwin = curwin;
8208 8225
8209 # ifdef FEAT_GUI 8226 # ifdef FEAT_GUI
8210 /* When GUI is active, also move/paste when 'mouse' is empty */ 8227 /* When GUI is active, also move/paste when 'mouse' is empty */
8211 if (!gui.in_use) 8228 if (!gui.in_use)
8212 # endif 8229 # endif
8215 8232
8216 undisplay_dollar(); 8233 undisplay_dollar();
8217 tpos = curwin->w_cursor; 8234 tpos = curwin->w_cursor;
8218 if (do_mouse(NULL, c, BACKWARD, 1L, 0)) 8235 if (do_mouse(NULL, c, BACKWARD, 1L, 0))
8219 { 8236 {
8220 start_arrow(&tpos); 8237 #ifdef FEAT_WINDOWS
8238 win_T *new_curwin = curwin;
8239
8240 if (curwin != old_curwin && win_valid(old_curwin))
8241 {
8242 /* Mouse took us to another window. We need to go back to the
8243 * previous one to stop insert there properly. */
8244 curwin = old_curwin;
8245 curbuf = curwin->w_buffer;
8246 }
8247 #endif
8248 start_arrow(curwin == old_curwin ? &tpos : NULL);
8249 #ifdef FEAT_WINDOWS
8250 if (curwin != new_curwin && win_valid(new_curwin))
8251 {
8252 curwin = new_curwin;
8253 curbuf = curwin->w_buffer;
8254 }
8255 #endif
8221 # ifdef FEAT_CINDENT 8256 # ifdef FEAT_CINDENT
8222 can_cindent = TRUE; 8257 can_cindent = TRUE;
8223 # endif 8258 # endif
8224 } 8259 }
8225 8260