aboutsummaryrefslogtreecommitdiffstats
path: root/lispref/os.texi
diff options
context:
space:
mode:
Diffstat (limited to 'lispref/os.texi')
-rw-r--r--lispref/os.texi299
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
1257This stands for the year with century. 1259This stands for the year with century.
1258@item %Z 1260@item %Z
1259This stands for the time zone abbreviation. 1261This stands for the time zone abbreviation (e.g., @samp{EST}).
1262@item %z
1263This stands for the time zone numerical offset (e.g., @samp{-0500}).
1260@end table 1264@end table
1261 1265
1262You can also specify the field width and type of padding for any of 1266You 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
1286Universal Time; @code{nil} means describe it using what Emacs believes 1290Universal Time; @code{nil} means describe it using what Emacs believes
1287is the local time zone (see @code{current-time-zone}). 1291is the local time zone (see @code{current-time-zone}).
1288 1292
1289This function uses the C library function @code{strftime} to do most of 1293This function uses the C library function @code{strftime}
1290the work. In order to communicate with that function, it first encodes 1294(@pxref{Formatting Calendar Time,,, libc, The GNU C Library Reference
1291its argument using the coding system specified by 1295Manual}) to do most of the work. In order to communicate with that
1292@code{locale-coding-system} (@pxref{Locales}); after @code{strftime} 1296function, it first encodes its argument using the coding system
1293returns the resulting string, @code{format-time-string} decodes the 1297specified by @code{locale-coding-system} (@pxref{Locales}); after
1294string using that same coding system. 1298@code{strftime} returns the resulting string,
1299@code{format-time-string} decodes the string using that same coding
1300system.
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
1388changes from user commands' changes and prevent a single undo entry 1394changes from user commands' changes and prevent a single undo entry
1389from growing to be quite large. 1395from growing to be quite large.
1390 1396
1397 Timer functions should also avoid calling functions that cause Emacs
1398to wait, such as @code{sit-for} (@pxref{Waiting}). This can lead to
1399unpredictable effects, since other timers (or even the same timer) can
1400run while waiting. If a timer function needs to perform an action
1401after a certain time has elapsed, it can do this by scheduling a new
1402timer.
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,
1392it should save and restore the match data. @xref{Saving Match Data}. 1405it 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
1469a timer to avoid waiting too long for an answer. @xref{Yes-or-No 1482a timer to avoid waiting too long for an answer. @xref{Yes-or-No
1470Queries}. 1483Queries}.
1471 1484
1485@defun cancel-timer timer
1486This cancels the requested action for @var{timer}, which should be a
1487timer---usually, one previously returned by @code{run-at-time} or
1488@code{run-with-idle-timer}. This cancels the effect of that call to
1489one of these functions; the arrival of the specified time will not
1490cause 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
1497certain length of time. Aside from how to set them up, idle timers
1498work 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
1473Set up a timer which runs when Emacs has been idle for @var{secs} 1501Set up a timer which runs when Emacs has been idle for @var{secs}
1474seconds. The value of @var{secs} may be an integer or a floating point 1502seconds. The value of @var{secs} may be an integer or a floating point
1475number. 1503number; a value of the type returned by @code{current-idle-time}
1504is also allowed.
1476 1505
1477If @var{repeat} is @code{nil}, the timer runs just once, the first time 1506If @var{repeat} is @code{nil}, the timer runs just once, the first time
1478Emacs remains idle for a long enough time. More often @var{repeat} is 1507Emacs 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
1480remains idle for @var{secs} seconds. 1509remains idle for @var{secs} seconds.
1481 1510
1482The function @code{run-with-idle-timer} returns a timer value which you 1511The function @code{run-with-idle-timer} returns a timer value which you
1483can use in calling @code{cancel-timer} (see below). 1512can 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.
1504input. Then it becomes idle again, and all the idle timers that are 1533input. Then it becomes idle again, and all the idle timers that are
1505set up to repeat will subsequently run another time, one by one. 1534set up to repeat will subsequently run another time, one by one.
1506 1535
1507@defun cancel-timer timer 1536@c Emacs 19 feature
1508Cancel the requested action for @var{timer}, which should be a value 1537@defun current-idle-time
1509previously returned by @code{run-at-time} or @code{run-with-idle-timer}. 1538This function returns the length of time Emacs has been idle, as a
1510This cancels the effect of that call to one of these functions; the 1539list of three integers: @code{(@var{high} @var{low} @var{microsec})}.
1511arrival of the specified time will not cause anything special to happen. 1540The integers @var{high} and @var{low} combine to give the number of
1541seconds 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
1549The third element, @var{microsec}, gives the microseconds since the
1550start of the current second (or 0 for systems that return time with
1551the resolution of only one second).
1552
1553The 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
1555call the same function again, after a few seconds more idleness.
1556Here'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
1595other input events before they become part of key sequences. These
1596features apply to each event in the order they are described here: each
1597event is first modified according to @code{extra-keyboard-modifiers},
1598then translated through @code{keyboard-translate-table} (if applicable),
1599and finally decoded with the specified keyboard coding system. If it is
1600being read as part of a key sequence, it is then added to the sequence
1601being 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
1606This variable lets Lisp programs ``press'' the modifier keys on the
1607keyboard. The value is a character. Only the modifiers of the
1608character matter. Each time the user types a keyboard key, it is
1609altered as if those modifier keys were held down. For instance, if
1610you bind @code{extra-keyboard-modifiers} to @code{?\C-\M-a}, then all
1611keyboard input characters typed during the scope of the binding will
1612have the control and meta modifiers applied to them. The character
1613@code{?\C-@@}, equivalent to the integer 0, does not count as a control
1614character for this purpose, but as a character with no modifiers.
1615Thus, setting @code{extra-keyboard-modifiers} to zero cancels any
1616modification.
1617
1618When using a window system, the program can ``press'' any of the
1619modifier keys in this way. Otherwise, only the @key{CTL} and @key{META}
1620keys can be virtually pressed.
1621
1622Note that this variable applies only to events that really come from
1623the keyboard, and has no effect on mouse events or any other events.
1624@end defvar
1625
1626@defvar keyboard-translate-table
1627This variable is the translate table for keyboard characters. It lets
1628you reshuffle the keys on the keyboard without changing any command
1629bindings. 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
1632If @code{keyboard-translate-table} is a char-table
1633(@pxref{Char-Tables}), then each character read from the keyboard is
1634looked up in this char-table. If the value found there is
1635non-@code{nil}, then it is used instead of the actual input character.
1636
1637Note that this translation is the first thing that happens to a
1638character after it is read from the terminal. Record-keeping features
1639such as @code{recent-keys} and dribble files record the characters after
1640translation.
1641
1642Note also that this translation is done before the characters are
1643supplied to input methods (@pxref{Input Methods}). Use
1644@code{translation-table-for-input} (@pxref{Translation of Characters}),
1645if you want to translate characters after input methods operate.
1646@end defvar
1647
1648@defun keyboard-translate from to
1649This function modifies @code{keyboard-translate-table} to translate
1650character code @var{from} into character code @var{to}. It creates
1651the keyboard translate table if necessary.
1652@end defun
1653
1654 Here's an example of using the @code{keyboard-translate-table} to
1655make @kbd{C-x}, @kbd{C-c} and @kbd{C-v} perform the cut, copy and paste
1656operations:
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
1668On a graphical terminal that supports extended @acronym{ASCII} input,
1669you can still get the standard Emacs meanings of one of those
1670characters by typing it with the shift key. That makes it a different
1671character as far as keyboard translation is concerned, but it has the
1672same usual meaning.
1673
1674 The remaining translation features translate subsequences of key
1675sequences being read. They are implemented in @code{read-key-sequence}
1676and have no effect on input read with @code{read-event}.
1677
1678@defvar function-key-map
1679This variable holds a keymap that describes the character sequences sent
1680by function keys on an ordinary character terminal. This keymap has the
1681same structure as other keymaps, but is used differently: it specifies
1682translations to make while reading key sequences, rather than bindings
1683for key sequences.
1684
1685If @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
1687key sequence, it is replaced with the events in @var{v}.
1688
1689For example, VT100 terminals send @kbd{@key{ESC} O P} when the
1690keypad @key{PF1} key is pressed. Therefore, we want Emacs to translate
1691that sequence of events into the single event @code{pf1}. We accomplish
1692this by ``binding'' @kbd{@key{ESC} O P} to @code{[pf1]} in
1693@code{function-key-map}, when using a VT100.
1694
1695Thus, 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
1697this back into @kbd{C-c @key{PF1}}, which it returns as the vector
1698@code{[?\C-c pf1]}.
1699
1700Entries in @code{function-key-map} are ignored if they conflict with
1701bindings made in the minor mode, local, or global keymaps. The intent
1702is that the character sequences that function keys send should not have
1703command bindings in their own right---but if they do, the ordinary
1704bindings take priority.
1705
1706The value of @code{function-key-map} is usually set up automatically
1707according to the terminal's Terminfo or Termcap entry, but sometimes
1708those need help from terminal-specific Lisp files. Emacs comes with
1709terminal-specific files for many common terminals; their main purpose is
1710to make entries in @code{function-key-map} beyond those that can be
1711deduced from Termcap and Terminfo. @xref{Terminal-Specific}.
1712@end defvar
1713
1714@defvar key-translation-map
1715This variable is another keymap used just like @code{function-key-map}
1716to 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
1722finished; it receives the results of translation by
1723@code{function-key-map}.
1724
1725@item
1726Non-prefix bindings in @code{key-translation-map} override actual key
1727bindings. 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
1732Note however that actual key bindings can have an effect on
1733@code{key-translation-map}, even though they are overridden by it.
1734Indeed, actual key bindings override @code{function-key-map} and thus
1735may alter the key sequence that @code{key-translation-map} receives.
1736Clearly, it is better to avoid this type of situation.
1737
1738The intent of @code{key-translation-map} is for users to map one
1739character set to another, including ordinary characters normally bound
1740to @code{self-insert-command}.
1741@end defvar
1742
1743@cindex key translation function
1744You can use @code{function-key-map} or @code{key-translation-map} for
1745more than simple aliases, by using a function, instead of a key
1746sequence, as the ``translation'' of a key. Then this function is called
1747to compute the translation of that key.
1748
1749The key translation function receives one argument, which is the prompt
1750that was specified in @code{read-key-sequence}---or @code{nil} if the
1751key sequence is being read by the editor command loop. In most cases
1752you can ignore the prompt value.
1753
1754If the function reads input itself, it can have the effect of altering
1755the event that follows. For example, here's how to define @kbd{C-c h}
1756to 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
1782Finally, if you have enabled keyboard character set decoding using
1783@code{set-keyboard-coding-system}, decoding is done after the
1784translations listed above. @xref{Terminal I/O Encoding}. In future
1785Emacs versions, character set decoding may be done before the other
1786translations.
1787
1788@node Recording Input 1655@node Recording Input
1789@subsection Recording Input 1656@subsection Recording Input
1790 1657