Last update: 2017/11/19      

GAMS mode for Emacs

Home (en) > GAMS > GAMS mode for Emacs

This is a macro for using GAMS (General Algebraic Modeling System) in Emacs.

Release information of GAMS mode is posted at

If you want to know about GAMS and Emacs, please see the following sites.

Main features

GAMS mode for Emacs offers the integrated and flexible environment for using GAMS in Emacs.

When you use GAMS, you must do the following jobs:

  1. Editing GAMS program file,
  2. Calling GAMS to execute the program,
  3. Reading the output file,
  4. Debugging the program,
  5. Examining the numerical values in the output file,

and so on... GAMS mode for Emacs offers various kinds of features which raise your efficiency in all of these jobs.

GAMS mode for Emacs offers the following four major modes (I skip the explanation of the Emacs terminology "major mode". If you cannot understand the terminology, I recommend that you read the introductory document of Emacs first).

  1. GAMS mode: for editing GAMS program files.
  2. GAMS-LST mode: for viewing LST files.
  3. GAMS-SIL mode: for viewing GAMS program structure.
  4. GAMS-TEMPLATE mode: for handling templates of programs.
  5. GAMS-OUTLINE mode: for viewing important items of LST files.

Furthermore, the following features are included in each major mode.

GAMS mode:

This is the major mode for editing GAMS program file.

  1. Inserting GAMS statements and dollar control options.
  2. Automatic registering of new statements and dollar control options.
  3. Calling GAMS from Emacs
  4. Like GAMSIDE, it colors a program file in accordance with the GAMS syntax.
  5. Handling templates of various programs (this is GAMS-TEMPLATE mode).
  6. Automatic indent.
  7. Reading GAMS manual.
  8. Extracting models from GAMS model library.
  9. Viewing GAMS program structure (GAMS-SIL mode).

I will explain each function in detail.

By resistering GAMS statements and dollar control options beforehand, (1) enables you to insert them into the program file easily. You can insert the long statements and dollar control options (that you are likely to mistype) without typing them by yourself. [statement.png], [dollar.png].

Although there are a lot of GAMS statements and dollar control options, only a part of them is registered by default in GAMS mode. It is because frequently used statements differ according to users, and because it is desirable to exclude rarely used statements from candidates of input function of (1). However, (2) enables you to register new statements and dollar control options. You can easily add the commands that you frequently use to the candidate for command inserting function of (1). [register.png].

(3) is the function to call GAMS directly from Emacs for executing the gms file.[process.png].

Like the GAMSIDE, (4) provides the colorization of GAMS program files accoring to GAMS syntax.

When editing GAMS program files, you may often use similar patterns frequently. In that case, you may copy and paste the program repeatedly. But it is surely more convenient if you can register frequently used patterns and select them. Or, although the pattern is not frequently used, it may be hard to remember it. Also in that case, it seems convenient if you can use registered patterns. (5) offers you the feature for registering various patterns easily. In addition to registering, you can modify, delete, rename, re-order existing templates easily. [template.png].

I think that many people agree with the opinion that the proper indent is important for writing programs that other people (or yourself) can read easily. But it is quite tedious to insert spaces and TABs manually by yourself. In GAMS mode, each line is automatically indented according to GAMS syntax.

GAMS-LST mode:

This is the major mode for viewing the output file (i.e. LST file).

  1. Display the error place and its meaning.
  2. Jump to the error place in the program file.
  3. Jump to the various places in the LST file.
  4. Color the content of the LST file.
  5. Display the important items of the LST file (this is the GAMS-OUTLINE mode).

In editing GAMS program, one of the most important job is debugging. Your efficiency of writing program crucially depends on the efficiency of debugging. (1) and (2) are the functions for that.

With (1) and (2), you can do the following jobs quickly with simple key operation. [error.png].

  • Call GAMS and execute the program.
  • Move to the LST file.
  • Examine the place and meaning of errors.
  • Go back to the error place in the program.

You can do similar things also in GAMSIDE, but, I think GAMS mode offers the more convenient environment.

LST files often become quite large. In that case, it is hard to search the output that you want to see. (3) provides you the feature for moving to various important items (such as PARAMETER, SET, VAR, EQU) in the LST file with simple key operation.

Function (4) colors the content of LST files.

As pointed out above, LST file is often very large and it is often very diffcult to find the numerical values that you want to see. And it is also diffcult to compare the numerical values in two different parts of the LST file. Although you may be able to resolve these problems by defining parameters that display only relevant values, it is more convenient if you can examine the content of the LST file in a simple way.

(5) provides the way for that. With this feature, you can easily view the important elements (PARAMETER, VAR, EQU etc.) in LST files.

You can see where the particular PARAMETER or VAR are and can see the content of them. You can also compare the numerical values in a part of the file with that in another part. [out-basic.png], [out-view.png], [out-select.png].

These are the simple explanation of this program. Of course, there are a lot of other functions!

This program has been tested only under GNU Emacs of version 24.5 on MS Windows 7/8 and not tested under other versions of Emacs and OS. But I received reports from persons who use other Emacs and OS that it works well in their environments. So, this program probably works in other Emacs and OS.

Bug reports and requests, suggestions are welcome! Please email me email. To report bugs, please use M-x gams-report-bug

Screenshots page

See Screenshots of GAMS mode for Emacs.

Download and installation

Renger van Nieuwkoop provides a nice introduction of GAMS mode in his blog (The Lazy Economist). If you newly install GAMS mode, you had better look at his blog.

[Note for installation]
Add the following line to your ".emacs.el"

    (setq font-lock-support-mode '((gams-mode . nil) (t . jit-lock-mode)))
Without this setting, coloring function of Emacs is not likely to work well in GAMS mode.

You can download developing version of GAMS mode from In addition, you can install GAMS mode from MELPA (developing version) or MELPA-stable (stable version). To use MELPA, put the following code in your init.el file.

    (add-to-list 'package-archives
                 '("melpa" . "") t)
    (add-to-list 'package-archives
                 '("melpa-stable" . "") t)
But note that this only installs gams-mode.el file and does not install other files.

The files included in the zip archive. First read this file. Change log file. If you want to know changes and newly added functions, please read it.
BUGS_PROBLES.txt Known bugs and problems. If you faces problems, please read this file first.
gams-mode.el The main lisp program.
gams-setting-sample.el A sample file for setting. Copy and paste the content of this file into your "~/.emacs.d/init.el"
gams-sample.gms A sample file to show how to use GAMS mode for Emacs.
sample-include.gms Put this file at the same directory as gams-sample.gms.
outline-sample.gms A sample file to show how to use GAMS-OUTLINE mode.
gams-template.txt A sample file of templates. Save this file in "~/.emacs.d/" directory.
refcard-gams.pdf Reference card for key-bindings.


Please read file.

Older versions

The zip archives of the older versions.

Changelogs of this page

  • 2009-07-19: Release GAMS mode ver. 3.0
  • 2009-03-10: Release GAMS mode ver. 2.7
  • 2009-01-07: Release GAMS mode ver. 2.6.1
  • 2008-12-20: Release GAMS mode ver. 2.6.
  • 2008-07-22: Release GAMS mode ver. 2.5.1: Minor change (bug fix)
  • 2008-03-29: Release GAMS mode ver. 2.5.