Mercurial > emacs
comparison lispref/os.texi @ 60452:53520941e72d
(Translating Input): Replace flow-control example
with a less obsolete example that uses `keyboard-translate'.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 06 Mar 2005 18:22:28 +0000 |
parents | cf30c1463800 |
children | acfc6c4c5fba 29e773288013 |
comparison
equal
deleted
inserted
replaced
60451:04426c0c07aa | 60452:53520941e72d |
---|---|
1616 If @code{keyboard-translate-table} is a char-table | 1616 If @code{keyboard-translate-table} is a char-table |
1617 (@pxref{Char-Tables}), then each character read from the keyboard is | 1617 (@pxref{Char-Tables}), then each character read from the keyboard is |
1618 looked up in this char-table. If the value found there is | 1618 looked up in this char-table. If the value found there is |
1619 non-@code{nil}, then it is used instead of the actual input character. | 1619 non-@code{nil}, then it is used instead of the actual input character. |
1620 | 1620 |
1621 In the example below, we set @code{keyboard-translate-table} to a | |
1622 char-table. Then we fill it in to swap the characters @kbd{C-s} and | |
1623 @kbd{C-\} and the characters @kbd{C-q} and @kbd{C-^}. Subsequently, | |
1624 typing @kbd{C-\} has all the usual effects of typing @kbd{C-s}, and vice | |
1625 versa. | |
1626 | |
1627 @cindex flow control example | |
1628 @example | |
1629 @group | |
1630 (defun evade-flow-control () | |
1631 "Replace C-s with C-\ and C-q with C-^." | |
1632 (interactive) | |
1633 @end group | |
1634 @group | |
1635 (setq keyboard-translate-table | |
1636 (make-char-table 'keyboard-translate-table nil)) | |
1637 @end group | |
1638 @group | |
1639 ;; @r{Swap @kbd{C-s} and @kbd{C-\}.} | |
1640 (aset keyboard-translate-table ?\034 ?\^s) | |
1641 (aset keyboard-translate-table ?\^s ?\034) | |
1642 @end group | |
1643 @group | |
1644 ;; @r{Swap @kbd{C-q} and @kbd{C-^}.} | |
1645 (aset keyboard-translate-table ?\036 ?\^q) | |
1646 (aset keyboard-translate-table ?\^q ?\036)) | |
1647 @end group | |
1648 @end example | |
1649 | |
1650 Note that this translation is the first thing that happens to a | 1621 Note that this translation is the first thing that happens to a |
1651 character after it is read from the terminal. Record-keeping features | 1622 character after it is read from the terminal. Record-keeping features |
1652 such as @code{recent-keys} and dribble files record the characters after | 1623 such as @code{recent-keys} and dribble files record the characters after |
1653 translation. | 1624 translation. |
1654 | 1625 |
1661 @defun keyboard-translate from to | 1632 @defun keyboard-translate from to |
1662 This function modifies @code{keyboard-translate-table} to translate | 1633 This function modifies @code{keyboard-translate-table} to translate |
1663 character code @var{from} into character code @var{to}. It creates | 1634 character code @var{from} into character code @var{to}. It creates |
1664 the keyboard translate table if necessary. | 1635 the keyboard translate table if necessary. |
1665 @end defun | 1636 @end defun |
1637 | |
1638 Here's an example of using the @code{keyboard-translate-table} to | |
1639 make @kbd{C-x}, @kbd{C-c} and @kbd{C-v} perform the cut, copy and paste | |
1640 operations: | |
1641 | |
1642 @example | |
1643 (keyboard-translate ?\C-x 'control-x) | |
1644 (keyboard-translate ?\C-c 'control-c) | |
1645 (keyboard-translate ?\C-v 'control-v) | |
1646 (global-set-key [control-x] 'kill-region) | |
1647 (global-set-key [control-c] 'kill-ring-save) | |
1648 (global-set-key [control-v] 'yank) | |
1649 @end example | |
1650 | |
1651 @noindent | |
1652 On a graphical terminal that supports extended @acronym{ASCII} input, | |
1653 you can still get the standard Emacs meanings of one of those | |
1654 characters by typing it with the shift key. That makes it a different | |
1655 character as far as keyboard translation is concerned, but it has the | |
1656 same usual meaning. | |
1666 | 1657 |
1667 The remaining translation features translate subsequences of key | 1658 The remaining translation features translate subsequences of key |
1668 sequences being read. They are implemented in @code{read-key-sequence} | 1659 sequences being read. They are implemented in @code{read-key-sequence} |
1669 and have no effect on input read with @code{read-event}. | 1660 and have no effect on input read with @code{read-event}. |
1670 | 1661 |