[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    Re: have compare in indenter api
From:       "Paul Giannaros" <paul () giannaros ! org>
Date:       2008-05-30 13:25:14
Message-ID: 3cce4fc80805300625l1610c238yee38f0cd3260e3bf () mail ! gmail ! com
[Download RAW message or body]

I think compare() is better implemented by switching over to
cursor/ranges in the API and just implemented the == operator for them
-- I'm fairly sure QtScript lets you do that. That would mean that you
could just do if(cursor1 == cursor2).
I'll look into that.

On Fri, May 30, 2008 at 2:07 PM, Dominik Haumann <dhdev@gmx.de> wrote:
> Hi Robin & Leo,
>
> those helpers are exactly what's needed. I think we need dozens of them :)
> Just commit it to svn.
> Btw, is anyone working on switching the API to cursor/range style? Instead
> of (example):
>  document.anchor(line, column, char)
>  document.anchor(cursor, char)
>
> Dominik
>
> On Tuesday 27 May 2008, Robin Pedersen wrote:
>> Thanks! I have a feeling I'll end up having a number of helper functions
>> to suggest, but so far I've not made any suggestions because I want to be
>> more sure what I actually need.
>>
>> The comparison function would certainly be useful in itself. In addition,
>> a helper function for the "lastAnchor" function that uses the comparison
>> would also be great (maybe a better name could be found).
>>
>> The "lastAnchor" function is basically an extension of the "anchor"
>> function currently available in KateScriptDocument. The "anchor" function
>> provides an easy way to find opening braces, and works with either '[',
>> '{' or '('. "lastAnchor" finds all, and returns the "last", i.e. the most
>> recently opened.
>>
>>
>> // Find the last open bracket before the current line.
>> // Result is a KTextEditor::Cursor object, with an extra attribute, 'ch'
>> // containing the type of bracket.
>> function lastAnchor(line)
>> {
>>    var anch = document.anchor(line, 0, '(');
>>    anch.ch = '(';
>>    var tmp1 = document.anchor(line, 0, '{');
>>    tmp1.ch = '{';
>>    var tmp2 = document.anchor(line, 0, '[');
>>    tmp2.ch = '[';
>>
>>    if (compare(tmp1, anch) == 1)
>>      anch = tmp1;
>>    if (compare(tmp2, anch) == 1)
>>      anch = tmp2;
>>
>>    return anch;
>> }
>>
>> On Tue, 27 May 2008 20:46:33 +0200, Leo Savernik <l.savernik@aon.at>
> wrote:
>> > Am Montag, 26. Mai 2008 schrieb Robin Pedersen:
>> >> +// Helper function to compare two KTextEditor::Cursor objects.
>> >> +// Returns 0 if equal, 1 if ca > cb, -1 if ca < cb
>> >> +function compare(ca, cb)
>> >> +{
>> >> +  if (ca.line == cb.line) {
>> >> +    if (ca.column == cb.column)
>> >> +      return 0;
>> >> +    else
>> >> +      return (ca.column > cb.column) ? 1 : -1;
>> >> +  }
>> >> +  return (ca.line > cb.line) ? 1 : -1;
>> >> +}
>> >
>> > I'd like to suggest to provide a built-in compare function for cursors
>> > in indenter scripts (called compare for simplicity). The ruby indenter
>> > is the
>> > first but certainly not the last one in need of such a primitive.
>> >
>> > mfg
>> >     Leo
>> > _______________________________________________
>> > KWrite-Devel mailing list
>> > KWrite-Devel@kde.org
>> > https://mail.kde.org/mailman/listinfo/kwrite-devel
>
>
> _______________________________________________
> KWrite-Devel mailing list
> KWrite-Devel@kde.org
> https://mail.kde.org/mailman/listinfo/kwrite-devel
>
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic