home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Atari / Gnu / gdb36p4b.zoo / readline / doc / readline.info (.txt) < prev   
GNU Info File  |  1993-10-05  |  57KB  |  1,300 lines

  1. This is Info file readline.info, produced by Makeinfo-1.55 from the
  2. input file rlman.texinfo.
  3.    This document describes the GNU Readline Library, a utility for
  4. aiding in the consitency of user interface across discrete programs
  5. that 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.info,  Node: Top,  Next: Command Line Editing,  Prev: (DIR),  Up: (DIR)
  19. GNU Readline Library
  20. ********************
  21.    This document describes the GNU Readline Library, a utility for
  22. aiding in the consistency of user interface across discrete programs
  23. that 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.info,  Node: Command Line Editing,  Next: Programming with GNU Readline,  Prev: Top,  Up: Top
  31. Command Line Editing
  32. ********************
  33.    This text describes GNU's command line editing interface.
  34. * Menu:
  35. * Introduction and Notation::    Notation used in this text.
  36. * Readline Interaction::    The minimum set of commands for editing a line.
  37. * Readline Init File::        Customizing Readline from a user's view.
  38. File: readline.info,  Node: Introduction and Notation,  Next: Readline Interaction,  Up: Command Line Editing
  39. Introduction to Line Editing
  40. ============================
  41.    In this tex a the following notation is used to describe keystrokes.
  42.    The text C-k is read as `Control-K' and describes the character
  43. produced when the Control key is depressed and the k key is struck.
  44.    The text M-k is read as `Meta-K' and describes the character
  45. produced when the meta key (if you have one) is depressed, and the k
  46. key is struck.  If you do not have a meta key, the identical keystroke
  47. can be generated by typing ESC first, and then typing k.  Either
  48. process is known as "metafying" the k key.
  49.    The text M-C-k is read as `Meta-Control-k' and describes the
  50. character produced by "metafying" C-k.
  51.    In addition, several keys have their own names.  Specifically, DEL,
  52. ESC, LFD, SPC, RET, and TAB all stand for themselves when seen in this
  53. text, or in an init file (*note Readline Init File::., for more info).
  54. File: readline.info,  Node: Readline Interaction,  Next: Readline Init File,  Prev: Introduction and Notation,  Up: Command Line Editing
  55. Readline Interaction
  56. ====================
  57.    Often during an interactive session you type in a long line of text,
  58. only to notice that the first word on the line is misspelled.  The
  59. Readline library gives you a set of commands for manipulating the text
  60. as you type it in, allowing you to just fix your typo, and not forcing
  61. you to retype the majority of the line.  Using these editing commands,
  62. you move the cursor to the place that needs correction, and delete or
  63. insert the text of the corrections.  Then, when you are satisfied with
  64. the line, you simply press RETURN.  You do not have to be at the end of
  65. the line to press RETURN; the entire line is accepted regardless of the
  66. location of the cursor within the line.
  67. * Menu:
  68. * Readline Bare Essentials::    The least you need to know about Readline.
  69. * Readline Movement Commands::    Moving about the input line.
  70. * Readline Killing Commands::    How to delete text, and how to get it back!
  71. * Readline Arguments::        Giving numeric arguments to commands.
  72. File: readline.info,  Node: Readline Bare Essentials,  Next: Readline Movement Commands,  Up: Readline Interaction
  73. Readline Bare Essentials
  74. ------------------------
  75.    In order to enter characters into the line, simply type them.  The
  76. typed character appears where the cursor was, and then the cursor moves
  77. one space to the right.  If you mistype a character, you can use DEL to
  78. back up, and delete the mistyped character.
  79.    Sometimes you may miss typing a character that you wanted to type,
  80. and not notice your error until you have typed several other
  81. characters.  In that case, you can type C-b to move the cursor to the
  82. left, and then correct your mistake.  Aftwerwards, you can move the
  83. cursor to the right with C-f.
  84.    When you add text in the middle of a line, you will notice that
  85. characters to the right of the cursor get `pushed over' to make room
  86. for the text that you have inserted.  Likewise, when you delete text
  87. behind the cursor, characters to the right of the cursor get `pulled
  88. back' to fill in the blank space created by the removal of the text.  A
  89. list of the basic bare essentials for editing the text of an input line
  90. follows.
  91.      Move back one character.
  92.      Move forward one character.
  93.      Delete the character to the left of the cursor.
  94.      Delete the character underneath the cursor.
  95. Printing characters
  96.      Insert itself into the line at the cursor.
  97.      Undo the last thing that you did.  You can undo all the way back
  98.      to an empty line.
  99. File: readline.info,  Node: Readline Movement Commands,  Next: Readline Killing Commands,  Prev: Readline Bare Essentials,  Up: Readline Interaction
  100. Readline Movement Commands
  101. --------------------------
  102.    The above table describes the most basic possible keystrokes that
  103. you need in order to do editing of the input line.  For your
  104. convenience, many other commands have been added in addition to C-b,
  105. C-f, C-d, and DEL.  Here are some commands for moving more rapidly
  106. about the line.
  107.      Move to the start of the line.
  108.      Move to the end of the line.
  109.      Move forward a word.
  110.      Move backward a word.
  111.      Clear the screen, reprinting the current line at the top.
  112.    Notice how C-f moves forward a character, while M-f moves forward a
  113. word.  It is a loose convention that control keystrokes operate on
  114. characters while meta keystrokes operate on words.
  115. File: readline.info,  Node: Readline Killing Commands,  Next: Readline Arguments,  Prev: Readline Movement Commands,  Up: Readline Interaction
  116. Readline Killing Commands
  117. -------------------------
  118.    The act of "cutting" text means to delete the text from the line, and
  119. to save away the deleted text for later use, just as if you had cut the
  120. text out of the line with a pair of scissors.  There is a
  121.    "Killing" text means to delete the text from the line, but to save
  122. it away for later use, usually by "yanking" it back into the line.  If
  123. the description for a command says that it `kills' text, then you can
  124. be sure that you can get the text back in a different (or the same)
  125. place later.
  126.    Here is the list of commands for killing text.
  127.      Kill the text from the current cursor position to the end of the
  128.      line.
  129.      Kill from the cursor to the end of the current word, or if between
  130.      words, to the end of the next word.
  131. M-DEL
  132.      Kill fromthe cursor the start ofthe previous word, or if between
  133.      words, to the start of the previous word.
  134.      Kill from the cursor to the previous whitespace.  This is
  135.      different than M-DEL because the word boundaries differ.
  136.    And, here is how to "yank" the text back into the line.  Yanking is
  137.      Yank the most recently killed text back into the buffer at the
  138.      cursor.
  139.      Rotate the kill-ring, and yank the new top.  You can only do this
  140.      if the prior command is C-y or M-y.
  141.    When you use a kill command, the text is saved in a "kill-ring".
  142. Any number of consecutive kills save all of the killed text together, so
  143. that when you yank it back, you get it in one clean sweep.  The kill
  144. ring is not line specific; the text that you killed on a previously
  145. typed line is available to be yanked back later, when you are typing
  146. another line.
  147. File: readline.info,  Node: Readline Arguments,  Prev: Readline Killing Commands,  Up: Readline Interaction
  148. Readline Arguments
  149. ------------------
  150.    You can pass numeric arguments to Readline commands.  Sometimes the
  151. argument acts as a repeat count, other times it is the sign of the
  152. argument that is significant.  If you pass a negative argument to a
  153. command which normally acts in a forward direction, that command will
  154. act in a backward direction.  For example, to kill text back to the
  155. start of the line, you might type M- C-k.
  156.    The general way to pass numeric arguments to a command is to type
  157. meta digits before the command.  If the first `digit' you type is a
  158. minus sign (-), then the sign of the argument will be negative.  Once
  159. you have typed one meta digit to get the argument started, you can type
  160. the remainder of the digits, and then the command.  For example, to give
  161. the C-d command an argument of 10, you could type M-1 0 C-d.
  162. File: readline.info,  Node: Readline Init File,  Prev: Readline Interaction,  Up: Command Line Editing
  163. Readline Init File
  164. ==================
  165.    Although the Readline library comes with a set of Emacs-like
  166. keybindings, it is possible that you would like to use a different set
  167. of keybindings.  You can customize programs that use Readline by putting
  168. commands in an "init" file in your home directory.  The name of this
  169. file is `~/.inputrc'.
  170.    When a program which uses the Readline library starts up, the
  171. `~/.inputrc' file is read, and the keybindings are set.
  172. * Menu:
  173. * Readline Init Syntax::    Syntax for the commands in `~/.inputrc'.
  174. * Readline Vi Mode::        Switching to `vi' mode in Readline.
  175. File: readline.info,  Node: Readline Init Syntax,  Next: Readline Vi Mode,  Up: Readline Init File
  176. Readline Init Syntax
  177. --------------------
  178.    You can start up with a vi-like editing mode by placing
  179.      `set editing-mode vi'
  180.    in your `~/.inputrc' file.
  181.    You can have Readline use a single line for display, scrolling the
  182. input between the two edges of the screen by placing
  183.      `set horizontal-scroll-mode On'
  184.    in your `~/.inputrc' file.
  185.    The syntax for controlling keybindings in the `~/.inputrc' file is
  186. simple.  First you have to know the name of the command that you want
  187. to change.  The following pages contain tables of the command name, the
  188. default keybinding, and a short description of what the command does.
  189.    Once you know the name of the command, simply place the name of the
  190. key you wish to bind the command to, a colon, and then the name of the
  191. command on a line in the `~/.inputrc' file.  Here is an example:
  192.      # This is a comment line.
  193.      Meta-Rubout:    backward-kill-word
  194.      Control-u:    universal-argument
  195. * Menu:
  196. * Commands For Moving::        Moving about the line.
  197. * Commands For History::    Getting at previous lines.
  198. * Commands For Text::        Commands for changing text.
  199. * Commands For Killing::    Commands for killing and yanking.
  200. * Numeric Arguments::        Specifying numeric arguments, repeat counts.
  201. * Commands For Completion::    Getting Readline to do the typing for you.
  202. * Miscellaneous Commands::    Other miscillaneous commands.
  203. File: readline.info,  Node: Commands For Moving,  Next: Commands For History,  Up: Readline Init Syntax
  204. Commands For Moving
  205. ...................
  206. `beginning-of-line (C-a)'
  207.      Move to the start of the current line.
  208. `end-of-line (C-e)'
  209.      Move to the end of the line.
  210. `forward-char (C-f)'
  211.      Move forward a character.
  212. `backward-char (C-b)'
  213.      Move back a character.
  214. `forward-word (M-f)'
  215.      Move forward to the end of the next word.
  216. `backward-word (M-b)'
  217.      Move back to the start of this, or the previous, word.
  218. `clear-screen (C-l)'
  219.      Clear the screen leaving the current line at the top of the screen.
  220. File: readline.info,  Node: Commands For History,  Next: Commands For Text,  Prev: Commands For Moving,  Up: Readline Init Syntax
  221. Commands For Manipulating The History
  222. .....................................
  223. `accept-line (Newline, Return)'
  224.      Accept the line regardless of where the cursor is.  If this line is
  225.      non-empty, add it too the history list.  If this line was a history
  226.      line, then restore the history line to its original state.
  227. `previous-history (C-p)'
  228.      Move `up' through the history list.
  229. `next-history (C-n)'
  230.      Move `down' through the history list.
  231. `beginning-of-history (M-<)'
  232.      Move to the first line in the history.
  233. `end-of-history (M->)'
  234.      Move to the end of the input history, i.e., the line you are
  235.      entering!
  236. `reverse-search-history (C-r)'
  237.      Search backward starting at the current line and moving `up'
  238.      through the history as necessary.  This is an incremental search.
  239. `forward-search-history (C-s)'
  240.      Search forward starting at the current line and moving `down'
  241.      through the the history as neccessary.
  242. File: readline.info,  Node: Commands For Text,  Next: Commands For Killing,  Prev: Commands For History,  Up: Readline Init Syntax
  243. Commands For Changing Text
  244. ..........................
  245. `delete-char (C-d)'
  246.      Delete the character under the cursor.  If the cursor is at the
  247.      beginning of the line, and there are no characters in the line, and
  248.      the last character typed was not C-d, then return EOF.
  249. `backward-delete-char (Rubout)'
  250.      Delete the character behind the cursor.  A numeric arg says to kill
  251.      the characters instead of deleting them.
  252. `quoted-insert (C-q, C-v)'
  253.      Add the next character that you type to the line verbatim.  This is
  254.      how to insert things like C-q for example.
  255. `tab-insert (M-TAB)'
  256.      Insert a tab character.
  257. `self-insert (a, b, A, 1, !, ...)'
  258.      Insert yourself.
  259. `transpose-chars (C-t)'
  260.      Drag the character before point forward over the character at
  261.      point.  Point moves forward as well.  If point is at the end of
  262.      the line, then transpose the two characters before point.
  263.      Negative args don't work.
  264. `transpose-words (M-t)'
  265.      Drag the word behind the cursor past the word in front of the
  266.      cursor moving the cursor over that word as well.
  267. `upcase-word (M-u)'
  268.      Uppercase the current (or following) word.  With a negative
  269.      argument, do the previous word, but do not move point.
  270. `downcase-word (M-l)'
  271.      Lowercase the current (or following) word.  With a negative
  272.      argument, do the previous word, but do not move point.
  273. `capitalize-word (M-c)'
  274.      Uppercase the current (or following) word.  With a negative
  275.      argument, do the previous word, but do not move point.
  276. File: readline.info,  Node: Commands For Killing,  Next: Numeric Arguments,  Prev: Commands For Text,  Up: Readline Init Syntax
  277. Killing And Yanking
  278. ...................
  279. `kill-line (C-k)'
  280.      Kill the text from the current cursor position to the end of the
  281.      line.
  282. `backward-kill-line ()'
  283.      Kill backward to the beginning of the line.  This is normally
  284.      unbound.
  285. `kill-word (M-d)'
  286.      Kill from the cursor to the end of the current word, or if between
  287.      words, to the end of the next word.
  288. `backward-kill-word (M-DEL)'
  289.      Kill the word behind the cursor.
  290. `unix-line-discard (C-u)'
  291.      Do what C-u used to do in Unix line input.  We save the killed
  292.      text on the kill-ring, though.
  293. `unix-word-rubout (C-w)'
  294.      Do what C-w used to do in Unix line input.  The killed text is
  295.      saved on the kill-ring.  This is different than backward-kill-word
  296.      because the word boundaries differ.
  297. `yank (C-y)'
  298.      Yank the top of the kill ring into the buffer at point.
  299. `yank-pop (M-y)'
  300.      Rotate the kill-ring, and yank the new top.  You can only do this
  301.      if the prior command is yank or yank-pop.
  302. File: readline.info,  Node: Numeric Arguments,  Next: Commands For Completion,  Prev: Commands For Killing,  Up: Readline Init Syntax
  303. Specifying Numeric Arguments
  304. ............................
  305. `digit-argument (M-0, M-1, ... M--)'
  306.      Add this digit to the argument already accumulating, or start a new
  307.      argument.  M- starts a negative argument.
  308. `universal-argument ()'
  309.      Do what C-u does in emacs.  By default, this is not bound.
  310. File: readline.info,  Node: Commands For Completion,  Next: Miscellaneous Commands,  Prev: Numeric Arguments,  Up: Readline Init Syntax
  311. Letting Readline Type For You
  312. .............................
  313. `complete (TAB)'
  314.      Attempt to do completion on the text before point.  This is
  315.      implementation defined.  Generally, if you are typing a filename
  316.      argument, you can do filename completion; if you are typing a
  317.      command, you can do command completion, if you are typing in a
  318.      symbol to GDB, you can do symbol name completion, if you are
  319.      typing in a variable to Bash, you can do variable name
  320.      completion...
  321. `possible-completions (M-?)'
  322.      List the possible completions of the text before point.
  323. File: readline.info,  Node: Miscellaneous Commands,  Prev: Commands For Completion,  Up: Readline Init Syntax
  324. Some Miscellaneous Commands
  325. ...........................
  326. `abort (C-g)'
  327.      Ding!  Stops things.
  328. `do-uppercase-version (M-a, M-b, ...)'
  329.      Run the command that is bound to your uppercase brother.
  330. `prefix-meta (ESC)'
  331.      Make the next character that you type be metafied.  This is for
  332.      people without a meta key.  ESC-f is equivalent to M-f.
  333. `undo (C-_)'
  334.      Incremental undo, separately remembered for each line.
  335. `revert-line (M-r)'
  336.      Undo all changes made to this line.  This is like typing the `undo'
  337.      command enough times to get back to the beginning.
  338. File: readline.info,  Node: Readline Vi Mode,  Prev: Readline Init Syntax,  Up: Readline Init File
  339. Readline Vi Mode
  340. ----------------
  341.    While the Readline library does not have a full set of Vi editing
  342. functions, it does contain enough to allow simple editing of the line.
  343.    In order to switch interactively between Emacs and Vi editing modes,
  344. use the command M-C-j (toggle-editing-mode).
  345.    When you enter a line in Vi mode, you are already placed in
  346. `insertion' mode, as if you had typed an `i'.  Pressing ESC switches
  347. you into `edit' mode, where you can edit the text of the line with the
  348. standard Vi movement keys, move to previous history lines with `k', and
  349. following lines with `j', and so forth.
  350.    This document describes the GNU Readline Library, a utility for
  351. aiding in the consitency of user interface across discrete programs
  352. that need to provide a command line interface.
  353.    Copyright (C) 1988 Free Software Foundation, Inc.
  354.    Permission is granted to make and distribute verbatim copies of this
  355. manual provided the copyright notice and this permission notice pare
  356. preserved on all copies.
  357.    Permission is granted to copy and distribute modified versions of
  358. this manual under the conditions for verbatim copying, provided that
  359. the entire resulting derived work is distributed under the terms of a
  360. permission notice identical to this one.
  361.    Permission is granted to copy and distribute translations of this
  362. manual into another language, under the above conditions for modified
  363. versions, except that this permission notice may be stated in a
  364. translation approved by the Foundation.
  365. File: readline.info,  Node: Programming with GNU Readline,  Next: Concept Index,  Prev: Command Line Editing,  Up: Top
  366. Programming with GNU Readline
  367. *****************************
  368.    This manual describes the interface between the GNU Readline Library
  369. and user programs.  If you are a programmer, and you wish to include the
  370. features found in GNU Readline in your own programs, such as completion,
  371. line editing, and interactive history manipulation, this documentation
  372. is for you.
  373. * Menu:
  374. * Default Behaviour::    Using the default behaviour of Readline.
  375. * Custom Functions::    Adding your own functions to Readline.
  376. * Custom Completers::    Supplanting or supplementing Readline's
  377.             completion functions.
  378. File: readline.info,  Node: Default Behaviour,  Next: Custom Functions,  Up: Programming with GNU Readline
  379. Default Behaviour
  380. =================
  381.    Many programs provide a command line interface, such as `mail',
  382. `ftp', and `sh'.  For such programs, the default behaviour of Readline
  383. is sufficient.  This section describes how to use Readline in the
  384. simplest way possible, perhaps to replace calls in your code to `gets
  385.    The function `readline' prints a prompt and then reads and returns a
  386. single line of text from the user.  The line which `readline ()'
  387. returns is allocated with `malloc ()'; you should `free ()' the line
  388. when you are done with it.  The declaration for `readline' in ANSI C is
  389.      `char *readline (char *PROMPT);'
  390.    So, one might say
  391.      `char *line = readline ("Enter a line: ");'
  392.    in order to read a line of text from the user.
  393.    The line which is returned has the final newline removed, so only the
  394. text of the line remains.
  395.    If readline encounters an `EOF' while reading the line, and the line
  396. is empty at that point, then `(char *)NULL' is returned.  Otherwise,
  397. the line is ended just as if a newline was typed.
  398.    If you want the user to be able to get at the line later, (with C-p
  399. for example), you must call `add_history ()' to save the line away in a
  400. "history" list of such lines.
  401.      `add_history (line)';
  402.    For full details on the GNU History Library, see the associated
  403. manual.
  404.    It is polite to avoid saving empty lines on the history list, since
  405. it is rare than someone has a burning need to reuse a blank line.  Here
  406. is a function which usefully replaces the standard `gets ()' library
  407. function:
  408.      /* A static variable for holding the line. */
  409.      static char *line_read = (char *)NULL;
  410.      
  411.      /* Read a string, and return a pointer to it.  Returns NULL on EOF. */
  412.      char *
  413.      do_gets ()
  414.      {
  415.        /* If the buffer has already been allocated, return the memory
  416.           to the free pool. */
  417.        if (line_read != (char *)NULL)
  418.          {
  419.            free (line_read);
  420.            line_read = (char *)NULL;
  421.          }
  422.      
  423.        /* Get a line from the user. */
  424.        line_read = readline ("");
  425.      
  426.        /* If the line has any text in it, save it on the history. */
  427.        if (line_read && *line_read)
  428.          add_history (line_read);
  429.      
  430.        return (line_read);
  431.      }
  432.    The above code gives the user the default behaviour of TAB
  433. completion: completion on file names.  If you do not want readline to
  434. complete on filenames, you can change the binding of the TAB key with
  435. `rl_bind_key ()'.
  436.      `int rl_bind_key (int KEY, (int (*)())FUNCTION);'
  437.    `rl_bind_key ()' takes 2 arguments; KEY is the character that you
  438. want to bind, and FUNCTION is the address of the function to run when
  439. KEY is pressed.  Binding TAB to `rl_insert ()' makes TAB just insert
  440. itself.
  441.    `rl_bind_key ()' returns non-zero if KEY is not a valid ASCII
  442. character code (between 0 and 255).
  443.      `rl_bind_key ('\t', rl_insert);'
  444.    This code should be executed once at the start of your program; you
  445. might write a function called `initialize_readline ()' which performs
  446. this and other desired initializations, such as installing custom
  447. completers, etc.
  448. File: readline.info,  Node: Custom Functions,  Next: Custom Completers,  Prev: Default Behaviour,  Up: Programming with GNU Readline
  449. Custom Functions
  450. ================
  451.    Readline provides a great many functions for manipulating the text of
  452. the line.  But it isn't possible to anticipate the needs of all
  453. programs.  This section describes the various functions and variables
  454. defined in within the Readline library which allow a user program to add
  455. customized functionality to Readline.
  456. * Menu:
  457. * The Function Type::    C declarations to make code readable.
  458. * Function Naming::    How to give a function you write a name.
  459. * Keymaps::        Making keymaps.
  460. * Binding Keys::    Changing Keymaps.
  461. * Function Writing::    Variables and calling conventions.
  462. * Allowing Undoing::    How to make your functions undoable.
  463. File: readline.info,  Node: The Function Type,  Next: Function Naming,  Up: Custom Functions
  464. The Function Type
  465. -----------------
  466.    For the sake of readabilty, we declare a new type of object, called
  467. "Function".  A `Function' is a C language function which returns an
  468. `int'.  The type declaration for `Function' is:
  469. `typedef int Function ();'
  470.    The reason for declaring this new type is to make it easier to write
  471. code describing pointers to C functions.  Let us say we had a variable
  472. called FUNC which was a pointer to a function.  Instead of the classic
  473. C declaration
  474.    `int (*)()func;'
  475.    we have
  476.    `Function *func;'
  477. File: readline.info,  Node: Function Naming,  Next: Keymaps,  Prev: The Function Type,  Up: Custom Functions
  478. Naming a Function
  479. -----------------
  480.    The user can dynamically change the bindings of keys while using
  481. Readline.  This is done by representing the function with a descriptive
  482. name.  The user is able to type the descriptive name when referring to
  483. the function.  Thus, in an init file, one might find
  484.      Meta-Rubout:    backward-kill-word
  485.    This binds the keystroke Meta-Rubout to the function *descriptively*
  486. named `backward-kill-word'.  You, as the programmer, should bind the
  487. functions you write to descriptive names as well.  Readline provides a
  488. function for doing that:
  489.  - Function: rl_add_defun (CHAR *NAME, FUNCTION *FUNCTION, INT KEY)
  490.      Add NAME to the list of named functions.  Make FUNCTION be the
  491.      function that gets called.  If KEY is not -1, then bind it to
  492.      FUNCTION using `rl_bind_key ()'.
  493.    Using this function alone is sufficient for most applications.  It is
  494. the recommended way to add a few functions to the default functions that
  495. Readline has built in already.  If you need to do more or different
  496. things than adding a function to Readline, you may need to use the
  497. underlying functions described below.
  498. File: readline.info,  Node: Keymaps,  Next: Binding Keys,  Prev: Function Naming,  Up: Custom Functions
  499. Selecting a Keymap
  500. ------------------
  501.    Key bindings take place on a "keymap".  The keymap is the
  502. association between the keys that the user types and the functions that
  503. get run.  You can make your own keymaps, copy existing keymaps, and tell
  504. Readline which keymap to use.
  505.  - Function: Keymap rl_make_bare_keymap ()
  506.      Returns a new, empty keymap.  The space for the keymap is
  507.      allocated with `malloc ()'; you should `free ()' it when you are
  508.      done.
  509.  - Function: Keymap rl_copy_keymap (KEYMAP MAP)
  510.      Return a new keymap which is a copy of MAP.
  511.  - Function: Keymap rl_make_keymap ()
  512.      Return a new keymap with the printing characters bound to
  513.      rl_insert, the lowercase Meta characters bound to run their
  514.      equivalents, and the Meta digits bound to produce numeric
  515.      arguments.
  516. File: readline.info,  Node: Binding Keys,  Next: Function Writing,  Prev: Keymaps,  Up: Custom Functions
  517. Binding Keys
  518. ------------
  519.    You associate keys with functions through the keymap.  Here are
  520. functions for doing that.
  521.  - Function: int rl_bind_key (INT KEY, FUNCTION *FUNCTION)
  522.      Binds KEY to FUNCTION in the currently selected keymap.  Returns
  523.      non-zero in the case of an invalid KEY.
  524.  - Function: int rl_bind_key_in_map (INT KEY, FUNCTION *FUNCTION,
  525.           KEYMAP MAP)
  526.      Bind KEY to FUNCTION in MAP.  Returns non-zero in the case of an
  527.      invalid KEY.
  528.  - Function: int rl_unbind_key (INT KEY)
  529.      Make KEY do nothing in the currently selected keymap.  Returns
  530.      non-zero in case of error.
  531.  - Function: int rl_unbind_key_in_map (INT KEY, KEYMAP MAP)
  532.      Make KEY be bound to the null function in MAP.  Returns non-zero
  533.      in case of error.
  534.  - Function: rl_generic_bind (INT TYPE, CHAR *KEYSEQ, CHAR *DATA,
  535.           KEYMAP MAP)
  536.      Bind the key sequence represented by the string KEYSEQ to the
  537.      arbitrary pointer DATA.  TYPE says what kind of data is pointed to
  538.      by DATA; right now this can be a function (`ISFUNC'), a macro
  539.      (`ISMACR'), or a keymap (`ISKMAP').  This makes new keymaps as
  540.      necessary.  The initial place to do bindings is in MAP.
  541. File: readline.info,  Node: Function Writing,  Next: Allowing Undoing,  Prev: Binding Keys,  Up: Custom Functions
  542. Writing a New Function
  543. ----------------------
  544.    In order to write new functions for Readline, you need to know the
  545. calling conventions for keyboard invoked functions, and the names of the
  546. variables that describe the current state of the line gathered so far.
  547.  - Variable: char *rl_line_buffer
  548.      This is the line gathered so far.  You are welcome to modify the
  549.      contents of this, but see Undoing, below.
  550.  - Variable: int rl_point
  551.      The offset of the current cursor position in RL_LINE_BUFFER.
  552.  - Variable: int rl_end
  553.      The number of characters present in `rl_line_buffer'.  When
  554.      `rl_point' is at the end of the line, then `rl_point' and `rl_end'
  555.      are equal.
  556.    The calling sequence for a command `foo' looks like
  557.      `foo (int count, int key)'
  558.    where COUNT is the numeric argument (or 1 if defaulted) and KEY is
  559. the key that invoked this function.
  560.    It is completely up to the function as to what should be done with
  561. the numeric argument; some functions use it as a repeat count, other
  562. functions as a flag, and some choose to ignore it.  In general, if a
  563. function uses the numeric argument as a repeat count, it should be able
  564. to do something useful with a negative argument as well as a positive
  565. argument.  At the very least, it should be aware that it can be passed a
  566. negative argument.
  567. File: readline.info,  Node: Allowing Undoing,  Prev: Function Writing,  Up: Custom Functions
  568. Allowing Undoing
  569. ----------------
  570.    Supporting the undo command is a painless thing to do, and makes your
  571. functions much more useful to the end user.  It is certainly easy to try
  572. something if you know you can undo it.  I could use an undo function for
  573. the stock market.
  574.    If your function simply inserts text once, or deletes text once, and
  575. it calls `rl_insert_text ()' or `rl_delete_text ()' to do it, then
  576. undoing is already done for you automatically, and you can safely skip
  577. this section.
  578.    If you do multiple insertions or multiple deletions, or any
  579. combination of these operations, you should group them together into
  580. one operation.  This can be done with `rl_begin_undo_group ()' and
  581. `rl_end_undo_group ()'.
  582.  - Function: rl_begin_undo_group ()
  583.      Begins saving undo information in a group construct.  The undo
  584.      information usually comes from calls to `rl_insert_text ()' and
  585.      `rl_delete_text ()', but they could be direct calls to
  586.      `rl_add_undo ()'.
  587.  - Function: rl_end_undo_group ()
  588.      Closes the current undo group started with `rl_begin_undo_group
  589.      ()'.  There should be exactly one call to `rl_end_undo_group ()'
  590.      for every call to `rl_begin_undo_group ()'.
  591.    Finally, if you neither insert nor delete text, but directly modify
  592. the existing text (e.g. change its case), you call `rl_modifying ()'
  593. once, just before you modify the text.  You must supply the indices of
  594. the text range that you are going to modify.
  595.  - Function: rl_modifying (INT START, INT END)
  596.      Tell Readline to save the text between START and END as a single
  597.      undo unit.  It is assumed that subsequent to this call you will
  598.      modify that range of text in some way.
  599. An Example
  600. ----------
  601.    Here is a function which changes lowercase characters to the
  602. uppercase equivalents, and uppercase characters to the lowercase
  603. equivalents.  If this function was bound to `M-c', then typing `M-c'
  604. would change the case of the character under point.  Typing `10 M-c'
  605. would change the case of the following 10 characters, leaving the
  606. cursor on the last character changed.
  607.      /* Invert the case of the COUNT following characters. */
  608.      invert_case_line (count, key)
  609.           int count, key;
  610.      {
  611.        register int start, end;
  612.      
  613.        start = rl_point;
  614.      
  615.        if (count < 0)
  616.          {
  617.            direction = -1;
  618.            count = -count;
  619.          }
  620.        else
  621.          direction = 1;
  622.      
  623.        /* Find the end of the range to modify. */
  624.        end = start + (count * direction);
  625.      
  626.        /* Force it to be within range. */
  627.        if (end > rl_end)
  628.          end = rl_end;
  629.        else if (end < 0)
  630.          end = -1;
  631.      
  632.        if (start > end)
  633.          {
  634.            int temp = start;
  635.            start = end;
  636.            end = temp;
  637.          }
  638.      
  639.        if (start == end)
  640.          return;
  641.      
  642.        /* Tell readline that we are modifying the line, so save the undo
  643.           information. */
  644.        rl_modifying (start, end);
  645.      
  646.        for (; start != end; start += direction)
  647.          {
  648.            if (uppercase_p (rl_line_buffer[start]))
  649.              rl_line_buffer[start] = to_lower (rl_line_buffer[start]);
  650.            else if (lowercase_p (rl_line_buffer[start]))
  651.              rl_line_buffer[start] = to_upper (rl_line_buffer[start]);
  652.          }
  653.        /* Move point to on top of the last character changed. */
  654.        rl_point = end - direction;
  655.      }
  656. File: readline.info,  Node: Custom Completers,  Prev: Custom Functions,  Up: Programming with GNU Readline
  657. Custom Completers
  658. =================
  659.    Typically, a program that reads commands from the user has a way of
  660. disambiguating between commands and data.  If your program is one of
  661. these, then it can provide completion for either commands, or data, or
  662. both commands and data.  The following sections describe how your
  663. program and Readline cooperate to provide this service to end users.
  664. * Menu:
  665. * How Completing Works::    The logic used to do completion.
  666. * Completion Functions::    Functions provided by Readline.
  667. * Completion Variables::    Variables which control completion.
  668. * A Short Completion Example::    An example of writing completer subroutines.
  669. File: readline.info,  Node: How Completing Works,  Next: Completion Functions,  Up: Custom Completers
  670. How Completing Works
  671. --------------------
  672.    In order to complete some text, the full list of possible completions
  673. must be available.  That is to say, it is not possible to accurately
  674. expand a partial word without knowing what all of the possible words
  675. that make sense in that context are.  The GNU Readline library provides
  676. the user interface to completion, and additionally, two of the most
  677. common completion functions; filename and username.  For completing
  678. other types of text, you must write your own completion function.  This
  679. section describes exactly what those functions must do, and provides an
  680. example function.
  681.    There are three major functions used to perform completion:
  682.   1. The user-interface function `rl_complete ()'.  This function is
  683.      called interactively with the same calling conventions as other
  684.      functions in readline intended for interactive use; i.e. COUNT,
  685.      and `invoking-key'.  It isolates the word to be completed and calls
  686.      `completion_matches ()' to generate a list of possible completions.
  687.      It then either lists the possible completions or actually performs
  688.      the completion, depending on which behaviour is desired.
  689.   2. The internal function `completion_matches ()' uses your
  690.      "generator" function to generate the list of possible matches, and
  691.      then returns the array of these matches.  You should place the
  692.      address of your generator function in
  693.      `rl_completion_entry_function'.
  694.   3. The generator function is called repeatedly from
  695.      `completion_matches ()', returning a string each time.  The
  696.      arguments to the generator function are TEXT and STATE.  TEXT is
  697.      the partial word to be completed.  STATE is zero the first time
  698.      the function is called, and a positive non-zero integer for each
  699.      subsequent call.  When the generator function returns `(char
  700.      *)NULL' this signals `completion_matches ()' that there are no more
  701.      possibilities left.
  702.  - Function: rl_complete (INT IGNORE, INT INVOKING_KEY)
  703.      Complete the word at or before point.  You have supplied the
  704.      function that does the initial simple matching selection algorithm
  705.      (see `completion_matches ()').  The default is to do filename
  706.      completion.
  707.    Note that `rl_complete ()' has the identical calling conventions as
  708. any other key-invokable function; this is because by default it is bound
  709. to the `TAB' key.
  710.  - Variable: Function *rl_completion_entry_function
  711.      This is a pointer to the generator function for `completion_matches
  712.      ()'.  If the value of `rl_completion_entry_function' is `(Function
  713.      *)NULL' then the default filename generator function is used,
  714.      namely `filename_entry_function ()'.
  715. File: readline.info,  Node: Completion Functions,  Next: Completion Variables,  Prev: How Completing Works,  Up: Custom Completers
  716. Completion Functions
  717. --------------------
  718.    Here is the complete list of callable completion functions present in
  719. Readline.
  720.  - Function: rl_complete_internal (INT WHAT_TO_DO)
  721.      Complete the word at or before point.  WHAT_TO_DO says what to do
  722.      with the completion.  A value of `?' means list the possible
  723.      completions.  `TAB' means do standard completion.  `*' means
  724.      insert all of the possible completions.
  725.  - Function: rl_complete (INT IGNORE, INT INVOKING_KEY)
  726.      Complete the word at or before point.  You have supplied the
  727.      function that does the initial simple matching selection algorithm
  728.      (see `completion_matches ()').  The default is to do filename
  729.      completion.  This just calls `rl_complete_internal ()' with an
  730.      argument of `TAB'.
  731.  - Function: rl_possible_completions ()
  732.      List the possible completions.  See description of `rl_complete
  733.      ()'.  This just calls `rl_complete_internal ()' with an argument of
  734.      `?'.
  735.  - Function: char **completion_matches (CHAR *TEXT, CHAR
  736.           *(*ENTRY_FUNCTION) ())
  737.      Returns an array of `(char *)' which is a list of completions for
  738.      TEXT.  If there are no completions, returns `(char **)NULL'.  The
  739.      first entry in the returned array is the substitution for TEXT.
  740.      The remaining entries are the possible completions.  The array is
  741.      terminated with a `NULL' pointer.
  742.      ENTRY_FUNCTION is a function of two args, and returns a `(char
  743.      *)'.  The first argument is TEXT.  The second is a state argument;
  744.      it is zero on the first call, and non-zero on subsequent calls.
  745.      It returns a `NULL'  pointer to the caller when there are no more
  746.      matches.
  747.  - Function: char *filename_completion_function (CHAR *TEXT, INT STATE)
  748.      A generator function for filename completion in the general case.
  749.      Note that completion in the Bash shell is a little different
  750.      because of all the pathnames that must be followed when looking up
  751.      the completion for a command.
  752.  - Function: char *username_completion_function (CHAR *TEXT, INT STATE)
  753.      A completion generator for usernames.  TEXT contains a partial
  754.      username preceded by a random character (usually `~').
  755. File: readline.info,  Node: Completion Variables,  Next: A Short Completion Example,  Prev: Completion Functions,  Up: Custom Completers
  756. Completion Variables
  757. --------------------
  758.  - Variable: Function *rl_completion_entry_function
  759.      A pointer to the generator function for `completion_matches ()'.
  760.      `NULL' means to use `filename_entry_function ()', the default
  761.      filename completer.
  762.  - Variable: Function *rl_attempted_completion_function
  763.      A pointer to an alternative function to create matches.  The
  764.      function is called with TEXT, START, and END.  START and END are
  765.      indices in `rl_line_buffer' saying what the boundaries of TEXT
  766.      are.  If this function exists and returns `NULL' then `rl_complete
  767.      ()' will call the value of `rl_completion_entry_function' to
  768.      generate matches, otherwise the array of strings returned will be
  769.      used.
  770.  - Variable: int rl_completion_query_items
  771.      Up to this many items will be displayed in response to a
  772.      possible-completions call.  After that, we ask the user if she is
  773.      sure she wants to see them all.  The default value is 100.
  774.  - Variable: char *rl_basic_word_break_characters
  775.      The basic list of characters that signal a break between words for
  776.      the completer routine.  The contents of this variable is what
  777.      breaks words in the Bash shell, i.e. " \t\n\"\\'`@$><=".
  778.  - Variable: char *rl_completer_word_break_characters
  779.      The list of characters that signal a break between words for
  780.      `rl_complete_internal ()'.  The default list is the contents of
  781.      `rl_basic_word_break_characters'.
  782.  - Variable: char *rl_special_prefixes
  783.      The list of characters that are word break characters, but should
  784.      be left in TEXT when it is passed to the completion function.
  785.      Programs can use this to help determine what kind of completing to
  786.      do.
  787.  - Variable: int rl_ignore_completion_duplicates
  788.      If non-zero, then disallow duplicates in the matches.  Default is
  789.      1.
  790.  - Variable: int rl_filename_completion_desired
  791.      Non-zero means that the results of the matches are to be treated as
  792.      filenames.  This is *always* zero on entry, and can only be changed
  793.      within a completion entry generator function.
  794.  - Variable: Function *rl_ignore_some_completions_function
  795.      This function, if defined, is called by the completer when real
  796.      filename completion is done, after all the matching names have
  797.      been generated.  It is passed a `NULL' terminated array of
  798.      pointers to `(char *)' known as MATCHES in the code.  The 1st
  799.      element (`matches[0]') is the maximal substring that is common to
  800.      all matches. This function can re-arrange the list of matches as
  801.      required, but each deleted element of the array must be `free()''d.
  802. File: readline.info,  Node: A Short Completion Example,  Prev: Completion Variables,  Up: Custom Completers
  803. A Short Completion Example
  804. --------------------------
  805.    Here is a small application demonstrating the use of the GNU Readline
  806. library.  It is called `fileman', and the source code resides in
  807. `readline/examples/fileman.c'.  This sample application provides
  808. completion of command names, line editing features, and access to the
  809. history list.
  810.      /* fileman.c -- A tiny application which demonstrates how to use the
  811.         GNU Readline library.  This application interactively allows users
  812.         to manipulate files and their modes. */
  813.      
  814.      #include <stdio.h>
  815.      #include <readline/readline.h>
  816.      #include <readline/history.h>
  817.      #include <sys/types.h>
  818.      #include <sys/file.h>
  819.      #include <sys/stat.h>
  820.      #include <sys/errno.h>
  821.      
  822.      /* The names of functions that actually do the manipulation. */
  823.      int com_list (), com_view (), com_rename (), com_stat (), com_pwd ();
  824.      int com_delete (), com_help (), com_cd (), com_quit ();
  825.      
  826.      /* A structure which contains information on the commands this program
  827.         can understand. */
  828.      
  829.      typedef struct {
  830.        char *name;                   /* User printable name of the function. */
  831.        Function *func;               /* Function to call to do the job. */
  832.        char *doc;                    /* Documentation for this function.  */
  833.      } COMMAND;
  834.      
  835.      COMMAND commands[] = {
  836.        { "cd", com_cd, "Change to directory DIR" },
  837.        { "delete", com_delete, "Delete FILE" },
  838.        { "help", com_help, "Display this text" },
  839.        { "?", com_help, "Synonym for `help'" },
  840.        { "list", com_list, "List files in DIR" },
  841.        { "ls", com_list, "Synonym for `list'" },
  842.        { "pwd", com_pwd, "Print the current working directory" },
  843.        { "quit", com_quit, "Quit using Fileman" },
  844.        { "rename", com_rename, "Rename FILE to NEWNAME" },
  845.        { "stat", com_stat, "Print out statistics on FILE" },
  846.        { "view", com_view, "View the contents of FILE" },
  847.        { (char *)NULL, (Function *)NULL, (char *)NULL }
  848.      };
  849.      
  850.      /* The name of this program, as taken from argv[0]. */
  851.      char *progname;
  852.      
  853.      /* When non-zero, this global means the user is done using this program. */
  854.      int done = 0;
  855.      
  856.      main (argc, argv)
  857.           int argc;
  858.           char **argv;
  859.      {
  860.        progname = argv[0];
  861.      
  862.        initialize_readline ();       /* Bind our completer. */
  863.      
  864.        /* Loop reading and executing lines until the user quits. */
  865.        while (!done)
  866.          {
  867.            char *line;
  868.      
  869.            line = readline ("FileMan: ");
  870.      
  871.            if (!line)
  872.              {
  873.                done = 1;             /* Encountered EOF at top level. */
  874.              }
  875.            else
  876.              {
  877.                /* Remove leading and trailing whitespace from the line.
  878.                   Then, if there is anything left, add it to the history list
  879.                   and execute it. */
  880.                stripwhite (line);
  881.      
  882.                if (*line)
  883.                  {
  884.                    add_history (line);
  885.                    execute_line (line);
  886.                  }
  887.              }
  888.      
  889.            if (line)
  890.              free (line);
  891.          }
  892.        exit (0);
  893.      }
  894.      
  895.      /* Execute a command line. */
  896.      execute_line (line)
  897.           char *line;
  898.      {
  899.        register int i;
  900.        COMMAND *find_command (), *command;
  901.        char *word;
  902.      
  903.        /* Isolate the command word. */
  904.        i = 0;
  905.        while (line[i] && !whitespace (line[i]))
  906.          i++;
  907.      
  908.        word = line;
  909.      
  910.        if (line[i])
  911.          line[i++] = '\0';
  912.      
  913.        command = find_command (word);
  914.      
  915.        if (!command)
  916.          {
  917.            fprintf (stderr, "%s: No such command for FileMan.\n", word);
  918.            return;
  919.          }
  920.      
  921.        /* Get argument to command, if any. */
  922.        while (whitespace (line[i]))
  923.          i++;
  924.      
  925.        word = line + i;
  926.      
  927.        /* Call the function. */
  928.        (*(command->func)) (word);
  929.      }
  930.      
  931.      /* Look up NAME as the name of a command, and return a pointer to that
  932.         command.  Return a NULL pointer if NAME isn't a command name. */
  933.      COMMAND *
  934.      find_command (name)
  935.           char *name;
  936.      {
  937.        register int i;
  938.      
  939.        for (i = 0; commands[i].name; i++)
  940.          if (strcmp (name, commands[i].name) == 0)
  941.            return (&commands[i]);
  942.      
  943.        return ((COMMAND *)NULL);
  944.      }
  945.      
  946.      /* Strip whitespace from the start and end of STRING. */
  947.      stripwhite (string)
  948.           char *string;
  949.      {
  950.        register int i = 0;
  951.      
  952.        while (whitespace (string[i]))
  953.          i++;
  954.      
  955.        if (i)
  956.          strcpy (string, string + i);
  957.      
  958.        i = strlen (string) - 1;
  959.      
  960.        while (i > 0 && whitespace (string[i]))
  961.          i--;
  962.      
  963.        string[++i] = '\0';
  964.      }
  965.      
  966.      /* **************************************************************** */
  967.      /*                                                                  */
  968.      /*                  Interface to Readline Completion                */
  969.      /*                                                                  */
  970.      /* **************************************************************** */
  971.      
  972.      /* Tell the GNU Readline library how to complete.  We want to try to complete
  973.         on command names if this is the first word in the line, or on filenames
  974.         if not. */
  975.      initialize_readline ()
  976.      {
  977.        char **fileman_completion ();
  978.      
  979.        /* Allow conditional parsing of the ~/.inputrc file. */
  980.        rl_readline_name = "FileMan";
  981.      
  982.        /* Tell the completer that we want a crack first. */
  983.        rl_attempted_completion_function = (Function *)fileman_completion;
  984.      }
  985.      
  986.      /* Attempt to complete on the contents of TEXT.  START and END show the
  987.         region of TEXT that contains the word to complete.  We can use the
  988.         entire line in case we want to do some simple parsing.  Return the
  989.         array of matches, or NULL if there aren't any. */
  990.      char **
  991.      fileman_completion (text, start, end)
  992.           char *text;
  993.           int start, end;
  994.      {
  995.        char **matches;
  996.        char *command_generator ();
  997.      
  998.        matches = (char **)NULL;
  999.      
  1000.        /* If this word is at the start of the line, then it is a command
  1001.           to complete.  Otherwise it is the name of a file in the current
  1002.           directory. */
  1003.        if (start == 0)
  1004.          matches = completion_matches (text, command_generator);
  1005.      
  1006.        return (matches);
  1007.      }
  1008.      
  1009.      /* Generator function for command completion.  STATE lets us know whether
  1010.         to start from scratch; without any state (i.e. STATE == 0), then we
  1011.         start at the top of the list. */
  1012.      char *
  1013.      command_generator (text, state)
  1014.           char *text;
  1015.           int state;
  1016.      {
  1017.        static int list_index, len;
  1018.        char *name;
  1019.      
  1020.        /* If this is a new word to complete, initialize now.  This includes
  1021.           saving the length of TEXT for efficiency, and initializing the index
  1022.           variable to 0. */
  1023.        if (!state)
  1024.          {
  1025.            list_index = 0;
  1026.            len = strlen (text);
  1027.          }
  1028.      
  1029.        /* Return the next name which partially matches from the command list. */
  1030.        while (name = commands[list_index].name)
  1031.          {
  1032.            list_index++;
  1033.      
  1034.            if (strncmp (name, text, len) == 0)
  1035.              return (name);
  1036.          }
  1037.      
  1038.        /* If no names matched, then return NULL. */
  1039.        return ((char *)NULL);
  1040.      }
  1041.      
  1042.      /* **************************************************************** */
  1043.      /*                                                                  */
  1044.      /*                       FileMan Commands                           */
  1045.      /*                                                                  */
  1046.      /* **************************************************************** */
  1047.      
  1048.      /* String to pass to system ().  This is for the LIST, VIEW and RENAME
  1049.         commands. */
  1050.      static char syscom[1024];
  1051.      
  1052.      /* List the file(s) named in arg. */
  1053.      com_list (arg)
  1054.           char *arg;
  1055.      {
  1056.        sprintf (syscom, "ls -FClg %s", arg);
  1057.        system (syscom);
  1058.      }
  1059.      
  1060.      com_view (arg)
  1061.           char *arg;
  1062.      {
  1063.        if (!valid_argument ("view", arg))
  1064.          return;
  1065.      
  1066.        sprintf (syscom, "cat %s | more", arg);
  1067.        system (syscom);
  1068.      }
  1069.      
  1070.      com_rename (arg)
  1071.           char *arg;
  1072.      {
  1073.        too_dangerous ("rename");
  1074.      }
  1075.      
  1076.      com_stat (arg)
  1077.           char *arg;
  1078.      {
  1079.        struct stat finfo;
  1080.      
  1081.        if (!valid_argument ("stat", arg))
  1082.          return;
  1083.      
  1084.        if (stat (arg, &finfo) == -1)
  1085.          {
  1086.            perror (arg);
  1087.            return;
  1088.          }
  1089.      
  1090.        printf ("Statistics for `%s':\n", arg);
  1091.      
  1092.        printf ("%s has %d link%s, and is %d bytes in length.\n", arg,
  1093.                finfo.st_nlink, (finfo.st_nlink == 1) ? "" : "s",  finfo.st_size);
  1094.        printf ("      Created on: %s", ctime (&finfo.st_ctime));
  1095.        printf ("  Last access at: %s", ctime (&finfo.st_atime));
  1096.        printf ("Last modified at: %s", ctime (&finfo.st_mtime));
  1097.      }
  1098.      
  1099.      com_delete (arg)
  1100.           char *arg;
  1101.      {
  1102.        too_dangerous ("delete");
  1103.      }
  1104.      
  1105.      /* Print out help for ARG, or for all of the commands if ARG is
  1106.         not present. */
  1107.      com_help (arg)
  1108.           char *arg;
  1109.      {
  1110.        register int i;
  1111.        int printed = 0;
  1112.      
  1113.        for (i = 0; commands[i].name; i++)
  1114.          {
  1115.            if (!*arg || (strcmp (arg, commands[i].name) == 0))
  1116.              {
  1117.                printf ("%s\t\t%s.\n", commands[i].name, commands[i].doc);
  1118.                printed++;
  1119.              }
  1120.          }
  1121.      
  1122.        if (!printed)
  1123.          {
  1124.            printf ("No commands match `%s'.  Possibilties are:\n", arg);
  1125.      
  1126.            for (i = 0; commands[i].name; i++)
  1127.              {
  1128.                /* Print in six columns. */
  1129.                if (printed == 6)
  1130.                  {
  1131.                    printed = 0;
  1132.                    printf ("\n");
  1133.                  }
  1134.      
  1135.                printf ("%s\t", commands[i].name);
  1136.                printed++;
  1137.              }
  1138.      
  1139.            if (printed)
  1140.              printf ("\n");
  1141.          }
  1142.      }
  1143.      
  1144.      /* Change to the directory ARG. */
  1145.      com_cd (arg)
  1146.           char *arg;
  1147.      {
  1148.        if (chdir (arg) == -1)
  1149.          perror (arg);
  1150.      
  1151.        com_pwd ("");
  1152.      }
  1153.      
  1154.      /* Print out the current working directory. */
  1155.      com_pwd (ignore)
  1156.           char *ignore;
  1157.      {
  1158.        char dir[1024];
  1159.      
  1160.        (void) getwd (dir);
  1161.      
  1162.        printf ("Current directory is %s\n", dir);
  1163.      }
  1164.      
  1165.      /* The user wishes to quit using this program.  Just set DONE non-zero. */
  1166.      com_quit (arg)
  1167.           char *arg;
  1168.      {
  1169.        done = 1;
  1170.      }
  1171.      
  1172.      /* Function which tells you that you can't do this. */
  1173.      too_dangerous (caller)
  1174.           char *caller;
  1175.      {
  1176.        fprintf (stderr,
  1177.                 "%s: Too dangerous for me to distribute.  Write it yourself.\n",
  1178.                 caller);
  1179.      }
  1180.      
  1181.      /* Return non-zero if ARG is a valid argument for CALLER, else print
  1182.         an error message and return zero. */
  1183.      int
  1184.      valid_argument (caller, arg)
  1185.           char *caller, *arg;
  1186.      {
  1187.        if (!arg || !*arg)
  1188.          {
  1189.            fprintf (stderr, "%s: Argument required.\n", caller);
  1190.            return (0);
  1191.          }
  1192.      
  1193.        return (1);
  1194.      }
  1195. File: readline.info,  Node: Concept Index,  Next: Function and Variable Index,  Prev: Programming with GNU Readline,  Up: Top
  1196. Concept Index
  1197. *************
  1198. * Menu:
  1199. * interaction, readline:                Readline Interaction.
  1200. * readline, function:                   Default Behaviour.
  1201. File: readline.info,  Node: Function and Variable Index,  Prev: Concept Index,  Up: Top
  1202. Function and Variable Index
  1203. ***************************
  1204. * Menu:
  1205. * char **completion_matches:            Completion Functions.
  1206. * char *filename_completion_function:   Completion Functions.
  1207. * char *rl_basic_word_break_characters: Completion Variables.
  1208. * char *rl_completer_word_break_characters: Completion Variables.
  1209. * char *rl_line_buffer:                 Function Writing.
  1210. * char *rl_special_prefixes:            Completion Variables.
  1211. * char *username_completion_function:   Completion Functions.
  1212. * Function *rl_attempted_completion_function: Completion Variables.
  1213. * Function *rl_completion_entry_function: How Completing Works.
  1214. * Function *rl_completion_entry_function: Completion Variables.
  1215. * Function *rl_ignore_some_completions_function: Completion Variables.
  1216. * int rl_bind_key:                      Binding Keys.
  1217. * int rl_bind_key_in_map:               Binding Keys.
  1218. * int rl_completion_query_items:        Completion Variables.
  1219. * int rl_end:                           Function Writing.
  1220. * int rl_filename_completion_desired:   Completion Variables.
  1221. * int rl_ignore_completion_duplicates:  Completion Variables.
  1222. * int rl_point:                         Function Writing.
  1223. * int rl_unbind_key:                    Binding Keys.
  1224. * int rl_unbind_key_in_map:             Binding Keys.
  1225. * Keymap rl_copy_keymap:                Keymaps.
  1226. * Keymap rl_make_bare_keymap:           Keymaps.
  1227. * Keymap rl_make_keymap:                Keymaps.
  1228. * readline ():                          Default Behaviour.
  1229. * rl_add_defun:                         Function Naming.
  1230. * rl_begin_undo_group:                  Allowing Undoing.
  1231. * rl_bind_key ():                       Default Behaviour.
  1232. * rl_complete:                          Completion Functions.
  1233. * rl_complete:                          How Completing Works.
  1234. * rl_complete_internal:                 Completion Functions.
  1235. * rl_end_undo_group:                    Allowing Undoing.
  1236. * rl_generic_bind:                      Binding Keys.
  1237. * rl_modifying:                         Allowing Undoing.
  1238. * rl_possible_completions:              Completion Functions.
  1239. Tag Table:
  1240. Node: Top
  1241. Node: Command Line Editing
  1242. Node: Introduction and Notation
  1243. Node: Readline Interaction
  1244. Node: Readline Bare Essentials
  1245. Node: Readline Movement Commands
  1246. Node: Readline Killing Commands
  1247. Node: Readline Arguments
  1248. Node: Readline Init File
  1249. Node: Readline Init Syntax
  1250. 10079
  1251. Node: Commands For Moving
  1252. 11547
  1253. Node: Commands For History
  1254. 12172
  1255. Node: Commands For Text
  1256. 13248
  1257. Node: Commands For Killing
  1258. 14915
  1259. Node: Numeric Arguments
  1260. 16042
  1261. Node: Commands For Completion
  1262. 16485
  1263. Node: Miscellaneous Commands
  1264. 17209
  1265. Node: Readline Vi Mode
  1266. 17897
  1267. Node: Programming with GNU Readline
  1268. 19507
  1269. Node: Default Behaviour
  1270. 20212
  1271. Node: Custom Functions
  1272. 23435
  1273. Node: The Function Type
  1274. 24234
  1275. Node: Function Naming
  1276. 24867
  1277. Node: Keymaps
  1278. 26119
  1279. Node: Binding Keys
  1280. 27034
  1281. Node: Function Writing
  1282. 28335
  1283. Node: Allowing Undoing
  1284. 29776
  1285. Node: Custom Completers
  1286. 33278
  1287. Node: How Completing Works
  1288. 34034
  1289. Node: Completion Functions
  1290. 36841
  1291. Node: Completion Variables
  1292. 39174
  1293. Node: A Short Completion Example
  1294. 41951
  1295. Node: Concept Index
  1296. 53534
  1297. Node: Function and Variable Index
  1298. 53823
  1299. End Tag Table
  1300.