Class ::tycho::EditProgram


Inherits: ::tycho::Edit - Source File - Contents: itk_options - public methods - public procs - protected methods - protected variable
This class defines a widget that provides an emacs-like editor specialized for editing program files. It colorizes the code, identifying comments, automatically indents the code, and fills blocks of comments. Derived classes are specialized to particular programming languages. This class provides a common infrastructure. In particular, it provides a common mechanism for handling line-oriented comments, and indentation driven by brackets, braces, and parentheses. It also tags and colors colors comments and the strings "FIXME" and "NOTE", provides infrastructure for tagging and coloring keywords, and provides a method for commenting out a region.

Note that there is both a procedure and a method that will generate documentation. The gendoc procedure can be used to generate documentation for any file, and the file does not have to be currently opened by tycho. gendoc is used by the Ptolemy man command. The gendocBuffer method is used to generate documentation for the current contents of a editor. gendoc and gendocBuffer both call internal functions (gendocFileInternal and gendocBufferInternal that do the real work. Child classes will usually redefine gendoc and gendocBuffer.


Itk_options

-stringcolor black
The color of strings.
-commentcolor black
The color of comments.
-fixmecolor black
The color of "FIXME".
-keywordcolor black
The color of keywords.
-proccolor black
The color of procedure names.
-classcolor black
The color of class names.
-methodcolor black
The color of method names.
-variablecolor black
The color of variable names.

Public constructs

Public Methods

closeParen paren
Override the base-class closeParen to also perform indentLine if the closeParen is the first character on the line.
commentSelection
Insert the fill prefix at the beginning of every line contained in the selection. Note that this command is undone (more or less) by "uncommentSelection", and not by the usual undo mechanism. If the first line is partially contained in the selection, then it is treated as if it were fully contained in the selection.
fillSelection
Fill the set of lines identified by the selection so that they are roughly the same length. Put the comment prefix on each, and mark the region as a comment.
gendocBuffer
Generate and display a doc file from the current file. If the doc file already exists and is newer than the source file, then it is simply displayed, not regenerated.

This is a dummy implementation, it merely copies the current file into a .htm file and displays it. Child classes will probably redefine this method.

help
Open a window with help on the current widget.
indentLine
Indent the line with the insert mark based on the indentation of of the previous non-blank line. If that line contains any unmatched parentheses, brackets, or braces, then the line will be indented an extra four spaces for each such unmatched. If the previous line ends in a slash, then this line will be indented an extra 8 spaces.
indentSelection
Indent the set of lines identified by the selection, if there is a selection. If there is no selection, ignore.
indicateReadOnly bool
Specify whether or not modifications are allowed in the displayed text. Note that this is independent of whether the associated file is readonly. It merely determines whether the buffer can be modified, not whether the file can be modified. To control the file, use toggleReadOnly.
keywords
In derived classes, returns a string with keywords separated by "|".
parseNow start stop
Tag and color line-oriented comments, strings that are entirely on one line, the strings "NOTE" and "FIXME", and keywords in the specified range of text. What constitutes a comment is determined by the protected method "commentRegexp", which returns a regular expression that identifies a comment. Keywords are specified by the method "keywords". If that method returns a null string, no keywords are highlighted. Note that highlighting keywords is a fairly expensive operation, so it may not be desirable to always highlight keywords.
spellCheckTags
Returns a list of tags to use when checking the spelling.
uncommentSelection
Remove the fill prefix at the beginning of every line contained in the selection. Note that this command is (more or less) undone by "commentSelection", and not by the usual undo mechanism. If the first line is partially contained in the selection, then it is treated as if it were fully contained in the selection.

Public Procs

gendoc file
Generate documentation for file. This procedure will probably be redefined in child classes.
gendocFileInternal file genDocFile genCommand
Helper proc for gendoc.

Protected constructs

Protected Methods

commentRegexp
Return the regular expression used to identify line-oriented comments. Here, comments are lines that contain the fillPrefix.
gendocBufferInternal genDocFile genCommand
Generate and display a doc file. If the doc file already exists and is newer than the source file, then it is simply displayed, not regenerated.

This method takes two arguments, both of which are eval'd.

  • The setdocCommand argument should contain the tcl command(s) to evaluate to set the docfile tcl variable, which contains the filename of the generated doc file.
  • The genCommand argument should contain the tcl command(s) to evaluate to actually generate the doc file. Usually this command refers to $tail
  • In the example below, we open the makefile and then sort it.

    set w [::tycho::EditProgram [::tycho::autoName .ep] -file makefile]
    $w gendoc {set docfile $root.sort} {exec sort $tail > $docfile}
    
    .

    Protected Variable

    caseSensitiveKeywords 1
    Change this to 0 in derived classes if keywords are not case sensitive.

    Index of classes



    Author: Edward A. Lee
    Version: @(#)EditProgram.itcl 1.39 12/01/96
    Copyright: (c) 1995-1996 The Regents of the University of California.