Changeset 1834

Show
Ignore:
Timestamp:
10/19/06 14:35:35 (2 years ago)
Author:
jstenar
Message:

pyreadline-refactor: Adding argument handling

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyreadline/branches/refactor/doc/ChangeLog

    r1833 r1834  
     12006-10-19 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
     2    * Adding argument handling. 
     3    * Adding argument to functions:forward_char, backward_char, forward_word, backward_word 
     4      forward_word_end, backward_word_end, beginning_of_line_extend_selection, end_of_line_extend_selection 
     5      forward_char_extend_selection, backward_char_extend_selection, forward_word_extend_selection, 
     6      backward_word_extend_selection, forward_word_end_extend_selection, backward_word_end_extend_selection, 
     7      delete_char, backward_delete_char, backward_delete_word, forward_delete_word,  
     8     
    192006-10-18 Jörgen Stenarson  <jorgen.stenarson -at- bostream.nu> 
    210    * Adding functionality to dump_functions 
  • pyreadline/branches/refactor/pyreadline/lineeditor/lineobj.py

    r1832 r1834  
    416416        self.selection_mark=-1 
    417417        self.point=EndOfLine 
    418          
    419     def forward_char(self): 
    420         self.selection_mark=-1 
    421         self.point=NextChar 
    422          
    423     def backward_char(self): 
    424         self.selection_mark=-1 
    425         self.point=PrevChar 
    426          
    427     def forward_word(self): 
    428         self.selection_mark=-1 
    429         self.point=NextWordStart 
     418 
     419    def forward_char(self,argument=1): 
     420        if argument<0: 
     421            self.backward_char(-argument) 
     422        self.selection_mark=-1 
     423        for x in range(argument): 
     424            self.point=NextChar 
     425         
     426    def backward_char(self,argument=1): 
     427        if argument<0: 
     428            self.forward_char(-argument) 
     429        self.selection_mark=-1 
     430        for x in range(argument): 
     431            self.point=PrevChar 
     432         
     433    def forward_word(self,argument=1): 
     434        if argument<0: 
     435            self.backward_word(-argument) 
     436        self.selection_mark=-1 
     437        for x in range(argument): 
     438            self.point=NextWordStart 
    430439        
    431     def forward_word_end(self): 
    432         self.selection_mark=-1 
    433         self.point=NextWordEnd 
    434         
    435     def backward_word(self): 
    436         self.selection_mark=-1 
    437         self.point=PrevWordStart 
     440    def backward_word(self,argument=1): 
     441        if argument<0: 
     442            self.forward_word(-argument) 
     443        self.selection_mark=-1 
     444        for x in range(argument): 
     445            self.point=PrevWordStart 
     446 
     447    def forward_word_end(self,argument=1): 
     448        if argument<0: 
     449            self.backward_word_end(-argument) 
     450        self.selection_mark=-1 
     451        for x in range(argument): 
     452            self.point=NextWordEnd 
     453 
     454    def backward_word_end(self,argument=1): 
     455        if argument<0: 
     456            self.forward_word_end(-argument) 
     457        self.selection_mark=-1 
     458        for x in range(argument): 
     459            self.point=NextWordEnd 
    438460 
    439461######### Movement select 
     
    447469            self.selection_mark=self.point 
    448470        self.point=EndOfLine 
    449          
    450     def forward_char_extend_selection(self): 
     471 
     472    def forward_char_extend_selection(self,argument=1): 
     473        if argument<0: 
     474            self.backward_char_extend_selection(-argument) 
    451475        if self.enable_selection and self.selection_mark<0: 
    452476            self.selection_mark=self.point 
    453         self.point=NextChar 
    454          
    455     def backward_char_extend_selection(self): 
     477        for x in range(argument): 
     478            self.point=NextChar 
     479         
     480    def backward_char_extend_selection(self,argument=1): 
     481        if argument<0: 
     482            self.forward_char_extend_selection(-argument) 
    456483        if self.enable_selection and self.selection_mark<0: 
    457484            self.selection_mark=self.point 
    458         self.point=PrevChar 
    459          
    460     def forward_word_extend_selection(self): 
     485        for x in range(argument): 
     486            self.point=PrevChar 
     487         
     488    def forward_word_extend_selection(self,argument=1): 
     489        if argument<0: 
     490            self.backward_word_extend_selection(-argument) 
    461491        if self.enable_selection and self.selection_mark<0: 
    462492            self.selection_mark=self.point 
    463         self.point=NextWordStart 
     493        for x in range(argument): 
     494            self.point=NextWordStart 
    464495        
    465     def forward_word_end_extend_selection(self): 
     496    def backward_word_extend_selection(self,argument=1): 
     497        if argument<0: 
     498            self.forward_word_extend_selection(-argument) 
    466499        if self.enable_selection and self.selection_mark<0: 
    467500            self.selection_mark=self.point 
    468         self.point=NextWordEnd 
     501        for x in range(argument): 
     502            self.point=PrevWordStart 
     503 
    469504        
    470     def backward_word_extend_selection(self): 
     505    def forward_word_end_extend_selection(self,argument=1): 
     506        if argument<0: 
     507            self.backward_word_end_extend_selection(-argument) 
    471508        if self.enable_selection and self.selection_mark<0: 
    472509            self.selection_mark=self.point 
    473         self.point=PrevWordStart 
     510        for x in range(argument): 
     511            self.point=NextWordEnd 
     512 
     513    def backward_word_end_extend_selection(self,argument=1): 
     514        if argument<0: 
     515            self.forward_word_end_extend_selection(-argument) 
     516        if self.enable_selection and self.selection_mark<0: 
     517            self.selection_mark=self.point 
     518        for x in range(argument): 
     519            self.point=PrevWordEnd 
     520 
    474521 
    475522######### delete        
     
    479526            if self.selection_mark<self.point: 
    480527                del self[self.selection_mark:self.point] 
     528                self.selection_mark=-1 
    481529            else:                 
    482530                del self[self.point:self.selection_mark] 
     531                self.selection_mark=-1 
    483532            return True 
    484533        else: 
     534            self.selection_mark=-1 
    485535            return False 
    486         self.selection_mark=-1 
    487  
    488     def delete_char(self): 
    489         if not self.delete_selection(): 
     536 
     537    def delete_char(self,argument=1): 
     538        if argument<0: 
     539            self.backward_delete_char(-argument) 
     540        if self.delete_selection(): 
     541            argument-=1 
     542        for x in range(argument): 
    490543            del self[Point] 
    491         self.selection_mark=-1 
    492          
    493     def backward_delete_char(self): 
    494         if not self.delete_selection(): 
     544         
     545    def backward_delete_char(self,argument=1): 
     546        if argument<0: 
     547            self.delete_char(-argument) 
     548        if self.delete_selection(): 
     549            argument-=1 
     550        for x in range(argument): 
    495551            if self.point>0: 
    496552                self.backward_char() 
    497553                self.delete_char() 
    498         self.selection_mark=-1 
    499  
    500     def backward_delete_word(self): 
    501         if not self.delete_selection(): 
    502             #del self[PrevWordEnd:Point] 
     554 
     555    def forward_delete_word(self,argument=1): 
     556        if argument<0: 
     557            self.backward_delete_word(-argument) 
     558        if self.delete_selection(): 
     559            argument-=1 
     560        for x in range(argument): 
     561            del self[Point:NextWordStart] 
     562 
     563    def backward_delete_word(self,argument=1): 
     564        if argument<0: 
     565            self.forward_delete_word(-argument) 
     566        if self.delete_selection(): 
     567            argument-=1 
     568        for x in range(argument): 
    503569            del self[PrevWordStart:Point] 
    504         self.selection_mark=-1 
    505  
    506     def forward_delete_word(self): 
    507         if not self.delete_selection(): 
    508             #del self[PrevWordEnd:Point] 
    509             del self[Point:NextWordStart] 
    510         self.selection_mark=-1 
    511570 
    512571    def delete_current_word(self): 
  • pyreadline/branches/refactor/pyreadline/modes/basemode.py

    r1832 r1834  
    2424        self.startup_hook=None 
    2525        self.pre_input_hook=None 
     26        self.argument=1 
     27        self.prevargument=None 
    2628         
    2729    def __repr__(self): 
     
    3941            return getattr(self.rlobj,x) 
    4042        return g 
     43 
     44    def _argreset(self): 
     45        val=self.argument 
     46        self.argument=1 
     47        return val 
     48    argument_reset=property(_argreset) 
    4149         
    4250    l_buffer=property(*_gs("l_buffer")) 
     
    5866    _clear_after=property(_g("_clear_after")) 
    5967    _set_cursor=property(_g("_set_cursor")) 
    60     _print_prompt=property(_g("_print_prompt")) 
    6168    _update_prompt_pos=property(_g("_update_prompt_pos")) 
    6269    _update_line=property(_g("_update_line")) 
     
    230237    def forward_char(self, e): # (C-f) 
    231238        '''Move forward a character. ''' 
    232         self.l_buffer.forward_char(
     239        self.l_buffer.forward_char(self.argument_reset
    233240 
    234241    def backward_char(self, e): # (C-b) 
    235242        '''Move back a character. ''' 
    236         self.l_buffer.backward_char(
     243        self.l_buffer.backward_char(self.argument_reset
    237244 
    238245    def forward_word(self, e): # (M-f) 
    239246        '''Move forward to the end of the next word. Words are composed of 
    240247        letters and digits.''' 
    241         self.l_buffer.forward_word() 
    242  
    243     def forward_word_end(self, e): # (M-f) 
    244         '''Move forward to the end of the next word. Words are composed of 
    245         letters and digits.''' 
    246         self.l_buffer.forward_word_end() 
     248        self.l_buffer.forward_word(self.argument_reset) 
    247249 
    248250    def backward_word(self, e): # (M-b) 
    249251        '''Move back to the start of the current or previous word. Words are 
    250252        composed of letters and digits.''' 
    251         self.l_buffer.backward_word() 
    252  
    253  
     253        self.l_buffer.backward_word(self.argument_reset) 
     254 
     255    def forward_word_end(self, e): # () 
     256        '''Move forward to the end of the next word. Words are composed of 
     257        letters and digits.''' 
     258        self.l_buffer.forward_word_end(self.argument_reset) 
     259 
     260    def backward_word_end(self, e): # () 
     261        '''Move forward to the end of the next word. Words are composed of 
     262        letters and digits.''' 
     263        self.l_buffer.backward_word_end(self.argument_reset) 
     264 
     265### Movement with extend selection 
    254266    def beginning_of_line_extend_selection(self, e): #  
    255267        '''Move to the start of the current line. ''' 
    256         self.l_buffer.beginning_of_line_extend_selection(
     268        self.l_buffer.beginning_of_line_extend_selection(self.argument_reset
    257269 
    258270    def end_of_line_extend_selection(self, e): #  
    259271        '''Move to the end of the line. ''' 
    260         self.l_buffer.end_of_line_extend_selection(
     272        self.l_buffer.end_of_line_extend_selection(self.argument_reset
    261273 
    262274    def forward_char_extend_selection(self, e): #  
    263275        '''Move forward a character. ''' 
    264         self.l_buffer.forward_char_extend_selection(
     276        self.l_buffer.forward_char_extend_selection(self.argument_reset
    265277 
    266278    def backward_char_extend_selection(self, e): # 
    267279        '''Move back a character. ''' 
    268         self.l_buffer.backward_char_extend_selection(
     280        self.l_buffer.backward_char_extend_selection(self.argument_reset
    269281 
    270282    def forward_word_extend_selection(self, e): #  
    271283        '''Move forward to the end of the next word. Words are composed of 
    272284        letters and digits.''' 
    273         self.l_buffer.forward_word_extend_selection() 
    274  
    275     def forward_word_end_extend_selection(self, e): #  
    276         '''Move forward to the end of the next word. Words are composed of 
    277         letters and digits.''' 
    278         self.l_buffer.forward_word_end_extend_selection() 
     285        self.l_buffer.forward_word_extend_selection(self.argument_reset) 
    279286 
    280287    def backward_word_extend_selection(self, e): #  
    281288        '''Move back to the start of the current or previous word. Words are 
    282289        composed of letters and digits.''' 
    283         self.l_buffer.backward_word_extend_selection() 
    284  
     290        self.l_buffer.backward_word_extend_selection(self.argument_reset) 
     291 
     292    def forward_word_end_extend_selection(self, e): #  
     293        '''Move forward to the end of the next word. Words are composed of 
     294        letters and digits.''' 
     295        self.l_buffer.forward_word_end_extend_selection(self.argument_reset) 
     296 
     297    def backward_word_end_extend_selection(self, e): #  
     298        '''Move forward to the end of the next word. Words are composed of 
     299        letters and digits.''' 
     300        self.l_buffer.forward_word_end_extend_selection(self.argument_reset) 
     301 
     302 
     303######## Change case 
    285304 
    286305    def upcase_word(self, e): # (M-u) 
     
    300319 
    301320 
    302  
     321######## 
    303322    def clear_screen(self, e): # (C-l) 
    304323        '''Clear the screen and redraw the current line, leaving the current 
     
    322341        the line, there are no characters in the line, and the last 
    323342        character typed was not bound to delete-char, then return EOF.''' 
    324         self.l_buffer.delete_char(
     343        self.l_buffer.delete_char(self.argument_reset
    325344 
    326345    def backward_delete_char(self, e): # (Rubout) 
    327346        '''Delete the character behind the cursor. A numeric argument means 
    328347        to kill the characters instead of deleting them.''' 
    329         self.l_buffer.backward_delete_char(
     348        self.l_buffer.backward_delete_char(self.argument_reset
    330349 
    331350    def backward_delete_word(self, e): # (Control-Rubout) 
    332351        '''Delete the character behind the cursor. A numeric argument means 
    333352        to kill the characters instead of deleting them.''' 
    334         self.l_buffer.backward_delete_word(
     353        self.l_buffer.backward_delete_word(self.argument_reset
    335354 
    336355    def forward_delete_word(self, e): # (Control-Delete) 
    337356        '''Delete the character behind the cursor. A numeric argument means 
    338357        to kill the characters instead of deleting them.''' 
    339         self.l_buffer.forward_delete_word(
     358        self.l_buffer.forward_delete_word(self.argument_reset
    340359 
    341360    def delete_horizontal_space(self, e): # () 
  • pyreadline/branches/refactor/pyreadline/modes/emacs.py

    r1832 r1834  
    357357        '''Add this digit to the argument already accumulating, or start a 
    358358        new argument. M-- starts a negative argument.''' 
    359         pass 
     359        args=e.char 
     360 
     361        c = self.console 
     362        line = self.l_buffer.get_line_text() 
     363        oldprompt=self.prompt 
     364        def nop(e): 
     365            pass 
     366        while 1: 
     367            x, y = self.prompt_end_pos 
     368            c.pos(0, y) 
     369            self.prompt="(arg: %s) "%args 
     370            self._print_prompt() 
     371            self._update_line() 
     372 
     373            event = c.getkeypress() 
     374            if event.keyinfo.keyname == 'enter': 
     375                break 
     376            elif event.char in "0123456789": 
     377                args+=event.char 
     378            else: 
     379                self.argument=int(args) 
     380                keyinfo=event.keyinfo.tuple() 
     381                if len(keyinfo[-1])>1: 
     382                    default=nop 
     383                else: 
     384                    default=self.self_insert 
     385                dispatch_func = self.key_dispatch.get(keyinfo,default) 
     386                log_sock("%s|%s"%(dispatch_func,str(keyinfo))) 
     387                dispatch_func(event) 
     388                break 
     389        log_sock("END arg=%s"%(self.argument)) 
     390        self.prompt=oldprompt 
     391        x, y = self.prompt_end_pos 
     392        c.pos(0, y) 
     393        self._print_prompt() 
     394        self._update_line() 
     395 
     396             
     397 
    360398 
    361399    def universal_argument(self, e): # ()