On Do, 07 Apr 2016, Christian Brabandt wrote:
> Bram wrote:
>
> > Can you give an explanation why this change is needed?
>
> when reading the script, Vim finds the `À`, whose second byte is the 80. And
> this is K_SPECIAL in Vim source and needs to be replaced by K_SPECIAL
> KS_SPECIAL KE_FILLER to be correctly parsed later in vgetorpeek when Vim sees
> the K_SPECIAL and increments the offset pointer of the typebuf struct by 2,
> thinking, that it needs to skip the next 2 special bytes. But since the
> K_SPECIAL has not been escaped correctly, it will skip two chars from the
> script file.
>
> > When recording key strokes and playing them back, does that still work?
>
> I will check and will try to create a test for that behaviour later when I
> come up with a proper patch.
Here is a patch, including a test.
I verified, that recording and replaying works as expected.
Unfortunately, replaying the macro does not work at all in the test and
I am not sure why. It fails however in the unpatched and patched version
the same way, so I assume, this is caused by the way the tests are
executed, because when running the test interactively, it works as
expected.
Best,
Christian
--
Durch Abwesenheit seine Hochschätzung oder Verehrung befördern: Wie
die Gegenwart den Ruhm vermindert, so vermehrt ihn die Abwesenheit.
-- Baltasar Gracián y Morales (Handorakel und Kunst der
Weltklugheit)
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
commit 75fb75012ae16db42439143b83deb52cbaf87b64
Author: Christian Brabandt <[email protected]>
Date: Fri Apr 8 22:13:16 2016 +0200
Fix input handling of reading 0x80 bytes using :source!
closes #728
diff --git a/src/getchar.c b/src/getchar.c
index 4a225e1..75c083b 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -3059,7 +3059,7 @@ inchar(
if (typebuf_changed(tb_change_cnt))
return 0;
- return fix_input_buffer(buf, len, script_char >= 0);
+ return fix_input_buffer(buf, len);
}
/*
@@ -3070,8 +3070,7 @@ inchar(
int
fix_input_buffer(
char_u *buf,
- int len,
- int script) /* TRUE when reading from a script */
+ int len)
{
int i;
char_u *p = buf;
@@ -3105,7 +3104,7 @@ fix_input_buffer(
}
else
#endif
- if (p[0] == NUL || (p[0] == K_SPECIAL && !script
+ if (p[0] == NUL || (p[0] == K_SPECIAL
#ifdef FEAT_AUTOCMD
/* timeout may generate K_CURSORHOLD */
&& (i < 2 || p[1] != KS_EXTRA || p[2] != (int)KE_CURSORHOLD)
diff --git a/src/misc1.c b/src/misc1.c
index ddd9a07..99303c7 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -3410,7 +3410,7 @@ get_keystroke(void)
if (n > 0)
{
/* Replace zero and CSI by a special key code. */
- n = fix_input_buffer(buf + len, n, FALSE);
+ n = fix_input_buffer(buf + len, n);
len += n;
waited = 0;
}
diff --git a/src/proto/getchar.pro b/src/proto/getchar.pro
index 97a2828..fd6ec5d 100644
--- a/src/proto/getchar.pro
+++ b/src/proto/getchar.pro
@@ -48,7 +48,7 @@ int vpeekc_any(void);
int char_avail(void);
void vungetc(int c);
int inchar(char_u *buf, int maxlen, long wait_time, int tb_change_cnt);
-int fix_input_buffer(char_u *buf, int len, int script);
+int fix_input_buffer(char_u *buf, int len);
int input_available(void);
int do_map(int maptype, char_u *arg, int mode, int abbrev);
int get_map_mode(char_u **cmdp, int forceit);
diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim
index 1eb76a6..b6bcce7 100644
--- a/src/testdir/test_alot.vim
+++ b/src/testdir/test_alot.vim
@@ -22,6 +22,7 @@ source test_reltime.vim
source test_searchpos.vim
source test_set.vim
source test_sort.vim
+source test_source.vim
source test_statusline.vim
source test_syn_attr.vim
source test_timers.vim
diff --git a/src/testdir/test_source.vim b/src/testdir/test_source.vim
new file mode 100644
index 0000000..57a748d
--- /dev/null
+++ b/src/testdir/test_source.vim
@@ -0,0 +1,43 @@
+" Test for using source!
+
+let g:text=['sobre se a constante divulgação das à nossa foo à nossa informações afeta',
+ \ 'sobre se a constante divulgação das à nossa foo à nossa informações afeta']
+
+function SetupSplitWindow()
+ sp Xfile.txt
+ call append('$', g:text)
+ w!
+endfunction
+
+function Test_read_and_source()
+ let lines = [ ':%s/Ã nossa/--Ã nossa--/g' ]
+ call writefile(lines, 'Xscript')
+ call SetupSplitWindow()
+ try
+ source! Xscript
+ catch
+ endtry
+ call assert_equal(['', 'sobre se a constante divulgação das --à nossa-- foo à nossa informações afeta',
+ \ 'sobre se a constante divulgação das --à nossa-- foo à nossa informações afeta'], getline(1,'$'))
+ bw!
+ call delete('Xfile.txt')
+endfunc
+
+" does not work when run using the tests, but works when running interactively
+func NoTest_record_macro()
+ call SetupSplitWindow()
+ :2
+ call feedkeys('qa0dfÃqj', 't')
+ call feedkeys('@a', 't')
+ call assert_equal(['', ' nossa foo à nossa informações afeta',
+ \ ' nossa foo à nossa informações afeta'], getline(1,'$'))
+ bw!
+ call delete('Xfile.txt')
+ call TestTearDown()
+endfunc
+
+func TestTearDown()
+ unlet! g:text
+ call delete('Xscript')
+ call delete('Xfile.txt')
+endfunc