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

List:       kwrite-devel
Subject:    Re: have compare in indenter api
From:       "Robin Pedersen" <robinpeder () gmail ! com>
Date:       2008-05-27 20:01:06
Message-ID: op.ubtwj4t59lgty9 () lenobin
[Download RAW message or body]

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



-- 
Robin Pedersen
_______________________________________________
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