MEdit - Programmable Text Editor
Tutorial
This tutorial will show you how to run MEdit and how to create your own commands.
Starting MEdit
First of all, MEdit is written entirely as a Tcl script medit.tcl.
Other scripts are included automatically.
In order to run medit, I use the following command:
$ wish medit.tcl
This command also works on Windows.
It is perfectly possible to include special line at the very beginning
of medit.tcl:
#!/usr/local/bin/wish
(check this path, it can be different on your system)
and set the executable flag for the script so that it behaves like
autonomous program.
On Windows, the ActiveState Tcl distribution allows to run Tcl scripts by just double-clicking them.
Command-line options
MEdit accepts only one option: -profile profilename
Apart from that, every other parameter is treated as a name of
file
that will be open just after starting.
For example:
$ wish medit.tcl -profile cpp myprog.cc myfunc.cc
The above command will start MEdit, which will load one of its predefined profiles for C++ programmers and also open two given files.
Startup settings
In the options.tcl file there are settings that
are
applied even before the first profile is loaded.
The two important instructions are:
# the name of default file encodingset currentencoding iso8859-2# set system encoding to enable Polish keyboardif {$tcl_platform(platform) == "windows"} { encoding system cp1250}
These settings are convenient for me, but they are not
necessarily convenient for you.
Moreover, depending on what keyboard mapping you use, the second
instruction may be completely wrong.
Please change these instructions to fit your needs (or remove them
completely from the options.tcl file if you are fine with
the default settings).
Similarly, all profiles (except the empty
profile), in
the "key bindings" script, contain the additional (bound to the left
Alt key) mapping for the Polish national characters on Unix systems.
You may or may not find them appropriate for you, and even if you use
Polish keyboard, it is possible to set up the environment so that these
additional bindings are not necessary.
Of course, feel free to apply the changes that will fit your needs.
Wrapper for automatic profile selection
There is a convenience wrapper, called medit_wrap.tcl
It analyzes its first parameter and automatically selects appropriate
profile (based on rules that are written in it, you can check what's
inside and change it).
In other words, the command:
$ wish medit_wrap.tcl myprog.cc
will open the myprog.cc file, using cpp
profile.
This is extremely useful, if you attach medit_wrap.tcl in
your file manager to the editing command - then, every time you click a
file for editing, you get the proper profile.
How does it look like?
Try to start the editor with the empty profile.
On my system, it looks like here:

You can see that the window is divided into three parts:
- On the left, there is a list of commands. Here it contains only one command, which is obligatory.
- The main widget is where you edit your text files.
- The status line (below)
- At the bottom, there is an auxiliary window, which can be used in whatever way you define in your profile.
Before we continue, please note that there are three types of commands:
- Script commands - these are Tcl scripts that can be run in the editor's context
- Text commands - these are simply macros, in other words, pieces of text which are not interpreted by MEdit
- Separators - they do nothing, but can be used to logically group commands
Now, right-click on the list of commands (the left-most frame).

The meaning of each entry in this menu is:
- Invoke - runs the script associated with the selected command (if the command is a script)
- Paste - inserts the text associated with the selected command into the edited file (if the command is a text)
- Text - it contains the submenu allowing you to add, insert and edit text commands
- Script - the same, but for scripts
- Separator - the same, but for separators
- Special - it contains the submenu allowing you to edit
special scripts:
oninitandonclose(they are executed when the profile is loaded and unloaded) - Delete entry - removes selected command from the list
- Save profile - obvious
- Save profile as... - you can use it to clone the profile
- Load profile - contains the list of profiles stored in special directory, it also allows to load profile from arbitrary file
- File encoding - select the encoding you want to use for reading and writing files.
Creating new separator
In order to create new separator in the list of commands,
right-click
on the list and select the "Add separator" from the "Separator" submenu.
The following window should appear:

Enter "-- My commands" in the entry field and press OK. The separator will be added to the list.
Creating new text command
Right-click on the list of commands and select the "Add text"
from the
"Text" submenu.
The window will open allowing you to enter the name for the text
command together with its contents:

Enter some text and click "Remember".
Now, double-click on the "Dear sir" command in the list. Do it several
times.
Creating new script command
Right-click on the list of commands and select the "Add
script" from
the "Script" submenu.
The window will open allowing you to enter the name for the script
command together with its contents:

The above script inserts into the editing window the current
time in
default formatting.
It uses the insertText command, which is obligatory and
has to be defined in the oninit script.
Now, execute this command. Do it several times.
Note:
When you click "Remember" button in the window where the commands are
edited, it means that the command definition is only remembered in the
current session. If you want to make it persistent, select the "Save
profile" from the menu.
Now you should understand, that there is absolutely no limit considering what MEdit can do for you.
You should now see the profiles that are ready to use. You can extend them, customize, edit their scripts, clone, etc. Just enjoy.