vim-jp / issues

有志で既知のバグや要望を検討・管理し、オフィシャルへの還元をしていきます。
https://vim-jp.org/
342 stars 11 forks source link

E315 occurs when typing text for search command in terminal-normal mode #1229

Open mnishz opened 5 years ago

mnishz commented 5 years ago

質問・報告の内容

Summary

E315 occurs when typing text for search command with the following conditions.

How to recreate

https://github.com/mnishz/E315_recreation

  1. vim -Nu NONE main.c
  2. :set incsearch
  3. :term
  4. cat 9500_lines
  5. <c-w>Ni
  6. gcc main.c
  7. ./a.out
  8. <c-w>N
  9. /type something

Please click the image to play GIF. e315

Failure sequence

main
    vim_main2
        main_loop
            normal_cmd
                nv_search
                    getcmdline
                        getcmdline_int
                            may_do_incsearch_highlighting
                                restore curwin->w_cursor in the function
                                validate_cursor
                                    curs_columns
                                        getvvcol
                                            getvcol
                                                ml_get_buf
                                                    E315

I think there are at least three points that can cause E315.

diff --git a/src/ex_getln.c b/src/ex_getln.c
index cba082a0b..77478a012 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -434,7 +435,7 @@ finish_incsearch_highlighting(

        p_magic = is_state->magic_save;

-       validate_cursor();      /* needed for TAB */
+       validate_cursor();      /* needed for TAB */  // nishi E315 here
        redraw_all_later(SOME_VALID);
        if (call_update_screen)
            update_screen(SOME_VALID);
@@ -592,7 +595,7 @@ may_do_incsearch_highlighting(
        ccline.cmdbuff[skiplen + patlen] = next_char;
     }

-    validate_cursor();
+    validate_cursor();  // nishi E315 here
     // May redraw the status line to show the cursor position.
     if (p_ru && curwin->w_status_height > 0)
        curwin->w_redr_status = TRUE;
@@ -659,11 +662,11 @@ may_adjust_incsearch_highlighting(
     out_flush();
     if (c == Ctrl_G)
     {
-       t = is_state->match_end;
+       t = is_state->match_end;  // nishi "t" could cause E315
        if (LT_POS(is_state->match_start, is_state->match_end))
            // Start searching at the end of the match not at the beginning of
            // the next column.
-           (void)decl(&t);
+           (void)decl(&t);  // nishi E315 here
        search_flags += SEARCH_COL;
     }
     else

Root cause

My 1st idea: Incsearch functions restore curwin->w_cursor to the last line after some lines in terminal were scrolled off. So, I thought that we can fix it by calling check_cusor() just after the restoring. But, on second though, it might not be expected behavior that terminal buffer is updated during terminal-normal mode. When I types text for search command, it seems that the buffer is updated and could be scrolled off.

:h Terminal-Normal The commands that would start insert mode, such as 'i' and 'a', return to Terminal-Job mode. The window will be updated to show the contents of the terminal.

I also found that any motion normal commands like 'G' update the buffer.

Recreation script

I tried to recreate this E315 using the following file, but it doesn't occur. https://github.com/mnishz/E315_recreation/blob/master/E315_recreation.vim

Vimのバージョン

8.1.875

OSの種類/ディストリ/バージョン

Linux Ubuntu 18.04 LTS 64 bit

使用している or 関係していそうなプラグイン

プラグインは関係なさそうです。

その他

特にありません。

mnishz commented 5 years ago

ご確認どうもありがとうございました。"patched" となっているけど、間違いかな? 素人目には真面目に直すの結構大変なんじゃないかと思ったのですが。。 もし解析内容におかしな点がなくて、すぐに patch ができるような感じでなければ、 同現象で困っている人 (どれだけいるか分かりませんが) への情報共有として vim-dev の issue に挙げておくのがいいかなと思ったのですがどうでしょうか。 その場合こちらは duplication で close ですかね。

h-east commented 5 years ago

"patched" となっているけど、間違いかな?

間違いでした:bow:

vim_devにreportしちゃってください。

その場合こちらは duplication で close ですかね。

オープン状態でOKです。

mnishz commented 5 years ago

間違いでした:bowing_man:

承知いたしました。

reportしましたー

h-east commented 5 years ago

8.1.0920 https://github.com/vim/vim/commit/29ae223ddcfcbbce46c7e1f4e8fa71b8f2674271

mnishz commented 5 years ago

進捗がすごい(語彙力

端末ノーマルモードのときにバッファの内容が更新される現象は直りましたが、 Bramさんも触れているように違うタイミングで発生するE315に変わったように見えます。 incsearchやsearch commandは関係なくて、端末ジョブモードに戻ったときに発生するようになりました。