Re: [Pydev-code] Line terminators in Pydev files + line numbers
Brought to you by:
fabioz
|
From: Don T. <nos...@gm...> - 2006-05-09 14:08:34
|
Fabio Zadrozny wrote:
> I notice that Eclipse seems to let you have differing line terminators
> in the same file, but that PySelection seems enforce one and only one
> type of line terminator as per Guido's directions. (I hope this is what
> you do).
>
>
> Actually, sort of... In PySelection, when the terminator is requested it
> will always return the same line terminator from the first line of the
> document.
I am using:
offset = selection.getAbsoluteCursorOffset()
lineno = selection.getLineOfOffset(offset)
line = selection.getLine(lineno)
to get the line containing the current cursor position. I then march up
and down the text grabbing lines until I have acquired the 'paragraph'
of text that contains the cursor.
Eventually I replace this paragraph with a reformatted paragraph. In
order to do this I need to figure out the offsets to the first character
of the original paragraph and to the last character of the delimiter on
the last line of the paragraph. Right now I am assuming that I can do
the latter by adding len(selection.getDelimiter(document)) to the last
character offset but this assumes that the delimiter on the last line is
the same size as the document delimiter.
It is possible that this is not true, for example by using a Windows
editor to change a document that originated on Linux. However, I believe
that CPython gets upset if mixed delimiters are used within the same
document so maybe this does not really matter.
In any case, I can use the IDocument method getLineDelimiter() to get
the line delimiter for a specific line, but it looks like you intended
PySelection to be the main interface for Jython extension scripts so
maybe you want add something like this one day.
BTW. I noticed that PySelection does not have a method
getStartLineOffset(lineno) that would be a pair with
getEndLineOffset(lineno). Not a big deal as it is easy to calculate.
> While I have your attention, is there any significance in PySelection's
> line numbering starting at 0 while the line number displayed by Eclipse
> starts at 1 ?
>
>
> Actually, where is this? I've checked:
>
> PySelection sel = new PySelection(new Document("foo\nbla"));
> assertEquals(0, sel.getLineOfOffset(1));
>
> So, it is returning 0 in the PySelection for the offset 1... Do you have
> an example where this is not the case?
I actually meant the line number shown at the bottom of the screen in
Eclipse - this line number always starts at 1, which is apparantly
internally known as line 0. So it looks like Eclipse is inconsistent
about starting at 0 or 1. No matter.
Thanks,
Don.
|