Nyquist and Emacs

Running Nyquist in an Emacs buffer

(see GNU Emacs user manual: compiling and testing programs - sub-chapter: running an external lisp)

Type the following lines by replacing "e:/programme/nyquist/ny.exe" with the path to your nyquist executable:

 M-x (setq inferior-lisp-program "e:/programme/nyquist/ny.exe")
 M-x run-lisp

Emacs opens a new buffer named "inferior-lisp" with the Nyquist interpreter running inside. You can either type your commands directly into the interpreter or you can do the following:

Go to the Emacs scratch buffer. I the status line you can read [(Lisp Interaction)] what means the buffer is in Lisp interaction mode. Then you type:

 M-x lisp-mode

In the status line appears (Lisp), the buffer is in Lisp mode now. Then, in the buffer, type some Nyquist code:

 (play (osc 60))

Place the cursor after the last paren and type:

 C-x C-e

C-x C-e is the Emacs abbreviation of: execute evaluation

On a Microsoft windows computer you will hear a one second sine wave sound. If you go to the "inferior-lisp" buffer you will see a Nyquist message:

 Saving sound file to temp.wav

 total samples: 44100
 AutoNorm: peak was 1,
     peak after normalization was 1,
     new normalization factor is 0.9

If you leave the scratch buffer in "Lisp Interaction" mode instead and type C-x C-e, Emacs will send your Nyquist code to the internal ELisp interpreter and the result will be that a debugger buffer is opened with a message like this:

 Debugger entered--Lisp error: (void-function play)
   (play (osc 60))
   eval((play (osc 60)))
 * call-interactively(eval-last-sexp)

If this happens to you then you know that your buffer is in the wrong Lisp mode. But you have learned that it is only a question of the buffer mode which Lisp interpreter will be used by Emacs. Now you know that you can use both - Emacs Lisp or Nyquist XLisp - whenever you like. You only have to switch the buffer mode.

For Nyquist XLisp evaluations you need "Lisp Mode". For Lisp mode you type:

 M-x lisp-mode

For Emacs Lisp (called ELisp) evaluations you need either "Emacs Lisp Mode" or "Lisp Interaction" mode.

For Emacs Lisp mode you type:

 M-x emacs-lisp-mode

For Lisp interaction mode you type:

 M-x lisp-interaction-mode

See also: The different Emacs Lisp modes

Nyquist and Emacs