Editing SIMION Text Files: Instructions on configuring and using various text editors (including SciTE, VIM, and Emacs) to effectively edit SIMION GEM and Lua files (e.g. syntax highlighting).
- Editing SIMION Text Files
- A Summary of SIMION support in SciTE, Emacs, and VIM
- The SciTE Editor - Installation
- The VIM Editor - Installation
- The Emacs Editor - Installation
- Older Notes (SIMION 7)
SIMION requires text files in various places such as .ion, .lua, .gem, and .fly2 (SIMION 8) files or .sl/.prg files (SIMION 7). You could just use a simple text editor like Windows Notepad, but an alternate and more advanced text editor offers the following benefits:
- Syntax highlighting for improved code readability and making certain errors (e.g. misspelled keywords) instantly visible.
- Displaying line numbers to locate reported errors.
- Detecting undefined variables.
- Extensive text editing capabilities.
- Invoking some compiler or interpreter (e.g. Lua) within the text editor.
One such more powerful text editor is SciTE (or the variant Notepad++), and there are even more powerful (but more complicated) ones like Emacs (including XEmacs and GNU Emacs variants) or VIM. If you’re not sure which to use, we recommend SciTE or the more GUI-ish variant Notepad++ for its relative simplicity and power.
A more Lua-specific editor is the
Once you have a text editor, you might want more integration into SIMION such as launching it from SIMION. See for example Appendix G (Text Editing) of the SIMION 8.x Manual. You also might want to configure your text editor for syntax highlighting of SIMION files or other such SIMION enhancements, and that is the focus of this article.
SciTE (as well as some versions of Emacs and VIM) comes with built-in support for syntax highlighting of Lua files. We have not (at least yet) developed support for syntax highlighting of other SIMION file types (e.g. GEM or PRG) in SciTE, but support for syntax highlighting these files in Emacs and VIM are available as plugins in the “SIMION Editor Files”, which can be freely download from simion.com and are also bundled with SIMION 8. The VIM plugins were generously provided to the SIMION community by SIMION user Robert Malek, and the Emacs plugins were developed by SIS.
The below discussion describes some things you can do to configure SciTE, VIMm and Emacs more effectively for use with SIMION.
Below is an example of editing a Lua program in SciTE (and also running it inside SciTE).
SciTE is a very lean and simple editor. It’s smaller and generally much easier to use than Emacs or VIM. It comes with built-in syntax highlighting support for Lua files.
The steps for setting up SciTE to work with SIMION files are provided below:
Download and Install SciTE for Windows. This can be downloaded from the SciTE website. You will want one of the Windows executable versions.
Use SciTE. SciTE is already set up to syntax highlight Lua files when you load an edit .lua files. No syntax highlighting is currently available for other SIMION file types in SciTE though, but you can still use SciTE for editing these files too.
Invoking the Lua Interpreter from SciTE You may find it
convenient to execute short Lua programs inside SciTE. As an example,
open SciTE and create a Lua file named
test.lua that contains
something simple like this:
Now, with this Lua program open in SciTE, select the SciTE Tools | Go menu item. Initially, you’ll probably get an error such as
>Lua-5.0.exe -o "test.luc" "test.lua" >The system cannot find the file specified.
This is because SciTE needs to be told where the Lua interpreter is
located. To fix this, select the Options | Open Global Options File
menu in SciTE. This will display the
SciTEGlobal.properties configuration file, which initially is
blank. Add the following line to it and save (this part is probably
command.go.*.lua="c:\program files\simion-8.1\simion.exe" --nogui lua "$(FileNameExt)"
Now switch back to the
test.lua program in SciTE and again select
the Tools | Go menu item. It should work fine now. See
If you want additional Lua debugging capabilities out of a text editor and with less effort than SciTE, you might consider a more Lua specific editor like ZeroBrane or Lua-edit (see Lua Editor Support).
One word of caution though: text editors like SciTE may understand Lua but they don’t have any special knowledge about SIMION. If you try to Tools | Go on a SIMION 8.0 workbench Lua program, it will probably complain about “simion.workbench_program”, “adjustable”, or “segment” not being defined. Those are concepts SIMION defines when flying ions. Still, you might find the above useful for testing individual pieces of Lua sample code or functions.
Below is an example of VIM editing a SIMION “GEM” geometry file:
The steps for setting up VIM to work with SIMION files are provided below:
Download and Install VIM for Windows. This can be downloaded
from www.vim.org by clicking the “Download” link and
choosing the “Self-installing executable for MS-Windows”
Download the Editor Files for SIMION and uncompress it into a temporary directory. These files can be downloaded from simion.com.
Copy the contained “vimfiles” directory into your Windows profile
directory. For example, if your Windows username is “me”, your
profile directory will likely be
c:\Documents and Settings\me .
Therefore, there will be a new directory
c:\Documents and Settings\me\vimfiles .
In Windows Explorer, open up any SIMION GEM, PRG, or SL file by right clicking on the file and selecting :guilabel:`Edit with Vim`.
Enable syntax highlighting. If the text does not appear syntax
highlighted (i.e. colored words), select the “Syntax Automatic” menu
item to enable this. To make this setting permanent, add the line “syntax
enable” to your
c:\Documents and Settings\me\.vimrc file (and creating
this file if it doesn’t exist).
Here some optional customizations you might want to make.
Setting “Easy Mode.” The first thing you should know about VIM is that VIM is what is called a “modal” editor (in contrast to “modeless” editors like Notepad, MS Word, and Emacs). Read the VIM documentation (otherwise, you will be confused).
You may instead prefer the “normal” way to edit text, and there is an
easy fix. Just add the line
source $VIMRUNTIME/evim.vim to your
.vimrc file. VIM will then start up in “Easy Mode,” which behaves
Make VIM your default editor for SIMION. By default, SIMION
opens the “EDY” text editor to edit files. EDY is, well, archaic.
To make SIMION use VIM, you need to set a few environment variables.
Assuming VIM has been installed into the
c:\vim\vim62 directory, the
environment variables should be set to
Under SIMION 8
Under modern versions of Windows, environment variables can be set from the Windows Control Panel | System | Advanced | Environment Variables. Alternately, if you are starting SIMION from .bat file, you can add the following lines to the top of that file:
Under SIMION 8
Change the color scheme. The color scheme can be changed from the
Edit | Color Scheme menu.
To make the color scheme permanent add something like “colorscheme desert”
Use \*.gemh files. A *.gemh file can be run through a C preprocessor to generate a *.gem file (not recommended in 8.1 or above). *.gemh files are also properly syntax highlighted. Refer to the simhfn.vim file for details.
Now, we’ll look at how to configure Emacs. Below is a screenshot of XEmacs editing an SL program:
The following steps enhance the ability of Emacs to work with SIMION files. Enhancements include syntax highlighting of GEM, PRG (or SL), and Lua files (actually Lua support comes preinstalled in XEmacs).
Locate the SIMION plugin files for Emacs (these are three
You can find these files compressed in the “Editor Files for SIMION”
(downloaded from simion.com). If you
have SIMION 8.x, a copy is also included in the
Install the editor files into Emacs.
Under XEmacs: Copy the three plugin files into some place where
XEmacs can find them. A convenient place is under your home directory
.xemacs subdirectory (typically,
c:\Documents and Settings\me\.xemacs where me is replaced by your Windows login
name), which also contains your Emacs initialization file (init.el).
If this file and directory do not exist, you may select the “Options |
Edit Init File” menu option under XEmacs, and XEmacs will offer to
create this .xemacs directory and display an (empty) init.el file for
you. Copy the plugin files into this directory, and add the following
lines to the init.el file (and save it) so that XEmacs loads and runs
the SIMION plugins upon startup:
(add-to-list 'load-path (expand-file-name "~/.xemacs")) (require 'simsl-mode) (require 'simprg-mode) (require 'simgem-mode)
Under GNU Emacs: Copy the three plugin files into some place
where Emacs can find them–for example, any directory reported when
you run the command M-“:” load-path (i.e. ESC key, followed by
“:” key, followed by
load-path). The file:
subdirectory, or a directory named in a
HOME environment variable will
often do. Then add the following lines to your
(require 'simsl-mode) (require 'simprg-mode) (require 'simgem-mode) (global-font-lock-mode t)
The .emacs or _emacs file should be located wherever your HOME directory is (or “c:" if the HOME environment variable is not set).
Unlike Xemacs, GNU Emacs (as of version 21.4.19) does not include a copy of lua-mode for editing Lua files. Lua mode may be installed separately: download lua-mode from LuaForge.
Using it. Restart Emacs. Now, whenever you open a SIMION GEM, PRG (or SL) or Lua file in Emacs, syntax highlighting will work.
Here some optional customizations you might want to make.
Make Emacs your default editor for SIMION. To make SIMION use Emacs,
you need to set a few environment variables. Assuming Emacs
has been installed into the
directory, the environment variables should be set to
For SIMION 8
Under modern versions of Windows, environment variables can be set from the Windows Control Panel, System | Advanced | Environment Variables. Alternately, if you are starting SIMION from a .bat file, you can add the following lines to the top of the .bat file:
For SIMION 8
set SIMION_EDITOR=c:\Program Files\xemacs\i586-pc-win32\xemacs.exe
ZeroBrane is a newer, Lua-specific IDE.
Note that the code analysis feature (“Project > Analyze”) will get tripped up by “adjustable” variables unless you replace then with “local” variables or perhaps patch it (instructions?).
Notepad++ is similar to SciTE in being based on Scintilla but has more of a user interface that makes it easier for a beginner. It has a Lua editing mode and editing modes for many other languages.
The manner to configure the VIM and Emacs text editors to syntax highlight and edit SIMION-related text files has been discussed. Similar methods could be used when setting up other text editors.
Special thanks is given to Robert Malek, who developed the VIM plugins. The VIM plugins are (c) 2004 Robert Malek and are made available by permission and packaged with SIMION.
SIMION + SL files include .prg/.sl.
The SIMION 7 EDY (SIMION 7.0) text editor is deprecated. Appendix H of the SIMION 7 manual describes this.
SL Toolkit Users: The copy of VIM included in the SL Toolkit 1.2 and above is preconfigured with the SIMION plugins. You may skip or skip the installation sections of this document. To use the SL Editor, just right click on a SIMION file (PRG, SL, GEM, or PATXT) in Windows Explorer and select SIMION: Edit.
For SIMION 7
GUI_EDITOR=c:\Program Files\xemacs\i586-pc-win32\xemacs.exe GUI_FILENAMES=LONG_FILENAMES set GUI_EDITOR=c:\Program Files\xemacs\i586-pc-win32\xemacs.exe set GUI_FILENAMES=LONG_FILENAMES GUI_EDITOR=c:\vim\vim62\gvim.exe GUI_FILENAMES=LONG_FILENAMES set GUI_EDITOR=c:\vim\vim62\gvim.exe set GUI_FILENAMES=LONG_FILENAMES
SL Toolkit (see the
Compile SL files to PRG code directly in VIM. If you want to use the SL
Compiler from VIM, open the
c:\Documents and Settings\me\vimfiles\compiler\simsl.vim
file and, if needed, edit the following line:
Compile SL files to PRG code directly in Emacs (for SL Toolkit only) The SL Toolkit’s SL Compiler (if you want to use it) can be invoked via the M-X compile command in Emacs. Match the location where the SL compiler is installed.
Now to compile an SL file, first open the SL file.
Then execute the command
:make (or press the hammer tool button).
If there is an error, the message will display. After pressing
enter, the cursor will move to the line of the error.