i finally found a way to make my .ghci-file readable, by
implementing multiline commands for ghci!-)

patch and test attached. patch seems to make no difference to existing tests (fast stage=2).

issues
   - multiline commands in ghci and .ghci would be great

   - they can only partially be implemented at user level
       (in particular, the user level implementation won't
       work in .ghci files, where it would be most useful)

- ghci has three separate command loops for file, readline, and cmdqueue, treating the queue slightly differently
       and spreading functionality over three pieces of code;
       moreover, fileLoop/readLineLoop are in control, and
       runCommands returns to them when it needs more input,
       making it difficult to implement multiline commands;

solutions in this patch

   - refactor ghci command loops into one (runCommands);
fileLoop/readLineLoop just feed single lines to runCommands, as does the new queryQueue; commands are read from the queue, or from the current feeder, if the queue is empty; all sources of commands are otherwise treated equally, in a single location

- add multiline commands ':{\n ..lines.. \n:}\n', which has become trivial after the refactoring, and works via stdin, in .ghci, via readFile, and via :cmd/:def

the refactoring should be independently useful, as a cleanup
and to bring common functionality into a single source location.
multiline commands have been asked for both to improve
interactive sessions, and to make .ghci files readable (without
this patch, my own .ghci file was unmaintainable). the syntax
i've chosen is:

   :{
       let
       { x = True
       ; y = False
       }
   :}

that is, multiline commands are clearly separated by ':{',':}',
each on a line of its own, and add no other functionality. in
particular, we do not:

   - enable anything but existing commands spread
       over multiple lines (no layout, no data)

   - read .ghci via stdin to make this work (that would
       interfere with type-ahead and with piping into ghci)

   - use '\' as line-continuations, as conventional, because
       those may appear in existing commands at the end
       (:info \\) or at the beginning (\x->x)

please review, and adopt for HEAD and STABLE.

(in addition to the patch and test, i also attach my .ghci,
so you can see this feature in action; if you recall the
original form of the :redir command, all squished into
a single line, you'll agree that this little feature makes
a great difference to maintainability of .ghci files;-)

btw, it seems that ghci tests are not protected from .ghci
files (shouldn't they be run with -ignore-dot-ghci?)! my own test tests stdin and :cmd readFile, but not .ghci, because i didn't know how to add a .ghci file for a single test only (should there be a ghci option to specify the .ghci-filename?).

enjoy!-)
claus

ps fileLoop/readLineLoop are no longer loops, but
    i left the names unchanged to simplify reviewing

Attachment: ghci-multiline-commands-testsuite.diff
Description: Binary data

Attachment: ghci-multiline-commands.diff
Description: Binary data

Attachment: ghci023.stdout
Description: Binary data

Attachment: ghci023.ghci
Description: Binary data

Attachment: ghci023.script
Description: Binary data

Attachment: .ghci
Description: Binary data

_______________________________________________
Cvs-ghc mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-ghc

Reply via email to