Last active
August 29, 2015 14:03
-
-
Save saitoha/7149d02fb524ac2c1b90 to your computer and use it in GitHub Desktop.
vim: correct termresponse behavior when "set ttymouse=" or "set ttymouse=dec"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff -r 0efec12f52ac src/os_unix.c | |
| --- a/src/os_unix.c Thu Jul 10 22:01:47 2014 +0200 | |
| +++ b/src/os_unix.c Sat Jul 12 21:41:54 2014 +0900 | |
| @@ -3667,8 +3667,6 @@ | |
| void | |
| check_mouse_termcode() | |
| { | |
| - xterm_conflict_mouse = FALSE; | |
| - | |
| # ifdef FEAT_MOUSE_XTERM | |
| if (use_xterm_mouse() | |
| # ifdef FEAT_MOUSE_URXVT | |
| @@ -3713,7 +3711,7 @@ | |
| # endif | |
| # ifdef FEAT_MOUSE_JSB | |
| - /* There is no conflict, but it was disabled for xterm before. */ | |
| + /* conflicts with xterm mouse: "\033[" and "\033[M" ??? */ | |
| if (!use_xterm_mouse() | |
| # ifdef FEAT_GUI | |
| && !gui.in_use | |
| @@ -3740,40 +3738,26 @@ | |
| # endif | |
| # ifdef FEAT_MOUSE_DEC | |
| - /* Conflicts with xterm mouse: "\033[" and "\033[M". | |
| - * Also conflicts with the xterm termresponse, skip this if it was | |
| - * requested already. */ | |
| + /* conflicts with xterm mouse: "\033[" and "\033[M" */ | |
| if (!use_xterm_mouse() | |
| -# ifdef FEAT_TERMRESPONSE | |
| - && !did_request_esc_sequence() | |
| -# endif | |
| # ifdef FEAT_GUI | |
| && !gui.in_use | |
| # endif | |
| ) | |
| - { | |
| set_mouse_termcode(KS_DEC_MOUSE, (char_u *)(term_is_8bit(T_NAME) | |
| ? IF_EB("\233", CSI_STR) : IF_EB("\033[", ESC_STR "["))); | |
| - xterm_conflict_mouse = TRUE; | |
| - } | |
| else | |
| del_mouse_termcode(KS_DEC_MOUSE); | |
| # endif | |
| # ifdef FEAT_MOUSE_PTERM | |
| /* same as the dec mouse */ | |
| if (!use_xterm_mouse() | |
| -# ifdef FEAT_TERMRESPONSE | |
| - && !did_request_esc_sequence() | |
| -# endif | |
| # ifdef FEAT_GUI | |
| && !gui.in_use | |
| # endif | |
| ) | |
| - { | |
| set_mouse_termcode(KS_PTERM_MOUSE, | |
| (char_u *) IF_EB("\033[", ESC_STR "[")); | |
| - xterm_conflict_mouse = TRUE; | |
| - } | |
| else | |
| del_mouse_termcode(KS_PTERM_MOUSE); | |
| # endif | |
| @@ -3794,8 +3778,6 @@ | |
| mch_setmouse(FALSE); | |
| setmouse(); | |
| } | |
| - /* It's OK to request the xterm version for uxterm. */ | |
| - resume_get_esc_sequence(); | |
| } | |
| else | |
| del_mouse_termcode(KS_URXVT_MOUSE); | |
| diff -r 0efec12f52ac src/term.c | |
| --- a/src/term.c Thu Jul 10 22:01:47 2014 +0200 | |
| +++ b/src/term.c Sat Jul 12 21:41:54 2014 +0900 | |
| @@ -153,11 +153,6 @@ | |
| static char_u *vim_tgetstr __ARGS((char *s, char_u **pp)); | |
| #endif /* HAVE_TGETENT */ | |
| -#if defined(FEAT_TERMRESPONSE) | |
| -static int xt_index_in = 0; | |
| -static int xt_index_out = 0; | |
| -#endif | |
| - | |
| static int detected_8bit = FALSE; /* detected 8-bit terminal */ | |
| static struct builtin_term builtin_termcaps[] = | |
| @@ -3264,7 +3259,7 @@ | |
| may_req_termresponse(); | |
| /* Immediately check for a response. If t_Co changes, we don't | |
| * want to redraw with wrong colors first. */ | |
| - if (crv_status == CRV_SENT) | |
| + if (crv_status != CRV_GET) | |
| check_for_codes_from_term(); | |
| } | |
| #endif | |
| @@ -3312,40 +3307,6 @@ | |
| } | |
| #if defined(FEAT_TERMRESPONSE) || defined(PROTO) | |
| -# if defined(UNIX) || defined(PROTO) | |
| -/* | |
| - * Return TRUE when the xterm version was requested or anything else that | |
| - * would send an ESC sequence back to Vim. | |
| - * If not sent yet, prevent it from being sent soon. | |
| - * Used to check whether it is OK to enable checking for DEC mouse codes, | |
| - * which conflict with may xterm ESC sequences. | |
| - */ | |
| - int | |
| -did_request_esc_sequence() | |
| -{ | |
| - if (crv_status == CRV_GET) | |
| - crv_status = 0; | |
| - if (u7_status == U7_GET) | |
| - u7_status = 0; | |
| - return crv_status == CRV_SENT || u7_status == U7_SENT | |
| - || xt_index_out > xt_index_in; | |
| -} | |
| - | |
| -/* | |
| - * If requesting the version was disabled in did_request_esc_sequence(), | |
| - * enable it again. | |
| - */ | |
| - void | |
| -resume_get_esc_sequence() | |
| -{ | |
| - if (crv_status == 0) | |
| - crv_status = CRV_GET; | |
| - if (u7_status == 0) | |
| - u7_status = U7_GET; | |
| -} | |
| -# endif | |
| - | |
| - | |
| /* | |
| * Request version string (for xterm) when needed. | |
| * Only do this after switching to raw mode, otherwise the result will be | |
| @@ -3358,8 +3319,6 @@ | |
| * Insert mode. | |
| * On Unix only do it when both output and input are a tty (avoid writing | |
| * request to terminal while reading from a file). | |
| - * Do not do this when a mouse is being detected that starts with the same ESC | |
| - * sequence as the termresponse. | |
| * The result is caught in check_termcode(). | |
| */ | |
| void | |
| @@ -3373,7 +3332,6 @@ | |
| # ifdef UNIX | |
| && isatty(1) | |
| && isatty(read_cmd_fd) | |
| - && !xterm_conflict_mouse | |
| # endif | |
| && *T_CRV != NUL) | |
| { | |
| @@ -4212,10 +4170,16 @@ | |
| #ifdef FEAT_TERMRESPONSE | |
| if (key_name[0] == NUL | |
| - /* URXVT mouse uses <ESC>[#;#;#M, but we are matching <ESC>[ */ | |
| + /* mouse codes of DEC, pterm, and URXVT starts with <ESC>[, so they | |
| + * conflict with other key codes or terminal responses */ | |
| +# ifdef FEAT_MOUSE_DEC | |
| + || key_name[0] == KS_DEC_MOUSE | |
| +# endif | |
| +# ifdef FEAT_MOUSE_PTERM | |
| + || key_name[0] == KS_PTERM_MOUSE | |
| +# endif | |
| +# ifdef FEAT_MOUSE_URXVT | |
| || key_name[0] == KS_URXVT_MOUSE | |
| -# ifdef FEAT_MBYTE | |
| - || u7_status == U7_SENT | |
| # endif | |
| ) | |
| { | |
| @@ -4269,36 +4233,42 @@ | |
| * u7_status is not "sent", it may be from a previous Vim that | |
| * just exited. But not for <S-F3>, it sends something | |
| * similar, check for row and column to make sense. */ | |
| - if (j == 1 && tp[i] == 'R' && row_char == '2' && col >= 2) | |
| + if (j == 1 && tp[i] == 'R') | |
| { | |
| - char *aw = NULL; | |
| - | |
| - LOG_TR("Received U7 status"); | |
| - u7_status = U7_GOT; | |
| -# ifdef FEAT_AUTOCMD | |
| - did_cursorhold = TRUE; | |
| + if (row_char == '2' && col >= 2) | |
| + { | |
| + char *aw = NULL; | |
| + | |
| + LOG_TR("Received U7 status"); | |
| + u7_status = U7_GOT; | |
| +# ifdef FEAT_AUTOCMD | |
| + did_cursorhold = TRUE; | |
| # endif | |
| - if (col == 2) | |
| - aw = "single"; | |
| - else if (col == 3) | |
| - aw = "double"; | |
| - if (aw != NULL && STRCMP(aw, p_ambw) != 0) | |
| - { | |
| - /* Setting the option causes a screen redraw. Do that | |
| - * right away if possible, keeping any messages. */ | |
| - set_option_value((char_u *)"ambw", 0L, (char_u *)aw, 0); | |
| + if (col == 2) | |
| + aw = "single"; | |
| + else if (col == 3) | |
| + aw = "double"; | |
| + if (aw != NULL && STRCMP(aw, p_ambw) != 0) | |
| + { | |
| + /* Setting the option causes a screen redraw. Do | |
| + * that right away if possible, keeping any | |
| + * messages. */ | |
| + set_option_value((char_u *)"ambw", 0L, | |
| + (char_u *)aw, 0); | |
| # ifdef DEBUG_TERMRESPONSE | |
| - { | |
| - char buf[100]; | |
| - int r = redraw_asap(CLEAR); | |
| - | |
| - sprintf(buf, "set 'ambiwidth', redraw_asap(): %d", | |
| - r); | |
| - log_tr(buf); | |
| + { | |
| + char buf[100]; | |
| + int r = redraw_asap(CLEAR); | |
| + | |
| + sprintf(buf, | |
| + "set 'ambiwidth', redraw_asap(): %d", | |
| + r); | |
| + log_tr(buf); | |
| + } | |
| +# else | |
| + redraw_asap(CLEAR); | |
| +# endif | |
| } | |
| -# else | |
| - redraw_asap(CLEAR); | |
| -# endif | |
| } | |
| key_name[0] = (int)KS_EXTRA; | |
| key_name[1] = (int)KE_IGNORE; | |
| @@ -5769,6 +5739,9 @@ | |
| * termcap codes from the terminal itself. | |
| * We get them one by one to avoid a very long response string. | |
| */ | |
| +static int xt_index_in = 0; | |
| +static int xt_index_out = 0; | |
| + | |
| static void | |
| req_codes_from_term() | |
| { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment