Next: , Previous: Using Guile Interactively, Up: Programming in Scheme


3.5 Using Guile in Emacs

There are several options for working on Guile Scheme code in Emacs. The simplest are to use Emacs's standard scheme-mode for editing code, and to run the interpreter when you need it by typing “guile” at the prompt of a *shell* buffer, but there are Emacs libraries available which add various bells and whistles to this. The following diagram shows these libraries and how they relate to each other, with the arrows indicating “builds on” or “extends”. For example, the Quack library builds on cmuscheme, which in turn builds on the standard scheme mode.

                 scheme
                    ^
                    |
              .-----+-----.
              |           |
          cmuscheme    xscheme
              ^
              |
        .-----+-----.
        |           |
      Quack        GDS

scheme, written by Bill Rozas and Dave Love, is Emacs's standard mode for Scheme code files. It provides Scheme-sensitive syntax highlighting, parenthesis matching, indentation and so on.

cmuscheme, written by Olin Shivers, provides a comint-based Scheme interaction buffer, so that you can run an interpreter more directly than with the *shell* buffer approach by typing M-x run-scheme. It also extends scheme-mode so that there are key presses for sending selected bits of code from a Scheme buffer to this interpreter. This means that when you are writing some code and want to check what an expression evaluates to, you can easily select that code and send it to the interpreter for evaluation, then switch to the interpreter to see what the result is. cmuscheme is included in the standard Emacs distribution.

Quack, written by Neil Van Dyke, adds a number of incremental improvements to the scheme/cmuscheme combination: convenient menu entries for looking up Scheme-related references (such as the SRFIs); enhanced indentation rules that are customized for particular Scheme interpreters, including Guile; an enhanced version of the run-scheme command that knows the names of the common Scheme interpreters and remembers which one you used last time; and so on. Quack is available from http://www.neilvandyke.org/quack.

GDS, written by Neil Jerram, also builds on the scheme/cmuscheme combination, but with a change to the way that Scheme code fragments are sent to the interpreter for evaluation. cmuscheme and Quack send code fragments to the interpreter's standard input, on the assumption that the interpreter is expecting to read Scheme expressions there, and then monitor the interpreter's standard output to infer what the result of the evaluation is. GDS doesn't use standard input and output like this. Instead, it sets up a socket connection between the Scheme interpreter and Emacs, and sends and receives messages using a simple protocol through this socket. The messages include requests to evaluate Scheme code, and responses conveying the results of an evaluation, thus providing similar function to cmuscheme or Quack. They also include requests for stack exploration and debugging, which go beyond what cmuscheme or Quack can do. The price of this extra power, however, is that GDS is Guile-specific. GDS requires the Scheme interpreter to run some GDS-specific library code; currently this code is written as a Guile module and uses features that are specific to Guile. GDS is now included in the Guile distribution; for previous Guile releases (1.8.4 and earlier) it can be obtained as part of the guile-debugging package from http://www.ossau.uklinux.net/guile.

Finally, xscheme is similar to cmuscheme — in that it starts up a Scheme interaction process and sends commands to that process's standard input — and to GDS — in that it has support beyond cmuscheme or Quack for exploring the Scheme stack when an error has occurred — but is implemented specifically for MIT/GNU Scheme. Hence it isn't really relevant to Guile work in Emacs, except as a reference for useful features that could be implemented in one of the other libraries mentioned here.

In summary, the best current choice for working on Guile code in Emacs is either Quack or GDS, depending on which of these libraries' features you find most important. For more information on Quack, please see the website referenced above. GDS is documented further in the rest of this section.