Mercurial > vim
comparison src/edit.c @ 2845:d641f141f937 v7.3.196
updated for version 7.3.196
Problem: Can't intercept a character that is going to be inserted.
Solution: Add the InsertCharPre autocommand event. (Jakson A. Aquino)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 19 May 2011 17:25:41 +0200 |
parents | 5381eb5b1eb9 |
children | 44ffd0a8abcd |
comparison
equal
deleted
inserted
replaced
2844:3059bacf05a5 | 2845:d641f141f937 |
---|---|
1379 #ifdef UNIX | 1379 #ifdef UNIX |
1380 if (c == intr_char) /* special interrupt char */ | 1380 if (c == intr_char) /* special interrupt char */ |
1381 goto do_intr; | 1381 goto do_intr; |
1382 #endif | 1382 #endif |
1383 | 1383 |
1384 normalchar: | |
1384 /* | 1385 /* |
1385 * Insert a nomal character. | 1386 * Insert a nomal character. |
1386 */ | 1387 */ |
1387 normalchar: | 1388 #ifdef FEAT_AUTOCMD |
1389 if (!p_paste) | |
1390 { | |
1391 /* Trigger the InsertCharPre event. Lock the text to avoid | |
1392 * weird things from happening. */ | |
1393 set_vim_var_char(c); | |
1394 ++textlock; | |
1395 if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL, | |
1396 FALSE, curbuf)) | |
1397 { | |
1398 /* Get the new value of v:char. If it is more than one | |
1399 * character insert it literally. */ | |
1400 char_u *s = get_vim_var_str(VV_CHAR); | |
1401 if (MB_CHARLEN(s) > 1) | |
1402 { | |
1403 if (stop_arrow() != FAIL) | |
1404 { | |
1405 ins_str(s); | |
1406 AppendToRedobuffLit(s, -1); | |
1407 } | |
1408 c = NUL; | |
1409 } | |
1410 else | |
1411 c = PTR2CHAR(s); | |
1412 } | |
1413 | |
1414 set_vim_var_string(VV_CHAR, NULL, -1); | |
1415 --textlock; | |
1416 | |
1417 /* If the new value is an empty string then don't insert a | |
1418 * char. */ | |
1419 if (c == NUL) | |
1420 break; | |
1421 } | |
1422 #endif | |
1388 #ifdef FEAT_SMARTINDENT | 1423 #ifdef FEAT_SMARTINDENT |
1389 /* Try to perform smart-indenting. */ | 1424 /* Try to perform smart-indenting. */ |
1390 ins_try_si(c); | 1425 ins_try_si(c); |
1391 #endif | 1426 #endif |
1392 | 1427 |
3489 } | 3524 } |
3490 else | 3525 else |
3491 return; | 3526 return; |
3492 } | 3527 } |
3493 p += len; | 3528 p += len; |
3494 #ifdef FEAT_MBYTE | 3529 c = PTR2CHAR(p); |
3495 c = mb_ptr2char(p); | |
3496 #else | |
3497 c = *p; | |
3498 #endif | |
3499 ins_compl_addleader(c); | 3530 ins_compl_addleader(c); |
3500 } | 3531 } |
3501 | 3532 |
3502 /* | 3533 /* |
3503 * Prepare for Insert mode completion, or stop it. | 3534 * Prepare for Insert mode completion, or stop it. |