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 encoding
set currentencoding iso8859-2

# set system encoding to enable Polish keyboard
if {$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:

empty

You can see that the window is divided into three parts:

Before we continue, please note that there are three types of commands:

Now, right-click on the list of commands (the left-most frame).

menu

The meaning of each entry in this menu is:

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:

addseprator

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:

addtext

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:

addscript

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.