Skip to content

Commit

Permalink
ver-1.0.2
Browse files Browse the repository at this point in the history
Adapt to groups as 1P2HORZ
Add "Cur line to center" and "Align by separator"
  • Loading branch information
kvichans committed Feb 3, 2016
1 parent 48a720d commit cb09663
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 13 deletions.
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ def less_main_grp(self): return RLS._move_splitter('main', 0.
def more_curr_grp(self): return RLS._move_splitter('curr', 1.05)
def less_curr_grp(self): return RLS._move_splitter('curr', 0.95)
def edit_strcomment_chars(self): return RLS.edit_strcomment_chars()
def scroll_to_center(self): return RLS.scroll_to_center()
def align_in_lines_by_sep(self): return RLS.align_in_lines_by_sep()
#class Command
104 changes: 93 additions & 11 deletions cd_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Authors:
Andrey Kvichansky (kvichans on github.com)
Version:
'1.0.1 2016-01-22'
'1.0.2 2016-02-03'
ToDo: (see end of file)
'''

Expand All @@ -26,6 +26,9 @@
NO_LEXER = "No lexer"
UPDATE_FILE = "File '{}' is updated"
USE_NOT_EMPTY = "Set not empty values"
ONLY_FOR_ML_SEL = "{} works with multiline selection"
NO_SPR_IN_LINES = "No seperator '{}' in selected lines"
DONT_NEED_CHANGE = "Dont need any changes"

pass; # Logging
pass; #from pprint import pformat
Expand Down Expand Up @@ -86,6 +89,9 @@ def _file_open(op_file):
#def _file_open

class Command:
def __init__(self):
self.data4_align_in_lines_by_sep = ''

def on_console_nav(self, ed_self, text):
pass; #LOG and log('text={}',text)
match = re.match('.*File "([^"]+)", line (\d+)', text) ##?? variants?
Expand Down Expand Up @@ -425,6 +431,7 @@ def _move_splitter(self, what, factor):
id_splt = 'B'

else: # Groups
# [('G'+str(i), list(zip(('|','V','P','F'), app.app_proc(app.PROC_GET_SPLIT, 'G'+str(i))))) for i in (1,2,3)]
# 2HORZ 0 G1 1
# 2VERT 0
# G1
Expand All @@ -435,9 +442,12 @@ def _move_splitter(self, what, factor):
# 1
# G2
# 2
# 3PLUS 0 G3 1
# 1P2VERT 0 G3 1
# G2
# 2
# 1P2HORZ 0
# G3
# 1 G2 2
# 4HORZ 0 G1 1 G2 2 G3 3
# 4VERT 0
# G1
Expand All @@ -459,9 +469,16 @@ def _move_splitter(self, what, factor):
return # No splitter

elif (what=='main'
and grouping!=app.GROUPS_3PLUS): id_splt = 'G1'
# and grouping!=app.GROUPS_3PLUS): id_splt = 'G1'
and grouping!=app.GROUPS_1P2VERT
and grouping!=app.GROUPS_1P2HORZ): id_splt = 'G1'

elif (what=='main'
# and grouping==app.GROUPS_3PLUS): id_splt = 'G3'
and grouping==app.GROUPS_1P2VERT): id_splt = 'G3'

elif (what=='main'
and grouping==app.GROUPS_3PLUS): id_splt = 'G3'
and grouping==app.GROUPS_1P2HORZ): id_splt = 'G3'

# what=='curr'
elif cur_grp==0:
Expand All @@ -470,7 +487,9 @@ def _move_splitter(self, what, factor):
elif grouping==app.GROUPS_2VERT: id_splt = 'G1' # h-self
elif grouping==app.GROUPS_3HORZ: id_splt = 'G1' # w-self
elif grouping==app.GROUPS_3VERT: id_splt = 'G1' # h-self
elif grouping==app.GROUPS_3PLUS: id_splt = 'G3' # w-self
# elif grouping==app.GROUPS_3PLUS: id_splt = 'G3' # w-self
elif grouping==app.GROUPS_1P2VERT: id_splt = 'G3' # w-self
elif grouping==app.GROUPS_1P2HORZ: id_splt = 'G3' # h-self
elif grouping==app.GROUPS_4HORZ: id_splt = 'G1' # w-self
elif grouping==app.GROUPS_4VERT: id_splt = 'G1' # h-self
elif grouping==app.GROUPS_4GRID: id_splt = 'G1' # w-self
Expand All @@ -482,7 +501,9 @@ def _move_splitter(self, what, factor):
elif grouping==app.GROUPS_2VERT: id_splt ='-G1' # h-top
elif grouping==app.GROUPS_3HORZ: id_splt = 'G2' # w-self
elif grouping==app.GROUPS_3VERT: id_splt = 'G2' # h-self
elif grouping==app.GROUPS_3PLUS: id_splt = 'G2' # h-self
# elif grouping==app.GROUPS_3PLUS: id_splt = 'G2' # h-self
elif grouping==app.GROUPS_1P2VERT: id_splt = 'G2' # h-self
elif grouping==app.GROUPS_1P2HORZ: id_splt = 'G2' # w-self
elif grouping==app.GROUPS_4HORZ: id_splt = 'G2' # w-self
elif grouping==app.GROUPS_4VERT: id_splt = 'G2' # h-self
elif grouping==app.GROUPS_4GRID: id_splt ='-G1' # w-left
Expand All @@ -492,7 +513,9 @@ def _move_splitter(self, what, factor):
if False:pass
elif grouping==app.GROUPS_3HORZ: id_splt ='-G2' # w-left
elif grouping==app.GROUPS_3VERT: id_splt ='-G2' # h-top
elif grouping==app.GROUPS_3PLUS: id_splt ='-G2' # h-top
# elif grouping==app.GROUPS_3PLUS: id_splt ='-G2' # h-top
elif grouping==app.GROUPS_1P2VERT: id_splt ='-G2' # h-top
elif grouping==app.GROUPS_1P2HORZ: id_splt ='-G2' # w-left
elif grouping==app.GROUPS_4HORZ: id_splt = 'G3' # w-self
elif grouping==app.GROUPS_4VERT: id_splt = 'G3' # h-self
elif grouping==app.GROUPS_4GRID: id_splt = 'G2' # w-self
Expand Down Expand Up @@ -638,6 +661,65 @@ def edit_strcomment_chars(self):
app.msg_status(UPDATE_FILE.format(usr_lexs_json))
#def edit_strcomment_chars

def scroll_to_center(self):
#wraped = apx.get_opt('wrap_mode', False, apx.CONFIG_LEV_FILE)
#last_on_top = apx.get_opt('show_last_line_on_top', False)
txt_lines = ed.get_line_count()
old_top_line= ed.get_top()
scr_lines = ed.get_prop(app.PROP_VISIBLE_LINES)
crt_line = ed.get_carets()[0][1]

new_top_line= crt_line - int(scr_lines/2)
new_top_line= max(new_top_line, 0)
new_top_line= min(new_top_line, txt_lines-1)
pass; #LOG and log('cur, old, new, scr={}',(crt_line, old_top_line, new_top_line, scr_lines))

if new_top_line!=old_top_line:
ed.set_top(new_top_line)
#def scroll_to_center

def align_in_lines_by_sep(self):
''' Add spaces for aline text in some lines
Example. Start lines
a= 0
b
c = 1
Aligned lines
a = 0
b
c = 1
'''
crts = ed.get_carets()
if len(crts)>1:
return app.msg_status(ONLY_SINGLE_CRT.format('Command'))
(cCrt, rCrt
,cEnd, rEnd) = crts[0]
if rEnd==-1 or rEnd==rCrt:
return app.msg_status(ONLY_FOR_ML_SEL.format('Command'))
spr = app.dlg_input('Enter separator string', self.data4_align_in_lines_by_sep)
spr = spr.strip()
if not spr:
return # Esc
self.data4_align_in_lines_by_sep = spr
((rTx1, cTx1)
,(rTx2, cTx2)) = apx.minmax((rCrt, cCrt), (rEnd, cEnd))
ls_txt = ed.get_text_substr(0,rTx1, 0,rTx2+(0 if 0==cEnd else 1))
if spr not in ls_txt:
return app.msg_status(NO_SPR_IN_LINES.format(spr))
lines = ls_txt.splitlines()
ln_poss = [(ln, ln.find(spr)) for ln in lines]
max_pos = max([p for (l,p) in ln_poss])
if max_pos== min([p if p>=0 else max_pos for (l,p) in ln_poss]):
return app.msg_status(DONT_NEED_CHANGE)
nlines = [ln if pos==-1 or max_pos==pos else
ln[:pos]+' '*(max_pos-pos)+ln[pos:]
for (ln,pos) in ln_poss
]
ed.delete(0,rTx1, 0,rTx2+(0 if 0==cEnd else 1))
ed.insert(0,rTx1, '\n'.join(nlines)+'\n')
ed.set_caret(0,rTx1+len(nlines), 0, rTx1)
#def align_in_lines_by_sep

#class Command

def find_matching_char(ed4find, cStart, rStart, opn2cls={'[':']', '{':'}', '(':')', '<':'>', '«':'»'}):
Expand Down Expand Up @@ -747,10 +829,10 @@ def get_word_or_quoted(text, start, not_word_chars='[](){}', quot_chars="'"+'"')
[-][kv-kv][20nov15] CopyTerm, ReplaceTerm
[-][kv-kv][20nov15] Comment/uncomment before cur term (or fix col?)
[+][kv-kv][24nov15] Wrap for "Find string from clipboard"
[ ][kv-kv][25nov15] Replace all as selected to cb-string: replace_all_sel_to_cb
[+][kv-kv][25nov15] Replace all as selected to cb-string: replace_all_sel_to_cb
[+][kv-kv][25nov15] Open selected file: open_selected
[+][kv-kv][25nov15] Catch on_console_nav
[ ][kv-kv][26nov15] Scroll on_console_nav, Find*
[ ][at-kv][09dec15] Refactor: find_pair
[ ][kv-kv][15dec15] Find cb-string via cmd_FinderAction (for use next/prev after)
[+][kv-kv][26nov15] Scroll on_console_nav, Find*
[+][at-kv][09dec15] Refactor: find_pair
[+][kv-kv][15dec15] Find cb-string via cmd_FinderAction (for use next/prev after)
'''
16 changes: 14 additions & 2 deletions install.inf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ menu=0

[item6]
section=commands
caption=CudaExt: Find clipboard string: prev
caption=CudaExt: Find clipboard string: previous
method=find_cb_string_prev
menu=0

Expand Down Expand Up @@ -165,7 +165,7 @@ method=to_next_tab
menu=0
[item31]
section=commands
caption=CudaExt: Activate prev tab (global loop)
caption=CudaExt: Activate previous tab (global loop)
method=to_prev_tab
menu=0

Expand Down Expand Up @@ -215,3 +215,15 @@ section=commands
caption=CudaExt: Edit stream comment chars for lexer
method=edit_strcomment_chars
menu=0

[item60]
section=commands
caption=CudaExt: Scroll current line to screen center
method=scroll_to_center
menu=0

[item70]
section=commands
caption=CudaExt: Align in lines by separator
method=align_in_lines_by_sep
menu=0
4 changes: 4 additions & 0 deletions readme/history.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.0.2 (2016-02-03)
added: Scroll cur line to screen center
added: Align in lines by separator

1.0.1 (2016-01-22)
change: rename cmds with "CudaExt: ..."

Expand Down

0 comments on commit cb09663

Please sign in to comment.