Quote:
$wrap is not the problem slecting wise (both methods offset the same ammount) non wrapped lines still return 1

By non-wrapped lines I mean "lines added with /aline without the -p switch". If such lines are long, $wrap() returns a number > 1, but in the main window they occupy only 1 physical line. The errors caused by this difference can accumulate, resulting in a big offset from the middle, like Line 77 in the example.

In this respect, our versions are equivalent: all mine does is speed up the the whole thing. As I said before, it doesn't solve the problem nor do I know of a way that does fully, at least not without storing the wrap state of each line that is added (and even then the alignment won't be perfect because /sline 'jumps' between entire lines, not wrapped physical lines).

That said, and provided the above kind of error doesn't get too big, the situation can get a little better if, before /sline makes the next jump, the script checks whether it will end up pushing the highlighted text up further from the middle than before. Here's a version that implements this:
Code:
alias selectmiddleline { 
  var %x = $1, %wanted = $calc($window(@ex1).dh / 2 / $window(@ex1).fontsize), %t
  window -hf @wrap -1 -1 $window(@ex1).dw $window(@ex1).dh
  while $line(@ex1,%x) != $null { 
    %t = $line(@wrap,0)
    echo -h @wrap $v1
    if $calc($line(@wrap,0) - %wanted) > 0 {
      if ($v1 > $calc(%wanted - %t)) dec %x
      sline -a @ex1 %x | close -@ @wrap | return 
    }   
    inc %x
  }
  close -@ @wrap 
  sline -a @ex1 $line(@ex1,0)
}


EDIT: corrected a silly omission regarding the size of the hidden @wrap window

Last edited by qwerty; 19/07/06 11:50 PM.