Add an example for extending xrepl, the very stupid way.

For the record, a way to do this permanently is to add something like
this to your ~/.racketrc:

  (eval '(begin
           (saved-values-char #\~)
           (defcommand eli "stuff" "eli says" ["Make eli say stuff"]
             (printf "Eli says: ~a\n" (getarg 'line)))
           (defcommand er #f "alias for errortrace" ["Runs errortrace"]
             (run-command 'errortrace)))
        (module->namespace 'xrepl/xrepl))

But this is too stupid even for a section that has "Hacking" in its title.

There should definitely be an organized way to do this.  This will
require several things:

* A decent API for doing these things for user code.  (So the above
  `eval' turns to a `require' for your file which uses this API.)  This
  goes beyond just documenting what's in there -- there are issues to
  resolve like some argument reading protocol (separating the
  declaration of argument types from the command implementation code),
  so a new command can call another with arguments that it reads.

* There should also be some ,set command for customization
  options (reading and changing) and code to use the preference file for
  doing that.  I almost started to do this, but currently there are only
  three values that this could apply to (`saved-values-char', `-number',
  and `wrap-column' (which might be better to dump and use
  `pretty-print-columns' instead)).

* Also, it might be nice to have some command to do the same for simple
  aliases.  (But this might get into shady parsing issues if it's more
  than just "I want `foo' to be an alias for an existing `bar' command".)
This commit is contained in:
Eli Barzilay 2011-07-18 15:23:09 -04:00
parent 5fb8390609
commit 3c1e624916

View File

@ -453,7 +453,7 @@ customize and extend it, but this will be added in the future.
Meanwhile, if you're interested in tweaking XREPL, the @cmd[enter]
command can be used as usual to go into its implementation. For
example:
example --- change an XREPL parameter:
@verbatim[#:indent 4]{
-> ,en xrepl/xrepl
xrepl/xrepl> ,e
@ -463,6 +463,14 @@ example:
123
-> ~
123}
or add a command:
@verbatim[#:indent 4]{
-> ,en xrepl/xrepl
xrepl/xrepl> (defcommand eli "stuff" "eli says" ["Make eli say stuff"]
(printf "Eli says: ~a\n" (getarg 'line)))
xrepl/xrepl> ,top
-> ,eli moo
Eli says: moo}
While this is not intended as @emph{the} way to extend and customize
XREPL, it is a useful debugging tool should you want to do so.