To: vim_dev@googlegroups.com Subject: Patch 9.0.0939 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0939 Problem: Still using simplified mappings when using the kitty keyboard protocol. Solution: Use the kitty_protocol_state value to decide whether to use simplified mappings. Improve how seenModifyOtherKeys is set and reset. Files: runtime/doc/map.txt, src/term.c, src/structs.h, src/getchar.c *** ../vim-9.0.0938/runtime/doc/map.txt 2022-11-23 20:19:17.125682463 +0000 --- runtime/doc/map.txt 2022-11-24 13:15:55.045191597 +0000 *************** *** 963,975 **** Xterm and a few other terminals can be put in a mode where keys with modifiers are sent with a special escape code. Vim recognizes these codes and can then make a difference between CTRL-H and Backspace, even when Backspace sends the ! character 8. And many more special keys. For xterm modifyOtherKeys is enabled in the builtin termcap entry. If this is not used you can enable modifyOtherKeys with these lines in your vimrc: > let &t_TI = "\[>4;2m" let &t_TE = "\[>4;m" In case the modifyOtherKeys mode causes problems you can disable it: > let &t_TI = "" let &t_TE = "" --- 971,988 ---- Xterm and a few other terminals can be put in a mode where keys with modifiers are sent with a special escape code. Vim recognizes these codes and can then make a difference between CTRL-H and Backspace, even when Backspace sends the ! character 8. And many more special keys, such as Tab and CTRL-I, which cannot ! be mapped separately otherwise. For xterm modifyOtherKeys is enabled in the builtin termcap entry. If this is not used you can enable modifyOtherKeys with these lines in your vimrc: > let &t_TI = "\[>4;2m" let &t_TE = "\[>4;m" + This sets modifyOtherKeys to level 2. Note that modifyOtherKeys level 1 does + not work. Some terminals do not support level 2 and then send key codes that + Vim will not be able to correctly recognize. + In case the modifyOtherKeys mode causes problems you can disable it: > let &t_TI = "" let &t_TE = "" *************** *** 993,1002 **** detected such an escape sequence use `:verbose map`, the first line will then show "Seen modifyOtherKeys: true" (possibly translated). A known side effect is that in Insert mode the raw escape sequence is inserted after the CTRL-V key. This can be used to check whether modifyOtherKeys is enabled: In Insert mode type CTRL-SHIFT-V CTRL-V, if you get one byte then ! modifyOtherKeys is off, if you get <1b>27;5;118~ then it is on. When the 'esckeys' option is off, then modifyOtherKeys will be disabled in Insert mode to avoid every key with a modifier causing Insert mode to end. --- 1006,1020 ---- detected such an escape sequence use `:verbose map`, the first line will then show "Seen modifyOtherKeys: true" (possibly translated). + This automatic detection depends on receiving an escape code starting with + "<1b>[27;". This is the normal way xterm sends these key codes. However, if + the *formatOtherKeys* resource is set another form is used that is not + recognized, therefore you must not set formatOtherKeys. + A known side effect is that in Insert mode the raw escape sequence is inserted after the CTRL-V key. This can be used to check whether modifyOtherKeys is enabled: In Insert mode type CTRL-SHIFT-V CTRL-V, if you get one byte then ! modifyOtherKeys is off, if you get <1b>[27;5;118~ then it is on. When the 'esckeys' option is off, then modifyOtherKeys will be disabled in Insert mode to avoid every key with a modifier causing Insert mode to end. *** ../vim-9.0.0938/src/term.c 2022-11-23 23:30:54.212631668 +0000 --- src/term.c 2022-11-24 13:18:35.505380671 +0000 *************** *** 3675,3683 **** --- 3675,3690 ---- { out_str(T_CTE); + // The seenModifyOtherKeys flag is not reset here. We do expect t_TE to + // disable modifyOtherKeys, but there is no way to detect it's enabled + // again after the following t_TI. We assume that when seenModifyOtherKeys + // was set before it will still be valid. + // When the kitty keyboard protocol is enabled we expect t_TE to disable // it. Remembering that it was detected to be enabled is useful in some // situations. + // The following t_TI is expected to request the state and then + // kitty_protocol_state will be set again. if (kitty_protocol_state == KKPS_ENABLED || kitty_protocol_state == KKPS_DISABLED) kitty_protocol_state = KKPS_DISABLED; *************** *** 5050,5058 **** int modifiers; char_u string[MAX_KEY_CODE_LEN + 1]; // Do not set seenModifyOtherKeys for kitty, it does send some sequences // like this but does not have the modifyOtherKeys feature. ! if (term_props[TPR_KITTY].tpr_status != TPR_YES) seenModifyOtherKeys = TRUE; if (trail == 'u') --- 5057,5078 ---- int modifiers; char_u string[MAX_KEY_CODE_LEN + 1]; + // Only set seenModifyOtherKeys for the "{lead}27;" code to avoid setting + // it for terminals using the kitty keyboard protocol. Xterm sends + // the form ending in "u" when the formatOtherKeys resource is set. We do + // not support this. + // + // Do not set seenModifyOtherKeys if there was a positive response at any + // time from requesting the kitty keyboard protocol state, these are not + // expected to support modifyOtherKeys level 2. + // // Do not set seenModifyOtherKeys for kitty, it does send some sequences // like this but does not have the modifyOtherKeys feature. ! if (trail != 'u' ! && (kitty_protocol_state == KKPS_INITIAL ! || kitty_protocol_state == KKPS_OFF ! || kitty_protocol_state == KKPS_AFTER_T_KE) ! && term_props[TPR_KITTY].tpr_status != TPR_YES) seenModifyOtherKeys = TRUE; if (trail == 'u') *************** *** 5237,5243 **** { // The protocol has various "progressive enhancement flags" values, but // we only check for zero and non-zero here. ! kitty_protocol_state = arg[0] == '0' ? KKPS_OFF : KKPS_ENABLED; key_name[0] = (int)KS_EXTRA; key_name[1] = (int)KE_IGNORE; --- 5257,5274 ---- { // The protocol has various "progressive enhancement flags" values, but // we only check for zero and non-zero here. ! if (arg[0] == '0') ! { ! kitty_protocol_state = KKPS_OFF; ! } ! else ! { ! kitty_protocol_state = KKPS_ENABLED; ! ! // Reset seenModifyOtherKeys just in case some key combination has ! // been seen that set it before we get the status response. ! seenModifyOtherKeys = FALSE; ! } key_name[0] = (int)KS_EXTRA; key_name[1] = (int)KE_IGNORE; *** ../vim-9.0.0938/src/structs.h 2022-11-02 13:30:37.538314551 +0000 --- src/structs.h 2022-11-24 12:42:30.538753668 +0000 *************** *** 1264,1270 **** int m_keylen; // strlen(m_keys) int m_mode; // valid mode int m_simplified; // m_keys was simplified, do not use this map ! // if seenModifyOtherKeys is TRUE int m_noremap; // if non-zero no re-mapping for m_str char m_silent; // used, don't echo commands char m_nowait; // used --- 1264,1270 ---- int m_keylen; // strlen(m_keys) int m_mode; // valid mode int m_simplified; // m_keys was simplified, do not use this map ! // if key_protocol_enabled() returns TRUE int m_noremap; // if non-zero no re-mapping for m_str char m_silent; // used, don't echo commands char m_nowait; // used *** ../vim-9.0.0938/src/getchar.c 2022-11-22 12:58:22.750664254 +0000 --- src/getchar.c 2022-11-24 13:17:31.729308620 +0000 *************** *** 2456,2461 **** --- 2456,2472 ---- } /* + * Return TRUE if the terminal sends modifiers with various keys. This is when + * modifyOtherKeys level 2 is enabled or the kitty keyboard protocol is + * enabled. + */ + static int + key_protocol_enabled(void) + { + return seenModifyOtherKeys || kitty_protocol_state == KKPS_ENABLED; + } + + /* * Handle mappings in the typeahead buffer. * - When something was mapped, return map_result_retry for recursive mappings. * - When nothing mapped and typeahead has a character: return map_result_get. *************** *** 2564,2570 **** // Skip ":lmap" mappings if keys were mapped. if (mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State) ! && !(mp->m_simplified && seenModifyOtherKeys && typebuf.tb_maplen == 0) && ((mp->m_mode & MODE_LANGMAP) == 0 || typebuf.tb_maplen == 0)) --- 2575,2581 ---- // Skip ":lmap" mappings if keys were mapped. if (mp->m_keys[0] == tb_c1 && (mp->m_mode & local_State) ! && !(mp->m_simplified && key_protocol_enabled() && typebuf.tb_maplen == 0) && ((mp->m_mode & MODE_LANGMAP) == 0 || typebuf.tb_maplen == 0)) *** ../vim-9.0.0938/src/version.c 2022-11-24 12:19:46.820586297 +0000 --- src/version.c 2022-11-24 12:27:43.499986630 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 939, /**/ -- hundred-and-one symptoms of being an internet addict: 131. You challenge authority and society by portnuking people /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///