~pyreadline/pyreadline/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
# -*- coding: utf-8 -*-
#*****************************************************************************
#       Copyright (C) 2006  Jorgen Stenarson. <jorgen.stenarson@bostream.nu>
#
#  Distributed under the terms of the BSD License.  The full license is in
#  the file COPYING, distributed as part of this software.
#*****************************************************************************
import re, operator, sys

import wordmatcher
import pyreadline.clipboard as clipboard
from pyreadline.logger import  log
from pyreadline.unicode_helper import ensure_unicode, biter

kill_ring_to_clipboard = False #set to true to copy every addition to kill ring to clipboard


class NotAWordError(IndexError):
    pass


def quote_char(c):
    if ord(c) > 0:
        return c

############## Line positioner ########################

class LinePositioner(object):
    def __call__(self, line):
        NotImplementedError(u"Base class !!!")

class NextChar(LinePositioner):
    def __call__(self, line):
        if line.point < len(line.line_buffer):
            return line.point + 1
        else:
            return line.point
NextChar = NextChar()

class PrevChar(LinePositioner):
    def __call__(self, line):
        if line.point > 0:
            return line.point - 1
        else:
            return line.point
PrevChar = PrevChar()

class NextWordStart(LinePositioner):
    def __call__(self, line):
        return line.next_start_segment(line.line_buffer, line.is_word_token)[line.point]
NextWordStart = NextWordStart()

class NextWordEnd(LinePositioner):
    def __call__(self, line):
        return line.next_end_segment(line.line_buffer, line.is_word_token)[line.point]
NextWordEnd = NextWordEnd()

class PrevWordStart(LinePositioner):
    def __call__(self, line):
        return line.prev_start_segment(line.line_buffer, line.is_word_token)[line.point]
PrevWordStart = PrevWordStart()


class WordStart(LinePositioner):
    def __call__(self, line):
        if line.is_word_token(line.get_line_text()[Point(line):Point(line) + 1]):
            if Point(line) > 0 and line.is_word_token(line.get_line_text()[Point(line) - 1:Point(line)]):
                return PrevWordStart(line)
            else:
                return line.point
        else:   
            raise NotAWordError(u"Point is not in a word")
WordStart = WordStart()

class WordEnd(LinePositioner):
    def __call__(self, line):
        if line.is_word_token(line.get_line_text()[Point(line):Point(line) + 1]):
            if line.is_word_token(line.get_line_text()[Point(line) + 1:Point(line) + 2]):
                return NextWordEnd(line)
            else:
                return line.point
        else:   
            raise NotAWordError(u"Point is not in a word")
WordEnd = WordEnd()

class PrevWordEnd(LinePositioner):
    def __call__(self, line):
        return line.prev_end_segment(line.line_buffer, line.is_word_token)[line.point]
PrevWordEnd = PrevWordEnd()

class PrevSpace(LinePositioner):
    def __call__(self, line):
        point = line.point
        if line[point - 1:point].get_line_text() == u" ":
            while point > 0 and line[point - 1:point].get_line_text() == u" ":
                point -= 1
        while point > 0 and line[point - 1:point].get_line_text() != u" ":
            point -= 1
        return point
PrevSpace = PrevSpace()


class StartOfLine(LinePositioner):
    def __call__(self, line):
        return 0
StartOfLine = StartOfLine()

class EndOfLine(LinePositioner):
    def __call__(self, line):
        return len(line.line_buffer)
EndOfLine = EndOfLine()

class Point(LinePositioner):
    def __call__(self, line):
        return line.point
Point = Point()

class Mark(LinePositioner):
    def __call__(self, line):
        return line.mark
k = Mark()

all_positioners = [(value.__class__.__name__, value) 
                        for key, value in globals().items() 
                         if isinstance(value, LinePositioner)]
all_positioners.sort()

############### LineSlice #################

class LineSlice(object):
    def __call__(self, line):
        NotImplementedError(u"Base class !!!")


class CurrentWord(LineSlice):
    def __call__(self, line):
        return slice(WordStart(line), WordEnd(line), None)
CurrentWord = CurrentWord()

class NextWord(LineSlice):
    def __call__(self, line):
        work = TextLine(line)
        work.point = NextWordStart
        start = work.point
        stop = NextWordEnd(work)
        return slice(start, stop)
NextWord = NextWord()

class PrevWord(LineSlice):
    def __call__(self, line):
        work = TextLine(line)
        work.point = PrevWordEnd
        stop = work.point
        start = PrevWordStart(work)
        return slice(start, stop)
PrevWord = PrevWord()

class PointSlice(LineSlice):
    def __call__(self, line):
        return slice(Point(line), Point(line) + 1, None)
PointSlice = PointSlice()


###############  TextLine  ######################

class TextLine(object):
    def __init__(self, txtstr, point = None, mark = None):
        self.line_buffer = []
        self._point = 0
        self.mark = -1
        self.undo_stack = []
        self.overwrite = False
        if isinstance(txtstr, TextLine): #copy 
            self.line_buffer = txtstr.line_buffer[:]
            if point is None:
                self.point = txtstr.point
            else:                
                self.point = point
            if mark is None:
                self.mark = txtstr.mark
            else:
                self.mark = mark
        else:            
            self._insert_text(txtstr)
            if point is None:
                self.point = 0
            else:
                self.point = point
            if mark is None:
                self.mark = -1
            else:
                self.mark = mark

        self.is_word_token = wordmatcher.is_word_token
        self.next_start_segment = wordmatcher.next_start_segment
        self.next_end_segment = wordmatcher.next_end_segment
        self.prev_start_segment = wordmatcher.prev_start_segment
        self.prev_end_segment = wordmatcher.prev_end_segment
        
    def push_undo(self):
        ltext = self.get_line_text()
        if self.undo_stack and ltext == self.undo_stack[-1].get_line_text():
            self.undo_stack[-1].point = self.point
        else:
            self.undo_stack.append(self.copy())

    def pop_undo(self):
        if len(self.undo_stack) >= 2:
            self.undo_stack.pop()
            self.set_top_undo()
            self.undo_stack.pop()
        else:
            self.reset_line()
            self.undo_stack = []

    def set_top_undo(self):
        if self.undo_stack:
            undo = self.undo_stack[-1]
            self.line_buffer = undo.line_buffer
            self.point = undo.point
            self.mark = undo.mark
        else:
            pass
        
    def __repr__(self):
        return u'TextLine("%s",point=%s,mark=%s)'%(self.line_buffer, self.point, self.mark)

    def copy(self):
        return self.__class__(self)

    def set_point(self,value):
        if isinstance(value, LinePositioner):
            value = value(self)
        assert  (value <= len(self.line_buffer))           
        if value > len(self.line_buffer):
            value = len(self.line_buffer)
        self._point = value
    def get_point(self):
        return self._point
    point = property(get_point, set_point)


    def visible_line_width(self, position = Point):
        """Return the visible width of the text in line buffer up to position."""
        extra_char_width = len([ None for c in self[:position].line_buffer if 0x2013 <= ord(c) <= 0xFFFD])
        return len(self[:position].quoted_text()) + self[:position].line_buffer.count(u"\t")*7 + extra_char_width

    def quoted_text(self):
        quoted = [ quote_char(c) for c in self.line_buffer ]
        self.line_char_width = [ len(c) for c in quoted ]
        return u''.join(map(ensure_unicode, quoted))

    def get_line_text(self):
        buf = self.line_buffer
        buf = map(ensure_unicode, buf)
        return u''.join(buf)
            
    def set_line(self, text, cursor = None):
        self.line_buffer = [ c for c in str(text) ]
        if cursor is None:
            self.point = len(self.line_buffer)
        else:
            self.point = cursor

    def reset_line(self):
        self.line_buffer = []
        self.point = 0

    def end_of_line(self):
        self.point = len(self.line_buffer)

    def _insert_text(self, text, argument=1):
        text = text * argument
        if self.overwrite:
            for c in biter(text):
                #if self.point:
                self.line_buffer[self.point] = c
                self.point += 1
        else:            
            for c in biter(text):
                self.line_buffer.insert(self.point, c)
                self.point += 1
    
    def __getitem__(self, key):
        #Check if key is LineSlice, convert to regular slice
        #and continue processing
        if isinstance(key, LineSlice): 
            key = key(self)
        if isinstance(key, slice):
            if key.step is None:
                pass
            else:
                raise Error
            if key.start is None:
                start = StartOfLine(self)
            elif isinstance(key.start,LinePositioner):
                start = key.start(self)
            else:
                start = key.start
            if key.stop is None:                   
                stop = EndOfLine(self)
            elif isinstance(key.stop, LinePositioner):
                stop = key.stop(self)
            else:
                stop = key.stop
            return self.__class__(self.line_buffer[start:stop], point=0)
        elif isinstance(key, LinePositioner):
            return self.line_buffer[key(self)]
        elif isinstance(key, tuple):
            raise IndexError(u"Cannot use step in line buffer indexing") #Multiple slice not allowed
        else:
            # return TextLine(self.line_buffer[key])
            return self.line_buffer[key]

    def __delitem__(self, key):
        point = self.point
        if isinstance(key, LineSlice):
            key = key(self)
        if isinstance(key, slice):
            start = key.start
            stop = key.stop
            if isinstance(start, LinePositioner):
                start = start(self)
            elif start is None:
                start=0
            if isinstance(stop, LinePositioner):
                stop = stop(self)
            elif stop is None:
                stop = EndOfLine(self)
        elif isinstance(key, LinePositioner):
            start = key(self)
            stop = start + 1
        else:
            start = key
            stop = key + 1
        prev = self.line_buffer[:start]
        rest = self.line_buffer[stop:]
        self.line_buffer = prev + rest
        if point > stop:
            self.point = point - (stop - start)
        elif point >= start and point <= stop:
            self.point = start


    def __setitem__(self, key, value):
        if isinstance(key, LineSlice):
            key = key(self)
        if isinstance(key, slice):
            start = key.start
            stop = key.stop
        elif isinstance(key, LinePositioner):
            start = key(self)
            stop = start + 1
        else:
            start = key
            stop = key + 1
        prev = self.line_buffer[:start]
        value = self.__class__(value).line_buffer
        rest = self.line_buffer[stop:]
        out = prev + value + rest
        if len(out) >= len(self):
            self.point = len(self)
        self.line_buffer = out

    def __len__(self):
        return len(self.line_buffer)

    def upper(self):
        self.line_buffer = [x.upper() for x in self.line_buffer]
        return self

    def lower(self):
        self.line_buffer = [x.lower() for x in self.line_buffer]
        return self
        
    def capitalize(self):
        self.set_line(self.get_line_text().capitalize(), self.point)
        return self
        
    def startswith(self, txt):
        return self.get_line_text().startswith(txt)

    def endswith(self, txt):
        return self.get_line_text().endswith(txt)

    def __contains__(self, txt):
        return txt in self.get_line_text()


lines = [TextLine(u"abc"),
         TextLine(u"abc def"),
         TextLine(u"abc def  ghi"),
         TextLine(u"  abc  def  "),
        ]
l = lines[2]
l.point = 5



class ReadLineTextBuffer(TextLine):
    def __init__(self,txtstr, point = None, mark = None):
        super(ReadLineTextBuffer, self).__init__(txtstr, point, mark)
        self.enable_win32_clipboard = True
        self.selection_mark = -1
        self.enable_selection = True
        self.kill_ring = []

    def __repr__(self):
        return u'ReadLineTextBuffer'\
               u'("%s",point=%s,mark=%s,selection_mark=%s)'%\
                 (self.line_buffer, self.point, self.mark,self.selection_mark)


    def insert_text(self, char, argument=1):
        self.delete_selection()
        self.selection_mark = -1
        self._insert_text(char, argument)
    
    def to_clipboard(self):
        if self.enable_win32_clipboard:
                clipboard.set_clipboard_text(self.get_line_text())
    
######### Movement

    def beginning_of_line(self):
        self.selection_mark = -1
        self.point = StartOfLine
        
    def end_of_line(self):
        self.selection_mark = -1
        self.point = EndOfLine

    def forward_char(self,argument = 1):
        if argument < 0:
            self.backward_char(-argument)
        self.selection_mark = -1
        for x in range(argument):
            self.point = NextChar
        
    def backward_char(self, argument=1):
        if argument < 0:
            self.forward_char(-argument)
        self.selection_mark = -1
        for x in range(argument):
            self.point = PrevChar
        
    def forward_word(self,argument=1):
        if argument<0:
            self.backward_word(-argument)
        self.selection_mark=-1
        for x in range(argument):
            self.point = NextWordStart
       
    def backward_word(self, argument=1):
        if argument < 0:
            self.forward_word(-argument)
        self.selection_mark = -1
        for x in range(argument):
            self.point = PrevWordStart

    def forward_word_end(self, argument=1):
        if argument < 0:
            self.backward_word_end(-argument)
        self.selection_mark = -1
        for x in range(argument):
            self.point = NextWordEnd

    def backward_word_end(self, argument=1):
        if argument < 0:
            self.forward_word_end(-argument)
        self.selection_mark = -1
        for x in range(argument):
            self.point = NextWordEnd

######### Movement select
    def beginning_of_line_extend_selection(self):
        if self.enable_selection and self.selection_mark < 0:
            self.selection_mark = self.point
        self.point = StartOfLine
        
    def end_of_line_extend_selection(self):
        if self.enable_selection and self.selection_mark < 0:
            self.selection_mark = self.point
        self.point = EndOfLine

    def forward_char_extend_selection(self,argument=1):
        if argument < 0:
            self.backward_char_extend_selection(-argument)
        if self.enable_selection and self.selection_mark < 0:
            self.selection_mark = self.point
        for x in range(argument):
            self.point = NextChar
        
    def backward_char_extend_selection(self, argument=1):
        if argument < 0:
            self.forward_char_extend_selection(-argument)
        if self.enable_selection and self.selection_mark < 0:
            self.selection_mark = self.point
        for x in range(argument):
            self.point = PrevChar
        
    def forward_word_extend_selection(self, argument=1):
        if argument < 0:
            self.backward_word_extend_selection(-argument)
        if self.enable_selection and self.selection_mark < 0:
            self.selection_mark = self.point
        for x in range(argument):
            self.point = NextWordStart
       
    def backward_word_extend_selection(self, argument=1):
        if argument < 0:
            self.forward_word_extend_selection(-argument)
        if self.enable_selection and self.selection_mark < 0:
            self.selection_mark = self.point
        for x in range(argument):
            self.point = PrevWordStart

       
    def forward_word_end_extend_selection(self, argument=1):
        if argument < 0:
            self.backward_word_end_extend_selection(-argument)
        if self.enable_selection and self.selection_mark < 0:
            self.selection_mark = self.point
        for x in range(argument):
            self.point = NextWordEnd

    def backward_word_end_extend_selection(self, argument=1):
        if argument < 0:
            self.forward_word_end_extend_selection(-argument)
        if self.enable_selection and self.selection_mark < 0:
            self.selection_mark = self.point
        for x in range(argument):
            self.point = PrevWordEnd


######### delete       

    def delete_selection(self):
        if self.enable_selection and self.selection_mark >= 0:
            if self.selection_mark < self.point:
                del self[self.selection_mark:self.point]
                self.selection_mark = -1
            else:                
                del self[self.point:self.selection_mark]
                self.selection_mark = -1
            return True
        else:
            self.selection_mark = -1
            return False

    def delete_char(self, argument=1):
        if argument < 0:
            self.backward_delete_char(-argument)
        if self.delete_selection():
            argument -= 1
        for x in range(argument):
            del self[Point]
        
    def backward_delete_char(self, argument=1):
        if argument < 0:
            self.delete_char(-argument)
        if self.delete_selection():
            argument -= 1
        for x in range(argument):
            if self.point > 0:
                self.backward_char()
                self.delete_char()

    def forward_delete_word(self, argument=1):
        if argument < 0:
            self.backward_delete_word(-argument)
        if self.delete_selection():
            argument -= 1
        for x in range(argument):
            del self[Point:NextWordStart]

    def backward_delete_word(self, argument=1):
        if argument < 0:
            self.forward_delete_word(-argument)
        if self.delete_selection():
            argument -= 1
        for x in range(argument):
            del self[PrevWordStart:Point]

    def delete_current_word(self):
        if not self.delete_selection():
            del self[CurrentWord]
        self.selection_mark =- 1
        
    def delete_horizontal_space(self):
        if self[Point] in " \t":
            del self[PrevWordEnd:NextWordStart]
        self.selection_mark = -1
######### Case

    def upcase_word(self):
        p = self.point
        try:
            self[CurrentWord] = self[CurrentWord].upper()
            self.point = p
        except NotAWordError:
            pass
        
    def downcase_word(self):
        p = self.point
        try:
            self[CurrentWord] = self[CurrentWord].lower()
            self.point = p
        except NotAWordError:
            pass
        
    def capitalize_word(self):
        p = self.point
        try:
            self[CurrentWord] = self[CurrentWord].capitalize()
            self.point = p
        except NotAWordError:
            pass
########### Transpose
    def transpose_chars(self):
        p2 = Point(self)
        if p2 == 0:
            return
        elif p2 == len(self):
            p2 = p2 - 1
        p1 = p2 - 1
        self[p2], self[p1] = self[p1], self[p2]
        self.point = p2 + 1

    def transpose_words(self):
        word1 = TextLine(self)
        word2 = TextLine(self)
        if self.point == len(self):
            word2.point = PrevWordStart
            word1.point = PrevWordStart(word2)
        else:
            word1.point = PrevWordStart
            word2.point = NextWordStart
        stop1 = NextWordEnd(word1)
        stop2 = NextWordEnd(word2)
        start1 = word1.point
        start2 = word2.point
        self[start2:stop2] = word1[Point:NextWordEnd]
        self[start1:stop1] = word2[Point:NextWordEnd]
        self.point = stop2
        

############ Kill

    def kill_line(self):
        self.add_to_kill_ring(self[self.point:])
        del self.line_buffer[self.point:]
    
    def kill_whole_line(self):
        self.add_to_kill_ring(self[:])
        del self[:]
    
    def backward_kill_line(self):
        del self[StartOfLine:Point]
        
    def unix_line_discard(self):
        del self[StartOfLine:Point]
        pass

    def kill_word(self):
        """Kills to next word ending"""
        del self[Point:NextWordEnd]

    def backward_kill_word(self):
        """Kills to next word ending"""
        if not self.delete_selection():
            del self[PrevWordStart:Point]
        self.selection_mark = -1

    def forward_kill_word(self):
        """Kills to next word ending"""
        if not self.delete_selection():
            del self[Point:NextWordEnd]
        self.selection_mark = -1

    def unix_word_rubout(self):
        if not self.delete_selection():
            del self[PrevSpace:Point]
        self.selection_mark = -1

    def kill_region(self):
        pass

    def copy_region_as_kill(self):
        pass

    def copy_backward_word(self):
        pass

    def copy_forward_word(self):
        pass
        

    def yank(self):
        self.paste_from_kill_ring()

    def yank_pop(self):
        pass

##############  Mark 

    def set_mark(self):
        self.mark = self.point
        
    def exchange_point_and_mark(self):
        pass


    def copy_region_to_clipboard(self): # ()
        u'''Copy the text in the region to the windows clipboard.'''
        if self.enable_win32_clipboard:
                mark = min(self.mark, len(self.line_buffer))
                cursor = min(self.point, len(self.line_buffer))
                if self.mark == -1:
                        return
                begin = min(cursor, mark)
                end = max(cursor, mark)
                toclipboard = u"".join(self.line_buffer[begin:end])
                clipboard.SetClipboardText(toclipboard)

    def copy_selection_to_clipboard(self): # ()
        u'''Copy the text in the region to the windows clipboard.'''
        if self.enable_win32_clipboard and self.enable_selection and self.selection_mark >= 0:
                selection_mark = min(self.selection_mark,len(self.line_buffer))
                cursor = min(self.point,len(self.line_buffer))
                if self.selection_mark == -1:
                        return
                begin = min(cursor, selection_mark)
                end = max(cursor, selection_mark)
                toclipboard = u"".join(self.line_buffer[begin:end])
                clipboard.SetClipboardText(toclipboard)


    def cut_selection_to_clipboard(self): # ()
        self.copy_selection_to_clipboard()
        self.delete_selection()
##############  Paste


############## Kill ring
    def add_to_kill_ring(self,txt):
        self.kill_ring = [txt]
        if kill_ring_to_clipboard:
            clipboard.SetClipboardText(txt.get_line_text())


    def paste_from_kill_ring(self):
        if self.kill_ring:
            self.insert_text(self.kill_ring[0])


##################################################################
q = ReadLineTextBuffer(u"asff asFArw  ewrWErhg", point=8)
q = TextLine(u"asff asFArw  ewrWErhg", point=8)

def show_pos(buff, pos, chr = u"."):
    l = len(buff.line_buffer)
    def choice(bool):
        if bool:
            return chr
        else:
            return u" "
    return u"".join([choice(pos==idx) for idx in range(l + 1)])


def test_positioner(buff, points, positioner):
    print (u" %s "%positioner.__class__.__name__).center(40, u"-")
    buffstr = buff.line_buffer
    
    print u'"%s"'%(buffstr)
    for point in points:
        b = TextLine(buff, point = point)
        out=[u" "] * (len(buffstr) + 1)
        pos = positioner(b)
        if pos == point:
            out[pos] = u"&"
        else:
            out[point] = u"."
            out[pos] = u"^"
        print u'"%s"'%(u"".join(out))
    
if __name__ == "__main__":

    print u'%-15s "%s"'%(u"Position", q.get_line_text())
    print u'%-15s "%s"'%(u"Point", show_pos(q, q.point))


    for name, positioner in all_positioners:
        pos = positioner(q)
        []
        print u'%-15s "%s"'%(name, show_pos(q, pos, u"^"))

    l = ReadLineTextBuffer(u"kjjk asads   asad")
    l.point = EndOfLine