LineNumber.mesa
Copyright Ó 1987, 1991 by Xerox Corporation. All rights reserved.
Peter B. Kessler, March 31, 1989 10:32:44 pm PST
Willie-s, October 14, 1991 1:17 pm PDT
Doug Wyatt, December 19, 1991 12:47 pm PST
Last tweaked by Mike Spreitzer September 11, 1992 7:46 am PDT
Line number button for Tioga viewers.
DIRECTORY
Menus USING [Menu, MenuLine, MenuProc],
Tioga USING [Node],
ViewerClasses USING [Viewer];
LineNumber: CEDAR DEFINITIONS ~ {
Types
Line: TYPE ~ CARD ¬ defaultLine;
defaultLine: Line ~ 0;
Offset: TYPE ~ INT[-1 .. INT.LAST];
A character position within a line.
noOffset: Offset ~ -1;
OffsetRange: TYPE ~ RECORD [first, last: Offset ¬ noOffset];
Identifies a character within, or a subrange of, a line.
[s, e] identifies characters [s..e] of the line.
[o, noOffset] identifies the character o chars into the line.
[noOffset, noOffset] identifies the whole line.
Position: TYPE ~ INT[0 .. INT.LAST] ¬ defaultPosition;
A character position within a document or branch.
Tioga says INT, but I want to restrict these to non-negatives.
defaultPosition: Position ~ 0;
firstPosition: Position ~ 0;
Returned for beginning of file.
lastPosition: Position ~ INT.LAST;
Returned for end of file.
PositionRange: TYPE ~ RECORD[initialPosition, finalPosition: Position]
¬ [initialPosition: defaultPosition, finalPosition: defaultPosition];
LaO: TYPE ~ RECORD [line: Line, offset: Offset ¬ noOffset];
A position expressed as a line number and an offset within that line,
or a whole line (when offset = noOffset).
LaORange: TYPE ~ RECORD [first, last: LaO];
SelectionId: TYPE ~ { primary, secondary, feedback };
Denotes choice of what selection to use, if there is a choice available.
EnumProc: TYPE ~ PROCEDURE [
line: Line,
positionRange: PositionRange]
RETURNS [quit: BOOLEAN ¬ FALSE];
Procedures
ToFeedbackSelection: PROCEDURE [
viewer: ViewerClasses.Viewer,
line: Line,
offsetRange: OffsetRange ¬ [],
skipCommentNodes: BOOLEAN ¬ FALSE]
RETURNS [];
Given an viewer, a (non-negative) line number, and an offset range, indicate the identified portion of that line with the feedback selection.
ToPositionRange: PROCEDURE [
branch: Tioga.Node,
line: Line,
offsetRange: OffsetRange ¬ [],
skipCommentNodes: BOOLEAN ¬ FALSE]
RETURNS [PositionRange];
Given a node, a line number, and an offset range, returns the position range in the document of the indicated portion of the given line from that node.
This assumes position numbers start at 0. There seem to be some viewers whose first character is at position 1, but I can't figure out why.
ToSelectionRange: PROC [viewer: ViewerClasses.Viewer, lines: LaORange, skipCommentNodes: BOOL ¬ FALSE, which: SelectionId ¬ feedback];
LinesToPositions: PROC [branch: Tioga.Node, lines: LaORange, skipCommentNodes: BOOL ¬ FALSE] RETURNS [PositionRange];
PositionsToLines: PROC [branch: Tioga.Node, positions: PositionRange, skipCommentNodes: BOOL ¬ FALSE] RETURNS [LaORange];
ToLine: PROCEDURE [
branch: Tioga.Node,
position: Position,
skipCommentNodes: BOOLEAN ¬ FALSE]
RETURNS [LaO];
Converts a character position to a line-oriented position; both a relative to the given branch.
Enumerate: PROCEDURE [
branch: Tioga.Node,
enumProc: EnumProc,
skipCommentNodes: BOOLEAN ¬ FALSE]
RETURNS [quit: BOOLEAN ¬ FALSE];
Calls the enumProc with the line number and position range for each line from branch,
returns TRUE when any call of enumProc returns TRUE.
AppendMenuButton: PROCEDURE [
menu: Menus.Menu,
line: Menus.MenuLine ¬ 0];
Append a ``Line'' button to the menu of a viewer.
MenuProc: Menus.MenuProc;
Given a line number in the selection, indicate that line in the viewer.
}.