To: vim_dev@googlegroups.com Subject: Patch 8.1.0032 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.0032 Problem: BS in prompt buffer starts new line. Solution: Do not allows BS over the prompt. Make term_sendkeys() handle special keys. Add a test. Files: src/option.c, src/terminal.c, src/testdir/test_prompt_buffer.vim *** ../vim-8.1.0031/src/option.c 2018-06-03 14:42:17.848505102 +0200 --- src/option.c 2018-06-04 16:51:10.811551036 +0200 *************** *** 12439,12444 **** --- 12439,12448 ---- can_bs( int what) /* BS_INDENT, BS_EOL or BS_START */ { + #ifdef FEAT_JOB_CHANNEL + if (what == BS_START && bt_prompt(curbuf)) + return FALSE; + #endif switch (*p_bs) { case '2': return TRUE; *** ../vim-8.1.0031/src/terminal.c 2018-05-21 22:50:22.514568516 +0200 --- src/terminal.c 2018-06-04 16:51:10.815551032 +0200 *************** *** 5094,5101 **** while (*msg != NUL) { ! send_keys_to_term(term, PTR2CHAR(msg), FALSE); ! msg += MB_CPTR2LEN(msg); } } --- 5094,5112 ---- while (*msg != NUL) { ! int c; ! ! if (*msg == K_SPECIAL && msg[1] != NUL && msg[2] != NUL) ! { ! c = TO_SPECIAL(msg[1], msg[2]); ! msg += 3; ! } ! else ! { ! c = PTR2CHAR(msg); ! msg += MB_CPTR2LEN(msg); ! } ! send_keys_to_term(term, c, FALSE); } } *** ../vim-8.1.0031/src/testdir/test_prompt_buffer.vim 2018-06-03 17:10:36.274226639 +0200 --- src/testdir/test_prompt_buffer.vim 2018-06-04 17:13:41.298470827 +0200 *************** *** 7,22 **** source shared.vim source screendump.vim ! func Test_prompt_basic() " We need to use a terminal window to be able to feed keys without leaving " Insert mode. if !has('terminal') ! return endif if has('win32') ! " TODO: make this work on MS-Windows ! return endif call writefile([ \ 'func TextEntered(text)', \ ' if a:text == "exit"', --- 7,26 ---- source shared.vim source screendump.vim ! func CanTestPromptBuffer() " We need to use a terminal window to be able to feed keys without leaving " Insert mode. if !has('terminal') ! return 0 endif if has('win32') ! " TODO: make the tests work on MS-Windows ! return 0 endif + return 1 + endfunc + + func WriteScript(name) call writefile([ \ 'func TextEntered(text)', \ ' if a:text == "exit"', *************** *** 44,51 **** \ 'set buftype=prompt', \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))', \ 'startinsert', ! \ ], 'Xpromptscript') ! let buf = RunVimInTerminal('-S Xpromptscript', {}) call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))}) call term_sendkeys(buf, "hello\") --- 48,64 ---- \ 'set buftype=prompt', \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))', \ 'startinsert', ! \ ], a:name) ! endfunc ! ! func Test_prompt_basic() ! if !CanTestPromptBuffer() ! return ! endif ! let scriptName = 'XpromptscriptBasic' ! call WriteScript(scriptName) ! ! let buf = RunVimInTerminal('-S ' . scriptName, {}) call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))}) call term_sendkeys(buf, "hello\") *************** *** 57,61 **** call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) call StopVimInTerminal(buf) ! call delete('Xpromptscript') endfunc --- 70,103 ---- call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) call StopVimInTerminal(buf) ! call delete(scriptName) ! endfunc ! ! func Test_prompt_editing() ! if !CanTestPromptBuffer() ! return ! endif ! let scriptName = 'XpromptscriptEditing' ! call WriteScript(scriptName) ! ! let buf = RunVimInTerminal('-S ' . scriptName, {}) ! call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))}) ! ! let bs = "\" ! call term_sendkeys(buf, "hello" . bs . bs) ! call WaitForAssert({-> assert_equal('% hel', term_getline(buf, 1))}) ! ! let left = "\" ! call term_sendkeys(buf, left . left . left . bs . '-') ! call WaitForAssert({-> assert_equal('% -hel', term_getline(buf, 1))}) ! ! let end = "\" ! call term_sendkeys(buf, end . "x") ! call WaitForAssert({-> assert_equal('% -helx', term_getline(buf, 1))}) ! ! call term_sendkeys(buf, "\exit\") ! call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) ! ! call StopVimInTerminal(buf) ! call delete(scriptName) endfunc *** ../vim-8.1.0031/src/version.c 2018-06-03 18:21:57.809890160 +0200 --- src/version.c 2018-06-04 17:05:58.770829349 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 32, /**/ -- I have a drinking problem -- I can't afford it. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///