patch 8.2.3864: cannot disable requesting key codes from xterm

Problem:    Cannot disable requesting key codes from xterm.
Solution:   Add the 'xtermcodes' option, default on.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index a5ff937..3e71ba1 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -9206,4 +9206,16 @@
 	screen.  When non-zero, characters are sent to the terminal one by
 	one.  For debugging purposes.
 
+					   *'xtermcodes'* *'noxtermcodes'*
+'xtermcodes'		boolean	(default on)
+			global
+	When detecting xterm patchlevel 141 or higher with the termresponse
+	mechanism and this option is set, Vim will request the actual termimal
+	key codes and number of colors from the terminal.  This takes care of
+	various configuration options of the terminal that cannot be obtained
+	from the termlib/terminfo entry, see |xterm-codes|.
+	A side effect may be that t_Co changes and Vim will redraw the
+	display.
+
+
  vim:tw=78:ts=8:noet:ft=help:norl:
diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt
index 8862d0a..3e90cc0 100644
--- a/runtime/doc/term.txt
+++ b/runtime/doc/term.txt
@@ -556,8 +556,15 @@
 adjust the various t_ codes.  This avoids the problem that the xterm can
 produce different codes, depending on the mode it is in (8-bit, VT102,
 VT220, etc.).  The result is that codes like <xF1> are no longer needed.
-Note: This is only done on startup.  If the xterm options are changed after
-Vim has started, the escape sequences may not be recognized anymore.
+
+One of the codes that can change is 't_Co', the number of colors.  This will
+trigger a redraw.  If this is a problem, reset the 'xtermcodes' option as
+early as possible: >
+	set noxtermcodes
+
+Note: Requesting the key codes is only done on startup.  If the xterm options
+are changed after Vim has started, the escape sequences may not be recognized
+anymore.
 
 							*xterm-true-color*
 Vim supports using true colors in the terminal (taken from |highlight-guifg|
diff --git a/runtime/optwin.vim b/runtime/optwin.vim
index 17fe276..9aa2db2 100644
--- a/runtime/optwin.vim
+++ b/runtime/optwin.vim
@@ -562,14 +562,22 @@
 call <SID>Header(gettext("terminal"))
 call <SID>AddOption("term", gettext("name of the used terminal"))
 call <SID>OptionG("term", &term)
+
 call <SID>AddOption("ttytype", gettext("alias for 'term'"))
 call <SID>OptionG("tty", &tty)
+
 call <SID>AddOption("ttybuiltin", gettext("check built-in termcaps first"))
 call <SID>BinOptionG("tbi", &tbi)
+
 call <SID>AddOption("ttyfast", gettext("terminal connection is fast"))
 call <SID>BinOptionG("tf", &tf)
+
+call <SID>AddOption("xtermcodes", gettext("request terminal key codes when an xterm is detected"))
+call <SID>BinOptionG("xtermcodes", &xtermcodes)
+
 call <SID>AddOption("weirdinvert", gettext("terminal that requires extra redrawing"))
 call <SID>BinOptionG("wiv", &wiv)
+
 call <SID>AddOption("esckeys", gettext("recognize keys that start with <Esc> in Insert mode"))
 call <SID>BinOptionG("ek", &ek)
 call <SID>AddOption("scrolljump", gettext("minimal number of lines to scroll at a time"))