Show
Ignore:
Timestamp:
08/10/06 11:19:54 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lispref/keymaps.texi

    r4131 r4140  
    3434* Changing Key Bindings::       Redefining a key in a keymap. 
    3535* Remapping Commands::          Bindings that translate one command to another. 
     36* Translation Keymaps::         Keymaps for translating sequences of events. 
    3637* Key Binding Commands::        Interactive interfaces for redefining keys. 
    3738* Scanning Keymaps::            Looking through all keymaps, for printing help. 
     
    643644 
    644645  Emacs has other keymaps that are used in a different way---translating 
    645 events within @code{read-key-sequence}.  @xref{Translating Input}. 
     646events within @code{read-key-sequence}.  @xref{Translation Keymaps}. 
    646647 
    647648  @xref{Standard Keymaps}, for a list of standard keymaps. 
     
    683684@section Searching the Active Keymaps 
    684685 
    685   After translation of the input events (@pxref{Translating Input}) 
     686  After translation of event subsequences (@pxref{Translation Keymaps}) 
    686687Emacs looks for them in the active keymaps.  Here is a pseudo-Lisp 
    687688description of the order in which the active keymaps are searched: 
     
    14731474@end defun 
    14741475 
     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 
    14751595@node Key Binding Commands 
    14761596@section Commands for Binding Keys