Porting Central
Skip to main content

Porting Central

srctext: A Superset of All Source Editing Packages

What srctext (and Source Views) Are

Srctext is common to all the source code editing views in EZ, such as ctext (for C programmers). See the end of this document for a complete list of these source views.

When editing source code with EZ, each individual language's source view uses a "template". This template contains style information and in most cases, example code. The style information causes your code to be displayed in a fixed-width (typewriter) font. The example code will appear whenever you edit a file that didn't already exist. Most templates contain dogtags, which will cause pertinent information to be filled in automatically when you edit a new file.

Starting a Source View

Whenever you edit a file with a recognized extension, EZ uses the appropriate source view to edit it. To find out which extensions are used by which source views, look at the file /usr/andrew/lib/global.ezinit, and read the help file for initfiles .

Example:

~> ez myfile.h will use the ctext source view to edit myfile.h.

Comparing Files

An interactive diff package called ezdiff is available for comparing your files in EZ. See the ez-diff help file for more information.

Compiling Programs

A package to compile your program within EZ, and parse errors so that you can step through them, is available. See the compile help file for more information.

How Source Views Work

When source code is edited with EZ, styles are superimposed on the text for the programmer's convenience. Comments are italicized, function names are displayed in bold type, and other styles are added depending on the particular language. These styles are not saved to the file, since most compilers wouldn't appreciate them; the styles exist only during editing.

Note: When the source views insert whitespace, they automatically insert the correct combination of tab and space characters, replacing spaces by tabs when possible without changing the look of the line. (Not applicable if the "use-tabs" option is turned off; see below.)

Special Keys

The source views remap keys to perform certain functions. Some are shortcuts for pop-up menus (see below). Others include:

The tab key.

Tab has three uses:

1.) If there is a selected region, all the lines within that region will be reindented to what source view considers the "correct" indentation. (Not applicable if "enable-indentation" is turned off; see below.)

2.) If there is no selected region and the text caret is positioned before any text on the current line (within the initial whitespace), then that line will be reindented as above.

3.) If the text caret is positioned after some non-whitespace text on the line, it will insert enough whitespace to move to the caret to the next tab column. Tab columns are positioned at multiples of "tab-size" (8 by default). Any existing whitespace at the caret position will be counted as if it were inserted (so the tab key will skip over whitespace to the next tab column if it is sitting on whitespace).

The Linefeed (Ctrl-J) key.

Linefeed does two things:

1.) It reindents the current line, just in case it needs to be fixed up (since sometimes the indentation after typing something is different).

2.) It inserts a newline, and then inserts the correct indentation for the new line (moving the caret to that point).

The Insert key.

[Ins] toggles between the normal "insert" mode, and "overstrike mode". Overstrike mode is only available when editing source code. It types over existing characters, except for tabs and newlines.

The Esc-1 (or Alt-1) key sequence.

In most languages, this will insert a comment at the end of the line. Its behavior depends on the options you have set (see below).

The Esc-2 (or Alt-2) key sequence.

In some languages, this will insert a "bang comment" or "in-line comment" at the end of the line. Its behavior depends of the options you have set (see below).

Pop-Up Menu Meanings

In addition to the regular EZ menu options, the source views supply an additional menu, the Source Text menu. It contains the following options:

Redo styles: (Esc-r or Alt-r key) Updates all the styles that are put on comments, function names, and keywords.

Indent line/region: (Tab key) See description of tab key, above.

Format line/region: (Esc-^R or Ctrl-Alt-r key) Does all the same things as the "Indent line/region" (Tab key), but it will also re-flow comments together, and break lines up appropriately if max-length has been set.

Compress region: If a region is selected, it will be "compressed" into a box. Otherwise, all nearby lines that are indented as far or farther than the line the caret is on will be "compressed" into a box. To restore the text, click a mouse button in the box. (If compressed text is saved, the file will contain the text in its original uncompressed form. No record of its being compressed is saved.)

Compress all inner indents: Similar to "Compress Region", but it will traverse the entire file, compressing all regions that are indented as far or farther than the line the caret is on. (Regions less than 3 lines long will not be compressed.)

Decompress all: Removes all the boxes and restores the text that was compressed inside them. To decompress a single box, just click a mouse button on it instead. The left mouse button will cause the decompressed text to be highlighted, so you can immediately re-compress it. The right mouse button will not affect the cursor's position.

Find Next too-long Line: (Esc-^T or Ctrl-Alt-t key) This appears whenever the max-length has been set (see below). It will find the next line that's longer than max-length, and highlight the offending characters.

Rename identifier: Prompts for identifier to replace and what to replace it with, then replaces all occurrences in the selected region with the desired string.

Force Upper On(Off): Toggles the force-upper option. When On, it will cause keywords to be made uppercase when they're typed in.

Customizing Source Views in Your Preferences File

For more information, see the help text for preferences . All the source views allow you to specify certain EZ preferences. Since the source view for each language has its own preferences, substitute (for example) "ctext", below when "?text" is specified. Default values are shown in italic.

ez.?text_Uppercase: WORD1,WORD2,...

This preference specifies a list of words to force uppercase (but without styles) when they're typed with the force-upper option turned on.

ez.?text_UserDef: WORD1,WORD2,...

This preference is for listing user-defined, or compiler-specific keywords. In most languages, the words MUST be uppercase to be recognized properly, but in languages like C, they need not be.

ez.CompressBoxFont: andysans8

This preference determines the font to be used in the boxes that represent "compressed" regions of code.

ez.CompressBoxForegroundColor: black

This preference sets the color of the string "nnn compressed lines" that appears in boxes of compressed code.

ez.CompressBoxBackgroundColor: white

Specifying this preference will replace the border drawn around compress boxes with a solid rectangle of the specified color.

ez.InitialRedoStyles: on

Switching this preference to off will prevent EZ from doing an automatic "Redo Styles" when it first comes up. It will come up noticeably faster for extremely large files, but you'll have to manually select the "Redo Styles" menu (or Alt-r key) to get the styles put in place.

ez.ReindentComments: yes

Comments will be reindented to line up with code when "Reindent line/region" is selected. But if this preference is set to no, comments will be left exactly where they are. (Note: global.preferences may change this default to no. Also, "Reformat line/region" always reindents comments; this preference does not affect it).

ez.WriteForDOS: <depends on platform>

This preference controls whether carriage returns are put into newly-created files when they're saved. The default is to do whatever is appropriate for the platform in use (yes on OS/2, no on AIX). This preference should only be changed if some sort of cross-platform development is being done.

Customizing Source Views in Your .ezinit File

For more information, see the help text for initfiles . All source views have several ezinit options in common. Specific ones may be found in the help text for that particular language.

level-indent <varies by language; usually 2 or 4>

Controls how far nested code gets indented. (Not applicable if preempted by more specific options, such as plmitext's "do-indent")

cont-indent 2

Controls how far the continued line is indented when a single statement is broken by a newline character. (Does not apply to wrapped lines)

reindent-comments <see ReindentComments preference>

If zero, comments will be left where they are when a line or region is reindented. If non-zero, comments will be reindented when a line or region is reindented. (This is only needed if you want special behavior for certain file extensions; it's more convenient to simply set the ez.ReindentComments preference)

comment-indent <3 for most languages>

Controls how far the continued line is indented when a comment is broken by a newline character. (Does not apply to wrapped lines)

comment-col <1 for most languages>

Specifies what column to put comments in when Esc-1 is pressed. Its value can be negative or positive, and this determines where Esc-1 puts the comment if the specified column already contains code. If positive, the comment will be placed farther out on that line. If negative, a new line will be inserted so the comment can be placed exactly there.

linecomment-col <1 for most languages>

Specifies what column to put comments in when Esc-2 is pressed. Its value can be negative or positive, and this determines where Esc-2 puts the comment if the specified column already contains code. If positive, the comment will be placed farther out on that line. If negative, a new line will be inserted so the comment can be placed exactly there.

remark-padding 1

Controls how closely a remark can get to code, when the code extends beyond "comment-col". Setting this to 0 will let the `/*' smash right up against the code. The default value 1 will force a minimum of one space to be maintained. (Notice that it won't necessarily ADD a space between code and comments that were ALREADY smashed together; it's only a preventative measure)

max-length <0 for most languages>

If non-zero, will display a warning when a file is saved containing lines exceeding that length. Zero means "no maximum length". Non-zero values are usually only used for code that must also be viewed on fixed-width terminals. An additional menu item, "Find Next too-long Line", will appear on the Source Text menu card (see above).

use-tabs <varies by language>

If 0, will indent exclusively with space characters. If non-zero, will optimize whitespace with tab characters wherever possible.

enable-indentation <1 for most languages>

All source views that "know" how to indent code will have this enabled by default. A value of zero will disable it so indentation must be done manually.

tab-stops <none>

This is a list of numbers separated by whitespace or commas. Each number is a "tab stop", which determines where the cursor will jump to next time Tab is pressed. (Not applicable when cursor is at front of line and "enable-indentation" is on, because the automatic indenting will preclude it)

tab-size 8

This adds a "tab stop" at every multiple of its specified value. If zero, only the "tab stops" explicitly specified in the "tab-stops" option above will be used. (Note: these "tab stops" should not be confused with "tab characters". "Tab stops" only determine where the cursor should jump to; the characters that actually get inserted are the optimal combination of space characters and tab characters that will get the cursor to the next "tab stop")

force-upper 0

If non-zero, will default to force-upper mode, which will uppercase keywords as you type them.

overstrike 0

If non-zero, will start EZ in overstrike mode.

origin-key

If set, the specified string will be appended to any text that is copied out of the file. In addition, the copied code will be scrambled such that it is unreadable. If and only if the text is pasted into a file with an identical copyright-key, the paste will behave normally. This attribute is most useful when set by the file itself, using "<@attributes" dogtags . (Note: if need be, the text scrambling can be defeated using the "srctextview-unscramble-region" proc)

write-for-DOS <depends on file>

The source views will automatically detect a DOS format file when it's loaded, and save it in that format. This attribute would be set to zero or one only to force all files with the specified extension to be written with just linefeeds, or carriagereturn+linefeeds, regardless of the file's original state.

To change any of these options, put them in an addfiletype line in your .ezinit file. If you don't already have a .ezinit, you should read the help text on initfiles to make sure you include global.ezinit in it. Example:

include /usr/andrew/lib/global.ezinit

addfiletype .h ctext "template=h;level-indent=2;comment-indent=3"

Customizing Source View Keybindings

Default keybindings in the source view can be found with the "Display Bound Keys" item on the "Misc" menu card. Each key and menu item is bound to a "proc". For example, the "Redo Styles" menu item and the Esc-r key are both bound to the "srctextview-redo-styles" proc.

The most common change is to bind the Enter key to do what Ctrl-J does. This can be done by adding the following line to your .ezinit file:

addkey srctextview-newline ^M

See the help text on initfiles for more information.

Customizing Source View Templates

The "template" is a file with a .tpl extension containing the example code that appears when editing a nonexistent file, as well as style information. Users who wish to create their own templates should first get some background information from the initfiles , templates , and lookz help files. Generally, you should copy whichever template is currently used into your own ~/tpls subdirectory. (The name of the template that is currently used can be found on the "addfiletype" line in the appropriate initfile.) Edit your own copy using EZ, and you can then change the appearance (font, color, and size) of the **comment** style, for example.

Related Topics