Text Subwindow line number
zifrony at TAURUS.BITNET
zifrony at TAURUS.BITNET
Fri Dec 23 04:58:36 AEST 1988
In Sun-Spots Digest, v7n47, unido!infhil!sun1a!boeker at uunet.uu.net
(Michael Boeker) needed to know how to determine the line number of a
position. As I have encountered a similar problem, needing to find the
line number clicked on by the user, I have the following method to solve
it:
1. I have created a mapping of the text window, noting in which position
each line starts by using textsw_index_for_file_line().
2. I have determined the location of the cursor in the text (the place where
the user clicked), by using window_get(src, TEXTSW_INSERTION_POINT, 0),
where src is my Textsw subwindow. Note that dbxtool does it in a smoother
way, and keeps the Textsw subwindow readonly; alas, I do not have the
source of dbxtool, and had to resort to these means to solve the problem.
3. I looped through my mapping, finding the first line whose first character
index is greater than my position, and voila, the line is found.
Please note that the file I am working with is not too big, thus the
search loop does not take too long. For huge files, I suppose a better
way has to be sought to solve the problem.
Doron Zifrony zifrony at taurus.bitnet || zifrony at Math.Tau.Ac.IL
Msc. Student
Tel Aviv University
Israel
More information about the Comp.sys.sun
mailing list