diff options
Diffstat (limited to 'lispref/os.texi')
| -rw-r--r-- | lispref/os.texi | 299 |
1 files changed, 83 insertions, 216 deletions
diff --git a/lispref/os.texi b/lispref/os.texi index e3634746988..f6682548e5b 100644 --- a/lispref/os.texi +++ b/lispref/os.texi | |||
| @@ -28,8 +28,10 @@ pertaining to the terminal and the screen. | |||
| 28 | * Processor Run Time:: Getting the run time used by Emacs. | 28 | * Processor Run Time:: Getting the run time used by Emacs. |
| 29 | * Time Calculations:: Adding, subtracting, comparing times, etc. | 29 | * Time Calculations:: Adding, subtracting, comparing times, etc. |
| 30 | * Timers:: Setting a timer to call a function at a certain time. | 30 | * Timers:: Setting a timer to call a function at a certain time. |
| 31 | * Terminal Input:: Recording terminal input for debugging. | 31 | * Idle Timers:: Setting a timer to call a function when Emacs has |
| 32 | * Terminal Output:: Recording terminal output for debugging. | 32 | been idle for a certain length of time. |
| 33 | * Terminal Input:: Accessing and recording terminal input. | ||
| 34 | * Terminal Output:: Controlling and recording terminal output. | ||
| 33 | * Sound Output:: Playing sounds on the computer's speaker. | 35 | * Sound Output:: Playing sounds on the computer's speaker. |
| 34 | * X11 Keysyms:: Operating on key symbols for X Windows | 36 | * X11 Keysyms:: Operating on key symbols for X Windows |
| 35 | * Batch Mode:: Running Emacs without terminal interaction. | 37 | * Batch Mode:: Running Emacs without terminal interaction. |
| @@ -1256,7 +1258,9 @@ This stands for the year without century (00-99). | |||
| 1256 | @item %Y | 1258 | @item %Y |
| 1257 | This stands for the year with century. | 1259 | This stands for the year with century. |
| 1258 | @item %Z | 1260 | @item %Z |
| 1259 | This stands for the time zone abbreviation. | 1261 | This stands for the time zone abbreviation (e.g., @samp{EST}). |
| 1262 | @item %z | ||
| 1263 | This stands for the time zone numerical offset (e.g., @samp{-0500}). | ||
| 1260 | @end table | 1264 | @end table |
| 1261 | 1265 | ||
| 1262 | You can also specify the field width and type of padding for any of | 1266 | You can also specify the field width and type of padding for any of |
| @@ -1286,12 +1290,14 @@ If @var{universal} is non-@code{nil}, that means to describe the time as | |||
| 1286 | Universal Time; @code{nil} means describe it using what Emacs believes | 1290 | Universal Time; @code{nil} means describe it using what Emacs believes |
| 1287 | is the local time zone (see @code{current-time-zone}). | 1291 | is the local time zone (see @code{current-time-zone}). |
| 1288 | 1292 | ||
| 1289 | This function uses the C library function @code{strftime} to do most of | 1293 | This function uses the C library function @code{strftime} |
| 1290 | the work. In order to communicate with that function, it first encodes | 1294 | (@pxref{Formatting Calendar Time,,, libc, The GNU C Library Reference |
| 1291 | its argument using the coding system specified by | 1295 | Manual}) to do most of the work. In order to communicate with that |
| 1292 | @code{locale-coding-system} (@pxref{Locales}); after @code{strftime} | 1296 | function, it first encodes its argument using the coding system |
| 1293 | returns the resulting string, @code{format-time-string} decodes the | 1297 | specified by @code{locale-coding-system} (@pxref{Locales}); after |
| 1294 | string using that same coding system. | 1298 | @code{strftime} returns the resulting string, |
| 1299 | @code{format-time-string} decodes the string using that same coding | ||
| 1300 | system. | ||
| 1295 | @end defun | 1301 | @end defun |
| 1296 | 1302 | ||
| 1297 | @defun seconds-to-time seconds | 1303 | @defun seconds-to-time seconds |
| @@ -1388,6 +1394,13 @@ both before and after changing the buffer, to separate the timer's | |||
| 1388 | changes from user commands' changes and prevent a single undo entry | 1394 | changes from user commands' changes and prevent a single undo entry |
| 1389 | from growing to be quite large. | 1395 | from growing to be quite large. |
| 1390 | 1396 | ||
| 1397 | Timer functions should also avoid calling functions that cause Emacs | ||
| 1398 | to wait, such as @code{sit-for} (@pxref{Waiting}). This can lead to | ||
| 1399 | unpredictable effects, since other timers (or even the same timer) can | ||
| 1400 | run while waiting. If a timer function needs to perform an action | ||
| 1401 | after a certain time has elapsed, it can do this by scheduling a new | ||
| 1402 | timer. | ||
| 1403 | |||
| 1391 | If a timer function calls functions that can change the match data, | 1404 | If a timer function calls functions that can change the match data, |
| 1392 | it should save and restore the match data. @xref{Saving Match Data}. | 1405 | it should save and restore the match data. @xref{Saving Match Data}. |
| 1393 | 1406 | ||
| @@ -1469,10 +1482,26 @@ calls one of those primitives. So use @code{with-timeout} only with a | |||
| 1469 | a timer to avoid waiting too long for an answer. @xref{Yes-or-No | 1482 | a timer to avoid waiting too long for an answer. @xref{Yes-or-No |
| 1470 | Queries}. | 1483 | Queries}. |
| 1471 | 1484 | ||
| 1485 | @defun cancel-timer timer | ||
| 1486 | This cancels the requested action for @var{timer}, which should be a | ||
| 1487 | timer---usually, one previously returned by @code{run-at-time} or | ||
| 1488 | @code{run-with-idle-timer}. This cancels the effect of that call to | ||
| 1489 | one of these functions; the arrival of the specified time will not | ||
| 1490 | cause anything special to happen. | ||
| 1491 | @end defun | ||
| 1492 | |||
| 1493 | @node Idle Timers | ||
| 1494 | @section Idle Timers | ||
| 1495 | |||
| 1496 | Here is how to set up a timer that runs when Emacs is idle for a | ||
| 1497 | certain length of time. Aside from how to set them up, idle timers | ||
| 1498 | work just like ordinary timers. | ||
| 1499 | |||
| 1472 | @deffn Command run-with-idle-timer secs repeat function &rest args | 1500 | @deffn Command run-with-idle-timer secs repeat function &rest args |
| 1473 | Set up a timer which runs when Emacs has been idle for @var{secs} | 1501 | Set up a timer which runs when Emacs has been idle for @var{secs} |
| 1474 | seconds. The value of @var{secs} may be an integer or a floating point | 1502 | seconds. The value of @var{secs} may be an integer or a floating point |
| 1475 | number. | 1503 | number; a value of the type returned by @code{current-idle-time} |
| 1504 | is also allowed. | ||
| 1476 | 1505 | ||
| 1477 | If @var{repeat} is @code{nil}, the timer runs just once, the first time | 1506 | If @var{repeat} is @code{nil}, the timer runs just once, the first time |
| 1478 | Emacs remains idle for a long enough time. More often @var{repeat} is | 1507 | Emacs remains idle for a long enough time. More often @var{repeat} is |
| @@ -1480,7 +1509,7 @@ non-@code{nil}, which means to run the timer @emph{each time} Emacs | |||
| 1480 | remains idle for @var{secs} seconds. | 1509 | remains idle for @var{secs} seconds. |
| 1481 | 1510 | ||
| 1482 | The function @code{run-with-idle-timer} returns a timer value which you | 1511 | The function @code{run-with-idle-timer} returns a timer value which you |
| 1483 | can use in calling @code{cancel-timer} (see below). | 1512 | can use in calling @code{cancel-timer} (@pxref{Timers}). |
| 1484 | @end deffn | 1513 | @end deffn |
| 1485 | 1514 | ||
| 1486 | @cindex idleness | 1515 | @cindex idleness |
| @@ -1504,11 +1533,49 @@ minutes, and even if there have been garbage collections and autosaves. | |||
| 1504 | input. Then it becomes idle again, and all the idle timers that are | 1533 | input. Then it becomes idle again, and all the idle timers that are |
| 1505 | set up to repeat will subsequently run another time, one by one. | 1534 | set up to repeat will subsequently run another time, one by one. |
| 1506 | 1535 | ||
| 1507 | @defun cancel-timer timer | 1536 | @c Emacs 19 feature |
| 1508 | Cancel the requested action for @var{timer}, which should be a value | 1537 | @defun current-idle-time |
| 1509 | previously returned by @code{run-at-time} or @code{run-with-idle-timer}. | 1538 | This function returns the length of time Emacs has been idle, as a |
| 1510 | This cancels the effect of that call to one of these functions; the | 1539 | list of three integers: @code{(@var{high} @var{low} @var{microsec})}. |
| 1511 | arrival of the specified time will not cause anything special to happen. | 1540 | The integers @var{high} and @var{low} combine to give the number of |
| 1541 | seconds of idleness, which is | ||
| 1542 | @ifnottex | ||
| 1543 | @var{high} * 2**16 + @var{low}. | ||
| 1544 | @end ifnottex | ||
| 1545 | @tex | ||
| 1546 | $high*2^{16}+low$. | ||
| 1547 | @end tex | ||
| 1548 | |||
| 1549 | The third element, @var{microsec}, gives the microseconds since the | ||
| 1550 | start of the current second (or 0 for systems that return time with | ||
| 1551 | the resolution of only one second). | ||
| 1552 | |||
| 1553 | The main use of this function is when an idle timer function wants to | ||
| 1554 | ``take a break'' for a while. It can set up another idle timer to | ||
| 1555 | call the same function again, after a few seconds more idleness. | ||
| 1556 | Here's an example: | ||
| 1557 | |||
| 1558 | @smallexample | ||
| 1559 | (defvar resume-timer nil | ||
| 1560 | "Timer that `timer-function' used to reschedule itself, or nil.") | ||
| 1561 | |||
| 1562 | (defun timer-function () | ||
| 1563 | ;; @r{If the user types a command while @code{resume-timer}} | ||
| 1564 | ;; @r{is active, the next time this function is called from} | ||
| 1565 | ;; @r{its main idle timer, deactivate @code{resume-timer}.} | ||
| 1566 | (when resume-timer | ||
| 1567 | (cancel-timer resume-timer)) | ||
| 1568 | ...@var{do the work for a while}... | ||
| 1569 | (when @var{taking-a-break} | ||
| 1570 | (setq resume-timer | ||
| 1571 | (run-with-idle-timer | ||
| 1572 | ;; Compute an idle time @var{break-length} | ||
| 1573 | ;; more than the current value. | ||
| 1574 | (time-add (current-idle-time) | ||
| 1575 | (seconds-to-time @var{break-length})) | ||
| 1576 | nil | ||
| 1577 | 'timer-function)))) | ||
| 1578 | @end smallexample | ||
| 1512 | @end defun | 1579 | @end defun |
| 1513 | 1580 | ||
| 1514 | @node Terminal Input | 1581 | @node Terminal Input |
| @@ -1521,8 +1588,6 @@ functions. | |||
| 1521 | 1588 | ||
| 1522 | @menu | 1589 | @menu |
| 1523 | * Input Modes:: Options for how input is processed. | 1590 | * Input Modes:: Options for how input is processed. |
| 1524 | * Translating Input:: Low level conversion of some characters or events | ||
| 1525 | into others. | ||
| 1526 | * Recording Input:: Saving histories of recent or all input events. | 1591 | * Recording Input:: Saving histories of recent or all input events. |
| 1527 | @end menu | 1592 | @end menu |
| 1528 | 1593 | ||
| @@ -1587,204 +1652,6 @@ is the character Emacs currently uses for quitting, usually @kbd{C-g}. | |||
| 1587 | @end table | 1652 | @end table |
| 1588 | @end defun | 1653 | @end defun |
| 1589 | 1654 | ||
| 1590 | @node Translating Input | ||
| 1591 | @subsection Translating Input Events | ||
| 1592 | @cindex translating input events | ||
| 1593 | |||
| 1594 | This section describes features for translating input events into | ||
| 1595 | other input events before they become part of key sequences. These | ||
| 1596 | features apply to each event in the order they are described here: each | ||
| 1597 | event is first modified according to @code{extra-keyboard-modifiers}, | ||
| 1598 | then translated through @code{keyboard-translate-table} (if applicable), | ||
| 1599 | and finally decoded with the specified keyboard coding system. If it is | ||
| 1600 | being read as part of a key sequence, it is then added to the sequence | ||
| 1601 | being read; then subsequences containing it are checked first with | ||
| 1602 | @code{function-key-map} and then with @code{key-translation-map}. | ||
| 1603 | |||
| 1604 | @c Emacs 19 feature | ||
| 1605 | @defvar extra-keyboard-modifiers | ||
| 1606 | This variable lets Lisp programs ``press'' the modifier keys on the | ||
| 1607 | keyboard. The value is a character. Only the modifiers of the | ||
| 1608 | character matter. Each time the user types a keyboard key, it is | ||
| 1609 | altered as if those modifier keys were held down. For instance, if | ||
| 1610 | you bind @code{extra-keyboard-modifiers} to @code{?\C-\M-a}, then all | ||
| 1611 | keyboard input characters typed during the scope of the binding will | ||
| 1612 | have the control and meta modifiers applied to them. The character | ||
| 1613 | @code{?\C-@@}, equivalent to the integer 0, does not count as a control | ||
| 1614 | character for this purpose, but as a character with no modifiers. | ||
| 1615 | Thus, setting @code{extra-keyboard-modifiers} to zero cancels any | ||
| 1616 | modification. | ||
| 1617 | |||
| 1618 | When using a window system, the program can ``press'' any of the | ||
| 1619 | modifier keys in this way. Otherwise, only the @key{CTL} and @key{META} | ||
| 1620 | keys can be virtually pressed. | ||
| 1621 | |||
| 1622 | Note that this variable applies only to events that really come from | ||
| 1623 | the keyboard, and has no effect on mouse events or any other events. | ||
| 1624 | @end defvar | ||
| 1625 | |||
| 1626 | @defvar keyboard-translate-table | ||
| 1627 | This variable is the translate table for keyboard characters. It lets | ||
| 1628 | you reshuffle the keys on the keyboard without changing any command | ||
| 1629 | bindings. Its value is normally a char-table, or else @code{nil}. | ||
| 1630 | (It can also be a string or vector, but this is considered obsolete.) | ||
| 1631 | |||
| 1632 | If @code{keyboard-translate-table} is a char-table | ||
| 1633 | (@pxref{Char-Tables}), then each character read from the keyboard is | ||
| 1634 | looked up in this char-table. If the value found there is | ||
| 1635 | non-@code{nil}, then it is used instead of the actual input character. | ||
| 1636 | |||
| 1637 | Note that this translation is the first thing that happens to a | ||
| 1638 | character after it is read from the terminal. Record-keeping features | ||
| 1639 | such as @code{recent-keys} and dribble files record the characters after | ||
| 1640 | translation. | ||
| 1641 | |||
| 1642 | Note also that this translation is done before the characters are | ||
| 1643 | supplied to input methods (@pxref{Input Methods}). Use | ||
| 1644 | @code{translation-table-for-input} (@pxref{Translation of Characters}), | ||
| 1645 | if you want to translate characters after input methods operate. | ||
| 1646 | @end defvar | ||
| 1647 | |||
| 1648 | @defun keyboard-translate from to | ||
| 1649 | This function modifies @code{keyboard-translate-table} to translate | ||
| 1650 | character code @var{from} into character code @var{to}. It creates | ||
| 1651 | the keyboard translate table if necessary. | ||
| 1652 | @end defun | ||
| 1653 | |||
| 1654 | Here's an example of using the @code{keyboard-translate-table} to | ||
| 1655 | make @kbd{C-x}, @kbd{C-c} and @kbd{C-v} perform the cut, copy and paste | ||
| 1656 | operations: | ||
| 1657 | |||
| 1658 | @example | ||
| 1659 | (keyboard-translate ?\C-x 'control-x) | ||
| 1660 | (keyboard-translate ?\C-c 'control-c) | ||
| 1661 | (keyboard-translate ?\C-v 'control-v) | ||
| 1662 | (global-set-key [control-x] 'kill-region) | ||
| 1663 | (global-set-key [control-c] 'kill-ring-save) | ||
| 1664 | (global-set-key [control-v] 'yank) | ||
| 1665 | @end example | ||
| 1666 | |||
| 1667 | @noindent | ||
| 1668 | On a graphical terminal that supports extended @acronym{ASCII} input, | ||
| 1669 | you can still get the standard Emacs meanings of one of those | ||
| 1670 | characters by typing it with the shift key. That makes it a different | ||
| 1671 | character as far as keyboard translation is concerned, but it has the | ||
| 1672 | same usual meaning. | ||
| 1673 | |||
| 1674 | The remaining translation features translate subsequences of key | ||
| 1675 | sequences being read. They are implemented in @code{read-key-sequence} | ||
| 1676 | and have no effect on input read with @code{read-event}. | ||
| 1677 | |||
| 1678 | @defvar function-key-map | ||
| 1679 | This variable holds a keymap that describes the character sequences sent | ||
| 1680 | by function keys on an ordinary character terminal. This keymap has the | ||
| 1681 | same structure as other keymaps, but is used differently: it specifies | ||
| 1682 | translations to make while reading key sequences, rather than bindings | ||
| 1683 | for key sequences. | ||
| 1684 | |||
| 1685 | If @code{function-key-map} ``binds'' a key sequence @var{k} to a vector | ||
| 1686 | @var{v}, then when @var{k} appears as a subsequence @emph{anywhere} in a | ||
| 1687 | key sequence, it is replaced with the events in @var{v}. | ||
| 1688 | |||
| 1689 | For example, VT100 terminals send @kbd{@key{ESC} O P} when the | ||
| 1690 | keypad @key{PF1} key is pressed. Therefore, we want Emacs to translate | ||
| 1691 | that sequence of events into the single event @code{pf1}. We accomplish | ||
| 1692 | this by ``binding'' @kbd{@key{ESC} O P} to @code{[pf1]} in | ||
| 1693 | @code{function-key-map}, when using a VT100. | ||
| 1694 | |||
| 1695 | Thus, typing @kbd{C-c @key{PF1}} sends the character sequence @kbd{C-c | ||
| 1696 | @key{ESC} O P}; later the function @code{read-key-sequence} translates | ||
| 1697 | this back into @kbd{C-c @key{PF1}}, which it returns as the vector | ||
| 1698 | @code{[?\C-c pf1]}. | ||
| 1699 | |||
| 1700 | Entries in @code{function-key-map} are ignored if they conflict with | ||
| 1701 | bindings made in the minor mode, local, or global keymaps. The intent | ||
| 1702 | is that the character sequences that function keys send should not have | ||
| 1703 | command bindings in their own right---but if they do, the ordinary | ||
| 1704 | bindings take priority. | ||
| 1705 | |||
| 1706 | The value of @code{function-key-map} is usually set up automatically | ||
| 1707 | according to the terminal's Terminfo or Termcap entry, but sometimes | ||
| 1708 | those need help from terminal-specific Lisp files. Emacs comes with | ||
| 1709 | terminal-specific files for many common terminals; their main purpose is | ||
| 1710 | to make entries in @code{function-key-map} beyond those that can be | ||
| 1711 | deduced from Termcap and Terminfo. @xref{Terminal-Specific}. | ||
| 1712 | @end defvar | ||
| 1713 | |||
| 1714 | @defvar key-translation-map | ||
| 1715 | This variable is another keymap used just like @code{function-key-map} | ||
| 1716 | to translate input events into other events. It differs from | ||
| 1717 | @code{function-key-map} in two ways: | ||
| 1718 | |||
| 1719 | @itemize @bullet | ||
| 1720 | @item | ||
| 1721 | @code{key-translation-map} goes to work after @code{function-key-map} is | ||
| 1722 | finished; it receives the results of translation by | ||
| 1723 | @code{function-key-map}. | ||
| 1724 | |||
| 1725 | @item | ||
| 1726 | Non-prefix bindings in @code{key-translation-map} override actual key | ||
| 1727 | bindings. For example, if @kbd{C-x f} has a non-prefix binding in | ||
| 1728 | @code{key-translation-map}, that translation takes effect even though | ||
| 1729 | @kbd{C-x f} also has a key binding in the global map. | ||
| 1730 | @end itemize | ||
| 1731 | |||
| 1732 | Note however that actual key bindings can have an effect on | ||
| 1733 | @code{key-translation-map}, even though they are overridden by it. | ||
| 1734 | Indeed, actual key bindings override @code{function-key-map} and thus | ||
| 1735 | may alter the key sequence that @code{key-translation-map} receives. | ||
| 1736 | Clearly, it is better to avoid this type of situation. | ||
| 1737 | |||
| 1738 | The intent of @code{key-translation-map} is for users to map one | ||
| 1739 | character set to another, including ordinary characters normally bound | ||
| 1740 | to @code{self-insert-command}. | ||
| 1741 | @end defvar | ||
| 1742 | |||
| 1743 | @cindex key translation function | ||
| 1744 | You can use @code{function-key-map} or @code{key-translation-map} for | ||
| 1745 | more than simple aliases, by using a function, instead of a key | ||
| 1746 | sequence, as the ``translation'' of a key. Then this function is called | ||
| 1747 | to compute the translation of that key. | ||
| 1748 | |||
| 1749 | The key translation function receives one argument, which is the prompt | ||
| 1750 | that was specified in @code{read-key-sequence}---or @code{nil} if the | ||
| 1751 | key sequence is being read by the editor command loop. In most cases | ||
| 1752 | you can ignore the prompt value. | ||
| 1753 | |||
| 1754 | If the function reads input itself, it can have the effect of altering | ||
| 1755 | the event that follows. For example, here's how to define @kbd{C-c h} | ||
| 1756 | to turn the character that follows into a Hyper character: | ||
| 1757 | |||
| 1758 | @example | ||
| 1759 | @group | ||
| 1760 | (defun hyperify (prompt) | ||
| 1761 | (let ((e (read-event))) | ||
| 1762 | (vector (if (numberp e) | ||
| 1763 | (logior (lsh 1 24) e) | ||
| 1764 | (if (memq 'hyper (event-modifiers e)) | ||
| 1765 | e | ||
| 1766 | (add-event-modifier "H-" e)))))) | ||
| 1767 | |||
| 1768 | (defun add-event-modifier (string e) | ||
| 1769 | (let ((symbol (if (symbolp e) e (car e)))) | ||
| 1770 | (setq symbol (intern (concat string | ||
| 1771 | (symbol-name symbol)))) | ||
| 1772 | @end group | ||
| 1773 | @group | ||
| 1774 | (if (symbolp e) | ||
| 1775 | symbol | ||
| 1776 | (cons symbol (cdr e))))) | ||
| 1777 | |||
| 1778 | (define-key function-key-map "\C-ch" 'hyperify) | ||
| 1779 | @end group | ||
| 1780 | @end example | ||
| 1781 | |||
| 1782 | Finally, if you have enabled keyboard character set decoding using | ||
| 1783 | @code{set-keyboard-coding-system}, decoding is done after the | ||
| 1784 | translations listed above. @xref{Terminal I/O Encoding}. In future | ||
| 1785 | Emacs versions, character set decoding may be done before the other | ||
| 1786 | translations. | ||
| 1787 | |||
| 1788 | @node Recording Input | 1655 | @node Recording Input |
| 1789 | @subsection Recording Input | 1656 | @subsection Recording Input |
| 1790 | 1657 | ||