Add basic :edit support
[ghc-hetmet.git] / docs / users_guide / ghci.xml
index e79fb46..76d4972 100644 (file)
@@ -402,7 +402,7 @@ hello
 </screen>
 </para></sect2>
 
-    <sect2>
+    <sect2 id="ghci-stmts">
       <title>Using <literal>do-</literal>notation at the prompt</title>
       <indexterm><primary>do-notation</primary><secondary>in GHCi</secondary></indexterm>
       <indexterm><primary>statements</primary><secondary>in GHCi</secondary></indexterm>
@@ -444,7 +444,13 @@ Prelude>
              <literal>Show</literal></para>
          </listitem>
        </itemizedlist>
-      </para>
+      The automatic printing of binding results can be supressed with
+      <option>:set -fno-print-bind-result</option> (this does not
+      supress printing the result of non-binding statements).
+      <indexterm><primary><option>-fno-print-bind-result</option></primary></indexterm><indexterm><primary><option>-fprint-bind-result</option></primary></indexterm>.
+      You might want to do this to prevent the result of binding
+      statements from being fully evaluated by the act of printing
+      them, for example.</para>
 
       <para>Of course, you can also bind normal non-IO expressions
       using the <literal>let</literal>-statement:</para>
@@ -604,6 +610,12 @@ Prelude IO>
       behaves in the same way for expressions typed at the
       prompt.</para>
 
+      <para>
+        Hint: GHCi will tab-complete names that are in scope; for
+        example, if you run GHCi and type <literal>J&lt;tab&gt;</literal>
+        then GHCi will expand it to <literal>Just </literal>.
+      </para>
+
       <sect3>
        <title>Qualified names</title>
 
@@ -873,10 +885,8 @@ $ ghci -lm
     <para>GHCi commands all begin with
     &lsquo;<literal>:</literal>&rsquo; and consist of a single command
     name followed by zero or more parameters.  The command name may be
-    abbreviated, as long as the abbreviation is not ambiguous.  All of
-    the builtin commands, with the exception of
-    <literal>:unset</literal> and <literal>:undef</literal>, may be
-    abbreviated to a single letter.</para>
+    abbreviated, with ambiguities being resolved in favour of the more
+    commonly used commands.</para>
 
     <variablelist>
       <varlistentry>
@@ -1003,6 +1013,21 @@ Prelude> :. cmds.ghci
 
       <varlistentry>
        <term>
+          <literal>:edit <optional><replaceable>file</replaceable></optional></literal>
+          <indexterm><primary><literal>:edit</literal></primary></indexterm>
+        </term>
+       <listitem>
+         <para>Opens an editor to edit the file
+         <replaceable>file</replaceable>, or the most recently loaded
+         module if <replaceable>file</replaceable> is omitted.  The
+         editor to invoke is taken from the <literal>EDITOR</literal>
+         environment variable, or a default editor on your system if
+         <literal>EDITOR</literal> is not set.</para>
+       </listitem>
+      </varlistentry>
+
+      <varlistentry>
+       <term>
           <literal>:help</literal>
           <indexterm><primary><literal>:help</literal></primary></indexterm>
         </term>
@@ -1074,6 +1099,38 @@ Prelude> :. cmds.ghci
 
       <varlistentry>
        <term>
+          <literal>:main <replaceable>arg<subscript>1</subscript></replaceable> ... <replaceable>arg<subscript>n</subscript></replaceable></literal>
+          <indexterm><primary><literal>:main</literal></primary></indexterm>
+        </term>
+        <listitem>
+          <para>
+            When a program is compiled and executed, it can use the
+            <literal>getArgs</literal> function to access the
+            command-line arguments.
+            However, we cannot simply pass the arguments to the
+            <literal>main</literal> function while we are testing in ghci,
+            as the <literal>main</literal> function doesn't take its
+            directly.
+          </para>
+
+          <para>
+            Instead, we can use the <literal>:main</literal> command.
+            This runs whatever <literal>main</literal> is in scope, with
+            any arguments being treated the same as command-line arguments,
+            e.g.:
+          </para>
+
+<screen>
+Prelude> let main = System.Environment.getArgs >>= print
+Prelude> :main foo bar
+["foo","bar"]
+</screen>
+
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+       <term>
           <literal>:module <optional>+|-</optional> <optional>*</optional><replaceable>mod<subscript>1</subscript></replaceable> ... <optional>*</optional><replaceable>mod<subscript>n</subscript></replaceable></literal>
           <indexterm><primary><literal>:module</literal></primary></indexterm>
         </term>