def _subst(self, which, wdex): """ Do completion. Params which Which variant to use 'next' / 'prev' / '#N' wdex What list to use 'word' / 'expr' / 'curr' """ pass #LOG and log('which, wdex={}',(which, wdex)) if wdex!='curr' and \ not self._prep_sess(wdex): return if not self.sess.bids: return app.msg_status(_('No in-text completions')) shft = 1 if which == 'next' else -1 if which == 'prev' else 0 bids_i = int(which) if which.isdigit() else \ self.sess.bids_i + shft if self.incr_bfr else \ self.sess.bids_i bids_i = bids_i % len(self.sess.bids) sub_s = self.sess.bids[bids_i] add_s = sub_s[len(self.sess.src_what):] pass #LOG and log('i, sub_s, add_s={}',(bids_i, sub_s, add_s)) if self.sess.added: ed.cmd(cmds.cCommand_Undo) pass #LOG and log('undo mod_ver, line={}',(ed.get_prop(app.PROP_MODIFIED_VERSION), ed.get_text_line(self.sess.row))) ed.delete(self.sess.src_kill_b, self.sess.row, self.sess.src_kill_e, self.sess.row) pass #LOG and log('kill mod_ver, line={}',(ed.get_prop(app.PROP_MODIFIED_VERSION), ed.get_text_line(self.sess.row))) ed.insert(self.sess.src_what_e, self.sess.row, add_s) pass #LOG and log('insr mod_ver, line={}',(ed.get_prop(app.PROP_MODIFIED_VERSION), ed.get_text_line(self.sess.row))) self.sess.added = True if False: pass elif self.sess.sel_sub == 'be': ed.set_caret(self.sess.src_what_e + len(add_s), self.sess.row, self.sess.src_what_b, self.sess.row) elif self.sess.sel_sub == 'eb': ed.set_caret(self.sess.src_what_b, self.sess.row, self.sess.src_what_e + len(add_s), self.sess.row) else: ed.set_caret(self.sess.src_what_e + len(add_s), self.sess.row) # ed.set_caret(self.sess.src_crt, self.sess.row) self.sess.pre_mver = ed.get_prop(app.PROP_MODIFIED_VERSION) self.sess.pre_crt0 = ed.get_carets()[0] # next_i = (self.sess.bids_i+shft) % len(self.sess.bids) # next_info = '' if 1==len(self.sess.bids) else \ # f(_('. Next #{}: "{}"'), next_i, self.sess.bids[next_i][:50]) # app.msg_status(f(_('In-text completion #{} ({}){}'), 1+self.sess.bids_i, len(self.sess.bids), next_info)) app.msg_status( f(_('In-text completion #{} ({})'), 1 + self.sess.bids_i, len(self.sess.bids))) # shft = 1 if which=='next' or which[0]=='#' else -1 self.sess.bids_i = bids_i self.incr_bfr = True
def duplicate(self): if ed.get_sel_mode() != app.SEL_NORMAL: return app.msg_status(ONLY_NORM_SEL_MODE.format(DUPLICATION)) crts = ed.get_carets() if len(crts) > 1: return app.msg_status(ONLY_SINGLE_CRT.format(DUPLICATION)) (cCrt, rCrt, cEnd, rEnd) = crts[0] bEmpSel = -1 == rEnd bUseFLn = get_opt('duplicate_full_line_if_no_sel', True) bSkip = get_opt('duplicate_move_down', True) if bEmpSel: if not bUseFLn: return # Dup whole row row_txt = ed.get_text_line(rCrt) ed.insert(0, rCrt, row_txt + '\n') # Move crt to next row if bSkip and (rCrt + 1) < ed.get_line_count(): _move_caret_down(cCrt, rCrt) return (rFr, cFr), (rTo, cTo) = minmax((rCrt, cCrt), (rEnd, cEnd)) pass #LOG and log('(cFr , rFr , cTo , rTo) ={}',(cFr , rFr , cTo , rTo)) sel_txt = ed.get_text_substr(cFr, rFr, cTo, rTo) pass #LOG and log('sel_txt={}',repr(sel_txt)) ed.insert(cFr, rFr, sel_txt)
def duplicate(self): if ed.get_sel_mode() != app.SEL_NORMAL: return app.msg_status(ONLY_NORM_SEL_MODE.format(DUPLICATION)) crts = ed.get_carets() if len(crts)>1: return app.msg_status(ONLY_SINGLE_CRT.format(DUPLICATION)) (cCrt, rCrt, cEnd, rEnd) = crts[0] if -1==cEnd: # Empty sel -- dup whole row row_txt = ed.get_text_line(rCrt) ed.insert(0, rCrt, row_txt+'\n') # Move crt to next row if (rCrt+1)<ed.get_line_count(): colCrt = pos2pos(cCrt , rCrt, 'smb2col') smbCrt1 = pos2pos(colCrt, rCrt+1, 'col2smb') ed.set_caret(smbCrt1, rCrt+1) return (rFr, cFr), (rTo, cTo) = minmax((rCrt, cCrt), (rEnd, cEnd)) #pass; LOG and log('(cCrt, rCrt, cEnd, rEnd)={}',(cCrt, rCrt, cEnd, rEnd)) pass; LOG and log('(cFr , rFr , cTo , rTo) ={}',(cFr , rFr , cTo , rTo)) sel_txt = ed.get_text_substr(cFr, rFr, cTo, rTo) pass; LOG and log('sel_txt={}',repr(sel_txt)) ed.insert(cFr, rFr, sel_txt) if -1==rEnd: # or rCrt==rEnd: # Move crt to next row colCrt = pos2pos(cCrt , rCrt, 'smb2col') smbCrt1 = pos2pos(colCrt, rCrt+1, 'col2smb') ed.set_caret(smbCrt1, rCrt+1)
def duplicate(self): if ed.get_sel_mode() != app.SEL_NORMAL: return app.msg_status(ONLY_NORM_SEL_MODE.format(DUPLICATION)) crts = ed.get_carets() if len(crts)>1: return app.msg_status(ONLY_SINGLE_CRT.format(DUPLICATION)) (cCrt, rCrt, cEnd, rEnd) = crts[0] bEmpSel = -1==rEnd bUseFLn = get_opt('duplicate_full_line_if_no_sel', True) bSkip = get_opt('duplicate_move_down', True) if bEmpSel: if not bUseFLn: return # Dup whole row row_txt = ed.get_text_line(rCrt) ed.insert(0, rCrt, row_txt+'\n') # Move crt to next row if bSkip and (rCrt+1)<ed.get_line_count(): _move_caret_down(cCrt, rCrt) return (rFr, cFr), (rTo, cTo) = minmax((rCrt, cCrt), (rEnd, cEnd)) pass; #LOG and log('(cFr , rFr , cTo , rTo) ={}',(cFr , rFr , cTo , rTo)) sel_txt = ed.get_text_substr(cFr, rFr, cTo, rTo) pass; #LOG and log('sel_txt={}',repr(sel_txt)) ed.insert(cFr, rFr, sel_txt)
def do_insert(self, s): x, y, x1, y1 = ed.get_carets()[0] if y1 >= 0: if (y, x) > (y1, x1): x, y, x1, y1 = x1, y1, x, y ed.set_caret(x, y) ed.replace(x, y, x1, y1, s) else: ed.insert(x, y, s) app.msg_status('Date/time inserted')
def _subst(self, which, wdex): """ Do completion. Params which Which variant to use 'next' / 'prev' / '#N' wdex What list to use 'word' / 'expr' / 'curr' """ pass; #LOG and log('which, wdex={}',(which, wdex)) if wdex!='curr' and \ not self._prep_sess(wdex): return if not self.sess.bids: return app.msg_status(_('No in-text completions')) shft = 1 if which=='next' else -1 if which=='prev' else 0 bids_i = int(which) if which.isdigit() else \ self.sess.bids_i + shft if self.incr_bfr else \ self.sess.bids_i bids_i = bids_i % len(self.sess.bids) sub_s = self.sess.bids[bids_i] add_s = sub_s[len(self.sess.src_what):] pass; #LOG and log('i, sub_s, add_s={}',(bids_i, sub_s, add_s)) if self.sess.added: ed.cmd(cmds.cCommand_Undo) pass; #LOG and log('undo mod_ver, line={}',(ed.get_prop(app.PROP_MODIFIED_VERSION), ed.get_text_line(self.sess.row))) ed.delete( self.sess.src_kill_b, self.sess.row ,self.sess.src_kill_e, self.sess.row) pass; #LOG and log('kill mod_ver, line={}',(ed.get_prop(app.PROP_MODIFIED_VERSION), ed.get_text_line(self.sess.row))) ed.insert( self.sess.src_what_e, self.sess.row, add_s) pass; #LOG and log('insr mod_ver, line={}',(ed.get_prop(app.PROP_MODIFIED_VERSION), ed.get_text_line(self.sess.row))) self.sess.added = True if False:pass elif self.sess.sel_sub=='be': ed.set_caret(self.sess.src_what_e+len(add_s), self.sess.row ,self.sess.src_what_b, self.sess.row) elif self.sess.sel_sub=='eb': ed.set_caret(self.sess.src_what_b, self.sess.row ,self.sess.src_what_e+len(add_s), self.sess.row) else: ed.set_caret(self.sess.src_what_e+len(add_s), self.sess.row) # ed.set_caret(self.sess.src_crt, self.sess.row) self.sess.pre_mver = ed.get_prop(app.PROP_MODIFIED_VERSION) self.sess.pre_crt0 = ed.get_carets()[0] # next_i = (self.sess.bids_i+shft) % len(self.sess.bids) # next_info = '' if 1==len(self.sess.bids) else \ # f(_('. Next #{}: "{}"'), next_i, self.sess.bids[next_i][:50]) # app.msg_status(f(_('In-text completion #{} ({}){}'), 1+self.sess.bids_i, len(self.sess.bids), next_info)) app.msg_status(f(_('In-text completion #{} ({})'), 1+self.sess.bids_i, len(self.sess.bids))) # shft = 1 if which=='next' or which[0]=='#' else -1 self.sess.bids_i = bids_i self.incr_bfr = True
def paste_to_1st_col(self): ''' Paste from clipboard without replacement caret/selection but only insert before current line ''' pass; #LOG and log('') clip = app.app_proc(app.PROC_GET_CLIP, '') if not clip: return clip = clip.replace('\r\n', '\n').replace('\r', '\n') if not (clip[-1] in '\r\n'): clip= clip + '\n' rnews = clip.count('\n') crts = ed.get_carets() if len(crts)>1: return app.msg_status(ONLY_SINGLE_CRT.format('Command')) (cCrt, rCrt, cEnd, rEnd) = crts[0] r4ins = min(rCrt, rCrt if -1==rEnd else rEnd) ed.insert(0, r4ins, clip) rCrtN = rCrt+ rnews rEndN = rEnd+(rnews if -1!=rEnd else 0) pass; #LOG and log('(rCrtN, rEndN)={}',(rCrtN, rEndN)) ed.set_caret(cCrt, rCrtN ,cEnd, rEndN) pass; return ##?? for icrt, (cCrt, rCrt, cEnd, rEnd) in reversed(list(enumerate(crts))): # for icrt, (cCrt, rCrt, cEnd, rEnd) in enumerate(crts): pass; #LOG and log('icrt, (cCrt, rCrt, cEnd, rEnd), rnews={}',(icrt, (cCrt, rCrt, cEnd, rEnd), rnews)) rCrtA = rCrt+rnews*icrt rEndA = rEnd+rnews*icrt if -1!=rEnd else -1 r4ins = min(rCrt, rCrt if -1==rEnd else rEnd) pass; #LOG and log('(rCrtA, rEndA), r4ins={}',((rCrtA, rEndA), r4ins)) ed.insert(0, r4ins, clip) rCrtN = rCrt+ rnews rEndN = rEnd+(rnews if -1!=rEnd else 0) pass; #LOG and log('(rCrtN, rEndN)={}',(rCrtN, rEndN)) ed.set_caret(cCrt, rCrtN ,cEnd, rEndN ,app.CARET_SET_INDEX+icrt)
def cmt_toggle_stream(self): ''' ''' if ed.get_sel_mode() != app.SEL_NORMAL: return app.msg_status(ONLY_NORM_SEL_MODE.format(COMMENTING)) lex = ed.get_prop(app.PROP_LEXER_CARET) (bgn ,end) = self._get_cmt_pair(lex) if not bgn: return app.msg_status(CMT_NO_STRM_4LEX.format(lex)) crts = ed.get_carets() pass; LOG and log('lex, get_carets()={}', (lex, crts)) pass; LOG and log('bgn,end={}', (bgn,end)) for icrt, (c1, r1, c2, r2) in enumerate(crts): pass; LOG and log('(r1, c1), (r2, c2)={}', ((r1, c1), (r2, c2))) if -1==c2: # Empty sel continue (r1, c1), (r2, c2) = minmax((r1, c1), (r2, c2)) pass; LOG and log('(r1, c1), (r2, c2)={}', ((r1, c1), (r2, c2))) selTx = ed.get_text_substr(c1, r1, c2, r2) cmted = selTx.startswith(bgn) and selTx.endswith(end) pass; LOG and log('cmted, selTx={}', (cmted, selTx)) if False:pass elif not cmted and r1==r2: # Comment ON, sel into one row ed.insert(c2, r2, end) ed.insert(c1, r1, bgn) ed.set_caret(c1, r1, c2+len(bgn)+len(end), r2, app.CARET_SET_INDEX+icrt) elif not cmted and r1!=r2: # Comment ON, sel ends on diff rows ed.insert(c2, r2, end) ed.insert(c1, r1, bgn) ed.set_caret(c1, r1, c2 +len(end), r2, app.CARET_SET_INDEX+icrt) elif cmted and r1==r2: # Comment OFF, sel into one row ed.delete(c2-len(end), r2, c2, r2) ed.delete(c1, r1, c1+len(bgn), r1) ed.set_caret(c1, r1, c2-len(bgn)-len(end), r2, app.CARET_SET_INDEX+icrt) elif cmted and r1!=r2: # Comment OFF, sel ends on diff rows ed.delete(c2-len(end), r2, c2, r2) ed.delete(c1, r1, c1+len(bgn), r1) ed.set_caret(c1, r1, c2 -len(end), r2, app.CARET_SET_INDEX+icrt)
def cmt_toggle_stream(self): ''' ''' if ed.get_sel_mode() != app.SEL_NORMAL: return app.msg_status(ONLY_NORM_SEL_MODE.format(COMMENTING)) lex = ed.get_prop(app.PROP_LEXER_CARET) ((bgn_sgn, end_sgn), bOnlyLn) = self._get_cmt_pair(lex) if not bgn_sgn: return app.msg_status(CMT_NO_STRM_4LEX.format(lex)) bUseFLn = get_opt('comment_full_line_if_no_sel', True) crts = ed.get_carets() pass #LOG and log('lex, get_carets()={}', (lex, crts)) pass #LOG and log('(bgn_sgn,end_sgn),bOnlyLn,bUseFLn={}', ((bgn_sgn,end_sgn),bOnlyLn,bUseFLn)) for icrt, (cCrt, rCrt, cEnd, rEnd) in enumerate(crts): pass #LOG and log('(cCrt, rCrt), (cEnd, rEnd)={}', ((cCrt, rCrt), (cEnd, rEnd))) bEmpSel = -1 == rEnd bDrtSel = -1 == rEnd or (rCrt, cCrt) > (rEnd, cEnd) if False: pass elif bEmpSel and (bUseFLn or bOnlyLn): # Use full line line = ed.get_text_line(rCrt) (cTx1, rTx1), (cTx2, rTx2) = (0, rCrt), (len(line), rCrt) elif bOnlyLn: # and not bEmpSel # Only full lines rTx1, rTx2 = minmax(rCrt, rEnd) line = ed.get_text_line(rTx2) (cTx1, rTx1), (cTx2, rTx2) = (0, rTx1), (len(line), rTx2) elif bEmpSel: # and not bUseFLn and not bOnlyLn continue else: (rTx1, cTx1), (rTx2, cTx2) = minmax((rCrt, cCrt), (rEnd, cEnd)) selTx = ed.get_text_substr(cTx1, rTx1, cTx2, rTx2) pass #LOG and log('(rTx1, cTx1), (rTx2, cTx2), selTx={}', ((rTx1, cTx1), (rTx2, cTx2), repr(selTx))) do_uncmt = selTx.startswith(bgn_sgn) and selTx.endswith(end_sgn) pass #LOG and log('do_uncmt={}', (do_uncmt)) if False: pass elif not do_uncmt and bOnlyLn: # Comment! ed.insert(0, rTx2 + 1, end_sgn + '\n') #! true insert sequence ed.insert(0, rTx1, bgn_sgn + '\n') #! true insert sequence (cNSel1, rNSel1, cNSel2, rNSel2) = 0, rTx1, len(end_sgn), rTx2 + 2 elif not do_uncmt: # Comment! ed.insert(cTx2, rTx2, end_sgn) #! true insert sequence ed.insert(cTx1, rTx1, bgn_sgn) #! true insert sequence if False: pass elif rTx1 == rTx2: # sel into one row (cNSel1, rNSel1, cNSel2, rNSel2 ) = cTx1, rTx1, cTx2 + len(bgn_sgn) + len(end_sgn), rTx2 elif rTx1 != rTx2: # sel ends on diff rows (cNSel1, rNSel1, cNSel2, rNSel2) = cTx1, rTx1, cTx2 + len(end_sgn), rTx2 elif do_uncmt and bOnlyLn: # UnComment! ed.delete(0, rTx2, 0, rTx2 + 1) #! true delete sequence ed.delete(0, rTx1, 0, rTx1 + 1) #! true delete sequence (cNSel1, rNSel1, cNSel2, rNSel2) = 0, rTx1, len(ed.get_text_line(rTx2 - 2)), rTx2 - 2 elif do_uncmt: # UnComment! ed.delete(cTx2 - len(end_sgn), rTx2, cTx2, rTx2) #! true delete sequence ed.delete(cTx1, rTx1, cTx1 + len(bgn_sgn), rTx1) #! true delete sequence if False: pass elif rTx1 == rTx2: # sel into one row (cNSel1, rNSel1, cNSel2, rNSel2 ) = cTx1, rTx1, cTx2 - len(bgn_sgn) - len(end_sgn), rTx2 elif rTx1 != rTx2: # sel ends on diff rows (cNSel1, rNSel1, cNSel2, rNSel2) = cTx1, rTx1, cTx2 - len(end_sgn), rTx2 pass #LOG and log('bDrtSel, (cNSel1, rNSel1), (cNSel2, rNSel2)={}', (bDrtSel, (cNSel1, rNSel1), (cNSel2, rNSel2))) if bDrtSel: ed.set_caret(cNSel2, rNSel2, cNSel1, rNSel1, app.CARET_SET_INDEX + icrt) else: ed.set_caret(cNSel1, rNSel1, cNSel2, rNSel2, app.CARET_SET_INDEX + icrt) #for icrt bSkip = get_opt('comment_move_down', True) if False: pass elif 1 == len(crts) and bEmpSel and bUseFLn and bSkip: _move_caret_down(cCrt, rCrt) if bOnlyLn and not do_uncmt: crt = ed.get_carets()[0] _move_caret_down(crt[0], crt[1]) crt = ed.get_carets()[0] _move_caret_down(crt[0], crt[1])
def cmt_toggle_stream(self): ''' ''' if ed.get_sel_mode() != app.SEL_NORMAL: return app.msg_status(f(_('{} works only with normal selection'), _('Commenting'))) lex = ed.get_prop(app.PROP_LEXER_CARET) ((bgn_sgn ,end_sgn) ,bOnlyLn)=self._get_cmt_pair(lex) if not bgn_sgn: return app.msg_status(f(_('No stream comment for lexer "{}"'), lex)) bUseFLn = apx.get_opt('comment_full_line_if_no_sel', True) crts = ed.get_carets() pass; #LOG and log('lex, get_carets()={}', (lex, crts)) pass; #LOG and log('(bgn_sgn,end_sgn),bOnlyLn,bUseFLn={}', ((bgn_sgn,end_sgn),bOnlyLn,bUseFLn)) for icrt, (cCrt, rCrt, cEnd, rEnd) in enumerate(crts): pass; #LOG and log('(cCrt, rCrt), (cEnd, rEnd)={}', ((cCrt, rCrt), (cEnd, rEnd))) bEmpSel = -1==rEnd bDrtSel = -1==rEnd or (rCrt, cCrt)>(rEnd, cEnd) if False:pass elif bEmpSel and (bUseFLn or bOnlyLn): # Use full line line = ed.get_text_line(rCrt) (cTx1, rTx1), (cTx2, rTx2) = (0, rCrt), (len(line), rCrt) elif bOnlyLn: # and not bEmpSel # Only full lines rTx1, rTx2 = apx.minmax(rCrt, rEnd) line = ed.get_text_line(rTx2) (cTx1, rTx1), (cTx2, rTx2) = (0, rTx1), (len(line), rTx2) elif bEmpSel: # and not bUseFLn and not bOnlyLn continue else: (rTx1, cTx1), (rTx2, cTx2) = apx.minmax((rCrt, cCrt), (rEnd, cEnd)) selTx = ed.get_text_substr(cTx1, rTx1, cTx2, rTx2) pass; #LOG and log('(rTx1, cTx1), (rTx2, cTx2), selTx={}', ((rTx1, cTx1), (rTx2, cTx2), repr(selTx))) do_uncmt= selTx.startswith(bgn_sgn) and selTx.endswith(end_sgn) pass; #LOG and log('do_uncmt={}', (do_uncmt)) if False:pass elif not do_uncmt and bOnlyLn: # Comment! ed.insert(0, rTx2+1, end_sgn+'\n') #! true insert sequence ed.insert(0, rTx1, bgn_sgn+'\n') #! true insert sequence (cNSel1, rNSel1 ,cNSel2, rNSel2) = 0, rTx1, len(end_sgn), rTx2+2 elif not do_uncmt: # Comment! ed.insert(cTx2, rTx2, end_sgn) #! true insert sequence ed.insert(cTx1, rTx1, bgn_sgn) #! true insert sequence if False:pass elif rTx1==rTx2: # sel into one row (cNSel1, rNSel1 ,cNSel2, rNSel2) = cTx1, rTx1, cTx2+len(bgn_sgn)+len(end_sgn), rTx2 elif rTx1!=rTx2: # sel ends on diff rows (cNSel1, rNSel1 ,cNSel2, rNSel2) = cTx1, rTx1, cTx2 +len(end_sgn), rTx2 elif do_uncmt and bOnlyLn: # UnComment! ed.delete(0, rTx2, 0, rTx2+1) #! true delete sequence ed.delete(0, rTx1, 0, rTx1+1) #! true delete sequence (cNSel1, rNSel1 ,cNSel2, rNSel2) = 0, rTx1, len(ed.get_text_line(rTx2-2)), rTx2-2 elif do_uncmt: # UnComment! ed.delete(cTx2-len(end_sgn), rTx2, cTx2, rTx2) #! true delete sequence ed.delete(cTx1, rTx1, cTx1+len(bgn_sgn), rTx1) #! true delete sequence if False:pass elif rTx1==rTx2: # sel into one row (cNSel1, rNSel1 ,cNSel2, rNSel2) = cTx1, rTx1, cTx2-len(bgn_sgn)-len(end_sgn), rTx2 elif rTx1!=rTx2: # sel ends on diff rows (cNSel1, rNSel1 ,cNSel2, rNSel2) = cTx1, rTx1, cTx2 -len(end_sgn), rTx2 pass; #LOG and log('bDrtSel, (cNSel1, rNSel1), (cNSel2, rNSel2)={}', (bDrtSel, (cNSel1, rNSel1), (cNSel2, rNSel2))) if bDrtSel: ed.set_caret(cNSel2, rNSel2, cNSel1, rNSel1, app.CARET_SET_INDEX+icrt) else: ed.set_caret(cNSel1, rNSel1, cNSel2, rNSel2, app.CARET_SET_INDEX+icrt) #for icrt bSkip = apx.get_opt('comment_move_down', True) if False:pass elif 1==len(crts) and bEmpSel and bUseFLn and bSkip: apx._move_caret_down(cCrt, rCrt) if bOnlyLn and not do_uncmt: crt=ed.get_carets()[0]; apx._move_caret_down(crt[0], crt[1]) crt=ed.get_carets()[0]; apx._move_caret_down(crt[0], crt[1])
def cmt_toggle_stream(self): ''' ''' if ed.get_sel_mode() != app.SEL_NORMAL: return app.msg_status(f(_('{} works only with normal selection'), _('Commenting'))) lex = ed.get_prop(app.PROP_LEXER_CARET) ((bgn_sgn ,end_sgn) ,bOnlyLn)=self._get_cmt_pair(lex) if not bgn_sgn: return app.msg_status(f(_('No stream comment for lexer "{}"'), lex)) bUseFLn = True crts = ed.get_carets() pass; #LOG and log('lex, get_carets()={}', (lex, crts)) pass; #LOG and log('(bgn_sgn,end_sgn),bOnlyLn,bUseFLn={}', ((bgn_sgn,end_sgn),bOnlyLn,bUseFLn)) for icrt, (cCrt, rCrt, cEnd, rEnd) in enumerate(crts): pass; #LOG and log('(cCrt, rCrt), (cEnd, rEnd)={}', ((cCrt, rCrt), (cEnd, rEnd))) bEmpSel = -1==rEnd bDrtSel = -1==rEnd or (rCrt, cCrt)>(rEnd, cEnd) bEntireLn = (rEnd>=0) and (cEnd==0) and (cCrt==0) bEntireLn1 = bEntireLn and abs(rEnd-rCrt)==1 bEntireLn2 = bEntireLn and abs(rEnd-rCrt)>1 if False:pass elif bEmpSel and (bUseFLn or bOnlyLn): # Use full line line = ed.get_text_line(rCrt) (cTx1, rTx1), (cTx2, rTx2) = (0, rCrt), (len(line), rCrt) elif bOnlyLn: # and not bEmpSel # Only full lines rTx1, rTx2 = apx.minmax(rCrt, rEnd) line = ed.get_text_line(rTx2) (cTx1, rTx1), (cTx2, rTx2) = (0, rTx1), (len(line), rTx2) elif bEmpSel: # and not bUseFLn and not bOnlyLn continue else: (rTx1, cTx1), (rTx2, cTx2) = apx.minmax((rCrt, cCrt), (rEnd, cEnd)) selTx = ed.get_text_substr(cTx1, rTx1, cTx2, rTx2) pass; #LOG and log('(rTx1, cTx1), (rTx2, cTx2), selTx={}', ((rTx1, cTx1), (rTx2, cTx2), repr(selTx))) do_uncmt= selTx.startswith(bgn_sgn) #and selTx.endswith(end_sgn) # don't check for ending of selection - for HTML and entire selected line(s) pass; #LOG and log('do_uncmt={}', (do_uncmt)) if False:pass elif not do_uncmt and bOnlyLn: # Comment! ed.insert(0, rTx2+1, end_sgn+'\n') #! true insert sequence ed.insert(0, rTx1, bgn_sgn+'\n') #! true insert sequence (cNSel1, rNSel1 ,cNSel2, rNSel2) = 0, rTx1, len(end_sgn), rTx2+2 elif not do_uncmt: # Comment! if bEntireLn1: s = ed.get_text_line(rTx1) ed.set_text_line(rTx1, bgn_sgn+s+end_sgn) (cNSel1, rNSel1 ,cNSel2, rNSel2) = (0, rTx1, 0, rTx2) elif bEntireLn2: ed.insert(0, rTx2, end_sgn+'\n') ed.insert(0, rTx1, bgn_sgn+'\n') (cNSel1, rNSel1 ,cNSel2, rNSel2) = (0, rTx1, 0, rTx2+2) else: ed.insert(cTx2, rTx2, end_sgn) #! true insert sequence ed.insert(cTx1, rTx1, bgn_sgn) #! true insert sequence if False:pass elif rTx1==rTx2: # sel into one row (cNSel1, rNSel1 ,cNSel2, rNSel2) = cTx1, rTx1, cTx2+len(bgn_sgn)+len(end_sgn), rTx2 elif rTx1!=rTx2: # sel ends on diff rows (cNSel1, rNSel1 ,cNSel2, rNSel2) = cTx1, rTx1, cTx2 +len(end_sgn), rTx2 elif do_uncmt and bOnlyLn: # UnComment! ed.delete(0, rTx2, 0, rTx2+1) #! true delete sequence ed.delete(0, rTx1, 0, rTx1+1) #! true delete sequence (cNSel1, rNSel1 ,cNSel2, rNSel2) = 0, rTx1, len(ed.get_text_line(rTx2-2)), rTx2-2 elif do_uncmt: # UnComment! if selTx.endswith(end_sgn): ed.delete(cTx2-len(end_sgn), rTx2, cTx2, rTx2) #! true delete sequence ed.delete(cTx1, rTx1, cTx1+len(bgn_sgn), rTx1) #! true delete sequence if False:pass elif rTx1==rTx2: # sel into one row (cNSel1, rNSel1 ,cNSel2, rNSel2) = cTx1, rTx1, cTx2-len(bgn_sgn)-len(end_sgn), rTx2 elif rTx1!=rTx2: # sel ends on diff rows (cNSel1, rNSel1 ,cNSel2, rNSel2) = cTx1, rTx1, cTx2 -len(end_sgn), rTx2 elif bEntireLn1: s = ed.get_text_line(rTx1) if s.startswith(bgn_sgn): s = s[len(bgn_sgn):] if s.endswith(end_sgn): s = s[:-len(end_sgn)] ed.set_text_line(rTx1, s) (cNSel1, rNSel1 ,cNSel2, rNSel2) = (0, rTx1, 0, rTx2) elif bEntireLn2: ed.delete(0, rTx2-1, 0, rTx2) ed.delete(0, rTx1, 0, rTx1+1) (cNSel1, rNSel1 ,cNSel2, rNSel2) = (0, rTx1, 0, rTx2-2) pass; #LOG and log('bDrtSel, (cNSel1, rNSel1), (cNSel2, rNSel2)={}', (bDrtSel, (cNSel1, rNSel1), (cNSel2, rNSel2))) if bDrtSel: ed.set_caret(cNSel2, rNSel2, cNSel1, rNSel1, app.CARET_SET_INDEX+icrt) else: ed.set_caret(cNSel1, rNSel1, cNSel2, rNSel2, app.CARET_SET_INDEX+icrt) #for icrt bSkip = apx.get_opt('comment_move_down', True) if False:pass elif 1==len(crts) and bEmpSel and bUseFLn and bSkip: apx._move_caret_down(cCrt, rCrt) if bOnlyLn and not do_uncmt: crt=ed.get_carets()[0]; apx._move_caret_down(crt[0], crt[1]) crt=ed.get_carets()[0]; apx._move_caret_down(crt[0], crt[1])