How to position indicator on specific line?

116 views
Skip to first unread message

zetah

unread,
Apr 9, 2012, 12:07:23 AM4/9/12
to scite-i...@googlegroups.com
From SciTELua.api, looks like every positioning available is done by column number and only one command can change current line - GotoLine(), so:

        editor.IndicatorCurrent = 2
    local d={1,2,3,4}
    for k, v in ipairs(d) do
        editor:GotoLine(v)
        editor:IndicatorFillRange(v,v)
    end

results on overwritten indicators only on line 1

How does this work? How can I draw indicator on Line 3 at position 5 with length 10?

zetah

unread,
Apr 9, 2012, 6:15:22 PM4/9/12
to scite-i...@googlegroups.com
Positioning seem to be in absolute column number and not relative to specific line

So for drawing indicator on Line 3 at position 5 with length 10, this needs to be done:

    editor:GotoLine(3)
 
editor:IndicatorFillRange(editor.CurrentPos + 5, 10)

where editor.CurrentPos retrieves absolute column number

Philippe Lhoste

unread,
Apr 10, 2012, 5:22:25 AM4/10/12
to scite-i...@googlegroups.com
On 10/04/2012 00:15, zetah wrote:
> Positioning seem to be in absolute column number and not relative to specific line
>
> So for drawing indicator on Line 3 at position 5 with length 10, this needs to be done:
>
> editor:GotoLine(3)
> editor:IndicatorFillRange(editor.CurrentPos + 5, 10)
>
> where editor.CurrentPos retrieves absolute column number

Not really. It is worth looking at Scintilla doc (or Scintilla.iface) to see the API to
Scintilla.
Relevant line in the iface file:

# Returns the position of the caret.
get position GetCurrentPos=2008(,)

At the start of the file:

## Each feature is defined by a line starting with fun, get, set, val or evt.
## get -> a property get function
## Types:
## position -> integer position in a document
## Line numbers and positions start at 0.

So it is not an "absolute column number" but the position of the caret in the document in
terms of character count.
There are also functions to get the line corresponding to a position:
local endLine = editor:LineFromPosition(endPos)
and the reverse (position of the start of the line):
local lineStartPos = editor:PositionFromLine(endLine)
You can have also the position of the end of the line:
local lineEndPos = editor.LineEndPosition[lineNb]

(extracted from my SciTEStartup.lua)
http://bazaar.launchpad.net/~philho/+junk/SciTESettings/view/head:/SciTEStartup.lua

--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

zetah

unread,
Apr 10, 2012, 5:51:56 AM4/10/12
to scite-i...@googlegroups.com
On Tuesday, April 10, 2012 11:22:25 AM UTC+2, PhiLho wrote:
It is worth looking at Scintilla doc (or Scintilla.iface) to see the API to Scintilla.

Ah, all right, good note. I'll consult that file in future.
 

So it is not an "absolute column number" but the position of the caret in the document in

terms of character count.


and that's what I meant. What is in your opinion absolute column number if not position in doc in terms of char count?

Philippe Lhoste

unread,
Apr 10, 2012, 7:20:44 AM4/10/12
to scite-i...@googlegroups.com
On 10/04/2012 11:51, zetah wrote:
> and that's what I meant. What is in your opinion absolute column number if not position in
> doc in terms of char count?

For me (but I am not a native English speaker), a column position is a position in a line.
A relative column position might mean n chars to the left or the right from a given
position (eg. caret position), an absolute column position would be a position from the
start of the line.
That's what GetColumn returns, for example.


BTW, Neil, I think the line:

get int GetLineEndPosition=2136(int line,)

should be:

get position GetLineEndPosition=2136(int line,)

zetah

unread,
Apr 10, 2012, 7:54:35 AM4/10/12
to scite-i...@googlegroups.com
On Tuesday, April 10, 2012 12:15:22 AM UTC+2, zetah wrote:

So for drawing indicator on Line 3 at position 5 with length 10, this needs to be done:

    editor:GotoLine(3)

worth noting is that SciTE counts from 0, so first line is 0 and instead editor:GotoLine(3)it should be editor:GotoLine(2)

John Yeung

unread,
Apr 10, 2012, 10:40:09 AM4/10/12
to scite-i...@googlegroups.com
On Tue, Apr 10, 2012 at 7:20 AM, Philippe Lhoste <Phi...@gmx.net> wrote:
> On 10/04/2012 11:51, zetah wrote:
>>
>> and that's what I meant. What is in your opinion
>> absolute column number if not position in
>> doc in terms of char count?
>
> For me (but I am not a native English speaker), a column
> position is a position in a line.

I agree with Philippe (and I'm a native English speaker). A column
position refers to position in a single line. The "document position
in terms of character count" is the position in the whole file.

So if your document has 4000 characters, and the last line of that
document has 56 characters, then the last character in the document
has file position (or document position) 3999, but column position 55
(in both cases assuming 0-based indexing).

Earlier, zetah wrote:

> Positioning seem to be in absolute column number
> and not relative to specific line

In English, this is a contradictory statement. By definition, columns
only refer to positions within a line. (Or you could say a column
position is a position on *all* lines, in the same way that in Excel,
column B is the second column in the sheet, and referring to that
column without referring to a specific row means the union of B1, B2,
B3, B4, etc.)

John

zetah

unread,
Apr 10, 2012, 9:40:11 PM4/10/12
to scite-i...@googlegroups.com
On Tuesday, April 10, 2012 4:40:09 PM UTC+2, John Yeung wrote:
Earlier, zetah wrote:

> Positioning seem to be in absolute column number
> and not relative to specific line

In English, this is a contradictory statement.  By definition, columns
only refer to positions within a line.  (Or you could say a column
position is a position on *all* lines, in the same way that in Excel,
column B is the second column in the sheet, and referring to that
column without referring to a specific row means the union of B1, B2,
B3, B4, etc.)


All right, semantics... I hope that if someone browse Internet for this reference and got point here it will be clear that SciTE/Scintilla does not position by line and column, as beginner would expect

OTOH, there is issue also with your definition of character count, which should be byte count, as "editor:IndicatorFillRange(5, 10)" marks different string in ascii text and in 2byte UTF-8 string.

John Yeung

unread,
Apr 10, 2012, 11:55:47 PM4/10/12
to scite-i...@googlegroups.com
On Tue, Apr 10, 2012 at 9:40 PM, zetah <klo...@gmail.com> wrote:
> OTOH, there is issue also with your definition of character
> count, which should be byte count, as
> "editor:IndicatorFillRange(5, 10)" marks different
> string in ascii text and in 2byte UTF-8 string.

Hm. I haven't had to deal with Unicode much, and I still primarily
use Python 2, so bytes and characters are almost the same thing for
me. But I think I prefer the concept that "characters" are
human-readable characters, no matter how many bytes they require to
represent.

John

Philippe Lhoste

unread,
Apr 11, 2012, 3:49:04 AM4/11/12
to scite-i...@googlegroups.com
On 11/04/2012 03:40, zetah wrote:
> All right, semantics...

Precise vocabulary is needed to communicate, particularly in the technical field. :-)

> I hope that if someone browse Internet for this reference and got
> point here it will be clear that SciTE/Scintilla does not position by line and column, as
> beginner would expect

Unlike some other editors, Scintilla has a continuous buffer (with a gap). Beside some
optimizations, it sees lines only by detecting line ending chars. It doesn't store data in
lines, but it offers an API to convert between position and line.
A line/column system can have issues, as it is not a grid, lines have different numbers of
columns. There is no perfect system...

> OTOH, there is issue also with your definition of character count, which should be byte
> count, as "editor:IndicatorFillRange(5, 10)" marks different string in ascii text and in
> 2byte UTF-8 string.

Yes, I misused the vocabulary here. It depends on the encoding of the buffer: in the
native code page (ISO-8859-1 or more probably CP-1252 for me), an accented char like é is
one byte. In an UTF-8 or UTF-16 encoding, it is two bytes (I think internally it uses
DBCS). A char like ♥ uses three bytes/positions, and can't be displayed with my local code
page. Etc.

Neil Hodgson

unread,
Apr 11, 2012, 8:38:33 AM4/11/12
to scite-i...@googlegroups.com
Philippe Lhoste:

> BTW, Neil, I think the line:
>
>    get int GetLineEndPosition=2136(int line,)
>
> should be:
>
>    get position GetLineEndPosition=2136(int line,)

OK, committed.

Neil

Reply all
Reply to author
Forward
0 new messages