home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fs.zip / octave / readline / doc / readline.i01 (.txt) < prev    next >
GNU Info File  |  2000-01-15  |  50KB  |  991 lines

  1. This is Info file readline.info, produced by Makeinfo-1.64 from the
  2. input file rlman.tex.
  3.    This document describes the GNU Readline Library, a utility which
  4. aids in the consistency of user interface across discrete programs that
  5. need to provide a command line interface.
  6.    Copyright (C) 1988, 1991 Free Software Foundation, Inc.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice pare
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided that
  12. the entire resulting derived work is distributed under the terms of a
  13. permission notice identical to this one.
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that this permission notice may be stated in a
  17. translation approved by the Foundation.
  18. File: readline,  Node: Top,  Next: Command Line Editing,  Up: (dir)
  19. GNU Readline Library
  20. ********************
  21.    This document describes the GNU Readline Library, a utility which
  22. aids in the consistency of user interface across discrete programs that
  23. need to provide a command line interface.
  24. * Menu:
  25. * Command Line Editing::       GNU Readline User's Manual.
  26. * Programming with GNU Readline::  GNU Readline Programmer's Manual.
  27. * Concept Index::           Index of concepts described in this manual.
  28. * Function and Variable Index::       Index of externally visible functions
  29.                    and variables.
  30. File: readline,  Node: Command Line Editing,  Next: Programming with GNU Readline,  Prev: Top,  Up: Top
  31. Command Line Editing
  32. ********************
  33.    This chapter describes the basic features of the GNU command line
  34. editing interface.
  35. * Menu:
  36. * Introduction and Notation::   Notation used in this text.
  37. * Readline Interaction::        The minimum set of commands for editing a line.
  38. * Readline Init File::          Customizing Readline from a user's view.
  39. * Bindable Readline Commands::  A description of most of the Readline commands
  40.                                 available for binding
  41. * Readline vi Mode::            A short description of how to make Readline
  42.                                 behave like the vi editor.
  43. File: readline,  Node: Introduction and Notation,  Next: Readline Interaction,  Up: Command Line Editing
  44. Introduction to Line Editing
  45. ============================
  46.    The following paragraphs describe the notation used to represent
  47. keystrokes.
  48.    The text C-k is read as `Control-K' and describes the character
  49. produced when the k key is pressed while the Control key is depressed.
  50.    The text M-k is read as `Meta-K' and describes the character
  51. produced when the meta key (if you have one) is depressed, and the k
  52. key is pressed.  If you do not have a meta key, the identical keystroke
  53. can be generated by typing ESC first, and then typing k.  Either
  54. process is known as "metafying" the k key.
  55.    The text M-C-k is read as `Meta-Control-k' and describes the
  56. character produced by "metafying" C-k.
  57.    In addition, several keys have their own names.  Specifically, DEL,
  58. ESC, LFD, SPC, RET, and TAB all stand for themselves when seen in this
  59. text, or in an init file (*note Readline Init File::.).
  60. File: readline,  Node: Readline Interaction,  Next: Readline Init File,  Prev: Introduction and Notation,  Up: Command Line Editing
  61. Readline Interaction
  62. ====================
  63.    Often during an interactive session you type in a long line of text,
  64. only to notice that the first word on the line is misspelled.  The
  65. Readline library gives you a set of commands for manipulating the text
  66. as you type it in, allowing you to just fix your typo, and not forcing
  67. you to retype the majority of the line.  Using these editing commands,
  68. you move the cursor to the place that needs correction, and delete or
  69. insert the text of the corrections.  Then, when you are satisfied with
  70. the line, you simply press RETURN.  You do not have to be at the end of
  71. the line to press RETURN; the entire line is accepted regardless of the
  72. location of the cursor within the line.
  73. * Menu:
  74. * Readline Bare Essentials::    The least you need to know about Readline.
  75. * Readline Movement Commands::  Moving about the input line.
  76. * Readline Killing Commands::   How to delete text, and how to get it back!
  77. * Readline Arguments::          Giving numeric arguments to commands.
  78. * Searching::                   Searching through previous lines.
  79. File: readline,  Node: Readline Bare Essentials,  Next: Readline Movement Commands,  Up: Readline Interaction
  80. Readline Bare Essentials
  81. ------------------------
  82.    In order to enter characters into the line, simply type them.  The
  83. typed character appears where the cursor was, and then the cursor moves
  84. one space to the right.  If you mistype a character, you can use your
  85. erase character to back up and delete the mistyped character.
  86.    Sometimes you may miss typing a character that you wanted to type,
  87. and not notice your error until you have typed several other
  88. characters.  In that case, you can type C-b to move the cursor to the
  89. left, and then correct your mistake.  Afterwards, you can move the
  90. cursor to the right with C-f.
  91.    When you add text in the middle of a line, you will notice that
  92. characters to the right of the cursor are `pushed over' to make room
  93. for the text that you have inserted.  Likewise, when you delete text
  94. behind the cursor, characters to the right of the cursor are `pulled
  95. back' to fill in the blank space created by the removal of the text.  A
  96. list of the basic bare essentials for editing the text of an input line
  97. follows.
  98.      Move back one character.
  99.      Move forward one character.
  100.      Delete the character to the left of the cursor.
  101.      Delete the character underneath the cursor.
  102. Printing characters
  103.      Insert the character into the line at the cursor.
  104.      Undo the last thing that you did.  You can undo all the way back
  105.      to an empty line.
  106. File: readline,  Node: Readline Movement Commands,  Next: Readline Killing Commands,  Prev: Readline Bare Essentials,  Up: Readline Interaction
  107. Readline Movement Commands
  108. --------------------------
  109.    The above table describes the most basic possible keystrokes that
  110. you need in order to do editing of the input line.  For your
  111. convenience, many other commands have been added in addition to C-b,
  112. C-f, C-d, and DEL.  Here are some commands for moving more rapidly
  113. about the line.
  114.      Move to the start of the line.
  115.      Move to the end of the line.
  116.      Move forward a word.
  117.      Move backward a word.
  118.      Clear the screen, reprinting the current line at the top.
  119.    Notice how C-f moves forward a character, while M-f moves forward a
  120. word.  It is a loose convention that control keystrokes operate on
  121. characters while meta keystrokes operate on words.
  122. File: readline,  Node: Readline Killing Commands,  Next: Readline Arguments,  Prev: Readline Movement Commands,  Up: Readline Interaction
  123. Readline Killing Commands
  124. -------------------------
  125.    "Killing" text means to delete the text from the line, but to save
  126. it away for later use, usually by "yanking" (re-inserting) it back into
  127. the line.  If the description for a command says that it `kills' text,
  128. then you can be sure that you can get the text back in a different (or
  129. the same) place later.
  130.    When you use a kill command, the text is saved in a "kill-ring".
  131. Any number of consecutive kills save all of the killed text together, so
  132. that when you yank it back, you get it all.  The kill ring is not line
  133. specific; the text that you killed on a previously typed line is
  134. available to be yanked back later, when you are typing another line.
  135.    Here is the list of commands for killing text.
  136.      Kill the text from the current cursor position to the end of the
  137.      line.
  138.      Kill from the cursor to the end of the current word, or if between
  139.      words, to the end of the next word.
  140. M-DEL
  141.      Kill from the cursor the start of the previous word, or if between
  142.      words, to the start of the previous word.
  143.      Kill from the cursor to the previous whitespace.  This is
  144.      different than M-DEL because the word boundaries differ.
  145.    And, here is how to "yank" the text back into the line.  Yanking
  146. means to copy the most-recently-killed text from the kill buffer.
  147.      Yank the most recently killed text back into the buffer at the
  148.      cursor.
  149.      Rotate the kill-ring, and yank the new top.  You can only do this
  150.      if the prior command is C-y or M-y.
  151. File: readline,  Node: Readline Arguments,  Next: Searching,  Prev: Readline Killing Commands,  Up: Readline Interaction
  152. Readline Arguments
  153. ------------------
  154.    You can pass numeric arguments to Readline commands.  Sometimes the
  155. argument acts as a repeat count, other times it is the sign of the
  156. argument that is significant.  If you pass a negative argument to a
  157. command which normally acts in a forward direction, that command will
  158. act in a backward direction.  For example, to kill text back to the
  159. start of the line, you might type `M-- C-k'.
  160.    The general way to pass numeric arguments to a command is to type
  161. meta digits before the command.  If the first `digit' you type is a
  162. minus sign (-), then the sign of the argument will be negative.  Once
  163. you have typed one meta digit to get the argument started, you can type
  164. the remainder of the digits, and then the command.  For example, to give
  165. the C-d command an argument of 10, you could type `M-1 0 C-d'.
  166. File: readline,  Node: Searching,  Prev: Readline Arguments,  Up: Readline Interaction
  167. Searching for Commands in the History
  168. -------------------------------------
  169.    Readline provides commands for searching through the command history
  170. for lines containing a specified string.  There are two search modes:
  171. INCREMENTAL and NON-INCREMENTAL.
  172.    Incremental searches begin before the user has finished typing the
  173. search string.  As each character of the search string is typed,
  174. readline displays the next entry from the history matching the string
  175. typed so far.  An incremental search requires only as many characters
  176. as needed to find the desired history entry.  The Escape character is
  177. used to terminate an incremental search.  Control-J will also terminate
  178. the search.  Control-G will abort an incremental search and restore the
  179. original line.  When the search is terminated, the history entry
  180. containing the search string becomes the current line.  To find other
  181. matching entries in the history list, type Control-S or Control-R as
  182. appropriate.  This will search backward or forward in the history for
  183. the next entry matching the search string typed so far.  Any other key
  184. sequence bound to a readline command will terminate the search and
  185. execute that command.  For instance, a `newline' will terminate the
  186. search and accept the line, thereby executing the command from the
  187. history list.
  188.    Non-incremental searches read the entire search string before
  189. starting to search for matching history lines.  The search string may be
  190. typed by the user or part of the contents of the current line.
  191. File: readline,  Node: Readline Init File,  Next: Bindable Readline Commands,  Prev: Readline Interaction,  Up: Command Line Editing
  192. Readline Init File
  193. ==================
  194.    Although the Readline library comes with a set of `emacs'-like
  195. keybindings installed by default, it is possible that you would like to
  196. use a different set of keybindings.  You can customize programs that
  197. use Readline by putting commands in an "inputrc" file in your home
  198. directory.  The name of this file is taken from the value of the
  199. environment variable `INPUTRC'.  If that variable is unset, the default
  200. is `~/.inputrc'.
  201.    When a program which uses the Readline library starts up, the init
  202. file is read, and the key bindings are set.
  203.    In addition, the `C-x C-r' command re-reads this init file, thus
  204. incorporating any changes that you might have made to it.
  205. * Menu:
  206. * Readline Init File Syntax::   Syntax for the commands in the inputrc file.
  207. * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
  208. * Sample Init File::            An example inputrc file.
  209. File: readline,  Node: Readline Init File Syntax,  Next: Conditional Init Constructs,  Up: Readline Init File
  210. Readline Init File Syntax
  211. -------------------------
  212.    There are only a few basic constructs allowed in the Readline init
  213. file.  Blank lines are ignored.  Lines beginning with a `#' are
  214. comments.  Lines beginning with a `$' indicate conditional constructs
  215. (*note Conditional Init Constructs::.).  Other lines denote variable
  216. settings and key bindings.
  217. Variable Settings
  218.      You can change the state of a few variables in Readline by using
  219.      the `set' command within the init file.  Here is how you would
  220.      specify that you wish to use `vi' line editing commands:
  221.           set editing-mode vi
  222.      Right now, there are only a few variables which can be set; so
  223.      few, in fact, that we just list them here:
  224.     `bell-style'
  225.           Controls what happens when Readline wants to ring the
  226.           terminal bell.  If set to `none', Readline never rings the
  227.           bell.  If set to `visible', Readline uses a visible bell if
  228.           one is available.  If set to `audible' (the default),
  229.           Readline attempts to ring the terminal's bell.
  230.     `comment-begin'
  231.           The string to insert at the beginning of the line when the
  232.           `insert-comment' command is executed.  The default value is
  233.           `"#"'.
  234.     `completion-query-items'
  235.           The number of possible completions that determines when the
  236.           user is asked whether he wants to see the list of
  237.           possibilities.  If the number of possible completions is
  238.           greater than this value, Readline will ask the user whether
  239.           or not he wishes to view them; otherwise, they are simply
  240.           listed.  The default limit is `100'.
  241.     `convert-meta'
  242.           If set to `on', Readline will convert characters with the
  243.           eigth bit set to an ASCII key sequence by stripping the eigth
  244.           bit and prepending an ESC character, converting them to a
  245.           meta-prefixed key sequence.  The default value is `on'.
  246.     `disable-completion'
  247.           If set to `On', readline will inhibit word completion.
  248.           Completion  characters will be inserted into the line as if
  249.           they had been mapped to `self-insert'.  The default is `off'.
  250.     `editing-mode'
  251.           The `editing-mode' variable controls which editing mode you
  252.           are using.  By default, Readline starts up in Emacs editing
  253.           mode, where the keystrokes are most similar to Emacs.  This
  254.           variable can be set to either `emacs' or `vi'.
  255.     `enable-keypad'
  256.           When set to `on', readline will try to enable the application
  257.           keypad when it is called.  Some systems need this to enable
  258.           the arrow keys.  The default is `off'.
  259.     `expand-tilde'
  260.           If set to `on', tilde expansion is performed when Readline
  261.           attempts word completion.  The default is `off'.
  262.     `horizontal-scroll-mode'
  263.           This variable can be set to either `on' or `off'.  Setting it
  264.           to `on' means that the text of the lines that you edit will
  265.           scroll horizontally on a single screen line when they are
  266.           longer than the width of the screen, instead of wrapping onto
  267.           a new screen line.  By default, this variable is set to `off'.
  268.     `keymap'
  269.           Sets Readline's idea of the current keymap for key binding
  270.           commands.  Acceptable `keymap' names are `emacs',
  271.           `emacs-standard', `emacs-meta', `emacs-ctlx', `vi',
  272.           `vi-command', and `vi-insert'.  `vi' is equivalent to
  273.           `vi-command'; `emacs' is equivalent to `emacs-standard'.  The
  274.           default value is `emacs'.  The value of the `editing-mode'
  275.           variable also affects the default keymap.
  276.     `mark-directories'
  277.           If set to `on', completed directory names have a slash
  278.           appended.  The default is `on'.
  279.     `mark-modified-lines'
  280.           This variable, when set to `on', says to display an asterisk
  281.           (`*') at the start of history lines which have been modified.
  282.           This variable is `off' by default.
  283.     `input-meta'
  284.           If set to `on', Readline will enable eight-bit input (it will
  285.           not strip the eighth bit from the characters it reads),
  286.           regardless of what the terminal claims it can support.  The
  287.           default value is `off'.  The name `meta-flag' is a synonym
  288.           for this variable.
  289.     `output-meta'
  290.           If set to `on', Readline will display characters with the
  291.           eighth bit set directly rather than as a meta-prefixed escape
  292.           sequence.  The default is `off'.
  293.     `show-all-if-ambiguous'
  294.           This alters the default behavior of the completion functions.
  295.           If set to `on', words which have more than one possible
  296.           completion cause the matches to be listed immediately instead
  297.           of ringing the bell.  The default value is `off'.
  298.     `visible-stats'
  299.           If set to `on', a character denoting a file's type is
  300.           appended to the filename when listing possible completions.
  301.           The default is `off'.
  302. Key Bindings
  303.      The syntax for controlling key bindings in the init file is
  304.      simple.  First you have to know the name of the command that you
  305.      want to change.  The following pages contain tables of the command
  306.      name, the default keybinding, and a short description of what the
  307.      command does.
  308.      Once you know the name of the command, simply place the name of
  309.      the key you wish to bind the command to, a colon, and then the
  310.      name of the command on a line in the init file.  The name of the
  311.      key can be expressed in different ways, depending on which is most
  312.      comfortable for you.
  313.     KEYNAME: FUNCTION-NAME or MACRO
  314.           KEYNAME is the name of a key spelled out in English.  For
  315.           example:
  316.                Control-u: universal-argument
  317.                Meta-Rubout: backward-kill-word
  318.                Control-o: "> output"
  319.           In the above example, `C-u' is bound to the function
  320.           `universal-argument', and `C-o' is bound to run the macro
  321.           expressed on the right hand side (that is, to insert the text
  322.           `> output' into the line).
  323.     "KEYSEQ": FUNCTION-NAME or MACRO
  324.           KEYSEQ differs from KEYNAME above in that strings denoting an
  325.           entire key sequence can be specified, by placing the key
  326.           sequence in double quotes.  Some GNU Emacs style key escapes
  327.           can be used, as in the following example, but the special
  328.           character names are not recognized.
  329.                "\C-u": universal-argument
  330.                "\C-x\C-r": re-read-init-file
  331.                "\e[11~": "Function Key 1"
  332.           In the above example, `C-u' is bound to the function
  333.           `universal-argument' (just as it was in the first example),
  334.           `C-x C-r' is bound to the function `re-read-init-file', and
  335.           `ESC [ 1 1 ~' is bound to insert the text `Function Key 1'.
  336.           The following escape sequences are available when specifying
  337.           key sequences:
  338.          ``\C-''
  339.                control prefix
  340.          ``\M-''
  341.                meta prefix
  342.          ``\e''
  343.                an escape character
  344.          ``\\''
  345.                backslash
  346.          ``\"''
  347.                "
  348.          ``\'''
  349.                '
  350.           When entering the text of a macro, single or double quotes
  351.           should be used to indicate a macro definition.  Unquoted text
  352.           is assumed to be a function name.  Backslash will quote any
  353.           character in the macro text, including `"' and `''.  For
  354.           example, the following binding will make `C-x \' insert a
  355.           single `\' into the line:
  356.                "\C-x\\": "\\"
  357. File: readline,  Node: Conditional Init Constructs,  Next: Sample Init File,  Prev: Readline Init File Syntax,  Up: Readline Init File
  358. Conditional Init Constructs
  359. ---------------------------
  360.    Readline implements a facility similar in spirit to the conditional
  361. compilation features of the C preprocessor which allows key bindings
  362. and variable settings to be performed as the result of tests.  There
  363. are three parser directives used.
  364. `$if'
  365.      The `$if' construct allows bindings to be made based on the
  366.      editing mode, the terminal being used, or the application using
  367.      Readline.  The text of the test extends to the end of the line; no
  368.      characters are required to isolate it.
  369.     `mode'
  370.           The `mode=' form of the `$if' directive is used to test
  371.           whether Readline is in `emacs' or `vi' mode.  This may be
  372.           used in conjunction with the `set keymap' command, for
  373.           instance, to set bindings in the `emacs-standard' and
  374.           `emacs-ctlx' keymaps only if Readline is starting out in
  375.           `emacs' mode.
  376.     `term'
  377.           The `term=' form may be used to include terminal-specific key
  378.           bindings, perhaps to bind the key sequences output by the
  379.           terminal's function keys.  The word on the right side of the
  380.           `=' is tested against the full name of the terminal and the
  381.           portion of the terminal name before the first `-'.  This
  382.           allows `sun' to match both `sun' and `sun-cmd', for instance.
  383.     `application'
  384.           The APPLICATION construct is used to include
  385.           application-specific settings.  Each program using the
  386.           Readline library sets the APPLICATION NAME, and you can test
  387.           for it.  This could be used to bind key sequences to
  388.           functions useful for a specific program.  For instance, the
  389.           following command adds a key sequence that quotes the current
  390.           or previous word in Bash:
  391.                $if Bash
  392.                # Quote the current or previous word
  393.                "\C-xq": "\eb\"\ef\""
  394.                $endif
  395. `$endif'
  396.      This command, as you saw in the previous example, terminates an
  397.      `$if' command.
  398. `$else'
  399.      Commands in this branch of the `$if' directive are executed if the
  400.      test fails.
  401. File: readline,  Node: Sample Init File,  Prev: Conditional Init Constructs,  Up: Readline Init File
  402. Sample Init File
  403. ----------------
  404.    Here is an example of an inputrc file.  This illustrates key
  405. binding, variable assignment, and conditional syntax.
  406.      # This file controls the behaviour of line input editing for
  407.      # programs that use the Gnu Readline library.  Existing programs
  408.      # include FTP, Bash, and Gdb.
  409.      #
  410.      # You can re-read the inputrc file with C-x C-r.
  411.      # Lines beginning with '#' are comments.
  412.      #
  413.      # Set various bindings for emacs mode.
  414.      
  415.      set editing-mode emacs
  416.      
  417.      $if mode=emacs
  418.      
  419.      Meta-Control-h: backward-kill-word      Text after the function name is ignored
  420.      
  421.      #
  422.      # Arrow keys in keypad mode
  423.      #
  424.      #"\M-OD":        backward-char
  425.      #"\M-OC":        forward-char
  426.      #"\M-OA":        previous-history
  427.      #"\M-OB":        next-history
  428.      #
  429.      # Arrow keys in ANSI mode
  430.      #
  431.      "\M-[D":        backward-char
  432.      "\M-[C":        forward-char
  433.      "\M-[A":        previous-history
  434.      "\M-[B":        next-history
  435.      #
  436.      # Arrow keys in 8 bit keypad mode
  437.      #
  438.      #"\M-\C-OD":       backward-char
  439.      #"\M-\C-OC":       forward-char
  440.      #"\M-\C-OA":       previous-history
  441.      #"\M-\C-OB":       next-history
  442.      #
  443.      # Arrow keys in 8 bit ANSI mode
  444.      #
  445.      #"\M-\C-[D":       backward-char
  446.      #"\M-\C-[C":       forward-char
  447.      #"\M-\C-[A":       previous-history
  448.      #"\M-\C-[B":       next-history
  449.      
  450.      C-q: quoted-insert
  451.      
  452.      $endif
  453.      
  454.      # An old-style binding.  This happens to be the default.
  455.      TAB: complete
  456.      
  457.      # Macros that are convenient for shell interaction
  458.      $if Bash
  459.      # edit the path
  460.      "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
  461.      # prepare to type a quoted word -- insert open and close double quotes
  462.      # and move to just after the open quote
  463.      "\C-x\"": "\"\"\C-b"
  464.      # insert a backslash (testing backslash escapes in sequences and macros)
  465.      "\C-x\\": "\\"
  466.      # Quote the current or previous word
  467.      "\C-xq": "\eb\"\ef\""
  468.      # Add a binding to refresh the line, which is unbound
  469.      "\C-xr": redraw-current-line
  470.      # Edit variable on current line.
  471.      "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
  472.      $endif
  473.      
  474.      # use a visible bell if one is available
  475.      set bell-style visible
  476.      
  477.      # don't strip characters to 7 bits when reading
  478.      set input-meta on
  479.      
  480.      # allow iso-latin1 characters to be inserted rather than converted to
  481.      # prefix-meta sequences
  482.      set convert-meta off
  483.      
  484.      # display characters with the eighth bit set directly rather than
  485.      # as meta-prefixed characters
  486.      set output-meta on
  487.      
  488.      # if there are more than 150 possible completions for a word, ask the
  489.      # user if he wants to see all of them
  490.      set completion-query-items 150
  491.      
  492.      # For FTP
  493.      $if Ftp
  494.      "\C-xg": "get \M-?"
  495.      "\C-xt": "put \M-?"
  496.      "\M-.": yank-last-arg
  497.      $endif
  498. File: readline,  Node: Bindable Readline Commands,  Next: Readline vi Mode,  Prev: Readline Init File,  Up: Command Line Editing
  499. Bindable Readline Commands
  500. ==========================
  501. * Menu:
  502. * Commands For Moving::         Moving about the line.
  503. * Commands For History::        Getting at previous lines.
  504. * Commands For Text::           Commands for changing text.
  505. * Commands For Killing::        Commands for killing and yanking.
  506. * Numeric Arguments::           Specifying numeric arguments, repeat counts.
  507. * Commands For Completion::     Getting Readline to do the typing for you.
  508. * Keyboard Macros::             Saving and re-executing typed characters
  509. * Miscellaneous Commands::      Other miscellaneous commands.
  510.    This section describes Readline commands that may be bound to key
  511. sequences.
  512. File: readline,  Node: Commands For Moving,  Next: Commands For History,  Up: Bindable Readline Commands
  513. Commands For Moving
  514. -------------------
  515. `beginning-of-line (C-a)'
  516.      Move to the start of the current line.
  517. `end-of-line (C-e)'
  518.      Move to the end of the line.
  519. `forward-char (C-f)'
  520.      Move forward a character.
  521. `backward-char (C-b)'
  522.      Move back a character.
  523. `forward-word (M-f)'
  524.      Move forward to the end of the next word.  Words are composed of
  525.      letters and digits.
  526. `backward-word (M-b)'
  527.      Move back to the start of this, or the previous, word.  Words are
  528.      composed of letters and digits.
  529. `clear-screen (C-l)'
  530.      Clear the screen and redraw the current line, leaving the current
  531.      line at the top of the screen.
  532. `redraw-current-line ()'
  533.      Refresh the current line.  By default, this is unbound.
  534. File: readline,  Node: Commands For History,  Next: Commands For Text,  Prev: Commands For Moving,  Up: Bindable Readline Commands
  535. Commands For Manipulating The History
  536. -------------------------------------
  537. `accept-line (Newline, Return)'
  538.      Accept the line regardless of where the cursor is.  If this line is
  539.      non-empty, add it to the history list.  If this line was a history
  540.      line, then restore the history line to its original state.
  541. `previous-history (C-p)'
  542.      Move `up' through the history list.
  543. `next-history (C-n)'
  544.      Move `down' through the history list.
  545. `beginning-of-history (M-<)'
  546.      Move to the first line in the history.
  547. `end-of-history (M->)'
  548.      Move to the end of the input history, i.e., the line you are
  549.      entering.
  550. `reverse-search-history (C-r)'
  551.      Search backward starting at the current line and moving `up'
  552.      through the history as necessary.  This is an incremental search.
  553. `forward-search-history (C-s)'
  554.      Search forward starting at the current line and moving `down'
  555.      through the the history as necessary.  This is an incremental
  556.      search.
  557. `non-incremental-reverse-search-history (M-p)'
  558.      Search backward starting at the current line and moving `up'
  559.      through the history as necessary using a non-incremental search
  560.      for a string supplied by the user.
  561. `non-incremental-forward-search-history (M-n)'
  562.      Search forward starting at the current line and moving `down'
  563.      through the the history as necessary using a non-incremental search
  564.      for a string supplied by the user.
  565. `history-search-forward ()'
  566.      Search forward through the history for the string of characters
  567.      between the start of the current line and the current cursor
  568.      position (the `point').  This is a non-incremental search.  By
  569.      default, this command is unbound.
  570. `history-search-backward ()'
  571.      Search backward through the history for the string of characters
  572.      between the start of the current line and the point.  This is a
  573.      non-incremental search.  By default, this command is unbound.
  574. `yank-nth-arg (M-C-y)'
  575.      Insert the first argument to the previous command (usually the
  576.      second word on the previous line).  With an argument N, insert the
  577.      Nth word from the previous command (the words in the previous
  578.      command begin with word 0).  A negative argument inserts the Nth
  579.      word from the end of the previous command.
  580. `yank-last-arg (M-., M-_)'
  581.      Insert last argument to the previous command (the last word of the
  582.      previous history entry).  With an argument, behave exactly like
  583.      `yank-nth-arg'.
  584. File: readline,  Node: Commands For Text,  Next: Commands For Killing,  Prev: Commands For History,  Up: Bindable Readline Commands
  585. Commands For Changing Text
  586. --------------------------
  587. `delete-char (C-d)'
  588.      Delete the character under the cursor.  If the cursor is at the
  589.      beginning of the line, there are no characters in the line, and
  590.      the last character typed was not `C-d', then return `EOF'.
  591. `backward-delete-char (Rubout)'
  592.      Delete the character behind the cursor.  A numeric arg says to kill
  593.      the characters instead of deleting them.
  594. `quoted-insert (C-q, C-v)'
  595.      Add the next character that you type to the line verbatim.  This is
  596.      how to insert key sequences like C-q, for example.
  597. `tab-insert (M-TAB)'
  598.      Insert a tab character.
  599. `self-insert (a, b, A, 1, !, ...)'
  600.      Insert yourself.
  601. `transpose-chars (C-t)'
  602.      Drag the character before the cursor forward over the character at
  603.      the cursor, moving the cursor forward as well.  If the insertion
  604.      point is at the end of the line, then this transposes the last two
  605.      characters of the line.  Negative argumentss don't work.
  606. `transpose-words (M-t)'
  607.      Drag the word behind the cursor past the word in front of the
  608.      cursor moving the cursor over that word as well.
  609. `upcase-word (M-u)'
  610.      Uppercase the current (or following) word.  With a negative
  611.      argument, do the previous word, but do not move the cursor.
  612. `downcase-word (M-l)'
  613.      Lowercase the current (or following) word.  With a negative
  614.      argument, do the previous word, but do not move the cursor.
  615. `capitalize-word (M-c)'
  616.      Capitalize the current (or following) word.  With a negative
  617.      argument, do the previous word, but do not move the cursor.
  618. File: readline,  Node: Commands For Killing,  Next: Numeric Arguments,  Prev: Commands For Text,  Up: Bindable Readline Commands
  619. Killing And Yanking
  620. -------------------
  621. `kill-line (C-k)'
  622.      Kill the text from the current cursor position to the end of the
  623.      line.
  624. `backward-kill-line (C-x Rubout)'
  625.      Kill backward to the beginning of the line.
  626. `unix-line-discard (C-u)'
  627.      Kill backward from the cursor to the beginning of the current line.
  628.      Save the killed text on the kill-ring.
  629. `kill-whole-line ()'
  630.      Kill all characters on the current line, no matter where the
  631.      cursor is.  By default, this is unbound.
  632. `kill-word (M-d)'
  633.      Kill from the cursor to the end of the current word, or if between
  634.      words, to the end of the next word.  Word boundaries are the same
  635.      as `forward-word'.
  636. `backward-kill-word (M-DEL)'
  637.      Kill the word behind the cursor.  Word boundaries are the same as
  638.      `backward-word'.
  639. `unix-word-rubout (C-w)'
  640.      Kill the word behind the cursor, using white space as a word
  641.      boundary.  The killed text is saved on the kill-ring.
  642. `delete-horizontal-space ()'
  643.      Delete all spaces and tabs around point.  By default, this is
  644.      unbound.
  645. `kill-region ()'
  646.      Kill the text between the point and the *mark* (saved cursor
  647.      position.  This text is referred to as the REGION.  By default,
  648.      this command is unbound.
  649. `copy-region-as-kill ()'
  650.      Copy the text in the region to the kill buffer, so you can yank it
  651.      right away.  By default, this command is unbound.
  652. `copy-backward-word ()'
  653.      Copy the word before point to the kill buffer.  By default, this
  654.      command is unbound.
  655. `copy-forward-word ()'
  656.      Copy the word following point to the kill buffer.  By default,
  657.      this command is unbound.
  658. `yank (C-y)'
  659.      Yank the top of the kill ring into the buffer at the current
  660.      cursor position.
  661. `yank-pop (M-y)'
  662.      Rotate the kill-ring, and yank the new top.  You can only do this
  663.      if the prior command is yank or yank-pop.
  664. File: readline,  Node: Numeric Arguments,  Next: Commands For Completion,  Prev: Commands For Killing,  Up: Bindable Readline Commands
  665. Specifying Numeric Arguments
  666. ----------------------------
  667. `digit-argument (M-0, M-1, ... M--)'
  668.      Add this digit to the argument already accumulating, or start a new
  669.      argument.  M- starts a negative argument.
  670. `universal-argument ()'
  671.      This is another way to specify an argument.  If this command is
  672.      followed by one or more digits, optionally with a leading minus
  673.      sign, those digits define the argument.  If the command is
  674.      followed by digits, executing `universal-argument' again ends the
  675.      numeric argument, but is otherwise ignored.  As a special case, if
  676.      this command is immediately followed by a character that is
  677.      neither a digit or minus sign, the argument count for the next
  678.      command is multiplied by four.  The argument count is initially
  679.      one, so executing this function the first time makes the argument
  680.      count four, a second time makes the argument count sixteen, and so
  681.      on.  By default, this is not bound to a key.
  682. File: readline,  Node: Commands For Completion,  Next: Keyboard Macros,  Prev: Numeric Arguments,  Up: Bindable Readline Commands
  683. Letting Readline Type For You
  684. -----------------------------
  685. `complete (TAB)'
  686.      Attempt to do completion on the text before the cursor.  This is
  687.      application-specific.  Generally, if you are typing a filename
  688.      argument, you can do filename completion; if you are typing a
  689.      command, you can do command completion, if you are typing in a
  690.      symbol to GDB, you can do symbol name completion, if you are
  691.      typing in a variable to Bash, you can do variable name completion,
  692.      and so on.
  693. `possible-completions (M-?)'
  694.      List the possible completions of the text before the cursor.
  695. `insert-completions (M-*)'
  696.      Insert all completions of the text before point that would have
  697.      been generated by `possible-completions'.
  698. File: readline,  Node: Keyboard Macros,  Next: Miscellaneous Commands,  Prev: Commands For Completion,  Up: Bindable Readline Commands
  699. Keyboard Macros
  700. ---------------
  701. `start-kbd-macro (C-x ()'
  702.      Begin saving the characters typed into the current keyboard macro.
  703. `end-kbd-macro (C-x ))'
  704.      Stop saving the characters typed into the current keyboard macro
  705.      and save the definition.
  706. `call-last-kbd-macro (C-x e)'
  707.      Re-execute the last keyboard macro defined, by making the
  708.      characters in the macro appear as if typed at the keyboard.
  709. File: readline,  Node: Miscellaneous Commands,  Prev: Keyboard Macros,  Up: Bindable Readline Commands
  710. Some Miscellaneous Commands
  711. ---------------------------
  712. `re-read-init-file (C-x C-r)'
  713.      Read in the contents of the inputrc file, and incorporate any
  714.      bindings or variable assignments found there.
  715. `abort (C-g)'
  716.      Abort the current editing command and ring the terminal's bell
  717.      (subject to the setting of `bell-style').
  718. `do-uppercase-version (M-a, M-b, M-X, ...)'
  719.      If the metafied character X is lowercase, run the command that is
  720.      bound to the corresponding uppercase character.
  721. `prefix-meta (ESC)'
  722.      Make the next character that you type be metafied.  This is for
  723.      people without a meta key.  Typing `ESC f' is equivalent to typing
  724.      `M-f'.
  725. `undo (C-_, C-x C-u)'
  726.      Incremental undo, separately remembered for each line.
  727. `revert-line (M-r)'
  728.      Undo all changes made to this line.  This is like typing the `undo'
  729.      command enough times to get back to the beginning.
  730. `tilde-expand (M-~)'
  731.      Perform tilde expansion on the current word.
  732. `set-mark (C-@)'
  733.      Set the mark to the current point.  If a numeric argument is
  734.      supplied, the mark is set to that position.
  735. `exchange-point-and-mark (C-x C-x)'
  736.      Swap the point with the mark.  The current cursor position is set
  737.      to the saved position, and the old cursor position is saved as the
  738.      mark.
  739. `character-search (C-])'
  740.      A character is read and point is moved to the next occurrence of
  741.      that character.  A negative count searches for previous
  742.      occurrences.
  743. `character-search-backward (M-C-])'
  744.      A character is read and point is moved to the previous occurrence
  745.      of that character.  A negative count searches for subsequent
  746.      occurrences.
  747. `insert-comment (M-#)'
  748.      The value of the `comment-begin' variable is inserted at the
  749.      beginning of the current line, and the line is accepted as if a
  750.      newline had been typed.
  751. `dump-functions ()'
  752.      Print all of the functions and their key bindings to the readline
  753.      output stream.  If a numeric argument is supplied, the output is
  754.      formatted in such a way that it can be made part of an INPUTRC
  755.      file.  This command is unbound by default.
  756. `dump-variables ()'
  757.      Print all of the settable variables and their values to the
  758.      readline output stream.  If a numeric argument is supplied, the
  759.      output is formatted in such a way that it can be made part of an
  760.      INPUTRC file.  This command is unbound by default.
  761. `dump-macros ()'
  762.      Print all of the readline key sequences bound to macros and the
  763.      strings they ouput.  If a numeric argument is supplied, the output
  764.      is formatted in such a way that it can be made part of an INPUTRC
  765.      file.  This command is unbound by default.
  766. File: readline,  Node: Readline vi Mode,  Prev: Bindable Readline Commands,  Up: Command Line Editing
  767. Readline vi Mode
  768. ================
  769.    While the Readline library does not have a full set of `vi' editing
  770. functions, it does contain enough to allow simple editing of the line.
  771. The Readline `vi' mode behaves as specified in the POSIX 1003.2
  772. standard.
  773.    In order to switch interactively between `emacs' and `vi' editing
  774. modes, use the command M-C-j (toggle-editing-mode).  The Readline
  775. default is `emacs' mode.
  776.    When you enter a line in `vi' mode, you are already placed in
  777. `insertion' mode, as if you had typed an `i'.  Pressing ESC switches
  778. you into `command' mode, where you can edit the text of the line with
  779. the standard `vi' movement keys, move to previous history lines with
  780. `k' and subsequent lines with `j', and so forth.
  781.    This document describes the GNU Readline Library, a utility for
  782. aiding in the consitency of user interface across discrete programs
  783. that need to provide a command line interface.
  784.    Copyright (C) 1988, 1994, 1996 Free Software Foundation, Inc.
  785.    Permission is granted to make and distribute verbatim copies of this
  786. manual provided the copyright notice and this permission notice pare
  787. preserved on all copies.
  788.    Permission is granted to copy and distribute modified versions of
  789. this manual under the conditions for verbatim copying, provided that
  790. the entire resulting derived work is distributed under the terms of a
  791. permission notice identical to this one.
  792.    Permission is granted to copy and distribute translations of this
  793. manual into another language, under the above conditions for modified
  794. versions, except that this permission notice may be stated in a
  795. translation approved by the Foundation.
  796. File: readline,  Node: Programming with GNU Readline,  Next: Concept Index,  Prev: Command Line Editing,  Up: Top
  797. Programming with GNU Readline
  798. *****************************
  799.    This chapter describes the interface between the GNU Readline
  800. Library and other programs.  If you are a programmer, and you wish to
  801. include the features found in GNU Readline such as completion, line
  802. editing, and interactive history manipulation in your own programs,
  803. this section is for you.
  804. * Menu:
  805. * Basic Behavior::    Using the default behavior of Readline.
  806. * Custom Functions::    Adding your own functions to Readline.
  807. * Readline Variables::            Variables accessible to custom
  808.                     functions.
  809. * Readline Convenience Functions::    Functions which Readline supplies to
  810.                     aid in writing your own
  811. * Custom Completers::    Supplanting or supplementing Readline's
  812.             completion functions.
  813. File: readline,  Node: Basic Behavior,  Next: Custom Functions,  Up: Programming with GNU Readline
  814. Basic Behavior
  815. ==============
  816.    Many programs provide a command line interface, such as `mail',
  817. `ftp', and `sh'.  For such programs, the default behaviour of Readline
  818. is sufficient.  This section describes how to use Readline in the
  819. simplest way possible, perhaps to replace calls in your code to
  820. `gets()' or `fgets ()'.
  821.    The function `readline ()' prints a prompt and then reads and returns
  822. a single line of text from the user.  The line `readline' returns is
  823. allocated with `malloc ()'; you should `free ()' the line when you are
  824. done with it.  The declaration for `readline' in ANSI C is
  825.      `char *readline (char *PROMPT);'
  826. So, one might say
  827.      `char *line = readline ("Enter a line: ");'
  828. in order to read a line of text from the user.  The line returned has
  829. the final newline removed, so only the text remains.
  830.    If `readline' encounters an `EOF' while reading the line, and the
  831. line is empty at that point, then `(char *)NULL' is returned.
  832. Otherwise, the line is ended just as if a newline had been typed.
  833.    If you want the user to be able to get at the line later, (with C-p
  834. for example), you must call `add_history ()' to save the line away in a
  835. "history" list of such lines.
  836.      `add_history (line)';
  837. For full details on the GNU History Library, see the associated manual.
  838.    It is preferable to avoid saving empty lines on the history list,
  839. since users rarely have a burning need to reuse a blank line.  Here is
  840. a function which usefully replaces the standard `gets ()' library
  841. function, and has the advantage of no static buffer to overflow:
  842.      /* A static variable for holding the line. */
  843.      static char *line_read = (char *)NULL;
  844.      
  845.      /* Read a string, and return a pointer to it.  Returns NULL on EOF. */
  846.      char *
  847.      rl_gets ()
  848.      {
  849.        /* If the buffer has already been allocated, return the memory
  850.           to the free pool. */
  851.        if (line_read)
  852.          {
  853.            free (line_read);
  854.            line_read = (char *)NULL;
  855.          }
  856.      
  857.        /* Get a line from the user. */
  858.        line_read = readline ("");
  859.      
  860.        /* If the line has any text in it, save it on the history. */
  861.        if (line_read && *line_read)
  862.          add_history (line_read);
  863.      
  864.        return (line_read);
  865.      }
  866.    This function gives the user the default behaviour of TAB
  867. completion: completion on file names.  If you do not want Readline to
  868. complete on filenames, you can change the binding of the TAB key with
  869. `rl_bind_key ()'.
  870.      `int rl_bind_key (int KEY, int (*FUNCTION)());'
  871.    `rl_bind_key ()' takes two arguments: KEY is the character that you
  872. want to bind, and FUNCTION is the address of the function to call when
  873. KEY is pressed.  Binding TAB to `rl_insert ()' makes TAB insert itself.
  874. `rl_bind_key ()' returns non-zero if KEY is not a valid ASCII character
  875. code (between 0 and 255).
  876.    Thus, to disable the default TAB behavior, the following suffices:
  877.      `rl_bind_key ('\t', rl_insert);'
  878.    This code should be executed once at the start of your program; you
  879. might write a function called `initialize_readline ()' which performs
  880. this and other desired initializations, such as installing custom
  881. completers (*note Custom Completers::.).
  882. File: readline,  Node: Custom Functions,  Next: Readline Variables,  Prev: Basic Behavior,  Up: Programming with GNU Readline
  883. Custom Functions
  884. ================
  885.    Readline provides many functions for manipulating the text of the
  886. line, but it isn't possible to anticipate the needs of all programs.
  887. This section describes the various functions and variables defined
  888. within the Readline library which allow a user program to add
  889. customized functionality to Readline.
  890. * Menu:
  891. * The Function Type::    C declarations to make code readable.
  892. * Function Writing::    Variables and calling conventions.
  893. File: readline,  Node: The Function Type,  Next: Function Writing,  Up: Custom Functions
  894. The Function Type
  895. -----------------
  896.    For readabilty, we declare a new type of object, called "Function".
  897. A `Function' is a C function which returns an `int'.  The type
  898. declaration for `Function' is:
  899. `typedef int Function ();'
  900.    The reason for declaring this new type is to make it easier to write
  901. code describing pointers to C functions.  Let us say we had a variable
  902. called FUNC which was a pointer to a function.  Instead of the classic
  903. C declaration
  904.    `int (*)()func;'
  905. we may write
  906.    `Function *func;'
  907. Similarly, there are
  908.      typedef void VFunction ();
  909.      typedef char *CPFunction (); and
  910.      typedef char **CPPFunction ();
  911. for functions returning no value, `pointer to char', and `pointer to
  912. pointer to char', respectively.
  913. File: readline,  Node: Function Writing,  Prev: The Function Type,  Up: Custom Functions
  914. Writing a New Function
  915. ----------------------
  916.    In order to write new functions for Readline, you need to know the
  917. calling conventions for keyboard-invoked functions, and the names of the
  918. variables that describe the current state of the line read so far.
  919.    The calling sequence for a command `foo' looks like
  920.      `foo (int count, int key)'
  921. where COUNT is the numeric argument (or 1 if defaulted) and KEY is the
  922. key that invoked this function.
  923.    It is completely up to the function as to what should be done with
  924. the numeric argument.  Some functions use it as a repeat count, some as
  925. a flag, and others to choose alternate behavior (refreshing the current
  926. line as opposed to refreshing the screen, for example).  Some choose to
  927. ignore it.  In general, if a function uses the numeric argument as a
  928. repeat count, it should be able to do something useful with both
  929. negative and positive arguments.  At the very least, it should be aware
  930. that it can be passed a negative argument.
  931. File: readline,  Node: Readline Variables,  Next: Readline Convenience Functions,  Prev: Custom Functions,  Up: Programming with GNU Readline
  932. Readline Variables
  933. ==================
  934.    These variables are available to function writers.
  935.  - Variable: char * rl_line_buffer
  936.      This is the line gathered so far.  You are welcome to modify the
  937.      contents of the line, but see *Note Allowing Undoing::.
  938.  - Variable: int rl_point
  939.      The offset of the current cursor position in `rl_line_buffer' (the
  940.      *point*).
  941.  - Variable: int rl_end
  942.      The number of characters present in `rl_line_buffer'.  When
  943.      `rl_point' is at the end of the line, `rl_point' and `rl_end' are
  944.      equal.
  945.  - Variable: int rl_mark
  946.      The mark (saved position) in the current line.  If set, the mark
  947.      and point define a *region*.
  948.  - Variable: int rl_done
  949.      Setting this to a non-zero value causes Readline to return the
  950.      current line immediately.
  951.  - Variable: int rl_pending_input
  952.      Setting this to a value makes it the next keystroke read.  This is
  953.      a way to stuff a single character into the input stream.
  954.  - Variable: char * rl_prompt
  955.      The prompt Readline uses.  This is set from the argument to
  956.      `readline ()', and should not be assigned to directly.
  957.  - Variable: char * rl_library_version
  958.      The version number of this revision of the library.
  959.  - Variable: char * rl_terminal_name
  960.      The terminal type, used for initialization.
  961.  - Variable: char * rl_readline_name
  962.      This variable is set to a unique name by each application using
  963.      Readline.  The value allows conditional parsing of the inputrc file
  964.      (*note Conditional Init Constructs::.).
  965.  - Variable: FILE * rl_instream
  966.      The stdio stream from which Readline reads input.
  967.  - Variable: FILE * rl_outstream
  968.      The stdio stream to which Readline performs output.
  969.  - Variable: Function * rl_startup_hook
  970.      If non-zero, this is the address of a function to call just before
  971.      `readline' prints the first prompt.
  972.  - Variable: Function * rl_event_hook
  973.      If non-zero, this is the address of a function to call periodically
  974.      when readline is waiting for terminal input.
  975.  - Variable: Function * rl_getc_function
  976.      If non-zero, `readline' will call indirectly through this pointer
  977.      to get a character from the input stream.  By default, it is set to
  978.      `rl_getc', the default `readline' character input function (*note
  979.      Utility Functions::.).
  980.  - Variable: VFunction * rl_redisplay_function
  981.      If non-zero, `readline' will call indirectly through this pointer
  982.      to update the display with the current contents of the editing
  983.      buffer.  By default, it is set to `rl_redisplay', the default
  984.      `readline' redisplay function (*note Redisplay::.).
  985.  - Variable: Keymap rl_executing_keymap
  986.      This variable is set to the keymap (*note Keymaps::.) in which the
  987.      currently executing readline function was found.
  988.  - Variable: Keymap rl_binding_keymap
  989.      This variable is set to the keymap (*note Keymaps::.) in which the
  990.      last key binding occurred.
  991.