Emacs tools
***********

Everyone writing code knows how important a good editor is. Most systems already come with Emacs, and excellent programmer's editor. MDK adds support to Emacs for both writing and debugging MIX programs. A major mode for MIXAL source files eases edition of your code, while integration with Emacs' debugging interface (GUD) lets you use mixvm without leaving your favourite text editor.

This chapter shows how to use the Elisp modules included in MDK, assuming that you have followed the installation instructions in see Emacs support.

MIXAL mode
==========

The module mixal-mode.el provides a new mode, mixal-mode, for editing MIXAL source files (mixal-mode has been developed and
documented by PIETER). When everything is installed correctly, Emacs will select it as the major mode for editing files with extension .mixal. You can also activate mixal-mode in any buffer issuing the Emacs command M-x mixal-mode.

Basics
------

The mode for editing mixal source files is inherited from fundamental-mode, meaning that all your favorite editing operations will still work. If you want a short introduction to Emacs, type C-h t inside Emacs to start the tutorial.

Mixal mode adds font locking. If you do not have font locking globally enabled, you can turn it on for mixal-mode by placing the following line in your .emacs file:

     (add-hook 'mixal-mode-hook 'turn-on-font-lock)

You can also customize the colors used to colour your mixal code by changing the requisite faces. This is the list of faces used by mixal-mode:

  * FONT-LOCK-COMMENT-FACE Face to use for comments.

  * MIXAL-FONT-LOCK-LABEL-FACE Face to use for label names.

  * MIXAL-FONT-LOCK-OPERATION-CODE-FACE Face to use for operation code names.

  * MIXAL-FONT-LOCK-ASSEMBLY-PSEUDOINSTRUCTION-FACE Face to use for assembly pseudo-instruction names.

Help system
-----------

When coding your program, you will be thinking, looking up documentation and editing files. Emacs already helps you with editing files, but Emacs can do much more. In particular, looking up documentation is one of its strong points. Besides the info system (which you are probably already using), mixal-mode defines commands for getting particular information about a MIX operation code.

With M-x mixal-describe-operation-code (or its keyboard shortcut C-h o) you will get the documentation about a particular MIX operation code. Keep in mind that these are not assembly (MIXAL) pseudoinstructions. When the point is around a MIXAL pseudoinstruction in your source file, Emacs will recognize it and will suggest the right MIX operation code.

Compiling and running
---------------------

After you have written your MIXAL program, you'll probably want to test it. This can be done with the MIX virtual machine. First you will need to compile your code into MIX byte code. This can be done within Emacs with the command M-x compile (C-c c). In case of compilation errors, you can jump to the offending source code line with M-x next-error.

Once the program compiles without errors, you can debug or run it. To invoke the debugger, use M-x mixal-debug (C-c d). Emacs will open a GUD buffer where you can use the debugging commands described in see mixvm.

If you just want to execute the program, you can do so with M-x mixal-run (C-c r). This will invoke mixvm, execute the program and show its output in a separate buffer.

GUD integration
===============

If you are an Emacs user and write your MIXAL programs using this editor, you will find the elisp program mixvm.el quite useful (mixvm.el has been kindly contributed by
PHILIP. mixvm.el is based on a study of gdb, perldb, and
pdb as found in gud.el, and rubydb3x.el distributed with
the source code to the Ruby language.). mixvm.el allows running the MIX virtual machine mixvm (see mixvm) inside an Emacs GUD buffer, while visiting the MIXAL source file in another buffer.

After installing mixvm.el (see Emacs support), you can initiate an MDK/GUD session inside Emacs with the command

     M-x mixvm

and you will have a mixvm prompt inside a newly created GUD buffer. GUD will reflect the current line in the corresponding source file buffer.