navigation map

Chapters:
  1: Introduction
  2: Simple example
  3: Invocation
  4: Finer Control
  5: X-Y Plots
  6: Contour Plots
  7: Image Plots
  8: Examples
  9: Gri Commands
  10: Programming
  11: Environment
  12: Emacs Mode
  13: History
  14: Installation
  15: Gri Bugs
  16: Test Suite
  17: Gri in Press
  18: Acknowledgments
  19: License

Indices:
  Concepts
  Commands
  Variables
index.html#Top NewCommands.html#AddingNewCommands Gri: How synonyms are parsed Gri: creating a complicated new command index.html#Top Gri: creating a complicated new command

10.11.3: Simple example of a new command

To make a new command called `Show The Time' insert the following into your `~/.grirc' resource file or into your command-file somewhere near the top, or at least before you use the command.


`Show The Time'
New command to show the time of day.
{
  show "\.time."
}

EXPLANATION:

  • The name of the new command is enclosed in angled single-quote marks. The words of the new command should begin with upper-case letters to prevent a name clash with a present or future built-in Gri command. Formatting convention: Make sure that the entire definition string, from the opening angled quote to the ending angled quote, appears on one line. Otherwise Gri will give an error like

    
    ERROR: Can't extract syntax for new command
    

  • Following the name line, you may optionally insert any number of lines which will become the `help' information for the new command. See the file `gri.cmd' for the recommended stylistic conventions in writing help information (see Invoking Gri). If your `help' text includes an example that uses an opening brace (`{') you must escape the brace with a backslash, e.g. (`\{').
  • Following the help lines, if they exist, the body of the new command is given, sandwiched between a starting line containing an opening brace (`{') as the only nonwhite character, and an ending line containing a closing brace (`}') as the only nonwhite character. Any valid Gri commands may be used in the body of the new command. It is acceptable to use other new commands in the body. Recursion is also allowed -- a new command is allowed to call itself (although there is a limit on nesting, of perhaps a thousand or so; this varies with the version of Gri). Formatting convention: It is usual, but not necessary, to use an indentation level of 2 spaces in the body of the new command.

The new command is invoked by `Show The Time'. Help for the command is found by `help Show The Time' or `help Show'.

navigation map