summaryrefslogtreecommitdiffstats
path: root/src/edit.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2012-06-01 14:57:51 +0200
committerBram Moolenaar <Bram@vim.org>2012-06-01 14:57:51 +0200
commit704984ac87979fd20b8ba732df3abd3197814f7f (patch)
tree82ed4412fed1e7b49246d5b9ae3f6ab8bbe41400 /src/edit.c
parentd2aed44c77f165a23c495e5836bc33d3133fea2e (diff)
updated for version 7.3.534v7.3.534
Problem: When using an InsertCharPre autocommand autoindent fails. Solution: Proper handling of v:char. (Alexey Radkov)
Diffstat (limited to 'src/edit.c')
-rw-r--r--src/edit.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/edit.c b/src/edit.c
index badebb0bd6..39985bdd57 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -10108,22 +10108,40 @@ get_nolist_virtcol()
do_insert_char_pre(c)
int c;
{
- char_u *res;
+ char_u *res;
+#ifdef FEAT_MBYTE
+ char_u buf[MB_MAXBYTES + 1];
+#else
+ char_u buf[2];
+#endif
/* Return quickly when there is nothing to do. */
if (!has_insertcharpre())
return NULL;
+#ifdef FEAT_MBYTE
+ if (has_mbyte)
+ buf[(*mb_char2bytes)(c, buf)] = NUL;
+ else
+#endif
+ {
+ buf[0] = c;
+ buf[1] = NUL;
+ }
+
/* Lock the text to avoid weird things from happening. */
++textlock;
- set_vim_var_char(c); /* set v:char */
+ set_vim_var_string(VV_CHAR, buf, -1); /* set v:char */
+ res = NULL;
if (apply_autocmds(EVENT_INSERTCHARPRE, NULL, NULL, FALSE, curbuf))
- /* Get the new value of v:char. It may be empty or more than one
- * character. */
- res = vim_strsave(get_vim_var_str(VV_CHAR));
- else
- res = NULL;
+ {
+ /* Get the value of v:char. It may be empty or more than one
+ * character. Only use it when changed, otherwise continue with the
+ * original character to avoid breaking autoindent. */
+ if (STRCMP(buf, get_vim_var_str(VV_CHAR)) != 0)
+ res = vim_strsave(get_vim_var_str(VV_CHAR));
+ }
set_vim_var_string(VV_CHAR, NULL, -1); /* clear v:char */
--textlock;