aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2006-07-31 18:37:18 +0000
committerRichard M. Stallman2006-07-31 18:37:18 +0000
commitf044bf27111d1a6000a0f6e987d8bdb10c4bbe9a (patch)
tree1fe2e75db2581d5f21e52d4963711bd684e1cff5
parent2410b13a189d3196e831bc0404394578575fe684 (diff)
downloademacs-f044bf27111d1a6000a0f6e987d8bdb10c4bbe9a.tar.gz
emacs-f044bf27111d1a6000a0f6e987d8bdb10c4bbe9a.zip
(Translation Keymaps): New node.
Update xrefs from Translating Input to Translation Keymaps.
-rw-r--r--lispref/keymaps.texi124
1 files changed, 122 insertions, 2 deletions
diff --git a/lispref/keymaps.texi b/lispref/keymaps.texi
index f93c94b8dfe..44b92ddfcb8 100644
--- a/lispref/keymaps.texi
+++ b/lispref/keymaps.texi
@@ -33,6 +33,7 @@ found. The whole process is called @dfn{key lookup}.
33* Functions for Key Lookup:: How to request key lookup. 33* Functions for Key Lookup:: How to request key lookup.
34* Changing Key Bindings:: Redefining a key in a keymap. 34* Changing Key Bindings:: Redefining a key in a keymap.
35* Remapping Commands:: Bindings that translate one command to another. 35* Remapping Commands:: Bindings that translate one command to another.
36* Translation Keymaps:: Keymaps for translating sequences of events.
36* Key Binding Commands:: Interactive interfaces for redefining keys. 37* Key Binding Commands:: Interactive interfaces for redefining keys.
37* Scanning Keymaps:: Looking through all keymaps, for printing help. 38* Scanning Keymaps:: Looking through all keymaps, for printing help.
38* Menu Keymaps:: Defining a menu as a keymap. 39* Menu Keymaps:: Defining a menu as a keymap.
@@ -642,7 +643,7 @@ only when the mode is used for the first time in a session.
642and exit commands. @xref{Intro to Minibuffers}. 643and exit commands. @xref{Intro to Minibuffers}.
643 644
644 Emacs has other keymaps that are used in a different way---translating 645 Emacs has other keymaps that are used in a different way---translating
645events within @code{read-key-sequence}. @xref{Translating Input}. 646events within @code{read-key-sequence}. @xref{Translation Keymaps}.
646 647
647 @xref{Standard Keymaps}, for a list of standard keymaps. 648 @xref{Standard Keymaps}, for a list of standard keymaps.
648 649
@@ -682,7 +683,7 @@ An error is signaled if @var{key} is not a string or a vector.
682@node Searching Keymaps 683@node Searching Keymaps
683@section Searching the Active Keymaps 684@section Searching the Active Keymaps
684 685
685 After translation of the input events (@pxref{Translating Input}) 686 After translation of event subsequences (@pxref{Translation Keymaps})
686Emacs looks for them in the active keymaps. Here is a pseudo-Lisp 687Emacs looks for them in the active keymaps. Here is a pseudo-Lisp
687description of the order in which the active keymaps are searched: 688description of the order in which the active keymaps are searched:
688 689
@@ -1472,6 +1473,125 @@ given the current active keymaps. If @var{command} is not remapped
1472@code{nil}. 1473@code{nil}.
1473@end defun 1474@end defun
1474 1475
1476@node Translation Keymaps
1477@section Keymaps for Translating Sequences of Events
1478
1479 This section describes keymaps that are used during reading a key
1480sequence, to translate certain event sequences into others.
1481@code{read-key-sequence} checks every subsequence of the key sequence
1482being read, as it is read, against @code{function-key-map} and then
1483against @code{key-translation-map}.
1484
1485@defvar function-key-map
1486This variable holds a keymap that describes the character sequences sent
1487by function keys on an ordinary character terminal. This keymap has the
1488same structure as other keymaps, but is used differently: it specifies
1489translations to make while reading key sequences, rather than bindings
1490for key sequences.
1491
1492If @code{function-key-map} ``binds'' a key sequence @var{k} to a vector
1493@var{v}, then when @var{k} appears as a subsequence @emph{anywhere} in a
1494key sequence, it is replaced with the events in @var{v}.
1495
1496For example, VT100 terminals send @kbd{@key{ESC} O P} when the
1497keypad @key{PF1} key is pressed. Therefore, we want Emacs to translate
1498that sequence of events into the single event @code{pf1}. We accomplish
1499this by ``binding'' @kbd{@key{ESC} O P} to @code{[pf1]} in
1500@code{function-key-map}, when using a VT100.
1501
1502Thus, typing @kbd{C-c @key{PF1}} sends the character sequence @kbd{C-c
1503@key{ESC} O P}; later the function @code{read-key-sequence} translates
1504this back into @kbd{C-c @key{PF1}}, which it returns as the vector
1505@code{[?\C-c pf1]}.
1506
1507Entries in @code{function-key-map} are ignored if they conflict with
1508bindings made in the minor mode, local, or global keymaps. The intent
1509is that the character sequences that function keys send should not have
1510command bindings in their own right---but if they do, the ordinary
1511bindings take priority.
1512
1513The value of @code{function-key-map} is usually set up automatically
1514according to the terminal's Terminfo or Termcap entry, but sometimes
1515those need help from terminal-specific Lisp files. Emacs comes with
1516terminal-specific files for many common terminals; their main purpose is
1517to make entries in @code{function-key-map} beyond those that can be
1518deduced from Termcap and Terminfo. @xref{Terminal-Specific}.
1519@end defvar
1520
1521@defvar key-translation-map
1522This variable is another keymap used just like @code{function-key-map}
1523to translate input events into other events. It differs from
1524@code{function-key-map} in two ways:
1525
1526@itemize @bullet
1527@item
1528@code{key-translation-map} goes to work after @code{function-key-map} is
1529finished; it receives the results of translation by
1530@code{function-key-map}.
1531
1532@item
1533Non-prefix bindings in @code{key-translation-map} override actual key
1534bindings. For example, if @kbd{C-x f} has a non-prefix binding in
1535@code{key-translation-map}, that translation takes effect even though
1536@kbd{C-x f} also has a key binding in the global map.
1537@end itemize
1538
1539Note however that actual key bindings can have an effect on
1540@code{key-translation-map}, even though they are overridden by it.
1541Indeed, actual key bindings override @code{function-key-map} and thus
1542may alter the key sequence that @code{key-translation-map} receives.
1543Clearly, it is better to avoid this type of situation.
1544
1545The intent of @code{key-translation-map} is for users to map one
1546character set to another, including ordinary characters normally bound
1547to @code{self-insert-command}.
1548@end defvar
1549
1550@cindex key translation function
1551You can use @code{function-key-map} or @code{key-translation-map} for
1552more than simple aliases, by using a function, instead of a key
1553sequence, as the ``translation'' of a key. Then this function is called
1554to compute the translation of that key.
1555
1556The key translation function receives one argument, which is the prompt
1557that was specified in @code{read-key-sequence}---or @code{nil} if the
1558key sequence is being read by the editor command loop. In most cases
1559you can ignore the prompt value.
1560
1561If the function reads input itself, it can have the effect of altering
1562the event that follows. For example, here's how to define @kbd{C-c h}
1563to turn the character that follows into a Hyper character:
1564
1565@example
1566@group
1567(defun hyperify (prompt)
1568 (let ((e (read-event)))
1569 (vector (if (numberp e)
1570 (logior (lsh 1 24) e)
1571 (if (memq 'hyper (event-modifiers e))
1572 e
1573 (add-event-modifier "H-" e))))))
1574
1575(defun add-event-modifier (string e)
1576 (let ((symbol (if (symbolp e) e (car e))))
1577 (setq symbol (intern (concat string
1578 (symbol-name symbol))))
1579@end group
1580@group
1581 (if (symbolp e)
1582 symbol
1583 (cons symbol (cdr e)))))
1584
1585(define-key function-key-map "\C-ch" 'hyperify)
1586@end group
1587@end example
1588
1589 If you have enabled keyboard character set decoding using
1590@code{set-keyboard-coding-system}, decoding is done after the
1591translations listed above. @xref{Terminal I/O Encoding}. However, in
1592future Emacs versions, character set decoding may be done at an
1593earlier stage.
1594
1475@node Key Binding Commands 1595@node Key Binding Commands
1476@section Commands for Binding Keys 1596@section Commands for Binding Keys
1477 1597