This package offers the Emacs lisp program for using the numerical software GAMS in Emacs (GAMS mode for Emacs).
The contents of this file.
- Introduction (brief overview)
- Basic Usage
Introduction (brief overview)
Introduction of GAMS mode for Emacs.
GAMS mode for Emacs offers the integrated and flexible environment for using GAMS in Emacs.
This section presents brief overview of what GAMS mode for Emacs is.
Please read the section "Installation"' below for information about how to
install GAMS mode. If you are upgrading from the previous version of GAMS
mode, the latest changes can be found in
You can obtain the latest version of this program at the web site GAMS mode for Emacs (https://github.com/ShiroTakeda/gams-mode/).
When you use GAMS, you must do the following jobs:
- Edit GAMS program file,
- Call GAMS to execute the program,
- Read the output file,
- Debug the program,
- Examine 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 five 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).
|GAMS mode:||Editing GAMS program files.|
|GAMS-LST mode:||Viewing LST files.|
|GAMS-SIL mode:||Viewing GAMS program structure.|
|GAMS-TEMPLATE mode:||Handling templates of programs.|
|GAMS-OUTLINE mode:||Viewing important items of LST files.|
Furthermore, the following features are included in each major mode.
This is the major mode for editing GAMS program file.
- Inserting GAMS statements and dollar control options.
- Automatic registering of new statements and dollar control options.
- Calling GAMS from Emacs
- Like GAMSIDE, it colors a program file in accordance with the GAMS syntax.
- Handling templates of various programs (this is GAMS-TEMPLATE mode).
- Automatic indent.
- Viewing GAMS program structure (GAMS-SIL mode).
- Reading GAMS manual.
- Extracting models from GAMS model library.
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.
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).
(3) is the function to call GAMS directly from Emacs for executing the gms file.
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.
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 (6).
When we write a GAMS program, we define many (sometimes hundreads of) variables, equations, sets and parameters and it is difficult to remember which identifier represents what. Feature (7) enables you to show the list of all identifiers defined in a program and you can see the structure of a program.
In addition, you can call a PDF manual viewer from Emacs (8) to read GAMS manuals and you can view GAMS model library in Emacs (9).
This is the major mode for viewing the output file (i.e. LST file).
- Display the error place and its meaning.
- Jump to the error place in the program file.
- Jump to the various places in the LST file.
- Color the content of the LST file.
- 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.
- 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. You are able to know what this function is like by looking at the screenshots placed at http://shirotakeda.org/en/gams/gams-mode/gams-ss.html.
These are the simple explanation of this program. Of course, there are a lot of other functions!
This program has been tested under GNU Emacs of version 24.5 on MS Windows 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, requests, and suggestions are all welcome!
See screenshots page.
First, I explain the files distributed in the package.
||This file. First read this.|
||Change log file. If you want to know changes and newly added functions, please read it.|
||Known bugs and problems|
||The main lisp program.|
||A sample file for setting.|
||A sample file of templates.|
||The foder of sample gams files.|
||A sample file to show how to use GAMS mode for Emacs.|
||A sample file to show how to use GAMS mode for Emacs (in Japanese)|
||A sample file to show how to use GAMS-OUTLINE mode.|
||A sample file to show how to use GAMS-OUTLINE mode (in Japanese)|
||A sample file to show how to use org-mdoe in GAMS-mode|
||A sample file to show how to use org-mdoe in GAMS-mode|
||Referece card of keybindins.|
||Folder of files used to explain GAMS-LXI mode|
If you are well acquainted with Emacs, installation is very easy. Here, I explain basic Emacs terminologies used below. But if you are a novice user of Emacs, I recommend you to read the web site such as http://www.gnu.org/software/emacs/manual/html_node/efaq-w32/index.html.
This is Unix terminology rather than Emacs'. This represents a user's HOME directory. A user's HOME directory means the directory (folder) where his configuration files are placed. If you are MS Windows VISTA/7/8 user, the default HOME directory is set to "c:\Users\username\AppData\Roaming". If you want to know to which directory your home directory is set, evaluate (getenv "HOME") in the scratch buffer on Emacs. You can set your HOME directory by the environemtal variable HOME. If you are MS Window VISTA/7/8 user, use control panel.
This is the configuration file that Emacs tries to read first when it is started. You can change the behavior of Emacs by writing various settings in this file. Note that this is the file that you must create by yourself and there exists no "init.el" file by default (unless the administrator has created it for you).
In Emacs terminology, non-nil means anything other than nil, and values such as 0, "a", or t all mean non-nil. But we usually use symbol t as non-nil. So, when I say "set non-nil to x", set t to x (i.e. (setq x t)).
Setting for shell
If you would like to call GAMS (gams.exe) from Emacs, it is necessary that you have installed the shell. If you are Emacs user on Windows, the default shell will be "cmdproxy.exe". Try to type F1 and v and shell-file-name RET. Then the default shell will be displayed.
If you are not MS Windows user, you have to use other shell. If you use, for example, bash(.exe), add the following in "~/.emacs.d/init.el"
(setq shell-file-name "bash")
Installation of GAMS mode.
Install from MELPA repository.
You can install GAMS mode (gams-mode.el) from MELPA repository. Type M-x list-packages and select gams-mode.
To use melpa, put the following code in your init.el file.
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t) (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t)
If you want to use a stable version, use GAMS mode in melpa-stable. If you want to use a developing version, use GAMS mode in melpa.
Note that it installs only gams-mode.el file and does not install sample files and explanatory files. So to use GAMS mode, you had better read GAMS mode web site first. http://shirotakeda.org/en/gams/gams-mode/
If the GAMS system folder is not included in PATH environemtal variable, you need to set GAMS system folder to PATH or you need to set the full path to gams.exe to the variable 'gams-process-command-name'. For example, your gams.exe is placed at "c:/GAMS/win64/GAMS24.1/", then add the following line to init.el:
(setq gams-process-command-name "c:/GAMS/win64/GAMS24.1/gams.exe")
In addition, you had better set 'gams-system-directory' like
(setq gams-system-directory "c:/GAMS/win64/GAMS24.1/")
If you want to color an Emacs buffer, add the followings, too.
(require 'font-lock) (global-font-lock-mode t) (setq font-lock-support-mode '((gams-mode . nil) (t . jit-lock-mode)))
This make the colorization function of Emacs on and GAMS mode buffer will
be colored. The third line is required because
causes troubles in GAMS mode.
Basically, this is all you must set. With these settings, when you open a file with extension "gms" ("lst"), GAMS mode (GAMS-LST mode) will automatically start. Byte-compiling gams-mode.el may raise the speed of GAMS mode (but you need not necessarily do it).
For Emacs 23 user, please read BUGS_PROBLEMS.txt file, too.
There is a sample setting file ("gams-setting-sample.el") distributed with this file. Please read it, too.
If you want to use GAMS-TEMPLATE mode, you had better copy the sample template file "gams-template.txt" in "~/.emacs.d/". This sample file contains a lot of useful templates for writing gms files.
There are several lisp variables which decide the important behaviors of GAMS and the GAMS mode. So, please read the customization part below, too.
To install gams-mode.el manually, you need to follow the procedure below (1 and 2 are not necessary when you install gams-mode.el by MELPA).
Put "gams-mode.el" file into one of the directories listed in
load-path. You can see the contents of
M-x customize-option <RET> load-path. Or add the directory where "gams-mode.el" is installed to
load-pathvariable. For this, add the following in your "~/.emacs.d/init.el" file:
(setq load-path (cons "~/emacs.d/lisp/gams/" ;; Set the installed directory! load-path))
Add the following into your "~/.emacs.d/init.el" startup file (after load-path setting)
In addition, you had better set proper values to
To learn how to use the GAMS mode, it is best to read "gams-sample.gms" file. "gams-sample.gms" file enables you to acquire necessary skills in a learning-by-doing way.
Here is the basic command listing. Try each command by yourself! You can see basic keybindins also in refcard-gams.pdf.
Key-binding Command explanation
||Insert GAMS statement with completion.|
||Insert GAMS dollar control option with completion.|
||Show the identifier declaration part.|
||Show the identifier list in the buffer.|
||Open included file.|
||Switch to the LST file and show errors if exist.|
||Switch to the LST file.|
||Evoke process menu.|
||Edit command and start GAMS.|
||Insert templates (GAMS-TEMPLATE).|
||Insert user defined comment template.|
||Insert an ontext-offtext pair.|
||Jump between ontext and offtext.|
||(Un)comment an ontext-offtext pair.|
||Remove an ontext-offtext pair.|
||View GAMS pdf manuals.|
||Change the level of font-lock (colorization)|
||Insert inline comment.|
||Insert end-of-line comment.|
||Jump to the error and show its number and meaning.|
||Jump back to the error place in the program file.|
||Jump to the input (GMS) file.|
||Close the buffer.|
||Start the GAMS-OUTLINE mode.|
||Jump to the next (previous) SOLVE SUMMARY.|
||Jump to the next (previous) REPORT SUMMARY.|
||Jump to the next (previous) VAR entry.|
||Jump to the next (previous) EQU entry.|
||Jump to the next (previous) PARAMETER entry.|
||Jump to a line you specify.|
||Jump to a line.|
||Wien the window.|
||Spit the window.|
||Moe a cursor to the other window.|
d,f,g,h,j,k Keys for scrollings (see the help in GAMS-LST mode).
For details, please see the help in both modes.
If you want to know how to use GAMS-TEMPLATE, please see the help in GAMS-TEMPLATE mode, (start GAMS-TEMPLATE mode (C-cC-e) and push ? in the Template List buffer).
If you want to use GAMS-OUTLINE mode, you had better see the sample GAMS file "outline-sample.gms". Try to run GAMS on that file. And if you want to know commands in GAMS-OUTLINE mode, please see the help in the GAMS-OUTLINE mode, (start GAMS-OUTLINE mode [type o in the LST mode] and push ? in the OUTLINE buffer).
You can custumize the behavior of Emacs and GAMS mode by changing the values of the following variables. Default value is given in 
You can change the value of these variables by adding in your "~/.emacs.d/init.el", for example,
(setq gams-process-command-name "c:/GAMS20.0/gams.exe") (setq gams-statement-upcase nil)
Or you can use
customize built in Emacs. Try M-x
customize-apropos-groups [RET] gams [RET.]
Please read the sample file "gams-setting-sample.el", too.
Basic customizable variables in GAMS and GAMS-LST mode:
"*GAMS program file name. If you do not include the GAMS system directory in PATH environmental variable, you must set the full path to GAMS program in this variable like c:/GAMS20.0/gams.exe."
gams-process-command-option ["ll=0 lo=3 pw=100 ps=9999"]
"*Command line options passed to GAMS"
"*The name of the file in which user specific statements are stored."
"*The column number used for fill-paragraph and auto-fill-mode."
"Non-nil means that font-lock-fontify buffer when recentering. If your computer is slow, you may better set this to nil."
"*List of gams program file extensions. If you open a file with an extension included in this list, GAMS mode starts automatically. It doen't matter whether upper case or lower case."
"*Hook run when gams-mode starts."
"*List of functions to be called when gams-mode.el is loaded."
"*Non-nil means that close parenthesis."
"*User defined comment template. You can insert the comment template
defined in this variable by executing
gams-insert-comment. % in the
string indicates the cursor place and will disappear after template
insertion. NB: You cannot include double quoatations and backslashes in
gams-docs-view-program ["c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe"]
"The full path to the pdf file viewer."
"The GAMS system directory."
"The default value for inline comment start symbol."
"The default value for inline comment end symbol."
"The default value for eol comment symbol."
"*The name of a file used to store templates."
"Nil means that save the content of
gams-template-file only when you quit Emacs. If non-nil, save
gams-user-template-alist every time you made changes. If your Emacs
often crashes, you may had better set it to non-nil."
"*The height of the GAMS-OUTLINE buffer with one LST buffer."
"*The height of the GAMS-OUTLINE buffer with two LST buffers."
There are also other customizable variables, mainly keybindings and fonts. You can see a full list of customizable variables by executing:
M-x customize-apropos-groups [RET] gams [RET]
See TODO file.
Bug reports, requests and suggestions are welcome! Write an email to me. Shiro Takeda email@example.com
To write the package GAMS mode, I have used a lot of excellent emacs lisp
codes written by other people. They include "YaTeX" (Yet Another LaTeX
mode), EPO (Editing Process Organizer), "RefTeX mode",
indent.el etc. In particular, I
would like to express acknowledgments to Yuuji Hirose who is the author of
YaTeX and EPO packages (they are available at
http://www.gentei.org/~yuuji/software). He also have written other lots
of cool lisp programs. You will be happy if you visit to his web site :-)