aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2007-10-09 05:05:39 +0000
committerStefan Monnier2007-10-09 05:05:39 +0000
commit4f4a84ec801ea0d62d32a1b5679def1e16d3f813 (patch)
tree86e671367bcef6d2b42e0a3ae0e1a83c32659f50
parentbeb9f7453ae9a4473cf43a16c186a090d77c4b3b (diff)
downloademacs-4f4a84ec801ea0d62d32a1b5679def1e16d3f813.tar.gz
emacs-4f4a84ec801ea0d62d32a1b5679def1e16d3f813.zip
Add new `input-decode-map' keymap and use it for temrinal
escape sequences. * keyboard.h (struct kboard): Add Vinput_decode_map. Remove Vlocal_key_translation_map. * keyboard.c (read_key_sequence): Add support for input-decode-map. (init_kboard): Init input-decode-map. Replace local-key-translation-map back with key-translation-map. (syms_of_keyboard): Declare input-decode-map. Remove local-key-translation-map. Update docstrings. (mark_kboards): Mark Vinput_decode_map. Don't mark Vlocal_key_translation_map. * keymap.c (Fdescribe_buffer_bindings): Describe input-decode-map. Replace local-key-translation-map back with key-translation-map. * term.c (term_get_fkeys_1, CONDITIONAL_REASSIGN): Bind in input-decode-map rather than function-key-map.
-rw-r--r--doc/emacs/custom.texi3
-rw-r--r--doc/lispref/keymaps.texi69
-rw-r--r--doc/lispref/maps.texi7
-rw-r--r--doc/lispref/os.texi2
-rw-r--r--doc/misc/viper.texi10
-rw-r--r--etc/NEWS12
-rw-r--r--src/ChangeLog16
-rw-r--r--src/keyboard.c146
-rw-r--r--src/keyboard.h15
-rw-r--r--src/keymap.c9
-rw-r--r--src/term.c20
11 files changed, 195 insertions, 114 deletions
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index d496ab84b19..1276c45af70 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -2419,7 +2419,8 @@ kept.@refill
2419 2419
2420 The usual purpose of the terminal-specific library is to map the 2420 The usual purpose of the terminal-specific library is to map the
2421escape sequences used by the terminal's function keys onto more 2421escape sequences used by the terminal's function keys onto more
2422meaningful names, using @code{function-key-map}. See the file 2422meaningful names, using @code{input-decode-map} (or
2423@code{function-key-map} before it). See the file
2423@file{term/lk201.el} for an example of how this is done. Many function 2424@file{term/lk201.el} for an example of how this is done. Many function
2424keys are mapped automatically according to the information in the 2425keys are mapped automatically according to the information in the
2425Termcap data base; the terminal-specific library needs to map only the 2426Termcap data base; the terminal-specific library needs to map only the
diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi
index eb10dfcbce3..2bd0de60f58 100644
--- a/doc/lispref/keymaps.texi
+++ b/doc/lispref/keymaps.texi
@@ -1512,17 +1512,18 @@ specifies a list of keymaps to search in. This argument is ignored if
1512 This section describes keymaps that are used during reading a key 1512 This section describes keymaps that are used during reading a key
1513sequence, to translate certain event sequences into others. 1513sequence, to translate certain event sequences into others.
1514@code{read-key-sequence} checks every subsequence of the key sequence 1514@code{read-key-sequence} checks every subsequence of the key sequence
1515being read, as it is read, against @code{function-key-map} and then 1515being read, as it is read, against @code{input-decode-map}, then
1516against @code{key-translation-map}. 1516@code{function-key-map}, and then against @code{key-translation-map}.
1517
1518@defvar input-decode-map
1517 1519
1518@defvar function-key-map
1519This variable holds a keymap that describes the character sequences sent 1520This variable holds a keymap that describes the character sequences sent
1520by function keys on an ordinary character terminal. This keymap has the 1521by function keys on an ordinary character terminal. This keymap has the
1521same structure as other keymaps, but is used differently: it specifies 1522same structure as other keymaps, but is used differently: it specifies
1522translations to make while reading key sequences, rather than bindings 1523translations to make while reading key sequences, rather than bindings
1523for key sequences. 1524for key sequences.
1524 1525
1525If @code{function-key-map} ``binds'' a key sequence @var{k} to a vector 1526If @code{input-decode-map} ``binds'' a key sequence @var{k} to a vector
1526@var{v}, then when @var{k} appears as a subsequence @emph{anywhere} in a 1527@var{v}, then when @var{k} appears as a subsequence @emph{anywhere} in a
1527key sequence, it is replaced with the events in @var{v}. 1528key sequence, it is replaced with the events in @var{v}.
1528 1529
@@ -1530,50 +1531,49 @@ For example, VT100 terminals send @kbd{@key{ESC} O P} when the
1530keypad @key{PF1} key is pressed. Therefore, we want Emacs to translate 1531keypad @key{PF1} key is pressed. Therefore, we want Emacs to translate
1531that sequence of events into the single event @code{pf1}. We accomplish 1532that sequence of events into the single event @code{pf1}. We accomplish
1532this by ``binding'' @kbd{@key{ESC} O P} to @code{[pf1]} in 1533this by ``binding'' @kbd{@key{ESC} O P} to @code{[pf1]} in
1533@code{function-key-map}, when using a VT100. 1534@code{input-decode-map}, when using a VT100.
1534 1535
1535Thus, typing @kbd{C-c @key{PF1}} sends the character sequence @kbd{C-c 1536Thus, typing @kbd{C-c @key{PF1}} sends the character sequence @kbd{C-c
1536@key{ESC} O P}; later the function @code{read-key-sequence} translates 1537@key{ESC} O P}; later the function @code{read-key-sequence} translates
1537this back into @kbd{C-c @key{PF1}}, which it returns as the vector 1538this back into @kbd{C-c @key{PF1}}, which it returns as the vector
1538@code{[?\C-c pf1]}. 1539@code{[?\C-c pf1]}.
1539 1540
1540Entries in @code{function-key-map} are ignored if they conflict with 1541The value of @code{input-decode-map} is usually set up automatically
1541bindings made in the minor mode, local, or global keymaps. The intent
1542is that the character sequences that function keys send should not have
1543command bindings in their own right---but if they do, the ordinary
1544bindings take priority.
1545
1546The value of @code{function-key-map} is usually set up automatically
1547according to the terminal's Terminfo or Termcap entry, but sometimes 1542according to the terminal's Terminfo or Termcap entry, but sometimes
1548those need help from terminal-specific Lisp files. Emacs comes with 1543those need help from terminal-specific Lisp files. Emacs comes with
1549terminal-specific files for many common terminals; their main purpose is 1544terminal-specific files for many common terminals; their main purpose is
1550to make entries in @code{function-key-map} beyond those that can be 1545to make entries in @code{input-decode-map} beyond those that can be
1551deduced from Termcap and Terminfo. @xref{Terminal-Specific}. 1546deduced from Termcap and Terminfo. @xref{Terminal-Specific}.
1552@end defvar 1547@end defvar
1553 1548
1554@defvar key-translation-map 1549@defvar function-key-map
1555This variable is another keymap used just like @code{function-key-map}
1556to translate input events into other events. It differs from
1557@code{function-key-map} in two ways:
1558 1550
1559@itemize @bullet 1551This variable holds a keymap similar to @code{input-decode-map} except
1560@item 1552that it describes key sequences which should be translated to
1561@code{key-translation-map} goes to work after @code{function-key-map} is 1553alternative interpretations that are usually preferred. It applies
1562finished; it receives the results of translation by 1554after @code{input-decode-map} and before @code{key-translation-map}.
1563@code{function-key-map}.
1564 1555
1565@item 1556Entries in @code{function-key-map} are ignored if they conflict with
1566Non-prefix bindings in @code{key-translation-map} override actual key 1557bindings made in the minor mode, local, or global keymaps. I.e.
1567bindings. For example, if @kbd{C-x f} has a non-prefix binding in 1558the remapping only applies if the original key sequence would
1568@code{key-translation-map}, that translation takes effect even though 1559otherwise not have any binding.
1569@kbd{C-x f} also has a key binding in the global map. 1560@end defvar
1570@end itemize
1571 1561
1572Note however that actual key bindings can have an effect on 1562@defvar key-translation-map
1573@code{key-translation-map}, even though they are overridden by it. 1563This variable is another keymap used just like @code{input-decode-map}
1574Indeed, actual key bindings override @code{function-key-map} and thus 1564to translate input events into other events. It differs from
1575may alter the key sequence that @code{key-translation-map} receives. 1565@code{input-decode-map} in that it goes to work after
1576Clearly, it is better to avoid this type of situation. 1566@code{function-key-map} is finished rather than before; it receives
1567the results of translation by @code{function-key-map}.
1568
1569Just like @code{input-decode-map}, but unlike @code{function-key-map},
1570this keymap is applied regardless of whether the input key-sequence
1571has a normal binding. Note however that actual key bindings can have
1572an effect on @code{key-translation-map}, even though they are
1573overridden by it. Indeed, actual key bindings override
1574@code{function-key-map} and thus may alter the key sequence that
1575@code{key-translation-map} receives. Clearly, it is better to avoid
1576this type of situation.
1577 1577
1578The intent of @code{key-translation-map} is for users to map one 1578The intent of @code{key-translation-map} is for users to map one
1579character set to another, including ordinary characters normally bound 1579character set to another, including ordinary characters normally bound
@@ -1581,7 +1581,8 @@ to @code{self-insert-command}.
1581@end defvar 1581@end defvar
1582 1582
1583@cindex key translation function 1583@cindex key translation function
1584You can use @code{function-key-map} or @code{key-translation-map} for 1584You can use @code{input-decode-map}, @code{function-key-map}, or
1585@code{key-translation-map} for
1585more than simple aliases, by using a function, instead of a key 1586more than simple aliases, by using a function, instead of a key
1586sequence, as the ``translation'' of a key. Then this function is called 1587sequence, as the ``translation'' of a key. Then this function is called
1587to compute the translation of that key. 1588to compute the translation of that key.
diff --git a/doc/lispref/maps.texi b/doc/lispref/maps.texi
index 5a5745b1b51..2e370f91238 100644
--- a/doc/lispref/maps.texi
+++ b/doc/lispref/maps.texi
@@ -113,7 +113,7 @@ The sparse keymap that displays the Special Props submenu of the Text
113Properties menu. 113Properties menu.
114 114
115@item function-key-map 115@item function-key-map
116The keymap for translating keypad and function keys.@* 116The keymap for translating key sequences to preferred alternatives.@*
117If there are none, then it contains an empty sparse keymap. 117If there are none, then it contains an empty sparse keymap.
118@xref{Translation Keymaps}. 118@xref{Translation Keymaps}.
119 119
@@ -151,6 +151,11 @@ A sparse keymap used by the @kbd{e} command of Info.
151@vindex Info-mode-map 151@vindex Info-mode-map
152A sparse keymap containing Info commands. 152A sparse keymap containing Info commands.
153 153
154@item input-decode-map
155The keymap for translating keypad and function keys.@*
156If there are none, then it contains an empty sparse keymap.
157@xref{Translation Keymaps}.
158
154@item isearch-mode-map 159@item isearch-mode-map
155@vindex isearch-mode-map 160@vindex isearch-mode-map
156A keymap that defines the characters you can type within incremental 161A keymap that defines the characters you can type within incremental
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 89b44a99353..68fba8d9774 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -279,7 +279,7 @@ trying the @samp{.elc} and @samp{.el} suffixes.
279@cindex Termcap 279@cindex Termcap
280 The usual function of a terminal-specific library is to enable 280 The usual function of a terminal-specific library is to enable
281special keys to send sequences that Emacs can recognize. It may also 281special keys to send sequences that Emacs can recognize. It may also
282need to set or add to @code{function-key-map} if the Termcap or 282need to set or add to @code{input-decode-map} if the Termcap or
283Terminfo entry does not specify all the terminal's function keys. 283Terminfo entry does not specify all the terminal's function keys.
284@xref{Terminal Input}. 284@xref{Terminal Input}.
285 285
diff --git a/doc/misc/viper.texi b/doc/misc/viper.texi
index 4e9eaaff40e..c86b2383168 100644
--- a/doc/misc/viper.texi
+++ b/doc/misc/viper.texi
@@ -1745,7 +1745,8 @@ Setting this variable too high may slow down your typing. Setting it too
1745low may make it hard to type macros quickly enough. 1745low may make it hard to type macros quickly enough.
1746@item viper-translate-all-ESC-keysequences @code{t} on tty, @code{nil} on windowing display 1746@item viper-translate-all-ESC-keysequences @code{t} on tty, @code{nil} on windowing display
1747Normally, Viper lets Emacs translate only those ESC key sequences that are 1747Normally, Viper lets Emacs translate only those ESC key sequences that are
1748defined in the low-level key-translation-map or function-key-map, such as those 1748defined in the low-level @code{input-decode-map}, @code{key-translation-map}
1749or @code{function-key-map}, such as those
1749emitted by the arrow and function keys. Other sequences, e.g., @kbd{\\e/}, are 1750emitted by the arrow and function keys. Other sequences, e.g., @kbd{\\e/}, are
1750treated as @kbd{ESC} command followed by a @kbd{/}. This is good for people 1751treated as @kbd{ESC} command followed by a @kbd{/}. This is good for people
1751who type fast and tend to hit other characters right after they hit 1752who type fast and tend to hit other characters right after they hit
@@ -2009,12 +2010,12 @@ not emit the right signals for Emacs to understand. To let Emacs know about
2009those keys, you will have to find out which key sequences they emit 2010those keys, you will have to find out which key sequences they emit
2010by typing @kbd{C-q} and then the key (you should switch to Emacs state 2011by typing @kbd{C-q} and then the key (you should switch to Emacs state
2011first). Then you can bind those sequences to their preferred forms using 2012first). Then you can bind those sequences to their preferred forms using
2012@code{function-key-map} as follows: 2013@code{input-decode-map} as follows:
2013 2014
2014@lisp 2015@lisp
2015(cond ((string= (getenv "TERM") "xterm") 2016(cond ((string= (getenv "TERM") "xterm")
2016(define-key function-key-map "\e[192z" [f11]) ; L1 2017(define-key input-decode-map "\e[192z" [f11]) ; L1
2017(define-key function-key-map "\e[195z" [f14]) ; L4, Undo 2018(define-key input-decode-map "\e[195z" [f14]) ; L4, Undo
2018@end lisp 2019@end lisp
2019 2020
2020The above illustrates how to do this for Xterm. On VT100, you would have to 2021The above illustrates how to do this for Xterm. On VT100, you would have to
@@ -2206,6 +2207,7 @@ So much about Viper-specific bindings.
2206Manual}, and the Emacs quick reference card for the general info on key 2207Manual}, and the Emacs quick reference card for the general info on key
2207bindings in Emacs. 2208bindings in Emacs.
2208 2209
2210@vindex @code{input-decode-map}
2209@vindex @code{function-key-map} 2211@vindex @code{function-key-map}
2210@vindex @code{viper-vi-global-user-map} 2212@vindex @code{viper-vi-global-user-map}
2211@vindex @code{viper-insert-global-user-map} 2213@vindex @code{viper-insert-global-user-map}
diff --git a/etc/NEWS b/etc/NEWS
index 5adc1bb886b..b2e185b6e63 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -257,6 +257,11 @@ supported on other platforms, but not on Windows due to using the winsock
257 257
258* Lisp Changes in Emacs 23.1 258* Lisp Changes in Emacs 23.1
259 259
260** New keymap `input-decode-map' overrides like key-translation-map, but
261applies before function-key-map. Also it is terminal-local contrary to
262key-translation-map. Terminal-specific key-sequences are generally added to
263this map rather than to function-key-map now.
264
260** Changes related to multiple tty support. 265** Changes related to multiple tty support.
261 266
262*** $TERM is now set to `dumb' for subprocesses. If you want to know the 267*** $TERM is now set to `dumb' for subprocesses. If you want to know the
@@ -289,11 +294,8 @@ being suspended/resumed as a parameter.
289 294
290*** New functions: `environment', `let-environment'. 295*** New functions: `environment', `let-environment'.
291 296
292*** New variables: `local-key-translation-map', `local-function-key-map'. 297*** New variable: `local-function-key-map'.
293These are in addition to the global key-translation-map and 298This in addition to the global function-key-map variable that already existed.
294function-key-map variables that already existed.
295
296??? How do the new variables relate to the old ones?
297 299
298*** `initial-environment' holds the environment inherited from Emacs's parent. 300*** `initial-environment' holds the environment inherited from Emacs's parent.
299 301
diff --git a/src/ChangeLog b/src/ChangeLog
index 9e1ef4b06f8..6374b29aedc 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,21 @@
12007-10-09 Stefan Monnier <monnier@iro.umontreal.ca> 12007-10-09 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 Add new `input-decode-map' keymap and use it for temrinal
4 escape sequences.
5 * keyboard.h (struct kboard): Add Vinput_decode_map.
6 Remove Vlocal_key_translation_map.
7 * keyboard.c (read_key_sequence): Add support for input-decode-map.
8 (init_kboard): Init input-decode-map.
9 Replace local-key-translation-map back with key-translation-map.
10 (syms_of_keyboard): Declare input-decode-map.
11 Remove local-key-translation-map. Update docstrings.
12 (mark_kboards): Mark Vinput_decode_map.
13 Don't mark Vlocal_key_translation_map.
14 * keymap.c (Fdescribe_buffer_bindings): Describe input-decode-map.
15 Replace local-key-translation-map back with key-translation-map.
16 * term.c (term_get_fkeys_1, CONDITIONAL_REASSIGN):
17 Bind in input-decode-map rather than function-key-map.
18
3 * lisp.h (XSETPSEUDOVECTOR): Don't set the tag anymore. 19 * lisp.h (XSETPSEUDOVECTOR): Don't set the tag anymore.
4 This was made redundant by the previous introduction of XSETPVECTYPE. 20 This was made redundant by the previous introduction of XSETPVECTYPE.
5 21
diff --git a/src/keyboard.c b/src/keyboard.c
index 0e9dfee877f..9068f944664 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -445,7 +445,7 @@ Lisp_Object Qcommand_hook_internal, Vcommand_hook_internal;
445/* Parent keymap of terminal-local function-key-map instances. */ 445/* Parent keymap of terminal-local function-key-map instances. */
446Lisp_Object Vfunction_key_map; 446Lisp_Object Vfunction_key_map;
447 447
448/* Parent keymap of terminal-local key-translation-map instances. */ 448/* Keymap of key translations that can override keymaps. */
449Lisp_Object Vkey_translation_map; 449Lisp_Object Vkey_translation_map;
450 450
451/* List of deferred actions to be performed at a later time. 451/* List of deferred actions to be performed at a later time.
@@ -9131,8 +9131,8 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9131 key's again in Vfunction_key_map. */ 9131 key's again in Vfunction_key_map. */
9132 volatile keyremap fkey; 9132 volatile keyremap fkey;
9133 9133
9134 /* Likewise, for key_translation_map. */ 9134 /* Likewise, for key_translation_map and input-decode-map. */
9135 volatile keyremap keytran; 9135 volatile keyremap keytran, indec;
9136 9136
9137 /* If we receive a `switch-frame' or `select-window' event in the middle of 9137 /* If we receive a `switch-frame' or `select-window' event in the middle of
9138 a key sequence, we put it off for later. 9138 a key sequence, we put it off for later.
@@ -9209,8 +9209,10 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9209 9209
9210 /* We may switch keyboards between rescans, so we need to 9210 /* We may switch keyboards between rescans, so we need to
9211 reinitialize fkey and keytran before each replay. */ 9211 reinitialize fkey and keytran before each replay. */
9212 indec.map = indec.parent = current_kboard->Vinput_decode_map;
9212 fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map; 9213 fkey.map = fkey.parent = current_kboard->Vlocal_function_key_map;
9213 keytran.map = keytran.parent = current_kboard->Vlocal_key_translation_map; 9214 keytran.map = keytran.parent = Vkey_translation_map;
9215 indec.start = indec.end = 0;
9214 fkey.start = fkey.end = 0; 9216 fkey.start = fkey.end = 0;
9215 keytran.start = keytran.end = 0; 9217 keytran.start = keytran.end = 0;
9216 9218
@@ -9299,7 +9301,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9299 Thus, if ESC O a has a function-key-map translation 9301 Thus, if ESC O a has a function-key-map translation
9300 and ESC o has a binding, don't return after ESC O, 9302 and ESC o has a binding, don't return after ESC O,
9301 so that we can translate ESC O plus the next character. */ 9303 so that we can translate ESC O plus the next character. */
9302 : (fkey.start < t || keytran.start < t)) 9304 : (/* indec.start < t || fkey.start < t || */ keytran.start < t))
9303 { 9305 {
9304 Lisp_Object key; 9306 Lisp_Object key;
9305 int used_mouse_menu = 0; 9307 int used_mouse_menu = 0;
@@ -9317,13 +9319,17 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9317 just one key. */ 9319 just one key. */
9318 volatile int echo_local_start, keys_local_start, local_first_binding; 9320 volatile int echo_local_start, keys_local_start, local_first_binding;
9319 9321
9320 eassert (fkey.end == t || (fkey.end > t && fkey.end <= mock_input)); 9322 eassert (indec.end == t || (indec.end > t && indec.end <= mock_input));
9323 eassert (indec.start <= indec.end);
9321 eassert (fkey.start <= fkey.end); 9324 eassert (fkey.start <= fkey.end);
9322 eassert (keytran.start <= keytran.end); 9325 eassert (keytran.start <= keytran.end);
9323 /* key-translation-map is applied *after* function-key-map. */ 9326 /* key-translation-map is applied *after* function-key-map
9327 which is itself applied *after* input-decode-map. */
9328 eassert (fkey.end <= indec.start);
9324 eassert (keytran.end <= fkey.start); 9329 eassert (keytran.end <= fkey.start);
9325 9330
9326 if (first_unbound < fkey.start && first_unbound < keytran.start) 9331 if (/* first_unbound < indec.start && first_unbound < fkey.start && */
9332 first_unbound < keytran.start)
9327 { /* The prefix upto first_unbound has no binding and has 9333 { /* The prefix upto first_unbound has no binding and has
9328 no translation left to do either, so we know it's unbound. 9334 no translation left to do either, so we know it's unbound.
9329 If we don't stop now, we risk staying here indefinitely 9335 If we don't stop now, we risk staying here indefinitely
@@ -9333,6 +9339,8 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9333 for (i = first_unbound + 1; i < t; i++) 9339 for (i = first_unbound + 1; i < t; i++)
9334 keybuf[i - first_unbound - 1] = keybuf[i]; 9340 keybuf[i - first_unbound - 1] = keybuf[i];
9335 mock_input = t - first_unbound - 1; 9341 mock_input = t - first_unbound - 1;
9342 indec.end = indec.start -= first_unbound + 1;
9343 indec.map = indec.parent;
9336 fkey.end = fkey.start -= first_unbound + 1; 9344 fkey.end = fkey.start -= first_unbound + 1;
9337 fkey.map = fkey.parent; 9345 fkey.map = fkey.parent;
9338 keytran.end = keytran.start -= first_unbound + 1; 9346 keytran.end = keytran.start -= first_unbound + 1;
@@ -9758,15 +9766,15 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9758 /* This is needed for the following scenario: 9766 /* This is needed for the following scenario:
9759 event 0: a down-event that gets dropped by calling replay_key. 9767 event 0: a down-event that gets dropped by calling replay_key.
9760 event 1: some normal prefix like C-h. 9768 event 1: some normal prefix like C-h.
9761 After event 0, first_unbound is 0, after event 1 fkey.start 9769 After event 0, first_unbound is 0, after event 1 indec.start,
9762 and keytran.start are both 1, so when we see that C-h is bound, 9770 fkey.start, and keytran.start are all 1, so when we see that
9763 we need to update first_unbound. */ 9771 C-h is bound, we need to update first_unbound. */
9764 first_unbound = max (t + 1, first_unbound); 9772 first_unbound = max (t + 1, first_unbound);
9765 else 9773 else
9766 { 9774 {
9767 Lisp_Object head; 9775 Lisp_Object head;
9768 9776
9769 /* Remember the position to put an upper bound on fkey.start. */ 9777 /* Remember the position to put an upper bound on indec.start. */
9770 first_unbound = min (t, first_unbound); 9778 first_unbound = min (t, first_unbound);
9771 9779
9772 head = EVENT_HEAD (key); 9780 head = EVENT_HEAD (key);
@@ -9851,21 +9859,27 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9851 /* If mock_input > t + 1, the above simplification 9859 /* If mock_input > t + 1, the above simplification
9852 will actually end up dropping keys on the floor. 9860 will actually end up dropping keys on the floor.
9853 This is probably OK for now, but even 9861 This is probably OK for now, but even
9854 if mock_input <= t + 1, we need to adjust fkey 9862 if mock_input <= t + 1, we need to adjust indec,
9855 and keytran. 9863 fkey, and keytran.
9856 Typical case [header-line down-mouse-N]: 9864 Typical case [header-line down-mouse-N]:
9857 mock_input = 2, t = 1, fkey.end = 1, 9865 mock_input = 2, t = 1, fkey.end = 1,
9858 last_real_key_start = 0. */ 9866 last_real_key_start = 0. */
9859 if (fkey.end > last_real_key_start) 9867 if (indec.end > last_real_key_start)
9860 { 9868 {
9861 fkey.end = fkey.start 9869 indec.end = indec.start
9862 = min (last_real_key_start, fkey.start); 9870 = min (last_real_key_start, indec.start);
9863 fkey.map = fkey.parent; 9871 indec.map = indec.parent;
9864 if (keytran.end > last_real_key_start) 9872 if (fkey.end > last_real_key_start)
9865 { 9873 {
9866 keytran.end = keytran.start 9874 fkey.end = fkey.start
9867 = min (last_real_key_start, keytran.start); 9875 = min (last_real_key_start, fkey.start);
9868 keytran.map = keytran.parent; 9876 fkey.map = fkey.parent;
9877 if (keytran.end > last_real_key_start)
9878 {
9879 keytran.end = keytran.start
9880 = min (last_real_key_start, keytran.start);
9881 keytran.map = keytran.parent;
9882 }
9869 } 9883 }
9870 } 9884 }
9871 if (t == last_real_key_start) 9885 if (t == last_real_key_start)
@@ -9919,8 +9933,28 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9919 /* Record what part of this_command_keys is the current key sequence. */ 9933 /* Record what part of this_command_keys is the current key sequence. */
9920 this_single_command_key_start = this_command_key_count - t; 9934 this_single_command_key_start = this_command_key_count - t;
9921 9935
9922 if (first_binding < nmaps && NILP (submaps[first_binding])) 9936 /* Look for this sequence in input-decode-map.
9937 Scan from indec.end until we find a bound suffix. */
9938 while (indec.end < t)
9939 {
9940 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
9941 int done, diff;
9942
9943 GCPRO4 (indec.map, fkey.map, keytran.map, delayed_switch_frame);
9944 done = keyremap_step (keybuf, bufsize, &indec, max (t, mock_input),
9945 1, &diff, prompt);
9946 UNGCPRO;
9947 if (done)
9948 {
9949 mock_input = diff + max (t, mock_input);
9950 goto replay_sequence;
9951 }
9952 }
9953
9954 if (first_binding < nmaps && NILP (submaps[first_binding])
9955 && indec.start >= t)
9923 /* There is a binding and it's not a prefix. 9956 /* There is a binding and it's not a prefix.
9957 (and it doesn't have any input-decode-map translation pending).
9924 There is thus no function-key in this sequence. 9958 There is thus no function-key in this sequence.
9925 Moving fkey.start is important in this case to allow keytran.start 9959 Moving fkey.start is important in this case to allow keytran.start
9926 to go over the sequence before we return (since we keep the 9960 to go over the sequence before we return (since we keep the
@@ -9933,12 +9967,12 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9933 /* If the sequence is unbound, see if we can hang a function key 9967 /* If the sequence is unbound, see if we can hang a function key
9934 off the end of it. */ 9968 off the end of it. */
9935 /* Continue scan from fkey.end until we find a bound suffix. */ 9969 /* Continue scan from fkey.end until we find a bound suffix. */
9936 while (fkey.end < t) 9970 while (fkey.end < indec.start)
9937 { 9971 {
9938 struct gcpro gcpro1, gcpro2, gcpro3; 9972 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
9939 int done, diff; 9973 int done, diff;
9940 9974
9941 GCPRO3 (fkey.map, keytran.map, delayed_switch_frame); 9975 GCPRO4 (indec.map, fkey.map, keytran.map, delayed_switch_frame);
9942 done = keyremap_step (keybuf, bufsize, &fkey, 9976 done = keyremap_step (keybuf, bufsize, &fkey,
9943 max (t, mock_input), 9977 max (t, mock_input),
9944 /* If there's a binding (i.e. 9978 /* If there's a binding (i.e.
@@ -9950,6 +9984,10 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9950 if (done) 9984 if (done)
9951 { 9985 {
9952 mock_input = diff + max (t, mock_input); 9986 mock_input = diff + max (t, mock_input);
9987 /* Adjust the input-decode-map counters. */
9988 indec.end += diff;
9989 indec.start += diff;
9990
9953 goto replay_sequence; 9991 goto replay_sequence;
9954 } 9992 }
9955 } 9993 }
@@ -9958,17 +9996,19 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9958 Scan from keytran.end until we find a bound suffix. */ 9996 Scan from keytran.end until we find a bound suffix. */
9959 while (keytran.end < fkey.start) 9997 while (keytran.end < fkey.start)
9960 { 9998 {
9961 struct gcpro gcpro1, gcpro2, gcpro3; 9999 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
9962 int done, diff; 10000 int done, diff;
9963 10001
9964 GCPRO3 (fkey.map, keytran.map, delayed_switch_frame); 10002 GCPRO4 (indec.map, fkey.map, keytran.map, delayed_switch_frame);
9965 done = keyremap_step (keybuf, bufsize, &keytran, max (t, mock_input), 10003 done = keyremap_step (keybuf, bufsize, &keytran, max (t, mock_input),
9966 1, &diff, prompt); 10004 1, &diff, prompt);
9967 UNGCPRO; 10005 UNGCPRO;
9968 if (done) 10006 if (done)
9969 { 10007 {
9970 mock_input = diff + max (t, mock_input); 10008 mock_input = diff + max (t, mock_input);
9971 /* Adjust the function-key-map counters. */ 10009 /* Adjust the function-key-map and input-decode-map counters. */
10010 indec.end += diff;
10011 indec.start += diff;
9972 fkey.end += diff; 10012 fkey.end += diff;
9973 fkey.start += diff; 10013 fkey.start += diff;
9974 10014
@@ -9981,7 +10021,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
9981 and is an upper case letter 10021 and is an upper case letter
9982 use the corresponding lower-case letter instead. */ 10022 use the corresponding lower-case letter instead. */
9983 if (first_binding >= nmaps 10023 if (first_binding >= nmaps
9984 && fkey.start >= t && keytran.start >= t 10024 && /* indec.start >= t && fkey.start >= t && */ keytran.start >= t
9985 && INTEGERP (key) 10025 && INTEGERP (key)
9986 && ((((XINT (key) & 0x3ffff) 10026 && ((((XINT (key) & 0x3ffff)
9987 < XCHAR_TABLE (current_buffer->downcase_table)->size) 10027 < XCHAR_TABLE (current_buffer->downcase_table)->size)
@@ -10012,7 +10052,7 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
10012 and is a shifted function key, 10052 and is a shifted function key,
10013 use the corresponding unshifted function key instead. */ 10053 use the corresponding unshifted function key instead. */
10014 if (first_binding >= nmaps 10054 if (first_binding >= nmaps
10015 && fkey.start >= t && keytran.start >= t 10055 && /* indec.start >= t && fkey.start >= t && */ keytran.start >= t
10016 && SYMBOLP (key)) 10056 && SYMBOLP (key))
10017 { 10057 {
10018 Lisp_Object breakdown; 10058 Lisp_Object breakdown;
@@ -10033,9 +10073,6 @@ read_key_sequence (keybuf, bufsize, prompt, dont_downcase_last,
10033 10073
10034 keybuf[t - 1] = new_key; 10074 keybuf[t - 1] = new_key;
10035 mock_input = max (t, mock_input); 10075 mock_input = max (t, mock_input);
10036 fkey.start = fkey.end = 0;
10037 keytran.start = keytran.end = 0;
10038
10039 goto replay_sequence; 10076 goto replay_sequence;
10040 } 10077 }
10041 } 10078 }
@@ -11460,10 +11497,9 @@ init_kboard (kb)
11460 kb->reference_count = 0; 11497 kb->reference_count = 0;
11461 kb->Vsystem_key_alist = Qnil; 11498 kb->Vsystem_key_alist = Qnil;
11462 kb->system_key_syms = Qnil; 11499 kb->system_key_syms = Qnil;
11500 kb->Vinput_decode_map = Fmake_sparse_keymap (Qnil);
11463 kb->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil); 11501 kb->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil);
11464 Fset_keymap_parent (kb->Vlocal_function_key_map, Vfunction_key_map); 11502 Fset_keymap_parent (kb->Vlocal_function_key_map, Vfunction_key_map);
11465 kb->Vlocal_key_translation_map = Fmake_sparse_keymap (Qnil);
11466 Fset_keymap_parent (kb->Vlocal_key_translation_map, Vkey_translation_map);
11467 kb->Vdefault_minibuffer_frame = Qnil; 11503 kb->Vdefault_minibuffer_frame = Qnil;
11468} 11504}
11469 11505
@@ -12196,8 +12232,8 @@ See Info node `(elisp)Multiple displays'. */);
12196 12232
12197 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map, 12233 DEFVAR_KBOARD ("local-function-key-map", Vlocal_function_key_map,
12198 doc: /* Keymap that translates key sequences to key sequences during input. 12234 doc: /* Keymap that translates key sequences to key sequences during input.
12199This is used mainly for mapping ASCII function key sequences into 12235This is used mainly for mapping key sequences into some preferred
12200real Emacs function key events (symbols). 12236key events (symbols).
12201 12237
12202The `read-key-sequence' function replaces any subsequence bound by 12238The `read-key-sequence' function replaces any subsequence bound by
12203`local-function-key-map' with its binding. More precisely, when the 12239`local-function-key-map' with its binding. More precisely, when the
@@ -12223,6 +12259,25 @@ define a binding on all terminals, change `function-key-map'
12223instead. Initially, `local-function-key-map' is an empty keymap that 12259instead. Initially, `local-function-key-map' is an empty keymap that
12224has `function-key-map' as its parent on all terminal devices. */); 12260has `function-key-map' as its parent on all terminal devices. */);
12225 12261
12262 DEFVAR_KBOARD ("input-decode-map", Vinput_decode_map,
12263 doc: /* Keymap that decodes input escape sequences.
12264This is used mainly for mapping ASCII function key sequences into
12265real Emacs function key events (symbols).
12266
12267The `read-key-sequence' function replaces any subsequence bound by
12268`local-function-key-map' with its binding. Contrary to `function-key-map',
12269this map applies its rebinding regardless of the presence of an ordinary
12270binding. So it is more like `key-translation-map' except that it applies
12271before `function-key-map' rather than after.
12272
12273If the binding is a function, it is called with one argument (the prompt)
12274and its return value (a key sequence) is used.
12275
12276The events that come from bindings in `input-decode-map' are not
12277themselves looked up in `input-decode-map'.
12278
12279This variable is keyboard-local. */);
12280
12226 DEFVAR_LISP ("function-key-map", &Vfunction_key_map, 12281 DEFVAR_LISP ("function-key-map", &Vfunction_key_map,
12227 doc: /* The parent keymap of all `local-function-key-map' instances. 12282 doc: /* The parent keymap of all `local-function-key-map' instances.
12228Function key definitions that apply to all terminal devices should go 12283Function key definitions that apply to all terminal devices should go
@@ -12231,18 +12286,11 @@ here. If a mapping is defined in both the current
12231definition will take precendence. */); 12286definition will take precendence. */);
12232 Vfunction_key_map = Fmake_sparse_keymap (Qnil); 12287 Vfunction_key_map = Fmake_sparse_keymap (Qnil);
12233 12288
12234 DEFVAR_KBOARD ("local-key-translation-map", Vlocal_key_translation_map, 12289 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
12235 doc: /* Keymap of key translations that can override keymaps. 12290 doc: /* Keymap of key translations that can override keymaps.
12236This keymap works like `function-key-map', but comes after that, 12291This keymap works like `function-key-map', but comes after that,
12237and its non-prefix bindings override ordinary bindings. 12292and its non-prefix bindings override ordinary bindings.
12238 12293Another difference is that it is global rather than keyboard-local. */);
12239`key-translation-map' has a separate binding for each terminal device.
12240(See Info node `(elisp)Multiple displays'.) If you need to set a key
12241translation on all terminals, change `global-key-translation-map' instead. */);
12242
12243 DEFVAR_LISP ("key-translation-map", &Vkey_translation_map,
12244 doc: /* The parent keymap of all `local-key-translation-map' instances.
12245Key translations that apply to all terminal devices should go here. */);
12246 Vkey_translation_map = Fmake_sparse_keymap (Qnil); 12294 Vkey_translation_map = Fmake_sparse_keymap (Qnil);
12247 12295
12248 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list, 12296 DEFVAR_LISP ("deferred-action-list", &Vdeferred_action_list,
@@ -12420,8 +12468,8 @@ mark_kboards ()
12420 mark_object (kb->Vlast_kbd_macro); 12468 mark_object (kb->Vlast_kbd_macro);
12421 mark_object (kb->Vsystem_key_alist); 12469 mark_object (kb->Vsystem_key_alist);
12422 mark_object (kb->system_key_syms); 12470 mark_object (kb->system_key_syms);
12471 mark_object (kb->Vinput_decode_map);
12423 mark_object (kb->Vlocal_function_key_map); 12472 mark_object (kb->Vlocal_function_key_map);
12424 mark_object (kb->Vlocal_key_translation_map);
12425 mark_object (kb->Vdefault_minibuffer_frame); 12473 mark_object (kb->Vdefault_minibuffer_frame);
12426 mark_object (kb->echo_string); 12474 mark_object (kb->echo_string);
12427 } 12475 }
diff --git a/src/keyboard.h b/src/keyboard.h
index a65bf8cfa02..2e50c4c5f1f 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -127,14 +127,15 @@ struct kboard
127 /* Cache for modify_event_symbol. */ 127 /* Cache for modify_event_symbol. */
128 Lisp_Object system_key_syms; 128 Lisp_Object system_key_syms;
129 129
130 /* Keymap mapping ASCII function key sequences onto their 130 /* Keymap mapping keys to alternative preferred forms.
131 preferred forms. Initialized by the terminal-specific lisp 131 See the DEFVAR for more documentation. */
132 files. See the DEFVAR for more documentation. */
133 Lisp_Object Vlocal_function_key_map; 132 Lisp_Object Vlocal_function_key_map;
134 133
135 /* Keymap of key translations that can override keymaps. */ 134 /* Keymap mapping ASCII function key sequences onto their preferred
136 Lisp_Object Vlocal_key_translation_map; 135 forms. Initialized by the terminal-specific lisp files. See the
137 136 DEFVAR for more documentation. */
137 Lisp_Object Vinput_decode_map;
138
138 /* Minibufferless frames on this display use this frame's minibuffer. */ 139 /* Minibufferless frames on this display use this frame's minibuffer. */
139 Lisp_Object Vdefault_minibuffer_frame; 140 Lisp_Object Vdefault_minibuffer_frame;
140 141
@@ -314,7 +315,7 @@ extern Lisp_Object read_char P_ ((int, int, Lisp_Object *, Lisp_Object,
314/* Parent keymap of terminal-local function-key-map instances. */ 315/* Parent keymap of terminal-local function-key-map instances. */
315extern Lisp_Object Vfunction_key_map; 316extern Lisp_Object Vfunction_key_map;
316 317
317/* Parent keymap of terminal-local key-translation-map instances. */ 318/* Keymap of key translations that can override keymaps. */
318extern Lisp_Object Vkey_translation_map; 319extern Lisp_Object Vkey_translation_map;
319 320
320extern int parse_menu_item P_ ((Lisp_Object, int, int)); 321extern int parse_menu_item P_ ((Lisp_Object, int, int));
diff --git a/src/keymap.c b/src/keymap.c
index 181d43a4f48..be23c20a3aa 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -3027,8 +3027,8 @@ You type Translation\n\
3027 insert ("\n", 1); 3027 insert ("\n", 1);
3028 } 3028 }
3029 3029
3030 if (!NILP (current_kboard->Vlocal_key_translation_map)) 3030 if (!NILP (Vkey_translation_map))
3031 describe_map_tree (current_kboard->Vlocal_key_translation_map, 0, Qnil, prefix, 3031 describe_map_tree (Vkey_translation_map, 0, Qnil, prefix,
3032 "Key translations", nomenu, 1, 0, 0); 3032 "Key translations", nomenu, 1, 0, 0);
3033 3033
3034 3034
@@ -3121,6 +3121,11 @@ You type Translation\n\
3121 describe_map_tree (current_kboard->Vlocal_function_key_map, 0, Qnil, prefix, 3121 describe_map_tree (current_kboard->Vlocal_function_key_map, 0, Qnil, prefix,
3122 "\f\nFunction key map translations", nomenu, 1, 0, 0); 3122 "\f\nFunction key map translations", nomenu, 1, 0, 0);
3123 3123
3124 /* Print the input-decode-map translations under this prefix. */
3125 if (!NILP (current_kboard->Vinput_decode_map))
3126 describe_map_tree (current_kboard->Vinput_decode_map, 0, Qnil, prefix,
3127 "\f\nInput decoding map translations", nomenu, 1, 0, 0);
3128
3124 UNGCPRO; 3129 UNGCPRO;
3125 return Qnil; 3130 return Qnil;
3126} 3131}
diff --git a/src/term.c b/src/term.c
index a6c69c71bef..b97e77b2320 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1274,9 +1274,9 @@ static char **term_get_fkeys_address;
1274static KBOARD *term_get_fkeys_kboard; 1274static KBOARD *term_get_fkeys_kboard;
1275static Lisp_Object term_get_fkeys_1 (); 1275static Lisp_Object term_get_fkeys_1 ();
1276 1276
1277/* Find the escape codes sent by the function keys for Vfunction_key_map. 1277/* Find the escape codes sent by the function keys for Vinput_decode_map.
1278 This function scans the termcap function key sequence entries, and 1278 This function scans the termcap function key sequence entries, and
1279 adds entries to Vfunction_key_map for each function key it finds. */ 1279 adds entries to Vinput_decode_map for each function key it finds. */
1280 1280
1281static void 1281static void
1282term_get_fkeys (address, kboard) 1282term_get_fkeys (address, kboard)
@@ -1306,14 +1306,14 @@ term_get_fkeys_1 ()
1306 KBOARD *kboard = term_get_fkeys_kboard; 1306 KBOARD *kboard = term_get_fkeys_kboard;
1307 1307
1308 /* This can happen if CANNOT_DUMP or with strange options. */ 1308 /* This can happen if CANNOT_DUMP or with strange options. */
1309 if (!initialized) 1309 if (!KEYMAPP (kboard->Vinput_decode_map))
1310 kboard->Vlocal_function_key_map = Fmake_sparse_keymap (Qnil); 1310 kboard->Vinput_decode_map = Fmake_sparse_keymap (Qnil);
1311 1311
1312 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++) 1312 for (i = 0; i < (sizeof (keys)/sizeof (keys[0])); i++)
1313 { 1313 {
1314 char *sequence = tgetstr (keys[i].cap, address); 1314 char *sequence = tgetstr (keys[i].cap, address);
1315 if (sequence) 1315 if (sequence)
1316 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence), 1316 Fdefine_key (kboard->Vinput_decode_map, build_string (sequence),
1317 Fmake_vector (make_number (1), 1317 Fmake_vector (make_number (1),
1318 intern (keys[i].name))); 1318 intern (keys[i].name)));
1319 } 1319 }
@@ -1333,13 +1333,13 @@ term_get_fkeys_1 ()
1333 if (k0) 1333 if (k0)
1334 /* Define f0 first, so that f10 takes precedence in case the 1334 /* Define f0 first, so that f10 takes precedence in case the
1335 key sequences happens to be the same. */ 1335 key sequences happens to be the same. */
1336 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k0), 1336 Fdefine_key (kboard->Vinput_decode_map, build_string (k0),
1337 Fmake_vector (make_number (1), intern ("f0"))); 1337 Fmake_vector (make_number (1), intern ("f0")));
1338 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k_semi), 1338 Fdefine_key (kboard->Vinput_decode_map, build_string (k_semi),
1339 Fmake_vector (make_number (1), intern ("f10"))); 1339 Fmake_vector (make_number (1), intern ("f10")));
1340 } 1340 }
1341 else if (k0) 1341 else if (k0)
1342 Fdefine_key (kboard->Vlocal_function_key_map, build_string (k0), 1342 Fdefine_key (kboard->Vinput_decode_map, build_string (k0),
1343 Fmake_vector (make_number (1), intern (k0_name))); 1343 Fmake_vector (make_number (1), intern (k0_name)));
1344 } 1344 }
1345 1345
@@ -1362,7 +1362,7 @@ term_get_fkeys_1 ()
1362 if (sequence) 1362 if (sequence)
1363 { 1363 {
1364 sprintf (fkey, "f%d", i); 1364 sprintf (fkey, "f%d", i);
1365 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence), 1365 Fdefine_key (kboard->Vinput_decode_map, build_string (sequence),
1366 Fmake_vector (make_number (1), 1366 Fmake_vector (make_number (1),
1367 intern (fkey))); 1367 intern (fkey)));
1368 } 1368 }
@@ -1379,7 +1379,7 @@ term_get_fkeys_1 ()
1379 { \ 1379 { \
1380 char *sequence = tgetstr (cap2, address); \ 1380 char *sequence = tgetstr (cap2, address); \
1381 if (sequence) \ 1381 if (sequence) \
1382 Fdefine_key (kboard->Vlocal_function_key_map, build_string (sequence), \ 1382 Fdefine_key (kboard->Vinput_decode_map, build_string (sequence), \
1383 Fmake_vector (make_number (1), \ 1383 Fmake_vector (make_number (1), \
1384 intern (sym))); \ 1384 intern (sym))); \
1385 } 1385 }