LineNumberDoc.tioga
Peter B. Kessler, April 2, 1989 3:48:39 pm PDT
Last tweaked by Mike Spreitzer September 11, 1992 9:34 am PDT
Line Number
CEDAR 7.0 —
Line Number
Peter B. Kessler
© Copyright 1987 Xerox Corporation. All rights reserved.
Abstract: The LineNumber package provides a programmer's interface to lines in Tioga documents. Included are the ability to enumerate a Tioga document by lines, to map from a line number to a Tioga position, to map from a Tioga position to a line number, and to highlight a given line with the feedback selection. There are also some user interface tools, along the lines of the EditorComforts Position button. Lines are defined as sequences of characters terminated by either an end-of-node or a newline character.
Created by: Peter B. Kessler
Maintained by: Peter B. Kessler <PeterKessler.pa>
Keywords: Tioga, line number, position range, interoperability, carriage return, line feed, newline.
XEROX  Xerox Corporation
   Palo Alto Research Center
   3333 Coyote Hill Road
   Palo Alto, California 94304

1. Programmer's Interface
LineNumber lets you enumerate a Tioga document through a procedure that is given the current line number and position range of the line. That makes it easy to write the maps from positions to line numbers and vice versa.
I wanted to highlight lines by number. LineNumber.ToFeedbackSelection does that. Then I wanted something like EditorComforts Position button, so I wrote that. Then I wanted to add a button to viewer like the Position button, LineNumber.AppendMenuButton does that.
Then, it seemed like the right way of controlling it was to register commands with TEditInput, so now you can use ShowLine, MessageLine, and StuffLine from the EditTool Operations, etc.
The end of a node is the end of a ``line''. A newline character (currently, an Ascii.CR or an Ascii.LF) inside a node also ends (and begins) a line.
Don't send me suggestions, just implement them.
2. User Interface
The TiogaLineNumberButton command adds a Line button to Tioga's places menu. Left-clicking the button takes a non-negative line number from the primary selection and highlights that line in the viewer. Middle-clicking displays in the message window the line number of the input focus (regardless of which viewer has the input focus). Plain left- or middle-clicking gets you the line number excluding comment nodes. If you want to include comment nodes in the display or count, hold down the SHIFT button. [[Shift-middle-clicking while the input focus is in a comment node gives weird results, but it gives the same kind of weird results as the Position button, because they're both based on the weirdness of TextNode.LocNumber.]] Right-clicking will stuff the last displayed (via middle-clicking) line number into the input focus (that's a really gross user interface, but it matches what the EditorComforts Position button does).
The selection used by left-clicking the button actually is more complicated; it should follow the syntax:
<int>[","<int>][".."<int>[","<int>]]
When "place..place" is used, this indicates a range of places to highlight; otherwise, a single place is highlighted. A "place" can be either a whole line (denoted by an <int>), or a character position within a line (denoted by <int>,<int> --- the first int is the line number, the second is the character offset within the line).
3. Shortfalls and wishlist
There are probably a bunch of off-by-1 errors, due to the fact that not all viewers start at position 0. I have a heuristic in there to try to figure out which ones start at position 1, but I could be wrong. If you have a better heuristic, put it in. Then there are lots of other opportunities for off-by-1 bugs, at nodes that end with newline characters, empty nodes, nodes with just newline characters, etc. If you find them, fix them.
When highlighting a single character, LineNumber does the same thing the `Position' button does: highlight that character plus the three following it.
Highlighting an empty node works just as badly as it does for the `Position' button.