diff options
| author | Richard M. Stallman | 2006-07-31 18:37:18 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2006-07-31 18:37:18 +0000 |
| commit | f044bf27111d1a6000a0f6e987d8bdb10c4bbe9a (patch) | |
| tree | 1fe2e75db2581d5f21e52d4963711bd684e1cff5 | |
| parent | 2410b13a189d3196e831bc0404394578575fe684 (diff) | |
| download | emacs-f044bf27111d1a6000a0f6e987d8bdb10c4bbe9a.tar.gz emacs-f044bf27111d1a6000a0f6e987d8bdb10c4bbe9a.zip | |
(Translation Keymaps): New node.
Update xrefs from Translating Input to Translation Keymaps.
| -rw-r--r-- | lispref/keymaps.texi | 124 |
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. | |||
| 642 | and exit commands. @xref{Intro to Minibuffers}. | 643 | and 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 |
| 645 | events within @code{read-key-sequence}. @xref{Translating Input}. | 646 | events 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}) |
| 686 | Emacs looks for them in the active keymaps. Here is a pseudo-Lisp | 687 | Emacs looks for them in the active keymaps. Here is a pseudo-Lisp |
| 687 | description of the order in which the active keymaps are searched: | 688 | description 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 | ||
| 1480 | sequence, to translate certain event sequences into others. | ||
| 1481 | @code{read-key-sequence} checks every subsequence of the key sequence | ||
| 1482 | being read, as it is read, against @code{function-key-map} and then | ||
| 1483 | against @code{key-translation-map}. | ||
| 1484 | |||
| 1485 | @defvar function-key-map | ||
| 1486 | This variable holds a keymap that describes the character sequences sent | ||
| 1487 | by function keys on an ordinary character terminal. This keymap has the | ||
| 1488 | same structure as other keymaps, but is used differently: it specifies | ||
| 1489 | translations to make while reading key sequences, rather than bindings | ||
| 1490 | for key sequences. | ||
| 1491 | |||
| 1492 | If @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 | ||
| 1494 | key sequence, it is replaced with the events in @var{v}. | ||
| 1495 | |||
| 1496 | For example, VT100 terminals send @kbd{@key{ESC} O P} when the | ||
| 1497 | keypad @key{PF1} key is pressed. Therefore, we want Emacs to translate | ||
| 1498 | that sequence of events into the single event @code{pf1}. We accomplish | ||
| 1499 | this by ``binding'' @kbd{@key{ESC} O P} to @code{[pf1]} in | ||
| 1500 | @code{function-key-map}, when using a VT100. | ||
| 1501 | |||
| 1502 | Thus, 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 | ||
| 1504 | this back into @kbd{C-c @key{PF1}}, which it returns as the vector | ||
| 1505 | @code{[?\C-c pf1]}. | ||
| 1506 | |||
| 1507 | Entries in @code{function-key-map} are ignored if they conflict with | ||
| 1508 | bindings made in the minor mode, local, or global keymaps. The intent | ||
| 1509 | is that the character sequences that function keys send should not have | ||
| 1510 | command bindings in their own right---but if they do, the ordinary | ||
| 1511 | bindings take priority. | ||
| 1512 | |||
| 1513 | The value of @code{function-key-map} is usually set up automatically | ||
| 1514 | according to the terminal's Terminfo or Termcap entry, but sometimes | ||
| 1515 | those need help from terminal-specific Lisp files. Emacs comes with | ||
| 1516 | terminal-specific files for many common terminals; their main purpose is | ||
| 1517 | to make entries in @code{function-key-map} beyond those that can be | ||
| 1518 | deduced from Termcap and Terminfo. @xref{Terminal-Specific}. | ||
| 1519 | @end defvar | ||
| 1520 | |||
| 1521 | @defvar key-translation-map | ||
| 1522 | This variable is another keymap used just like @code{function-key-map} | ||
| 1523 | to 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 | ||
| 1529 | finished; it receives the results of translation by | ||
| 1530 | @code{function-key-map}. | ||
| 1531 | |||
| 1532 | @item | ||
| 1533 | Non-prefix bindings in @code{key-translation-map} override actual key | ||
| 1534 | bindings. 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 | |||
| 1539 | Note however that actual key bindings can have an effect on | ||
| 1540 | @code{key-translation-map}, even though they are overridden by it. | ||
| 1541 | Indeed, actual key bindings override @code{function-key-map} and thus | ||
| 1542 | may alter the key sequence that @code{key-translation-map} receives. | ||
| 1543 | Clearly, it is better to avoid this type of situation. | ||
| 1544 | |||
| 1545 | The intent of @code{key-translation-map} is for users to map one | ||
| 1546 | character set to another, including ordinary characters normally bound | ||
| 1547 | to @code{self-insert-command}. | ||
| 1548 | @end defvar | ||
| 1549 | |||
| 1550 | @cindex key translation function | ||
| 1551 | You can use @code{function-key-map} or @code{key-translation-map} for | ||
| 1552 | more than simple aliases, by using a function, instead of a key | ||
| 1553 | sequence, as the ``translation'' of a key. Then this function is called | ||
| 1554 | to compute the translation of that key. | ||
| 1555 | |||
| 1556 | The key translation function receives one argument, which is the prompt | ||
| 1557 | that was specified in @code{read-key-sequence}---or @code{nil} if the | ||
| 1558 | key sequence is being read by the editor command loop. In most cases | ||
| 1559 | you can ignore the prompt value. | ||
| 1560 | |||
| 1561 | If the function reads input itself, it can have the effect of altering | ||
| 1562 | the event that follows. For example, here's how to define @kbd{C-c h} | ||
| 1563 | to 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 | ||
| 1591 | translations listed above. @xref{Terminal I/O Encoding}. However, in | ||
| 1592 | future Emacs versions, character set decoding may be done at an | ||
| 1593 | earlier 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 | ||