home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / elisp.i21 < prev    next >
Encoding:
GNU Info File  |  1993-06-14  |  50.6 KB  |  1,213 lines

  1. This is Info file elisp, produced by Makeinfo-1.47 from the input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual, for
  7. Emacs Version 18.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  10. Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28. 
  29. File: elisp,  Node: Input to Processes,  Next: Signals to Processes,  Prev: Process Information,  Up: Processes
  30.  
  31. Sending Input to Processes
  32. ==========================
  33.  
  34.    Asynchronous subprocesses receive input when it is sent to them by
  35. Emacs, which is done with the functions in this section.  You must
  36. specify the process to send input to, and the input data to send.  The
  37. data appears on the "standard input" of the subprocess.
  38.  
  39.    Some operating systems have limited space for buffered input in a
  40. PTY.  On these systems, the subprocess will cease to read input
  41. correctly if you send an input line longer than the system can handle.
  42. You cannot avoid the problem by breaking the input into pieces and
  43. sending them separately, for the operating system will still have to put
  44. all the pieces together in the input buffer before it lets the
  45. subprocess read the line.  The only solution is to put the input in a
  46. temporary file, and send the process a brief command to read that file.
  47.  
  48.  -- Function: process-send-string PROCESS-NAME STRING
  49.      This function sends PROCESS-NAME the contents of STRING as
  50.      standard input.  The argument PROCESS-NAME must be a process or
  51.      the name of a process.
  52.  
  53.      The function returns `nil'.
  54.  
  55.           (process-send-string "shell<1>" "ls\n")
  56.                => nil
  57.           
  58.           ---------- Buffer: *shell* ----------
  59.           ...
  60.           introduction.texi               syntax-tables.texi~
  61.           introduction.texi~              text.texi
  62.           introduction.txt                text.texi~
  63.           ...
  64.           ---------- Buffer: *shell* ----------
  65.  
  66.  -- Command: process-send-region PROCESS-NAME START END
  67.      This function sends the text in the region defined by START and
  68.      END as standard input to PROCESS-NAME, which is a process or a
  69.      process name.
  70.  
  71.      An error is signaled unless both START and END are integers or
  72.      markers that indicate positions in the current buffer.  (It is
  73.      unimportant which number is larger.)
  74.  
  75.  -- Function: process-send-eof &optional PROCESS-NAME
  76.      This function makes PROCESS-NAME see an end-of-file in its input. 
  77.      The EOF comes after any text already sent to it.
  78.  
  79.      If PROCESS-NAME is not supplied, or if it is `nil', then this
  80.      function sends the EOF to the current buffer's process.  An error
  81.      is signaled if the current buffer has no process.
  82.  
  83.      The function returns PROCESS-NAME.
  84.  
  85.           (process-send-eof "shell")
  86.                => "shell"
  87.  
  88. 
  89. File: elisp,  Node: Signals to Processes,  Next: Output from Processes,  Prev: Input to Processes,  Up: Processes
  90.  
  91. Sending Signals to Processes
  92. ============================
  93.  
  94.    "Sending a signal" to a subprocess is a way of interrupting its
  95. activities.  There are several different signals, each with its own
  96. meaning.  For example, the signal `SIGINT' means that the user has
  97. typed `C-c', or that some analogous thing has happened.
  98.  
  99.    Each signal has a standard effect on the subprocess.  Most signals
  100. kill the subprocess, but some stop or resume execution instead.  Most
  101. signals can optionally be handled by programs; if the program handles
  102. the signal, then we can say nothing in general about its effects.
  103.  
  104.    The set of signals and their names is defined by the operating
  105. system; Emacs has facilities for sending only a few of the signals that
  106. are defined.  Emacs can send signals only to its own subprocesses.
  107.  
  108.    You can send signals explicitly by calling the function in this
  109. section.  Emacs also sends signals automatically at certain times:
  110. killing a buffer sends a `SIGHUP' signal to all its associated
  111. processes; killing Emacs sends a `SIGHUP' signal to all remaining
  112. processes.  (`SIGHUP' is a signal that usually indicates that the user
  113. hung up the phone.)
  114.  
  115.    Each of the signal-sending functions takes two optional arguments:
  116. PROCESS-NAME and CURRENT-GROUP.
  117.  
  118.    The argument PROCESS-NAME must be either a process, the name of one,
  119. or `nil'.  If it is `nil', the process defaults to the process
  120. associated with the current buffer.  An error is signaled if
  121. PROCESS-NAME does not identify a process.
  122.  
  123.    The argument CURRENT-GROUP is a flag that makes a difference when
  124. you are running a job-control shell as an Emacs subprocess.  If it is
  125. non-`nil', then the signal is sent to the current process-group of the
  126. terminal which Emacs uses to communicate with the subprocess.  If the
  127. process is a job-control shell, this means the shell's current subjob. 
  128. If it is `nil', the signal is sent to the process group of the
  129. immediate subprocess of Emacs.  If the subprocess is a job-control
  130. shell, this is the shell itself.
  131.  
  132.    The flag CURRENT-GROUP has no effect when a pipe is used to
  133. communicate with the subprocess, because the operating system does not
  134. support the distinction in the case of pipes.  For the same reason,
  135. job-control shells won't work when a pipe is used.  See
  136. `process-connection-type' in *Note Asynchronous Processes::.
  137.  
  138.  -- Function: interrupt-process &optional PROCESS-NAME CURRENT-GROUP
  139.      This function interrupts the process PROCESS-NAME by sending the
  140.      Unix signal `SIGINT'.  Outside of Emacs, typing the "interrupt
  141.      character" (usually `C-c' on Berkeley Unix) sends this signal.
  142.      When the argument CURRENT-GROUP is non-`nil', you can think of
  143.      this function as "typing `C-c'" on the terminal by which Emacs
  144.      talks to the subprocess.
  145.  
  146.  -- Function: kill-process &optional PROCESS-NAME CURRENT-GROUP
  147.      This function kills the process PROCESS-NAME by sending the Unix
  148.      signal `SIGKILL'.  This signal kills the subprocess immediately,
  149.      and cannot be handled by the subprocess.
  150.  
  151.  -- Function: quit-process &optional PROCESS-NAME CURRENT-GROUP
  152.      This function sends the Unix signal `SIGQUIT' to the process
  153.      PROCESS-NAME.  This signal is the one sent by the "quit character"
  154.      (usually `C-b' or `C-\') when you are not inside Emacs.
  155.  
  156.  -- Function: stop-process &optional PROCESS-NAME CURRENT-GROUP
  157.      This function stops the process PROCESS-NAME by sending the Unix
  158.      signal `SIGTSTP'.  Use `continue-process' to resume its execution.
  159.  
  160.      On systems with job control, the "stop character" (usually `C-z')
  161.      sends this signal (outside of Emacs).  When CURRENT-GROUP is
  162.      non-`nil', you can think of this function as "typing `C-z'" on the
  163.      terminal Emacs uses to communicate with the subprocess.
  164.  
  165.  -- Function: continue-process &optional PROCESS-NAME CURRENT-GROUP
  166.      This function resumes execution of the process PROCESS by sending
  167.      it the Unix signal `SIGCONT'.  This presumes that PROCESS-NAME was
  168.      stopped previously.
  169.  
  170. 
  171. File: elisp,  Node: Output from Processes,  Next: Sentinels,  Prev: Signals to Processes,  Up: Processes
  172.  
  173. Receiving Output from Processes
  174. ===============================
  175.  
  176.    There are two ways to receive the output that a subprocess writes to
  177. its standard output stream.  The output can be inserted in a buffer,
  178. which is called the associated buffer of the process, or a function
  179. called the "filter function" can be called to act on the output.
  180.  
  181. * Menu:
  182.  
  183. * Process Buffers::       If no filter, output is put in a buffer.
  184. * Filter Functions::      Filter functions accept output from the process.
  185. * Accepting Output::      Explicitly permitting subprocess output.
  186.                             Waiting for subprocess output.
  187.  
  188. 
  189. File: elisp,  Node: Process Buffers,  Next: Filter Functions,  Prev: Output from Processes,  Up: Output from Processes
  190.  
  191. Process Buffers
  192. ---------------
  193.  
  194.    A process can (and usually does) have an "associated buffer", which
  195. is an ordinary Emacs buffer that is used for two purposes: storing the
  196. output from the process, and deciding when to kill the process.  You
  197. can also use the buffer to identify a process to operate on, since in
  198. normal practice only one process is associated with any given buffer.
  199. Many applications of processes also use the buffer for editing input to
  200. be sent to the process, but this is not built into Emacs Lisp.
  201.  
  202.    Unless the process has a filter function (*note Filter Functions::.),
  203. its output is inserted in the associated buffer.  The position to insert
  204. the output is determined by the `process-mark' (*note Process
  205. Information::.), which is then updated to point to the end of the text
  206. just inserted.  Usually, but not always, the `process-mark' is at the
  207. end of the buffer.  If the process has no buffer and no filter
  208. function, its output is discarded.
  209.  
  210.  -- Function: process-buffer PROCESS
  211.      This function returns the associated buffer of the process PROCESS.
  212.  
  213.           (process-buffer (get-process "shell"))
  214.                => #<buffer *shell*>
  215.  
  216.  -- Function: process-mark PROCESS
  217.      This function returns the marker which controls where additional
  218.      output from the process will be inserted in the process buffer
  219.      (*note Process Buffers::.).  When output is inserted, the marker
  220.      is updated to point at the end of the output.  This causes
  221.      successive batches of output to be inserted consecutively.
  222.  
  223.      If PROCESS does not insert its output into a buffer, then
  224.      `process-mark' returns a marker that points nowhere.
  225.  
  226.      Filter functions normally should use this marker in the same
  227.      fashion as is done by direct insertion of output in the buffer.  A
  228.      good example of a filter function that uses `process-mark' is
  229.      found at the end of the following section.
  230.  
  231.      When the user is expected to enter input in the process buffer for
  232.      transmission to the process, the process marker is useful for
  233.      distinguishing the new input from previous output.
  234.  
  235.  -- Function: set-process-buffer PROCESS BUFFER
  236.      This function sets the buffer associated with PROCESS to BUFFER. 
  237.      If BUFFER is `nil', the process will not be associated with any
  238.      buffer.
  239.  
  240.  -- Function: get-buffer-process BUFFER-OR-NAME
  241.      This function returns the process associated with BUFFER-OR-NAME.
  242.      If there are several processes associated with it, then one is
  243.      chosen. (Presently, the one chosen is the one most recently
  244.      created.)  It is usually a bad idea to have more than one process
  245.      associated with the same buffer.
  246.  
  247.           (get-buffer-process "*shell*")
  248.                => #<process shell>
  249.  
  250.      If the process's buffer is killed, the actual child process is
  251.      killed with a `SIGHUP' signal (*note Signals to Processes::.).
  252.  
  253. 
  254. File: elisp,  Node: Filter Functions,  Next: Accepting Output,  Prev: Process Buffers,  Up: Output from Processes
  255.  
  256. Process Filter Functions
  257. ------------------------
  258.  
  259.    A process "filter function" is a function that receives the standard
  260. output from the associated process.  If a process has a filter, then
  261. *all* standard output from that process is passed to the filter rather
  262. than be inserted into a buffer or discarded.  The process buffer is
  263. used for output from the process only when there is no filter.
  264.  
  265.    A filter function must accept two arguments: the associated process
  266. and a string, which is the output.  The function is then free to do
  267. whatever it chooses with the output.
  268.  
  269.    A filter function runs only while Emacs is waiting (e.g., for
  270. terminal input, or for time to elapse, or for process output).  This
  271. avoids the timing errors that could result from running filters at
  272. random places in the middle of other Lisp programs.  You may explicitly
  273. cause Emacs to wait, so that filter functions will run, by calling
  274. `sit-for', `sleep-for' or `accept-process-output' (*note Accepting
  275. Output::.).  Emacs is also waiting when the command loop is reading
  276. input.
  277.  
  278.    Quitting is normally inhibited within a filter function--otherwise,
  279. the effect of typing `C-g' at command level or to quit a user command
  280. would be unpredictable.  If you want to permit quitting inside a filter
  281. function, bind `inhibit-quit' to `nil'. *Note Quitting::.
  282.  
  283.    Many filter functions sometimes or always insert the text in the
  284. process's buffer, mimicking the actions of Emacs when there is no
  285. filter.  Such filter functions need to use `set-buffer' in order to be
  286. sure to insert in that buffer.  To avoid setting the current buffer
  287. semipermanently, these filter functions must use `unwind-protect' to
  288. make sure to restore the previous current buffer.  They should also
  289. update the process marker, and in some cases update the value of point.
  290. Here is how to do these things:
  291.  
  292.      (defun ordinary-insertion-filter (proc string)
  293.        (let ((old-buffer (current-buffer)))
  294.          (unwind-protect
  295.          (let (moving)
  296.            (set-buffer (process-buffer proc))
  297.            (setq moving (= (point) (process-mark proc)))
  298.            (save-excursion
  299.              ;; Insert the text, moving the process-marker.
  300.              (goto-char (process-mark proc))
  301.              (insert string)
  302.              (set-marker (process-mark proc) (point)))
  303.            (if moving (goto-char (process-mark proc))))
  304.            (set-buffer old-buffer))))
  305.  
  306. The reason to use an explicit `unwind-protect' rather than letting
  307. `save-excursion' restore the current buffer is so as to preserve the
  308. change in point made by `goto-char'.
  309.  
  310.    To make the filter force the process buffer to be visible whenever
  311. new text arrives, insert the following line just before the
  312. `unwind-protect':
  313.  
  314.      (display-buffer (process-buffer proc))
  315.  
  316.    To force point to move to the end of the new output no matter where
  317. it was previously, eliminate the variable `moving' and call `goto-char'
  318. unconditionally.
  319.  
  320.    All filter functions that do regexp searching or matching should save
  321. and restore the match data.  Otherwise, a filter function that runs
  322. during a call to `sit-for' might clobber the match data of the program
  323. that called `sit-for'.  *Note Match Data::.
  324.  
  325.    The output to the function may come in chunks of any size.  A program
  326. that produces the same output twice in a row may send it as one batch
  327. of 200 characters one time, and five batches of 40 characters the next.
  328.  
  329.  -- Function: set-process-filter PROCESS FILTER
  330.      This function gives PROCESS the filter function FILTER.  If FILTER
  331.      is `nil', then the process will have no filter.
  332.  
  333.  -- Function: process-filter PROCESS
  334.      This function returns the filter function of PROCESS, or `nil' if
  335.      it has none.
  336.  
  337.    Here is an example of use of a filter function:
  338.  
  339.      (defun keep-output (process output)
  340.         (setq kept (cons output kept)))
  341.           => keep-output
  342.      (setq kept nil)
  343.           => nil
  344.      (set-process-filter (get-process "shell") 'keep-output)
  345.           => keep-output
  346.      (process-send-string "shell" "ls ~/other\n")
  347.           => nil
  348.      kept
  349.           => ("lewis@slug[8] % "
  350.      "FINAL-W87-SHORT.MSS    backup.otl              kolstad.mss~
  351.      address.txt             backup.psf              kolstad.psf
  352.      backup.bib~             david.mss               resume-Dec-86.mss~
  353.      backup.err              david.psf               resume-Dec.psf
  354.      backup.mss              dland                   syllabus.mss
  355.      "
  356.      "#backups.mss#          backup.mss~             kolstad.mss
  357.      ")
  358.  
  359.    Here is another, more realistic example, which demonstrates how to
  360. use the process mark to do insertion in the same fashion as is done when
  361. there is no filter function:
  362.  
  363.      ;; Insert input in the buffer specified by `my-shell-buffer'
  364.      ;; and make sure that buffer is shown in some window.
  365.      (defun my-process-filter (proc str)
  366.          (let ((cur (selected-window))
  367.                (pop-up-windows t))
  368.            (pop-to-buffer my-shell-buffer)
  369.            (goto-char (point-max))
  370.            (insert str)
  371.            (set-marker (process-mark proc) (point-max))
  372.            (select-window cur)))
  373.  
  374. 
  375. File: elisp,  Node: Accepting Output,  Prev: Filter Functions,  Up: Output from Processes
  376.  
  377. Accepting Output from Processes
  378. -------------------------------
  379.  
  380.    Output from asynchronous subprocesses normally arrives only while
  381. Emacs is waiting for some sort of external event, such as elapsed time
  382. or terminal input.  Occasionally it is useful in a Lisp program to
  383. explicitly permit output to arrive at a specific point, or even to wait
  384. until output arrives from a process.
  385.  
  386.  -- Function: accept-process-output &optional PROCESS
  387.      This function allows Emacs to read pending output from processes. 
  388.      The output is inserted in the associated buffers or given to their
  389.      filter functions.  If PROCESS is non-`nil' then this function does
  390.      not return until some output has been received from PROCESS.
  391.  
  392. 
  393. File: elisp,  Node: Sentinels,  Next: VMS Subprocesses,  Prev: Output from Processes,  Up: Processes
  394.  
  395. Sentinels: Detecting Process Status Changes
  396. -------------------------------------------
  397.  
  398.    A "process sentinel" is a function that is called whenever the
  399. associated process changes status for any reason, including signals
  400. (whether sent by Emacs or caused by the process's own actions) that
  401. terminate, stop, or continue the process.  The process sentinel is also
  402. called if the process exits.  The sentinel receives two arguments: the
  403. process for which the event occurred, and a string describing the type
  404. of event.
  405.  
  406.    The string describing the event looks like one of the following:
  407.  
  408.    * `"finished\n"'.
  409.  
  410.    * `"exited abnormally with code EXITCODE\n"'.
  411.  
  412.    * `"NAME-OF-SIGNAL\n"'.
  413.  
  414.    * `"NAME-OF-SIGNAL (core dumped)\n"'.
  415.  
  416.    A sentinel runs only while Emacs is waiting (e.g., for terminal
  417. input, or for time to elapse, or for process output).  This avoids the
  418. timing errors that could result from running them at random places in
  419. the middle of other Lisp programs.  You may explicitly cause Emacs to
  420. wait, so that sentinels will run, by calling `sit-for', `sleep-for' or
  421. `accept-process-output' (*note Accepting Output::.).  Emacs is also
  422. waiting when the command loop is reading input.
  423.  
  424.    Quitting is normally inhibited within a sentinel--otherwise, the
  425. effect of typing `C-g' at command level or to quit a user command would
  426. be unpredictable.  If you want to permit quitting inside a sentinel,
  427. bind `inhibit-quit' to `nil'.  *Note Quitting::.
  428.  
  429.    All sentinels that do regexp searching or matching should save and
  430. restore the match data.  Otherwise, a sentinel that runs during a call
  431. to `sit-for' might clobber the match data of the program that called
  432. `sit-for'.  *Note Match Data::.
  433.  
  434.  -- Function: set-process-sentinel PROCESS SENTINEL
  435.      This function associates SENTINEL with PROCESS.  If SENTINEL is
  436.      `nil', then the process will have no sentinel. The default
  437.      behavior when there is no sentinel is to insert a message in the
  438.      process's buffer when the process status changes.
  439.  
  440.           (defun msg-me (process event)
  441.              (princ
  442.                (format "Process: %s had the event `%s'" process event)))
  443.           (set-process-sentinel (get-process "shell") 'msg-me)
  444.                => msg-me
  445.           (kill-process (get-process "shell"))
  446.                -| Process: #<process shell> had the event `killed'
  447.                => #<process shell>
  448.  
  449.  -- Function: process-sentinel PROCESS
  450.      This function returns the sentinel of PROCESS, or `nil' if it has
  451.      none.
  452.  
  453.  -- Function: waiting-for-user-input-p
  454.      While a sentinel or filter function is running, this function
  455.      returns non-`nil' if Emacs was waiting for keyboard input from the
  456.      user at the time the sentinel or filter function was called, `nil'
  457.      if it was not.
  458.  
  459. 
  460. File: elisp,  Node: VMS Subprocesses,  Next: TCP,  Prev: Sentinels,  Up: Processes
  461.  
  462. Subprocess Functions for VMS
  463. ============================
  464.  
  465.    The ordinary subprocess functions do not work on VMS in version 18.
  466. Instead, these functions are available.
  467.  
  468.  -- Function: default-subprocess-input-handler
  469.      This function is the default input handler for input from spawned
  470.      subprocesses.
  471.  
  472.  -- Function: spawn-subprocess INTEGER &optional FILTER SENTINEL
  473.      This function spawns an asynchronous VMS subprocess for command
  474.      processing.  The arguments are INTEGER, an integer to identify the
  475.      subprocess in future operations; FILTER, a function to be called
  476.      when output arrives from the subprocess; and SENTINEL, a function
  477.      to be called when the subprocess terminates.
  478.  
  479.      If FILTER is `nil', output is inserted in the current buffer.  If
  480.      SENTINEL is `nil', nothing special is done when the subprocess
  481.      terminates.
  482.  
  483.      When the filter is called, it receives two arguments; INTEGER to
  484.      identify the process, and a string containing the output.
  485.  
  486.      When the sentinel is called, it receives just one argument,
  487.      INTEGER.
  488.  
  489.  -- Function: send-command-to-subprocess INTEGER COMMAND
  490.      This function sends the string COMMAND to a VMS subprocess
  491.      numbered INTEGER.
  492.  
  493.  -- Function: stop-subprocess INTEGER
  494.      This function terminates the VMS subprocess numbered INTEGER.
  495.  
  496.    In version 19, these functions have been eliminated, and the ordinary
  497. subprocess functions are implemented on VMS.
  498.  
  499. 
  500. File: elisp,  Node: TCP,  Prev: VMS Subprocesses,  Up: Processes
  501.  
  502. TCP
  503. ===
  504.  
  505.    Emacs Lisp programs can open TCP connections to other processes on
  506. the same machine or other machines.  A network connection is handled by
  507. Lisp much like a subprocess, and is represented by a process object.
  508. However, the process you are communicating with is not a child of the
  509. Emacs process, so you can't kill it or send it signals.  All you can do
  510. is send and receive data.  `delete-process' closes the connection, but
  511. does not kill the process at the other end of it.
  512.  
  513.    You can distinguish process objects representing network connections
  514. from those representing subprocesses with the `process-status' function.
  515.  
  516.  -- Function: open-network-stream NAME BUFFER-OR-NAME HOST SERVICE
  517.      This function opens a TCP connection for a service to a host.  It
  518.      returns a process object to represent the connection.
  519.  
  520.      The NAME argument specifies the name for the process object.  It
  521.      is modified as necessary to make it unique.
  522.  
  523.      The BUFFER-OR-NAME argument is the buffer to associate with the
  524.      connection.  Output from the connection is inserted in the buffer,
  525.      unless you specify a filter function to handle the output.  If
  526.      BUFFER-OR-NAME is `nil', it means that the connection is not
  527.      associated with any buffer.
  528.  
  529.      The arguments HOST and SERVICE specify where to connect to; HOST
  530.      is the host name (a string), and SERVICE is the name of the
  531.      service desired (a string) or an integer specifying a port number
  532.      to connect to.
  533.  
  534. 
  535. File: elisp,  Node: System Interface,  Next: Emacs Display,  Prev: Processes,  Up: Top
  536.  
  537. Operating System Interface
  538. **************************
  539.  
  540.    This chapter is about starting and getting out of Emacs, access to
  541. values in the operating system environment, and terminal input, output
  542. and flow control.
  543.  
  544.    *Note Building Emacs::, for related information.  See also *Note
  545. Emacs Display::, for additional operating system status information
  546. which pertain to the terminal and the screen.
  547.  
  548. * Menu:
  549.  
  550. * Starting Up::         Customizing Emacs start-up processing.
  551. * Getting Out::         How exiting works (permanent or temporary).
  552. * System Environment::  Distinguish the name and kind of system.
  553. * Terminal Input::      Recording terminal input for debugging.
  554. * Terminal Output::     Recording terminal output for debugging.
  555. * Flow Control::        How to turn output flow control on or off.
  556. * Batch Mode::          Running Emacs without terminal interaction.
  557.  
  558. 
  559. File: elisp,  Node: Starting Up,  Next: Getting Out,  Prev: System Interface,  Up: System Interface
  560.  
  561. Starting Up Emacs
  562. =================
  563.  
  564.    This section describes what Emacs does when it is started, and how
  565. you can customize these actions.
  566.  
  567. * Menu:
  568.  
  569. * Start-up Summary::        Sequence of actions Emacs performs at start-up.
  570. * Init File::               Details on reading the init file (`.emacs').
  571. * Terminal-Specific::       How the terminal-specific Lisp file is read.
  572. * Command Line Arguments::  How command line arguments are processed,
  573.                               and how you can customize them.
  574.  
  575. 
  576. File: elisp,  Node: Start-up Summary,  Next: Init File,  Prev: Starting Up,  Up: Starting Up
  577.  
  578. Summary: Sequence of Actions at Start Up
  579. ----------------------------------------
  580.  
  581.    The order of operations performed (in `startup.el') by Emacs when it
  582. is started up is as follows:
  583.  
  584.   1. It loads `.emacs' unless `-q' was specified on command line. (This
  585.      is not done in `-batch' mode.)  `.emacs' is found in the user's
  586.      home directory; the `-u' option can specify the user name whose
  587.      home directory should be used.
  588.  
  589.   2. It loads `default.el' unless `inhibit-default-init' is non-`nil'. 
  590.      (This is not done in `-batch' mode or if `-q' was specified on
  591.      command line.)
  592.  
  593.   3. It loads the terminal-specific Lisp file, if any, except when in
  594.      batch mode.
  595.  
  596.   4. It runs `term-setup-hook'.
  597.  
  598.   5. It runs `window-setup-hook'.
  599.  
  600.   6. It displays copyleft and nonwarranty, plus basic use information,
  601.      unless the value of `inhibit-startup-message' is non-`nil'.
  602.  
  603.      This display is also inhibited in batch mode, and if the current
  604.      buffer is not `*scratch*'.
  605.  
  606.   7. It processes any remaining command line arguments.
  607.  
  608.  -- User Option: inhibit-startup-message
  609.      This variable inhibits the initial startup messages (the
  610.      nonwarranty, etc.).  If it is non-`nil', then the messages are not
  611.      printed.
  612.  
  613.      This variable exists so you can set it in your personal init file,
  614.      once you are familiar with the contents of the startup message. 
  615.      Do not set this variable in the init file of a new user, or in a
  616.      way that affects more than one user, because that would prevent
  617.      new users from receiving the information they are supposed to see.
  618.  
  619. 
  620. File: elisp,  Node: Init File,  Next: Terminal-Specific,  Prev: Start-Up Summary,  Up: Starting Up
  621.  
  622. The Init File: `.emacs'
  623. -----------------------
  624.  
  625.    When you start Emacs, it normally attempts to load the file `.emacs'
  626. from your home directory.  This file, if it exists, must contain Lisp
  627. code.  It is called your "init file".  The command line switches `-q'
  628. and `-u' can be used to control the use of the init file; `-q' says not
  629. to load an init file, and `-u' says to load a specified user's init
  630. file instead of yours.  *Note Entering Emacs: (emacs)Entering Emacs.
  631.  
  632.    Emacs may also have a "default init file", which is the library
  633. named `default.el'.  Emacs finds the `default.el' file through the
  634. standard search path for libraries (*note How Programs Do Loading::.). 
  635. The Emacs distribution does not have any such file; you may create one
  636. at your site for local customizations.  If the default init file
  637. exists, it is loaded whenever you start Emacs, except in batch mode or
  638. if `-q' is specified.  But your own personal init file, if any, is
  639. loaded first; if it sets `inhibit-default-init' to a non-`nil' value,
  640. then Emacs will not load the `default.el' file.
  641.  
  642.    If there is a great deal of code in your `.emacs' file, you should
  643. move it into another file named `SOMETHING.el', byte-compile it (*note
  644. Byte Compilation::.), and make your `.emacs' file load the other file
  645. using `load' (*note Loading::.).
  646.  
  647.    *Note Init File Examples: (emacs)Init File Examples, for examples of
  648. how to make various commonly desired customizations in your `.emacs'
  649. file.
  650.  
  651.  -- User Option: inhibit-default-init
  652.      This variable prevents Emacs from loading the default
  653.      initialization library file for your session of Emacs.  If its
  654.      value is non-`nil', then the default library is not loaded.  The
  655.      default value is `nil'.
  656.  
  657. 
  658. File: elisp,  Node: Terminal-Specific,  Next: Command Line Arguments,  Prev: Init File,  Up: Starting Up
  659.  
  660. Terminal-Specific Initialization
  661. --------------------------------
  662.  
  663.    Each terminal type can have its own Lisp library that Emacs will load
  664. when run on that type of terminal.  For a terminal type named TERMTYPE,
  665. the library is called `term/TERMTYPE'.  Emacs finds the file by
  666. searching the `load-path' directories as it does for other files, and
  667. trying the `.elc' and `.el' suffixes. Normally, terminal-specific Lisp
  668. library is located in `emacs/lisp/term', a subdirectory of the
  669. `emacs/lisp' directory in which most Emacs Lisp libraries are kept.
  670.  
  671.    The library's name is constructed by concatenating the value of the
  672. variable `term-file-prefix' and the terminal type.  Normally,
  673. `term-file-prefix' has the value `"term/"'; changing this is not
  674. recommended.
  675.  
  676.    The usual purpose of a terminal-specific library is to define the
  677. escape sequences used by a terminal's function keys.  See the file
  678. `term/vt100.el' for an example of a terminal-specific library.
  679.  
  680.    Function keys are handled by a two-level procedure.  The first level
  681. is dependent on the specific type of terminal and maps Emacs's input
  682. sequences to the function keys that they represent.  The second level is
  683. independent of terminal type and is customized by users; function keys
  684. are mapped into meanings at this level.  The terminal-specific library
  685. handles the first level of the process and the library `keypad.el'
  686. handles the second level of mapping.
  687.  
  688.    When the name of the terminal type contains a hyphen, only the part
  689. of the name before the first hyphen is significant in choosing the
  690. library name.  Thus, terminal types `aaa-48' and `aaa-30-rv' both use
  691. the `term/aaa' library.  If necessary, the library can evaluate
  692. `(getenv "TERM")' to find the full name of the terminal type.
  693.  
  694.    Your `.emacs' file can prevent the loading of the terminal-specific
  695. library by setting `term-file-prefix' to `nil'.  This feature is very
  696. useful when experimenting with your own peculiar customizations.
  697.  
  698.    You can also arrange to override some of the actions of the
  699. terminal-specific library by setting the variable `term-setup-hook'. 
  700. If it is not `nil', Emacs calls the value of the variable
  701. `term-setup-hook' as a function of no arguments at the end of Emacs
  702. initialization, after Emacs has already loaded both your `.emacs' file
  703. and any terminal-specific libraries.  You can use this variable to
  704. define initializations for terminals that do not have their own
  705. libraries.
  706.  
  707.  -- Variable: term-file-prefix
  708.      If the `term-file-prefix' variable is non-`nil', Emacs loads a
  709.      terminal-specific initialization file as follows:
  710.  
  711.           (load (concat term-file-prefix (getenv "TERM")))
  712.  
  713.      You may set the `term-file-prefix' variable to `nil' in your
  714.      `.emacs' file if you do not wish to load the
  715.      terminal-initialization file.  To do this, put the following in
  716.      your `.emacs' file: `(setq term-file-prefix nil)'.
  717.  
  718.  -- Variable: term-setup-hook
  719.      The value of this variable is either `nil' or a function to be
  720.      called by Emacs after loading your `.emacs' file, the default
  721.      initialization file (if any) and after loading terminal-specific
  722.      Lisp code.  The function is called with no arguments.
  723.  
  724.      You can use `term-setup-hook' to override the definitions made by
  725.      a terminal-specific file.
  726.  
  727.    See also `window-setup-hook' in *Note Window Systems::.
  728.  
  729. 
  730. File: elisp,  Node: Command Line Arguments,  Prev: Terminal-Specific,  Up: Starting Up
  731.  
  732. Command Line Arguments
  733. ----------------------
  734.  
  735.    You can use command line arguments to request various actions when
  736. you start Emacs.  Since you do not need to start Emacs more than once
  737. per day, and will often leave your Emacs session running longer than
  738. that, command line arguments are hardly ever used.  As a practical
  739. matter, it is best to avoid making the habit of using them, since this
  740. habit would encourage you to kill and restart Emacs unnecessarily
  741. often.  These options exist for two reasons: to be compatible with
  742. other editors (for invocation by other programs) and to enable shell
  743. scripts to run specific Lisp programs.
  744.  
  745.  -- Function: command-line
  746.      This function parses the command line which Emacs was called with,
  747.      processes it, loads the user's `.emacs' file and displays the
  748.      initial nonwarranty information, etc.
  749.  
  750.  -- Variable: command-line-processed
  751.      The value of this variable is `t' once the command line has been
  752.      processed.
  753.  
  754.      If you redump Emacs by calling `dump-emacs', you must set this
  755.      variable to `nil' first in order to cause the new dumped Emacs to
  756.      process its new command line arguments.
  757.  
  758.  -- Variable: command-switch-alist
  759.      The value of this variable is an alist of user-defined command-line
  760.      options and associated handler functions.  This variable exists so
  761.      you can add elements to it.
  762.  
  763.      A "command line option" is an argument on the command line of the
  764.      form:
  765.  
  766.           -OPTION
  767.  
  768.      The elements of the `command-switch-alist' look like this:
  769.  
  770.           (OPTION . HANDLER-FUNCTION)
  771.  
  772.      For each element, the HANDLER-FUNCTION receives the switch name as
  773.      its sole argument.
  774.  
  775.      In some cases, the option is followed in the command line by an
  776.      argument.  In these cases, the HANDLER-FUNCTION can find all the
  777.      remaining command-line arguments in the variable
  778.      `command-line-args-left'.  (The entire list of command-line
  779.      arguments is in `command-line-args'.)
  780.  
  781.      The command line arguments are parsed by the `command-line-1'
  782.      function in the `startup.el' file.  See also *Note Command Line
  783.      Switches and Arguments: (emacs)Command Switches.
  784.  
  785.  -- Variable: command-line-args
  786.      The value of this variable is the arguments passed by the shell to
  787.      Emacs, as a list of strings.
  788.  
  789. 
  790. File: elisp,  Node: Getting Out,  Next: System Environment,  Prev: Starting Up,  Up: System Interface
  791.  
  792. Getting out of Emacs
  793. ====================
  794.  
  795.    There are two ways to get out of Emacs: you can kill the Emacs job,
  796. which exits permanently, or you can suspend it, which permits you to
  797. reenter the Emacs process later.  As a practical matter, you seldom kill
  798. Emacs--only when you are about to log out.  Suspending is much more
  799. common.
  800.  
  801. * Menu:
  802.  
  803. * Killing Emacs::        Exiting Emacs irreversibly.
  804. * Suspending Emacs::     Exiting Emacs reversibly.
  805.  
  806. 
  807. File: elisp,  Node: Killing Emacs,  Next: Suspending Emacs,  Prev: Getting Out,  Up: Getting Out
  808.  
  809. Killing Emacs
  810. -------------
  811.  
  812.    Killing Emacs means ending the execution of the Emacs process. It
  813. will return to its superior process.
  814.  
  815.    All the information in the Emacs process, aside from files that have
  816. been saved, is lost when the Emacs is killed.  Because killing Emacs
  817. inadvertently can lose a lot of work, Emacs will query for confirmation
  818. before actually terminating if you have buffers that need saving or
  819. subprocesses that are running.
  820.  
  821.  -- Function: kill-emacs &optional NO-QUERY
  822.      This function exits the Emacs process and kills it.
  823.  
  824.      Normally, if there are modified files or if there are running
  825.      processes, `kill-emacs' asks the user for confirmation before
  826.      exiting.  However, if NO-QUERY is supplied and non-`nil', then
  827.      Emacs exits without confirmation.
  828.  
  829.      If NO-QUERY is an integer, then it is used as the exit status of
  830.      the Emacs process.  (This is useful primarily in batch operation;
  831.      see *Note Batch Mode::.)
  832.  
  833.      If NO-QUERY is a string, its contents are stuffed into the
  834.      terminal input buffer so that the shell (or whatever program next
  835.      reads input) can read them.
  836.  
  837.  -- Variable: kill-emacs-hook
  838.      The value of the `kill-emacs-hook' variable is either `nil' or is
  839.      that of a function to be called by `kill-emacs'.  The hook is
  840.      called before anything else is done by `kill-emacs'.
  841.  
  842. 
  843. File: elisp,  Node: Suspending Emacs,  Prev: Killing Emacs,  Up: Getting Out
  844.  
  845. Suspending Emacs
  846. ----------------
  847.  
  848.    "Suspending Emacs" means stopping Emacs temporarily and returning
  849. control to its superior process, which is usually the shell.  This
  850. allows you to resume editing later in the same Emacs process, with the
  851. same buffers, the same kill ring, the same undo history, and so on.  To
  852. resume Emacs, use the appropriate command in the parent shell--most
  853. likely `fg'.
  854.  
  855.    Some operating systems do not support suspension of jobs; on these
  856. systems, "suspension" actually creates a new shell temporarily as a
  857. subprocess of Emacs.  Then you would exit the shell to return to Emacs.
  858.  
  859.    Suspension is not useful with window systems such as X Windows,
  860. because the Emacs job may not have a parent that can resume it again,
  861. and in any case you can give input to some other job such as a shell
  862. merely by moving to a different window.  Therefore, suspending is not
  863. allowed under X Windows.
  864.  
  865.  -- Function: suspend-emacs STRING
  866.      This function stops Emacs and returns to the superior process.  It
  867.      returns `nil'.
  868.  
  869.      If STRING is non-`nil', its characters are sent to be read as
  870.      terminal input by Emacs's superior shell.  The characters in STRING
  871.      will not be echoed by the superior shell; just the results will
  872.      appear.
  873.  
  874.      Before suspending, Emacs examines the symbol `suspend-hook'.  If
  875.      it is bound, and its value is non-`nil', then the value is called
  876.      as a function of no arguments.  If the function returns non-`nil',
  877.      then `suspend-emacs' returns immediately and suspension does not
  878.      occur.
  879.  
  880.      After Emacs resumes, the symbol `suspend-resume-hook' is examined.
  881.       If it is bound and non-`nil', then the value is called as a
  882.      function of no arguments.
  883.  
  884.      The next redisplay after resumption will redraw the entire screen,
  885.      unless `no-redraw-on-reenter' is set (*note Screen Attributes::.).
  886.  
  887.      In the following example, note that `pwd' is not echoed after
  888.      Emacs is suspended.  But it is read and executed by the shell.
  889.  
  890.           (suspend-emacs)
  891.                => nil
  892.           
  893.           (setq suspend-hook
  894.               (function (lambda ()
  895.                         (not (y-or-n-p "Really suspend? ")))))
  896.                => (lambda nil (not (y-or-n-p "Really suspend? ")))
  897.           (setq suspend-resume-hook
  898.               (function (lambda () (message "Resumed!"))))
  899.                => (lambda nil (message "Resumed!"))
  900.           (suspend-emacs "pwd")
  901.                => nil
  902.           ---------- Buffer: Minibuffer ----------
  903.           Really suspend? `y'
  904.           
  905.           ---------- Parent Shell ----------
  906.           lewis@slug[23] % /user/lewis/manual
  907.           lewis@slug[24] % fg
  908.           
  909.           ---------- Echo Area ----------
  910.           Resumed!
  911.  
  912.  -- Variable: suspend-hook
  913.      The value of the `suspend-hook' variable, if not `nil', is called
  914.      as a function with no arguments by `suspend-emacs' before Emacs is
  915.      actually suspended.  If the function returns non-`nil', then
  916.      suspension does not take place.
  917.  
  918.  -- Variable: suspend-resume-hook
  919.      The value of the `suspend-resume-hook' variable, if not `nil', is
  920.      called as a function with no arguments after resumption of an
  921.      Emacs session that was suspended with `suspend-emacs'.
  922.  
  923. 
  924. File: elisp,  Node: System Environment,  Next: Terminal Input,  Prev: Getting Out,  Up: System Interface
  925.  
  926. Operating System Environment
  927. ============================
  928.  
  929.    Emacs provides access to variables in the operating system
  930. environment through various functions.  These variables include the
  931. name of the system, the user's UID, and so on.
  932.  
  933.  -- Variable: system-type
  934.      The value of this variable is a symbol indicating the type of
  935.      operating system Emacs is operating on.  Here is a table of the
  936.      symbols for the operating systems that Emacs can run on up to
  937.      version 18.51.
  938.  
  939.     `berkeley-unix'
  940.           Berkeley BSD 4.1, 4.2, or 4.3.
  941.  
  942.     `hpux'
  943.           Hewlett-Packard operating system, version 5, 6, or 7.
  944.  
  945.     `silicon-graphics-unix'
  946.           Silicon Graphics Iris 3.5 or 3.6.
  947.  
  948.     `rtu'
  949.           RTU 3.0, UCB universe.
  950.  
  951.     `unisoft-unix'
  952.           UniSoft's UniPlus 5.0 or 5.2.
  953.  
  954.     `usg-unix-v'
  955.           AT&T's System V.0, System V Release 2.0, 2.2, or 3.
  956.  
  957.     `vax-vms'
  958.           VMS VMS version 4 or 5.
  959.  
  960.     `xenix'
  961.           SCO Xenix 386 Release 2.2.
  962.  
  963.      We do not wish to add new symbols to make finer distinctions
  964.      unless it is absolutely necessary!  In fact, it would be nice to
  965.      eliminate a couple of possibilities in the future.
  966.  
  967.  -- Function: getenv VAR
  968.      This function returns the value of the environment variable VAR,
  969.      as a string.
  970.  
  971.           (getenv "USER")
  972.                => "lewis"
  973.           
  974.           lewis@slug[10] % printenv
  975.           PATH=.:/user/lewis/bin:/usr/bin:/usr/local/bin
  976.           USER=lewis
  977.           TERM=ibmapa16
  978.           SHELL=/bin/csh
  979.           HOME=/user/lewis
  980.  
  981.  -- Function: user-login-name
  982.      This function returns the name under which the user is logged in.
  983.      This is based on the effective UID, not the real UID.
  984.  
  985.           (user-login-name)
  986.                => "lewis"
  987.  
  988.  -- Function: user-real-login-name
  989.      This function returns the name under which the user logged in.
  990.      This is based on the real UID, not the effective UID.  This
  991.      differs from `user-login-name' only when running with the setuid
  992.      bit.
  993.  
  994.  -- Function: user-full-name
  995.      This function returns the full name of the user.
  996.  
  997.           (user-full-name)
  998.                => "Bil Lewis"
  999.  
  1000.  -- Function: user-real-uid
  1001.      This function returns the real UID of the user.
  1002.  
  1003.           (user-real-uid)
  1004.                => 19
  1005.  
  1006.  -- Function: user-uid
  1007.      This function returns the effective UID of the user.
  1008.  
  1009.  -- Function: system-name
  1010.      This function returns the name of the machine you are running on.
  1011.           (system-name)
  1012.                => "prep.ai.mit.edu"
  1013.  
  1014.  -- Function: current-time-string
  1015.      This function returns the current time and date as a
  1016.      humanly-readable string.  The format of the string is unvarying;
  1017.      the number of characters used for each part is always the same, so
  1018.      you can reliably use `substring' to extract pieces of it. 
  1019.      However, it would be wise to count the characters from the
  1020.      beginning of the string rather than from the end, as additional
  1021.      information describing the time zone may be added in version 19.
  1022.  
  1023.           (current-time-string)
  1024.                => "Wed Oct 14 22:21:05 1987"
  1025.  
  1026.  -- Function: load-average
  1027.      This function returns the current 1 minute, 5 minute and 15 minute
  1028.      load averages in a list.  The values are integers that are 100
  1029.      times the system load averages.  (The load averages indicate the
  1030.      number of processes trying to run.)
  1031.  
  1032.           (load-average)
  1033.                => (169 48 36)
  1034.           
  1035.           lewis@rocky[5] % uptime
  1036.            11:55am  up 1 day, 19:37,  3 users,  load average: 1.69, 0.48, 0.36
  1037.  
  1038.  -- Function: setprv PRIVILEGE-NAME &optional SETP GETPRV
  1039.      This function sets or resets a VMS privilege.  (It does not exist
  1040.      on Unix.)  The first arg is the privilege name, as a string.  The
  1041.      second argument, SETP, is `t' or `nil', indicating whether the
  1042.      privilege is to be turned on or off.  Its default is `nil'.  The
  1043.      function returns `t' if success, `nil' if not.
  1044.  
  1045.      If the third argument, GETPRV, is non-`nil', `setprv' does not
  1046.      change the privilege, but returns `t' or `nil' indicating whether
  1047.      the privilege is currently enabled.
  1048.  
  1049. 
  1050. File: elisp,  Node: Terminal Input,  Next: Terminal Output,  Prev: System Environment,  Up: System Interface
  1051.  
  1052. Terminal Input
  1053. ==============
  1054.  
  1055.    The terminal input functions and variables keep track of or
  1056. manipulate terminal input.
  1057.  
  1058.    See *Note Emacs Display::, for related functions.
  1059.  
  1060.  -- Function: recent-keys
  1061.      This function returns a string comprising the last 100 characters
  1062.      read from the terminal.  These are the last 100 characters read by
  1063.      Emacs, no exceptions.
  1064.  
  1065.           (recent-keys)
  1066.           => "erminal.  These are the last 100 characters read by Emacs, no
  1067.           exceptions.
  1068.           
  1069.           @example
  1070.           (recent-keys)^U^X^E"
  1071.  
  1072.      Here the string `@example' is a Texinfo command that was inserted
  1073.      in the source file for the manual, and `^U^X^E' are the characters
  1074.      that were typed to evaluate the expression `(recent-keys)'.
  1075.  
  1076.  -- Command: open-dribble-file FILENAME
  1077.      This function opens a "dribble file" named FILENAME.  When a
  1078.      dribble file is open, Emacs copies all keyboard input characters
  1079.      to that file.  (The contents of keyboard macros are not typed on
  1080.      the keyboard so they are not copied to the dribble file.)
  1081.  
  1082.      You close the dribble file by calling this function with an
  1083.      argument of `""'.  The function always returns `nil'.
  1084.  
  1085.      This function is normally used to record the input necessary to
  1086.      trigger an Emacs bug, for the sake of a bug report.
  1087.  
  1088.           (open-dribble-file "$j/dribble")
  1089.                => nil
  1090.  
  1091.    See also the `open-termscript' function (*note Terminal Output::.).
  1092.  
  1093.  -- Function: set-input-mode INTERRUPT FLOW QUIT-CHAR
  1094.      This function sets the mode for reading keyboard input.  If
  1095.      INTERRUPT is non-null, then Emacs uses input interrupts.  If it is
  1096.      `nil', then it uses CBREAK mode.
  1097.  
  1098.      If FLOW is non-`nil', then Emacs uses XON/XOFF (`C-q', `C-s') flow
  1099.      control for output to terminal.  This has no effect except in
  1100.      CBREAK mode.  *Note Flow Control::.
  1101.  
  1102.      The normal setting is system dependent.  Some systems always use
  1103.      CBREAK mode regardless of what is specified.
  1104.  
  1105.      If QUIT-CHAR is non-`nil', it specifies the character to use for
  1106.      quitting.  Normally this is 7, the code for `C-g'. *Note
  1107.      Quitting::.
  1108.  
  1109.  -- Variable: meta-flag
  1110.      This variable tells Emacs whether to treat the 0200 bit in keyboard
  1111.      input as the Meta bit.  `nil' means no, and anything else means
  1112.      yes.  In version 19, `meta-flag' will be a function instead of a
  1113.      variable.
  1114.  
  1115.  -- Variable: keyboard-translate-table
  1116.      This variable defines the translate table for keyboard input.  This
  1117.      allows the user to redefine the keys on the keyboard without
  1118.      changing any command bindings.  Its value must be a string or
  1119.      `nil'.
  1120.  
  1121.      If `keyboard-translate-table' is a string, then each character read
  1122.      from the keyboard is looked up in this string and the character in
  1123.      the string is used instead.  If the string is of length N,
  1124.      character codes N and up are untranslated.
  1125.  
  1126.      In the example below, `keyboard-translate-table' is set to a
  1127.      string of 128 characters.  Then the characters `C-s' and `C-\' are
  1128.      swapped and the characters `C-q' and `C-^' are swapped. After
  1129.      executing this function, typing `C-\' has all the usual effects of
  1130.      typing `C-s', and vice versa.  (*Note Flow Control:: for more
  1131.      information on this subject.)
  1132.  
  1133.           (defun evade-flow-control ()
  1134.             "Replace C-s with C-\ and C-q with C-^."
  1135.             (interactive)
  1136.             (let ((the-table (make-string 128 0)))
  1137.               (let ((i 0))
  1138.                 (while (< i 128)
  1139.                   (aset the-table i i)
  1140.                   (setq i (1+ i))))
  1141.           
  1142.               ;; Swap `C-s' and `C-\'.
  1143.               (aset the-table ?\034 ?\^s)
  1144.               (aset the-table ?\^s ?\034)
  1145.               ;; Swap `C-q' and `C-^'.
  1146.               (aset the-table ?\036 ?\^q)
  1147.               (aset the-table ?\^q ?\036)
  1148.           
  1149.               (setq keyboard-translate-table the-table)))
  1150.  
  1151.      Note that this translation is the first thing that happens after a
  1152.      character is read from the terminal.  As a result, record-keeping
  1153.      features such as `recent-keys' and `open-dribble-file' record the
  1154.      translated characters.
  1155.  
  1156. 
  1157. File: elisp,  Node: Terminal Output,  Next: Flow Control,  Prev: Terminal Input,  Up: System Interface
  1158.  
  1159. Terminal Output
  1160. ===============
  1161.  
  1162.    The terminal output functions send or keep track of output sent from
  1163. the computer to the terminal.  The `baud-rate' function tells you what
  1164. Emacs thinks is the output baud rate of the terminal.
  1165.  
  1166.  -- Function: baud-rate
  1167.      This function returns the output baud rate of the terminal.
  1168.  
  1169.           (baud-rate)
  1170.                => 9600
  1171.  
  1172.      If you are running across a network, and different parts of the
  1173.      network work at different baud rates, the value returned by Emacs
  1174.      may be different from the value used by your local terminal.  Some
  1175.      network protocols communicate the local terminal speed to the
  1176.      remote machine, so that Emacs and other programs can get the
  1177.      proper value, but others do not.  If the machine where Emacs is
  1178.      running has the wrong speed setting, you can specify the right
  1179.      speed using the `stty' program.  However, you will have to start
  1180.      Emacs afresh to make this take effect.
  1181.  
  1182.      *Note:* In version 19, `baud-rate' is a variable so that you can
  1183.      change it conveniently within Emacs.
  1184.  
  1185.  -- Function: send-string-to-terminal STRING
  1186.      This function sends STRING to the terminal without alteration.
  1187.      Control characters in STRING will have terminal-dependent effects.
  1188.  
  1189.      One use of this function is to define function keys on terminals
  1190.      that have downloadable function key definitions.  For example,
  1191.      this is how on certain terminals to define function key 4 to move
  1192.      forward four characters (by transmitting the characters `C-u C-f'
  1193.      to the computer):
  1194.  
  1195.           (send-string-to-terminal "\eF4\^U\^F")
  1196.                => nil
  1197.  
  1198.  -- Command: open-termscript FILENAME
  1199.      This function is used to open a "termscript file" that will record
  1200.      all the characters sent by Emacs to the terminal.  It returns
  1201.      `nil'.  Termscript files are useful for investigating problems
  1202.      where Emacs garbles the screen, problems which are due to incorrect
  1203.      termcap entries or to undesirable settings of terminal options more
  1204.      often than actual Emacs bugs.  Once you are certain which
  1205.      characters were actually output, you can determine reliably
  1206.      whether they correspond to the termcap specifications in use.
  1207.  
  1208.      See also `open-dribble-file' in *Note Terminal Input::.
  1209.  
  1210.           (open-termscript "../junk/termscript")
  1211.                => nil
  1212.  
  1213.