SIMION®
The field and particle trajectory simulator
Industry standard charged particle optics software
Refine your design: model > simulate > view > analyze > program > optimize it.
SIMION v8.1.3.0-TEST posted.
About | Documentation | Community/Support | Downloads | Ordering

Editing SIMION Text Files

Editing SIMION Text Files: Instructions on configuring and using various text editors (including SciTE, VIM, and Emacs) to effectively edit SIMION SL, PRG, GEM, and Lua files (e.g. syntax highlighting).

Introduction

SIMION requires text files in various places such as .ion, .lua (SIMION 8), .prg/.sl (SIMION 7), .gem, and .fly2 (SIMION 8) files. You could just use a simple text editor like Windows Notepad (or use the antiquated SIMION 7.0 “EDY” editor), 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.
  • Extensive text editing capabilities.
  • Invoking some compiler or interpreter (e.g. Lua or SL) 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 LuaEdit IDE. See also Lua Editor Support.

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.0 Manual or p. H-1 of the SIMION 7 Manual or for instructions on configuring that. 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.

A Summary of SIMION support in SciTE, Emacs, and VIM

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 and the SL Toolkit (see the lib/emacs and lib/vimfiles directories). 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.

Attention 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.

Downloading VIM and Emacs Plugins

The “Editor Files for SIMION” contain customization files for the VIM and Emacs text editors. If you do not have them already (in SIMION 8 or SL), you may downloaded from simion.com.

The SciTE Editor - Installation

Below is an example of editing a Lua program in SciTE (and also running it inside SciTE).

screenshot of SciTE text editor

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:

print("hello world")

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 not obvious):

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 screenshot above.

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 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.

The VIM Editor - Installation

Below is an example of VIM editing a SIMION “GEM” geometry file:

screenshot of VIM text editor with SL Editor plugins

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” (e.g. gvim##.exe).

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).

The VIM Editor - Optional Tweaks

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 quite normally.

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

SIMION_EDITOR=c:\vim\vim62\gvim.exe

Under SIMION 7

GUI_EDITOR=c:\vim\vim62\gvim.exe
GUI_FILENAMES=LONG_FILENAMES

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

set SIMION_EDITOR=c:\vim\vim62\gvim.exe

Under SIMION 7

set GUI_EDITOR=c:\vim\vim62\gvim.exe
set GUI_FILENAMES=LONG_FILENAMES

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” to your .vimrc file.

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:

setlocal makeprg=c:\\sim7\\sl\\bin\\sl.bat%

to 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.

Use \*.gemh files. A *.gemh file can be run through a C preprocessor to generate a *.gem file. *.gemh files are also properly syntax highlighted. Refer to the simhfn.vim file for details.

The Emacs Editor - Installation

Now, we’ll look at how to configure Emacs. Below is a screenshot of XEmacs editing an SL program:

_images/xemacs.png

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).

Steps:

Download and install Emacs for Windows. - The two flavors are XEmacs and GNU Emacs. If in doubt, the author recommends XEmacs.

Locate the SIMION plugin files for Emacs (these are three files: :file:`simgem-mode.el`, :file:`simsl-mode.el`, and :file:`simprg-mode.el`). You can find these files compressed in the “Editor Files for SIMION” (downloaded from simion.com). If you have SIMION 8.0, a copy is also included in the c:\Program Files\SIMION-8.1\lib\emacs directory.

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 in the .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:c:\\, Emacs site-lib subdirectory, or a directory named in a HOME environment variable will often do. Then add the following lines to your .emacs or _emacs file:

(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.

The Emacs Editor - Optional Tweaks

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 c:\Program Filesxemacsi586-pc-win32 directory, the environment variables should be set to

For SIMION 8

SIMION_EDITOR=c:\Program Files\xemacs\i586-pc-win32\xemacs.exe

For SIMION 7

GUI_EDITOR=c:\Program Files\xemacs\i586-pc-win32\xemacs.exe
GUI_FILENAMES=LONG_FILENAMES

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

For SIMION 7

set GUI_EDITOR=c:\Program Files\xemacs\i586-pc-win32\xemacs.exe
set GUI_FILENAMES=LONG_FILENAMES

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.

Conclusion

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 on the simion.com website and packaged with SL.

–D.Manura, Scientific Instrument Services, Inc. 2004-04, 2006-11.

Any comments on this web page? (will be sent to SIS SIMION Support)
[Optional] Your name: email: phone/fax: