-
Notifications
You must be signed in to change notification settings - Fork 4
/
cd_fif_api.py
1592 lines (1515 loc) · 73.8 KB
/
cd_fif_api.py
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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
''' Plugin for CudaText editor
Authors:
Andrey Kvichansky (kvichans on github.com)
Version:
'3.1.21 2023-12-27'
ToDo: (see end of file)
'''
import re, os, sys, locale, json, collections, traceback, time
from datetime import datetime, timedelta
from fnmatch import fnmatch
import cudatext as app
from cudatext import ed
import cudax_lib as apx
from .cd_plug_lib import *
from chardet.universaldetector import UniversalDetector
OrdDict = collections.OrderedDict
CFG_FILE= 'cuda_find_in_files.json'
get_opt = lambda opt, defv=None: apx.get_opt(opt, defv, user_json=CFG_FILE)
pass; Tr.to_file= get_opt('fif_log_file', '')
pass; #Tr.tr = Tr(get_opt('fif_log_file', '')) if get_opt('fif_log_file', '') else Tr.tr
pass; LOG = (-1== 1) or get_opt('fif_LOG' , False) # Do or dont logging.
pass; FNDLOG = (-2== 2) and LOG or get_opt('fif_FNDLOG', False)
pass; RPTLOG = (-3== 3) and LOG or get_opt('fif_RPTLOG', False)
pass; NAVLOG = (-4== 4) and LOG or get_opt('fif_NAVLOG', False)
pass; DBG_DATA_TO_REPORT = get_opt('fif_DBG_data_to_report', False)
pass; from pprint import pformat
pass; pf=lambda d:pformat(d,width=150)
pass; ##!! waits correction
_ = get_translation(__file__) # I18N
_statusbar = None
def use_statusbar(st):
global _statusbar
_statusbar = st
def msg_status(msg, process_messages=True):
pass; #log('###',())
if _statusbar:
app.statusbar_proc(_statusbar, app.STATUSBAR_SET_CELL_TEXT, tag=1, value=msg)
if process_messages:
app.app_idle()
else:
app.msg_status(msg, process_messages)
RPT_FIND_SIGN = _('+Search')
RPT_REPL_SIGN = _('+Replace')
IN_PROJ_FOLDS = _('<Project Folders>')
IN_OPEN_FILES = _('<Open Files>')
root_is_proj = lambda rt: (rt[:2]+rt[-1]).upper() in ('<P>')
root_is_tabs = lambda rt: (rt[:2]+rt[-1]).upper() in ('<O>', '<T>')
roots_is_proj = lambda rts:1==len(rts) and root_is_proj(rts[0])
roots_is_tabs = lambda rts:1==len(rts) and root_is_tabs(rts[0])
TOTB_USED_TAB = _('<prior tab>')
TOTB_NEW_TAB = _('<new tab>')
SHTP_SHORT_R = _('path(r):line')
SHTP_SHORT_RCL = _('path(r:c:l):line')
SHTP_SHRTS_R = _('path/(r):line')
SHTP_SHRTS_RCL = _('path/(r:c:l):line')
SHTP_MIDDL_R = _('dir/file(r):line')
SHTP_MIDDL_RCL = _('dir/file(r:c:l):line')
SHTP_SPARS_R = _('dir/file/(r):line')
SHTP_SPARS_RCL = _('dir/file/(r:c:l):line')
ENCO_DETD = _('detect')
lexers_l = get_opt('fif_lexers' , ['Search results', 'FiF'])
FIF_LEXER = apx.choose_avail_lexer(lexers_l) #select_lexer(lexers_l)
lexers_l = list(map(lambda s: s.upper(), lexers_l))
def fit_mark_style_for_attr(js:dict)->dict:
""" Convert
{"color_back":"", "color_font":"", "font_bold":false, "font_italic":false
,"color_border":"", "borders":{"l":"","r":"","b":"","t":""}}
to dict with params for call ed.attr
(color_bg=COLOR_NONE, color_font=COLOR_NONE, font_bold=0, font_italic=0,
color_border=COLOR_NONE, border_left=0, border_right=0, border_down=0, border_up=0)
"""
V_L = ['solid', 'dash', '2px', 'dotted', 'rounded', 'wave']
shex2int= apx.html_color_to_int
kwargs = {}
if js.get('color_back' , ''): kwargs['color_bg'] = shex2int(js['color_back'])
if js.get('color_font' , ''): kwargs['color_font'] = shex2int(js['color_font'])
if js.get('color_border', ''): kwargs['color_border'] = shex2int(js['color_border'])
if js.get('font_bold' , False):kwargs['font_bold'] = 1
if js.get('font_italic' , False):kwargs['font_italic'] = 1
jsbr = js.get('borders', {})
if jsbr.get('left' , ''): kwargs['border_left'] = V_L.index(jsbr['left' ])+1
if jsbr.get('right' , ''): kwargs['border_right'] = V_L.index(jsbr['right' ])+1
if jsbr.get('bottom', ''): kwargs['border_down'] = V_L.index(jsbr['bottom'])+1
if jsbr.get('top' , ''): kwargs['border_up'] = V_L.index(jsbr['top' ])+1
pass; #log("kwargs={}",(kwargs))
return kwargs
#def fit_mark_style_for_attr
def api_reload_opts():
global LOG, FNDLOG, RPTLOG, NAVLOG, DBG_DATA_TO_REPORT
pass; LOG = (-1== 1) or get_opt('fif_LOG' , False) # Do or dont logging.
pass; FNDLOG = (-2== 2) and LOG or get_opt('fif_FNDLOG', False)
pass; RPTLOG = (-3== 3) and LOG or get_opt('fif_RPTLOG', False)
pass; NAVLOG = (-4== 4) and LOG or get_opt('fif_NAVLOG', False)
pass; DBG_DATA_TO_REPORT = get_opt('fif_DBG_data_to_report', False)
global FIF_LEXER,lexers_l,USE_SEL_ON_START,ESC_FULL_STOP,REPORT_FAIL,FOLD_PREV_RES,LEN_TRG_IN_TITLE
global BLOCKSIZE,CONTEXT_WIDTH,SKIP_FILE_SIZE,AUTO_SAVE,FOCUS_TO_RPT,SAVE_REQ_TO_RPT,TAB_SIZE_IN_RPT
global MARK_FIND_STYLE,MARK_TREPL_STYLE,MARK_FREPL_STYLE
global ALWAYS_EXCL,STORE_PREV_RSLT
lexers_l = get_opt('fif_lexers' , ['Search results', 'FiF'])
FIF_LEXER = apx.choose_avail_lexer(lexers_l) #select_lexer(lexers_l)
lexers_l = list(map(lambda s: s.upper(), lexers_l))
USE_SEL_ON_START= get_opt('fif_use_selection_on_start' , False)
ESC_FULL_STOP = get_opt('fif_esc_full_stop' , False)
REPORT_FAIL = get_opt('fif_report_no_matches' , False)
FOLD_PREV_RES = get_opt('fif_fold_prev_res' , False)
LEN_TRG_IN_TITLE= get_opt('fif_len_target_in_title' , 10)
BLOCKSIZE = get_opt('fif_read_head_size(bytes)' , get_opt('fif_read_head_size', 1024))
CONTEXT_WIDTH = get_opt('fif_context_width' , 1)
SKIP_FILE_SIZE = get_opt('fif_skip_file_size_more_Kb' , 0)
AUTO_SAVE = get_opt('fif_auto_save_if_file' , False)
FOCUS_TO_RPT = get_opt('fif_focus_to_rpt' , True)
SAVE_REQ_TO_RPT = get_opt('fif_save_request_to_rpt' , False)
TAB_SIZE_IN_RPT = get_opt('fif_lexer_auto_tab_size' , 2)
MARK_FIND_STYLE = get_opt('fif_mark_style' , {'borders':{'bottom':'dotted'}})
MARK_TREPL_STYLE= get_opt('fif_mark_true_replace_style' , {'borders':{'bottom':'solid'}})
MARK_FREPL_STYLE= get_opt('fif_mark_false_replace_style', {'borders':{'bottom':'wave'},'color_border':'#777'})
MARK_FIND_STYLE = fit_mark_style_for_attr(MARK_FIND_STYLE)
MARK_TREPL_STYLE= fit_mark_style_for_attr(MARK_TREPL_STYLE)
MARK_FREPL_STYLE= fit_mark_style_for_attr(MARK_FREPL_STYLE)
ALWAYS_EXCL = get_opt('fif_always_not_in_files' , '/.svn /.git /.hg /.idea')
STORE_PREV_RSLT = get_opt('fif_store_prev_results' , True)
pass; #log("STORE_PREV_RSLT={}",(STORE_PREV_RSLT))
#def api_reload_opts
api_reload_opts()
if 'sw'==app.__name__:
FOLD_PREV_RES = False
REQ_KEY = (' '*100)+'_req_info_='
def report_extract_request(red):
""" Extract first(!) request info from the report.
If no req-info return ('', None)
Return (what, opts)
"""
line_req = red.get_text_line(0) # First
if REQ_KEY not in line_req: return None
req_opts= line_req[line_req.index(REQ_KEY)+len(REQ_KEY):]
return req_opts
#def report_extract_request
SPRTR = -0xFFFFFFFF
last_ed_num = 0
last_rpt_tid= None
def report_to_tab(rpt_data:dict
, rpt_info:dict
, rpt_type:dict
, how_walk:dict
, what_find:dict
, what_save:dict
, progressor=None
, req_opts=None):
pass; LOG and log('(== |paths|={}',len(rpt_data))
pass; RPTLOG and log('rpt_type={}',rpt_type)
pass; #RPTLOG and log('rpt_data=¶{}',pf(rpt_data))
pass; #RPTLOG and log('what_find={}',what_find)
pass; #RPTLOG and log('what_save={}',what_save)
global last_ed_num, last_rpt_tid
# Choose/Create tab for report
rpt_ed = rpt_type.get('rpt_to_ed')
if 'rpt_to_ed' in rpt_type: rpt_ed.set_prop(app.PROP_RO, False)
def create_new(_title_ext='')->app.Editor:
app.file_open('')
new_ed = ed
new_ed.set_prop(app.PROP_ENC, 'UTF-8')
pass; #log("_title_ext={}",(_title_ext))
new_ed.set_prop(app.PROP_TAB_TITLE, _('Results')+_title_ext) #??
return new_ed
title_ext = f(' ({})', what_find['find'][:LEN_TRG_IN_TITLE])
if False:pass
elif rpt_ed: pass
elif rpt_type['totb']==TOTB_NEW_TAB:
pass; RPTLOG and log('!new',)
rpt_ed = create_new(title_ext)
elif rpt_type['totb']==TOTB_USED_TAB: #if reed_tab: #or join_to_end:
# Try to use prev or old
pass; RPTLOG and log('!used',)
olds = []
for h in app.ed_handles():
try_ed = app.Editor(h)
ed_tag = try_ed.get_prop(app.PROP_TAG, '')
ed_id = try_ed.get_prop(app.PROP_TAB_ID)
ed_lxr = try_ed.get_prop(app.PROP_LEXER_FILE, '')
pass; #RPTLOG and log('tit, ed_tag={}',(try_ed.get_prop(app.PROP_TAB_TITLE), ed_tag))
if ed_tag.startswith('FiF_') or ed_lxr.upper() in lexers_l:
olds+= [(ed_tag, ed_id)]
if ed_tag == 'FiF_'+str(last_ed_num):
rpt_ed = try_ed
pass; #RPTLOG and log('found ed',)
break #for h
pass; #RPTLOG and log('found={}',)
if rpt_ed is None and olds:
rpt_ed = apx.get_tab_by_id(max(olds)[1]) # last used ed
pass; #RPTLOG and log('get from olds',)
elif rpt_type['totb'].startswith('tab:'): #if reed_tab: #or join_to_end:
# Try to use pointed tab
the_title = rpt_type['totb'][len('tab:'):]
pass; RPTLOG and log('!pointed the_title={}',(the_title))
cands = [app.Editor(h) for h in app.ed_handles()
if app.Editor(h).get_prop(app.PROP_TAB_TITLE)==the_title]
rpt_ed = cands[0] if cands else None
elif rpt_type['totb'].startswith('file:'):
# Try to use pointed file
the_file = rpt_type['totb'][len('file:'):]
pass; RPTLOG and log('!pointed the_file={}',(the_file))
if os.path.isfile(the_file):
cands = [app.Editor(h) for h in app.ed_handles()
if app.Editor(h).get_filename()==the_file]
if cands:
rpt_ed = cands[0]
else:
app.file_open(the_file)
rpt_ed = ed
else:
pass; RPTLOG and log('!else',())
pass
rpt_ed = create_new(title_ext) if rpt_ed is None else rpt_ed
last_rpt_tid= rpt_ed.get_prop(app.PROP_TAB_ID)
if rpt_ed.get_filename():
rpt_ed.set_prop(app.PROP_TAB_TITLE, os.path.basename(rpt_ed.get_filename())+title_ext) #??
last_ed_num += 1
rpt_ed.set_prop(app.PROP_TAG, 'FiF_'+str(last_ed_num))
rpt_ed.focus() if FOCUS_TO_RPT else None
# Prepare tab
if not rpt_type['join']:
rpt_ed.set_text_all('')
rpt_ed.attr( app.MARKERS_DELETE_ALL)
# Fold prev res
if rpt_type['join'] and FOLD_PREV_RES: #?and rpt_ed.get_prop(app.PROP_GUTTER_FOLD)
pass; RPTLOG and log('?? fold',)
fold_all_roots(rpt_ed, RPT_REPL_SIGN, RPT_FIND_SIGN)
pass; RPTLOG and log('ok fold',)
# Fill tab
# rpt_ed.set_prop(app.PROP_LEXER_FILE,'') #?? optimized?
def mark_fragment(rw:int, cl:int, ln:int, to_ed=rpt_ed, style=MARK_FIND_STYLE):
pass; #RPTLOG and log('rw={}',rw)
to_ed.attr( app.MARKERS_ADD
, x=cl, y=rw, len=ln
, **style
)
def append_line(line:str, to_ed=rpt_ed)->int:
''' Append one line to end of to_ed. Return row of added line.'''
pass; #RPTLOG and log('line={}',repr(line))
line = line.rstrip('\r\n')
if to_ed.get_line_count()==1 and not to_ed.get_text_line(0):
# Empty doc
to_ed.set_text_line(0, line)
return 0
else:
to_ed.set_text_line(-1, line)
return to_ed.get_line_count()-2
#def append_line
def calc_width(_rpt_data, _algn, _need_rcl, _need_pth, _only_fn):
# Find max(len(*)) for path, row, col, ln
_fl_wd, _rw_wd, _cl_wd, _ln_wd = 0, 0, 0, 0
if not _algn:
return _fl_wd, _rw_wd, _cl_wd, _ln_wd
max_rw, max_cl, max_ln = 0, 0, 0
for _path_d in _rpt_data:
_path = _path_d['file'] if _need_pth else ''
_path = os.path.basename(_path) if _need_pth and _only_fn else _path
_fl_wd = max(_fl_wd , len(_path))
for _item in _path_d.get('items', ''):
max_rw = max(max_rw, _item.get('row', 0))
if not _need_rcl: continue#for item
max_cl = max(max_cl, _item.get('col', 0))
max_ln = max(max_ln, _item.get('ln', 0))
#for item
#for path_d
_rw_wd = len(str(max_rw))
_cl_wd = len(str(max_cl))
_ln_wd = len(str(max_ln))
return _fl_wd, _rw_wd, _cl_wd, _ln_wd
#def calc_width
# def calc_width4depth(rpt_data, algn, need_rcl, need_pth, only_fn):
# # Find max(len(*)) for path, row, col, ln
# wds = {}
## fl_wd, rw_wd, cl_wd, ln_wd = 0, 0, 0, 0
# if not algn:
# return wds # fl_wd, rw_wd, cl_wd, ln_wd
## max_rw, max_cl, max_ln = 0, 0, 0
# for path_d in rpt_data:
# dept = 1+path_d.get('dept', 0)
# wds_d = wds.setdefault(dept, {})
# path = path_d['file'] if need_pth else ''
# path = os.path.basename(path) if need_pth and only_fn else path
# wds_d['fl'] = max(wds_d.get('fl', 0), len(path))
# for item in path_d.get('items', ''):
# wds_d['max_rw'] = max(wds_d.get('max_rw', 0), item.get('row', 0))
# if not need_rcl: continue#for item
# wds_d['max_cl'] = max(wds_d.get('max_cl', 0), item.get('col', 0))
# wds_d['max_ln'] = max(wds_d.get('max_ln', 0), item.get('ln', 0))
# #for item
# #for path_d
# for wds_d in wds.values():
# wds_d['rw'] = len(str(wds_d.get('max_rw', 0)))
# wds_d['cl'] = len(str(wds_d.get('max_cl', 0)))
# wds_d['ln'] = len(str(wds_d.get('max_ln', 0)))
# return wds
# #def calc_width4depth
onfn = not what_save['count']
shtp = rpt_type['shtp']
algn = rpt_type['algn']
need_rcl= shtp in (SHTP_SHORT_RCL, SHTP_SHRTS_RCL, SHTP_MIDDL_RCL, SHTP_SPARS_RCL)
need_pth= shtp in (SHTP_SHORT_R, SHTP_SHORT_RCL, SHTP_MIDDL_R, SHTP_MIDDL_RCL)
only_fn = shtp in (SHTP_MIDDL_R, SHTP_MIDDL_RCL)
roots = how_walk['roots']
root = roots[0] if 1==len(roots) else '_no_root_'
# root = how_walk['root']
repl_b = what_find['repl'] is not None
pass; RPTLOG and log('algn, need_rcl, need_pth, only_fn={}',(algn, need_rcl, need_pth, only_fn))
fl_wd, rw_wd, cl_wd, ln_wd = calc_width( rpt_data, algn, need_rcl, need_pth, only_fn)
rw_wd += 1 if repl_b else 0
pass; RPTLOG and log('fl_wd,rw_wd,cl_wd,ln_wd={}',(fl_wd,rw_wd,cl_wd,ln_wd))
# wds = calc_width4depth( rpt_data, algn, need_rcl, need_pth, only_fn)
# pass; RPTLOG and log('wds={}',(wds))
line_1 = f(_('{} for "{}" in "{}" from {} ({} matches in {}({}) files)')
,RPT_FIND_SIGN
,what_find['find']
,how_walk['file_incl']
,(repr(roots[0]) if 1==len(roots) else repr(roots)).replace('\\\\','\\').replace("'", '"')
# ,root
,rpt_info['frgms']
,rpt_info['files']
,rpt_info['cllc_files']) \
if not repl_b else \
f(_('{} "{}" to "{}" in "{}" from {} ({} changes in {}({}) files)')
,RPT_REPL_SIGN
,what_find['find']
,what_find['repl']
,how_walk['file_incl']
,(repr(roots[0]) if 1==len(roots) else repr(roots)).replace('\\\\','\\').replace("'", '"')
# ,root
,rpt_info['frgms']
,rpt_info['files']
,rpt_info['cllc_files'])
line_1 += ' ' + REQ_KEY + req_opts if req_opts else ''
row4crt = append_line(line_1)
# rpt_ed.lock() #?? Pack undo to one cmd
rpt_stop = False
try:
for path_n, path_d in enumerate(rpt_data): #NOTE: rpt main loop
if progressor and (0==path_n%37):# or 0==rpt_ed.get_line_count()%137):
pc = int(100*path_n/len(rpt_data))
progressor.set_progress( f(_('[ESC?] Report: {}%'), pc))
if progressor.need_break():
progressor.prefix += f(_('(Report stopped on {}%) '), pc)
append_line( f('\t<{}>', progressor.prefix))
rpt_stop= True
break#for path
has_cnt = 'count' in path_d and 0<path_d['count'] # skip count==0
has_itm = 'items' in path_d
path = path_d['file']
isfl = path_d.get('isfl')
pass; RPTLOG and log('path,root={}',(path,root))
if shtp in (SHTP_SHRTS_R, SHTP_SHRTS_RCL):
pass
elif shtp in (SHTP_MIDDL_R, SHTP_MIDDL_RCL, SHTP_SPARS_R, SHTP_SPARS_RCL) and \
path!=root:
if isfl:
path= os.path.basename(path)
pass; RPTLOG and log('(basename)path={}',path)
elif 'prnt' in path_d and path_d['prnt'] is not None:
path= os.path.relpath(path, path_d['prnt']['file'])
pass; RPTLOG and log('(prnt-rel)path={}',path)
else:
path= os.path.relpath(path, root) if root!='_no_root_' else path
pass; RPTLOG and log('(root-rel)path={}',path)
dept = 1+path_d.get('dept', 0)
c9dt = c9*dept
pass; RPTLOG and log('onfn,has_cnt,isfl,has_itm,c9dt={}',(onfn,has_cnt,isfl,has_itm,repr(c9dt)))
if False:pass
elif not has_cnt and onfn and not isfl: pass
elif onfn and isfl: append_line(c9dt+'<'+path+'>')
elif has_cnt and onfn: append_line(c9dt+f('<{}>: #{}', path, path_d['count']))
elif onfn: append_line(c9dt+'<'+path+'>')
elif not has_cnt and not has_itm: pass
elif has_cnt and not has_itm: append_line(c9dt+f('<{}>: #{}', path, path_d['count']))
elif has_itm:
items = path_d['items']
prefix = ''
new_row = -1
pre_rw = -1
if shtp in (SHTP_SPARS_R, SHTP_SPARS_RCL):
append_line(c9dt+f('<{}>: #{}', os.path.basename(path), len(items)))
path= ''
c9dt= c9*(1+dept)
pass; RPTLOG and log('SPARS path,c9dt={}',(path,repr(c9dt)))
if shtp in (SHTP_SHRTS_R, SHTP_SHRTS_RCL):
append_line(c9dt+f('<{}>: #{}', path, len(items)))
path= ''
c9dt= c9*(1+dept)
pass; RPTLOG and log('SPARS path,c9dt={}',(path,repr(c9dt)))
for item_n, item in enumerate(items):
if progressor and (1000==item_n%1039):
pc = int(100*path_n/len(rpt_data))
progressor.set_progress( f(_('[ESC?] Report: {}%'), pc))
if progressor.need_break():
progressor.prefix += f(_('(Report stopped on {}%) '), pc)
append_line( f('\t<{}>', progressor.prefix))
rpt_stop= True
break#for item
pass; #RPTLOG and log('item={}',(item))
src_rw = item.get('row', 0)
if SPRTR==src_rw:
# Separator
append_line(c9dt+'<>:')
continue#for path_n
if not repl_b and \
shtp not in (SHTP_SPARS_R, SHTP_SPARS_RCL) and \
src_rw==pre_rw and prefix and new_row!=-1 and 'col' in item and 'ln' in item:
# Add mark in old line
mark_fragment(new_row, item['col']+len(prefix), item['ln'], rpt_ed)
continue#for path_n
repl_tf = item.get('res', 0)
repl_o = repl_b and repl_tf
# rw_wd = 1+rw_wd if repl_b else rw_wd
# src_rw = abs(src_rw)
src_rw_ = '=' if repl_o else '!' if repl_b else ''
pass; #LOG and log('repl_b,repl_o,rw_wd,src_rw_={}',(repl_b,repl_o,rw_wd,src_rw_))
src_cl = item.get('col', -1)
src_ln = item.get('ln', -1)
src_rw_s= src_rw_+ str(1+src_rw)
# src_cl_s= '0' if repl_o else '' if -1==src_cl else str(1+src_cl)
# src_ln_s= '0' if repl_o else '' if -1==src_ln else str( src_ln)
src_cl_s= '' if -1==src_cl else str(1+src_cl)
src_ln_s= '' if -1==src_ln else str( src_ln)
if algn:
path = path.ljust( fl_wd, ' ')
src_rw_s= src_rw_s.rjust(rw_wd, ' ')
src_cl_s= src_cl_s.rjust(cl_wd, ' ')
src_ln_s= src_ln_s.rjust(ln_wd, ' ')
prefix = c9dt+f('<{}({}:{}:{})>: ', path, src_rw_s, src_cl_s, src_ln_s) \
if need_pth and need_rcl else \
c9dt+f('<{}({})>: ' , path, src_rw_s ) \
if need_pth and not need_rcl else \
c9dt+f('<({}:{}:{})>: ' , src_rw_s, src_cl_s, src_ln_s) \
if not need_pth and need_rcl else \
c9dt+f('<({})>: ' , src_rw_s )
new_row = append_line(prefix+item.get('line',''))
pass; #RPTLOG and log('new_row, prefix={}',(new_row, prefix))
if 'col' in item and 'ln' in item:
mark_fragment(new_row, item['col']+len(prefix), item['ln'], rpt_ed
,MARK_TREPL_STYLE
if repl_tf==1 else
MARK_FREPL_STYLE
if repl_tf==2 else
MARK_FIND_STYLE)
pre_rw = src_rw
#for item
#elif has_itm
if rpt_stop: break#for path
#for path_n
except Exception:# as ex:
# log(f(_('Error:{}'),ex))
log(traceback.format_exc())
finally:
pass
# rpt_ed.unlock() #?? Pack undo to one cmd
pass; # Append work data to report
pass; DBG_DATA_TO_REPORT and rpt_ed.set_text_line(-1, '')
pass; DBG_DATA_TO_REPORT and rpt_ed.insert(0,rpt_ed.get_line_count()-1, json.dumps(rpt_type, indent=2))
pass; DBG_DATA_TO_REPORT and rpt_ed.insert(0,rpt_ed.get_line_count()-1, json.dumps(rpt_data, indent=2))
pass; #log('apx.get_opt(tab_size, 0, apx.CONFIG_LEV_LEX_ONLY, ed_cfg=None,lexer=FIF_LEXER)={}',apx.get_opt('tab_size', 0, apx.CONFIG_LEV_LEX_ONLY, ed_cfg=None,lexer=FIF_LEXER))
need_tab_size = TAB_SIZE_IN_RPT>0 and (
apx.get_opt('tab_size', 0, apx.CONFIG_LEV_LEX_ONLY, ed_cfg=None,lexer=FIF_LEXER)==0
if apx.version(0)>='0.6.5' else
apx.get_opt('tab_size', 0, apx.CONFIG_LEV_LEX, ed_cfg=None,lexer=FIF_LEXER)==
apx.get_opt('tab_size', 0, apx.CONFIG_LEV_DEF) )
pass; #log('TAB_SIZE_IN_RPT,need_tab_size={}',TAB_SIZE_IN_RPT,need_tab_size)
if need_tab_size:
apx.set_opt('tab_size', TAB_SIZE_IN_RPT, apx.CONFIG_LEV_LEX, ed_cfg=None,lexer=FIF_LEXER)
apx.set_opt('tab_size', TAB_SIZE_IN_RPT, apx.CONFIG_LEV_FILE, ed_cfg=rpt_ed)
rpt_ed.set_prop(app.PROP_LEXER_FILE, FIF_LEXER)
# # AT-hack to update folding
# line0 = rpt_ed.get_text_line(0)
# rpt_ed.set_text_line(0, '')
# rpt_ed.set_text_line(0, line0)
# app.app_idle()
if app.app_api_version()>='1.0.162':
if app.app_api_version()<'1.0.289':
pass; RPTLOG and log('rpt_ed.lexer_scan(row4crt) row4crt={}',row4crt)
rpt_ed.lexer_scan(row4crt)
else:
pass; RPTLOG and log('rpt_ed.action(app.EDACTION_LEXER_SCAN, row4crt) row4crt={}',row4crt)
rpt_ed.action(app.EDACTION_LEXER_SCAN, row4crt)
pass; #RPTLOG and log('row4crt={}',row4crt)
rpt_ed.set_caret(0, row4crt)
if AUTO_SAVE and rpt_ed.get_filename() and os.path.isfile(rpt_ed.get_filename()):
rpt_ed.save()
pass; LOG and log('==) stoped={}',(rpt_stop))
if 'rpt_to_ed' in rpt_type: rpt_ed.set_prop(app.PROP_RO, True)
#def report_to_tab
############################################
# Using report to nav
def _open_and_nav(where:str, how_act:str, path:str, rw=-1, cl=-1, ln=-1):
""" Return True if nav successed. """
pass; NAVLOG and log('where, how_act={}',(where, how_act))
pass; NAVLOG and log('path,rw,cl,ln={}',(path,rw,cl,ln))
op_ed = None
if path.startswith('tab:'):
tab_id = int(path.split('/')[0].split(':')[1])
pass; NAVLOG and log('tab_id={}',(tab_id))
op_ed = apx.get_tab_by_id(tab_id)
if not op_ed: return msg_status(f(_("No tab for navigation"), ))
elif not os.path.isfile(path):
pass; NAVLOG and log('not isfile',())
return
the_ed_id = ed.get_prop(app.PROP_TAB_ID)
the_ed_grp = ed.get_prop(app.PROP_INDEX_GROUP)
pass; NAVLOG and log('the_ed_id={}',(the_ed_id))
# Already opened?
if not op_ed:
for h in app.ed_handles():
t_ed = app.Editor(h)
if t_ed.get_filename() and os.path.samefile(path, t_ed.get_filename()):
op_ed = t_ed
pass; NAVLOG and log('found filename',())
break
if not op_ed:
# Open it
ed_grp = ed.get_prop(app.PROP_INDEX_GROUP)
grps = apx.get_groups_count() # len({app.Editor(h).get_prop(app.PROP_INDEX_GROUP) for h in app.ed_handles()})
op_grp = -1 \
if 1==grps else\
-1 \
if where=='same' else\
(ed_grp+1)%grps \
if where=='next' else\
(ed_grp-1)%grps \
if where=='prev' else\
int(where[3]) \
if where[0:3]=='gr#' else\
-1
pass; NAVLOG and log('ed_grp, grps, op_grp={}',(ed_grp, grps, op_grp))
app.file_open(path, op_grp)
op_ed = ed
op_ed.focus()
pass; NAVLOG and log('ok op_ed.focus()',())
nav_to_frag(op_ed, rw, cl, ln, how_act, indent_vert=apx.get_opt('find_indent_vert', -5, ed_cfg=op_ed))
if how_act=='move' or the_ed_grp == ed.get_prop(app.PROP_INDEX_GROUP):
op_ed.focus()
else:
the_ed = apx.get_tab_by_id(the_ed_id)
the_ed.focus()
return True
#def _open_and_nav
def nav_as(path, ed_as):
op_ed = None
if path.startswith('tab:'):
tab_id = int(path.split('/')[0].split(':')[1])
pass; NAVLOG and log('tab_id={}',(tab_id))
op_ed = apx.get_tab_by_id(tab_id)
if not op_ed: return msg_status(_("No tab for navigation"))
else:
if not os.path.isfile(path): return msg_status(_("No file for navigation"))
op_ed = ed_of_file_open(path)
if not op_ed:
app.file_open(path)
op_ed = ed
op_ed.set_caret(*ed_as.get_carets()[0])
#def nav_as
def nav_to_frag(op_ed, rw, cl, ln, how_act='', indent_vert=-5):
unfold_line(op_ed, rw)
if cl!=-1:
# op_ed.set_prop(app.PROP_COLUMN_LEFT, '0')
op_ed.set_prop(app.PROP_SCROLL_HORZ, '0')
if False:pass
elif rw==-1:
pass
elif cl==-1 and how_act=='move':
op_ed.set_caret( 0, rw)
elif cl==-1:
l_ln= len(op_ed.get_text_line(rw))
op_ed.set_caret( 0, rw, l_ln, rw) # inverted sel to show line head if window is narrow
elif ln==-1:
op_ed.set_caret( cl, rw)
else:
op_ed.set_caret( cl+ln, rw, cl, rw)
if rw!=-1:
top_row = max(0, rw - min(5, abs(indent_vert)))
op_ed.set_prop(app.PROP_LINE_TOP, top_row)
#def nav_to_frag
reSP = re.compile( r'(?P<S>\t+)' # Shift !
r'<(?P<P>[^>]+)>') # Path !
reSPR = re.compile( r'(?P<S>\t+)' # Shift !
r'<(?P<P>[^>]+)' # Path !
r'\((?P<R> *=?\d+)' # Row !
r'(?P<C>: *\d+)?' # Col?
r'(?P<L>: *\d+)?\)>')# Len?
reSR = re.compile( r'(?P<S>\t+)' # Shift !
r'<\((?P<R> *=?\d+)' # Row !
r'(?P<C>: *\d+)?' # Col?
r'(?P<L>: *\d+)?\)>')# Len?
def _parse_line(line:str, what:str)->tuple: #NOTE: nav _parse_line
pass; NAVLOG and log('what, line={}',(what, line))
if what=='SP':
mtSP = reSP.search(line)
if mtSP:
gdct= mtSP.groupdict()
pass; NAVLOG and log('ok mtSP gdct={}', gdct)
return mtSP.group(0), gdct['S'], gdct['P']
return (None,)*3
mtSR = reSR.search(line)
if mtSR:
gdct= mtSR.groupdict()
pass; NAVLOG and log('ok mtSR gdct={}', gdct)
rw = gdct['R'].lstrip(' ').lstrip('=')
cl = gdct['C']
ln = gdct['L']
return mtSR.group(0), gdct['S'], '' \
,int(rw)-1, int(cl[1:])-1 if cl else -1, int(ln[1:]) if ln else -1
mtSPR = reSPR.search(line)
if mtSPR:
gdct= mtSPR.groupdict()
pass; NAVLOG and log('ok mtSPR gdct={}', gdct)
rw = gdct['R'].lstrip(' ').lstrip('=')
cl = gdct['C']
ln = gdct['L']
return mtSPR.group(0), gdct['S'], gdct['P'].rstrip() \
,int(rw)-1, int(cl[1:])-1 if cl else -1, int(ln[1:]) if ln else -1
mtSP = reSP.search(line)
if mtSP:
gdct= mtSP.groupdict()
pass; NAVLOG and log('ok mtSP gdct={}', gdct)
return mtSP.group(0), gdct['S'], gdct['P'], -1, -1, -1
return (None,)*6
#def _parse_line
def _build_path(ted, path:str, row:int, shft:str)->str:
# Try to build path from prev lines
for t_row in range(row-1, -1, -1): #NOTE: nav build path
t_line = ted.get_text_line(t_row)
pass; NAVLOG and log('t_row, t_line={}', (t_row, t_line))
if t_line.startswith('+'): break#for t_row as top
if len(shft) <= len(t_line)-len(t_line.lstrip('\t')): continue#for t_row as same level
t_fll, \
t_sft, \
t_pth = _parse_line(t_line, 'SP')
pass; NAVLOG and log('t_sft, t_pth={}', (t_sft, t_pth))
if len(t_sft) == len(shft):
pass; NAVLOG and log('skip: t_sft==shft', ())
continue#for t_row
if len(t_sft) > len(shft):
pass; NAVLOG and log('bad: t_sft>shft', ())
return msg_status(f(_("Line {} has bad data for navigation"), 1+t_row))
path = os.path.join(t_pth, path) if path else t_pth
pass; NAVLOG and log('new path={}', (path))
if os.path.isfile(path):
break#for t_row
shft = t_sft
#for t_row
return path
#def _build_path
def get_data4nav(ted, row:int):
line = ted.get_text_line(row)
full, \
shft, \
path, \
rw,cl,ln= _parse_line(line, 'all')
pass; NAVLOG and log('full={}', full)
pass; NAVLOG and log('shft, path, rw, cl, ln={}', (shft, path, rw, cl, ln))
pass; NAVLOG and log('path={}', (path))
if not full:
pass; NAVLOG and log('return (path, rw, cl, ln)={}', ([None]*4))
return [None]*4
# if not full: return msg_status(f(_("Line {} has no data for navigation"), 1+row))
if os.path.isfile(path) or path.startswith('tab:'):
pass; NAVLOG and log('return (path, rw, cl, ln)={}', (path, rw, cl, ln))
return (path, rw, cl, ln)
# return _open_and_nav(where, how_act, path, rw, cl, ln)
path = _build_path(ted, path, row, shft)
if True: # os.path.isfile(path):
pass; NAVLOG and log('return (path, rw, cl, ln)={}', (path, rw, cl, ln))
return (path, rw, cl, ln)
# return _open_and_nav(where, how_act, path, rw, cl, ln)
# return [None]*4
#def get_data4nav
def jump_to(drct:str, what:str):
global last_rpt_tid
pass; NAVLOG and log('drct,what,last_rpt_tid={}',(drct,what,last_rpt_tid))
if not last_rpt_tid:return msg_status(_('Undefined report to jump. Fill new report or navigate with old one.'))
rpt_ed = apx.get_tab_by_id(last_rpt_tid)
if not rpt_ed: return msg_status(_('Undefined report to jump. Fill new report or navigate with old one.'))
crts = rpt_ed.get_carets()
if len(crts)>1: return msg_status(_("Command doesn't work with multi-carets"))
# last_row= crts[0][1]
all_rows= rpt_ed.get_line_count()
act_grp = ed.get_prop(app.PROP_INDEX_GROUP)
rpt_grp = rpt_ed.get_prop(app.PROP_INDEX_GROUP)
where = 'gr#'+str(act_grp)
how_act = 'move'
base_row= crts[0][1]
line = rpt_ed.get_text_line(base_row)
if line.startswith(RPT_FIND_SIGN):
base_path = '/waiting/'
base_rw = 0
else:
path,rw,\
cl, ln = get_data4nav(rpt_ed, base_row)
if not path \
or not (os.path.isfile(path) or path.startswith('tab:')):
return msg_status(f(_('Line "{}":{} has no data for navigation'), rpt_ed.get_prop(app.PROP_TAB_TITLE, ''), 1+base_row))
base_path = path
base_rw = rw
pass; NAVLOG and log('base_path,base_rw={}',(base_path,base_rw))
def set_rpt_active_row(_row):
grp_tab = app.ed_group(rpt_grp)
rpt_vis = grp_tab.get_prop(app.PROP_TAB_ID) == rpt_ed.get_prop(app.PROP_TAB_ID)
rpt_act = ed.get_prop(app.PROP_TAB_ID) == rpt_ed.get_prop(app.PROP_TAB_ID)
if rpt_vis:
rpt_ed.focus()
rpt_ed.set_caret( 0, _row)
tid = None
if rpt_vis \
and not (rpt_ed.get_prop(app.PROP_LINE_TOP) <= _row <= ed.get_prop(app.PROP_LINE_BOTTOM)):
if not rpt_act:
tid = ed.get_prop(app.PROP_TAB_ID)
rpt_ed.focus()
rpt_ed.set_prop( app.PROP_LINE_TOP, max(0, _row - max(5, apx.get_opt('find_indent_vert', -5))))
if not rpt_act:
apx.get_tab_by_id(tid).focus()
#def set_rpt_active_row
row = base_row
while True:
row += 1 if drct=='next' else -1
if not 0<=row<all_rows: return msg_status(_('No data to jump'))
line = rpt_ed.get_text_line(row)
if not line.lstrip(c9).startswith('<') \
or line.startswith(RPT_FIND_SIGN): return msg_status(_('No data to jump'))
path,rw,\
cl, ln = get_data4nav(rpt_ed, row)
pass; NAVLOG and log('path,rw={}',(path,rw))
if not path \
or not (os.path.isfile(path) or path.startswith('tab:')):
continue#while
if what=='rslt' \
and (-1==base_rw and -1==rw or -1!=base_rw and -1!=rw):
# Jump to nearest result
set_rpt_active_row(row)
return _open_and_nav(where, how_act, path, rw, cl, ln)
if what=='file' and base_path!=path \
and (-1==base_rw and -1==rw or -1!=base_rw and -1!=rw):
# Jump to result from next file
set_rpt_active_row(row)
return _open_and_nav(where, how_act, path, rw, cl, ln)
if what=='fold' \
and not base_path.startswith('tab:') \
and not path.startswith('tab:') \
and os.path.dirname(base_path)!=os.path.dirname(path) \
and (-1==base_rw and -1==rw or -1!=base_rw and -1!=rw):
# Jump to result from next folder
set_rpt_active_row(row)
return _open_and_nav(where, how_act, path, rw, cl, ln)
#while
#def jump_to
def nav_to_src(where:str, how_act='move', _ed=ed):
""" Try to open file and navigate to row[+col+sel].
Return True if nav successed.
FiF-res structure variants
+text about finding
¬<abs-path>
¬<abs-path>: info
¬<abs-path(row)>: info
¬<abs-path(row:col)>: info
¬<abs-path(row:col:len)>: info
+text about finding
¬<dir>
¬¬<rel-path(row)>: info
¬¬<rel-path(row:col)>: info
¬¬<rel-path(row:col:len)>: info
+text about finding
¬<dir>
¬¬<rel-path>
¬¬¬<(row)>: info
¬¬¬<(row:col)>: info
¬¬¬<(row:col:len)>: info
"""
global last_rpt_tid
pass; NAVLOG and log('where, how_act={}',(where, how_act))
crts = _ed.get_carets()
if len(crts)>1: return msg_status(_("Command doesn't work with multi-carets"))
last_rpt_tid= _ed.get_prop(app.PROP_TAB_ID)
row = crts[0][1]
pass; _t = get_data4nav(_ed, row)
pass; NAVLOG and log('get_data4nav(ed, row)={}',(_t))
pass; path,rw,cl,ln = _t
# path,rw,\
# cl, ln = get_data4nav(_ed, row)
if path and (os.path.isfile(path) or path.startswith('tab:')):
return _open_and_nav(where, how_act, path, rw, cl, ln)
msg_status(f(_("Line {} has no data for navigation"), 1+row))
#def nav_to_src
def fold_all_roots(rpt_ed:app.Editor, what1:str, what2:str):
# pass; RPTLOG and log('?? fold ver="{}"',app.app_api_version())
if app.app_api_version()<'1.0.162': return
# Waiting
pass; #RPTLOG and log('?? fold',)
fold_rngs = rpt_ed.folding(app.FOLDING_ENUM)
if not fold_rngs:
for loop in range(10):
time.sleep(0.1)
app.app_idle()
if rpt_ed.folding(app.FOLDING_ENUM):
pass; #RPTLOG and log('wait ok loop={}',loop)
break
else:
pass; #RPTLOG and log('wait fail',)
return
pass; #RPTLOG and log('fold_rngs={}',fold_rngs)
if not fold_rngs:
pass; #RPTLOG and log('fail - no rngs',)
return
for rng_num, rng_info in enumerate(fold_rngs[:]):
pass; #RPTLOG and log('?? rng_num={}',rng_num)
rng_bgn, rng_end, rng_off, rng_stapled, rng_folded = rng_info
if rng_bgn==rng_end: # simple rng
pass; #RPTLOG and log('simple rng rng_num={}',rng_num)
continue
if rng_folded: # already
pass; #RPTLOG and log('already rng_num={}',rng_num)
continue
rng_1st_line= rpt_ed.get_text_line(rng_bgn).strip()
if not rng_1st_line.startswith(what1) and not rng_1st_line.startswith(what2):
pass; #RPTLOG and log('not startswith rng_num={}',rng_num)
continue
pass; #RPTLOG and log('?? FOLDING_FOLD rng_num={}',rng_num)
rpt_ed.folding(app.FOLDING_FOLD, rng_num)
pass; #RPTLOG and log('ok FOLDING_FOLD rng_num={}',rng_num)
#def fold_all_roots
##############################################################################
def find_in_files(how_walk:dict, what_find:dict, what_save:dict, how_rpt:dict, progressor=None)->(list, dict):
""" Scan files by how_walk:
'roots' ![str] disk folder(s)
or <in proj files>
or <in open files> to scan tabs
// 'root' !str disk folder or <in open files> to scan tabs
'depth' int(-1) -1=all, 0=only root
'file_incl' !str
'file_excl' str('')
'sort_type' str('') '','date,desc','date,asc'
'only_frst' int(0) 0=all
'skip_hidn' bool(T)
'skip_binr' bool(F)
'skip_size' int(0) 0=all Kbyte
'enco' [str] ['UTF-8']
to find fragments by what_find:
'find' !str
'repl' str(None) Replace with
'mult' bool(F) Multylines
'reex' bool(F)
'case' bool(F)
'word' bool(F)
and to save info by what_save:
'count' bool(T) Need counts
'place' bool(T) Need places
# 'fragm' bool(F) Need fragments
'lines' bool(T) Need lines with fragments
From par how_rpt use keys:
'sprd' bool(F) Separate dirs
'cntx' bool(F) Append around lines
Return
[{file:'path'
,isfl=<True for file>} if not what_save['count']
,{file:'path'
,isfl=<True for file>
,count:int} if what_save['count'] and not what_save['place']
,{file:'path'
,isfl=<True for file>
,count:int if what_save['count']
,items:[
{row:N,col:N,ln:N} if what_save['place'] and not what_save['fragm']
]}
,{file:'path'
,isfl=<True for file>
,count:int if what_save['count']
,items:[
{row:N,col:N,ln:N if what_save['place']
,fragm:'text'} if what_save['fragm']
}
,{file:'path'
,isfl=<True for file>
,count:int if what_save['count']
,items:[
{row:N,col:N,ln:N if what_save['place']
,fragm:'text' if what_save['fragm']
,lines:'line' if what_save['lines']
}
}
,...]
"""
pass; #FNDLOG and log('ESC_FULL_STOP={}',ESC_FULL_STOP)
pass; #FNDLOG and log('how_walk={}',pf(how_walk))
pass; FNDLOG and log('what_find={}',pf(what_find))
pass; FNDLOG and log('what_save={}',pf(what_save))
rsp_l = []
rsp_i = dict(cllc_files=0
,cllc_stopped=False
,find_stopped=False
,brow_files=0, files=0, frgms=0)
roots = how_walk['roots']
# root = how_walk['root']
if roots_is_proj(roots):
# if roots==[IN_PROJ_FOLDS]:
try:
from cuda_project_man import global_project_info
roots = global_project_info['nodes'][:]
pass; LOG and log('roots={}',(roots))
how_walk['roots'] = roots
except Exception as ex:
pass; LOG and log('ex={}',(ex))
# except:
roots = []
how_walk['roots'] = roots
pass; LOG and log('roots={}',(roots))
files, \
cllc_stp= collect_tabs(how_walk) \
if roots_is_tabs(roots) else \
collect_files(how_walk, progressor)
if cllc_stp and ESC_FULL_STOP: return [], {}
pass; #FNDLOG and log('#collect_files={}',len(files))
pass; #FNDLOG and log('files={}',pf(files))
rsp_i['cllc_files'] = len(files)
rsp_i['cllc_stopped'] = cllc_stp
frst = what_find.get('only_frst', 0)
pttn_s = what_find['find']
repl_s = what_find['repl']
mult_b = what_find['mult']
case_b = what_find['case']
flags = re.M if mult_b else 0 \
+ 0 if case_b else re.I
if not what_find['reex']:
if what_find['word'] and re.match('^\w+$', pttn_s):
pttn_s = r'\b'+pttn_s+r'\b'
else:
pttn_s = re.escape(pttn_s)
pass; #FNDLOG and log('pttn_s, flags, repl_s={}',(pttn_s, flags, repl_s))
pttn_r = re.compile(pttn_s, flags)
cnt_b = what_save['count']
plc_b = what_save['place']
lin_b = what_save['lines']
spr_dirs= how_rpt['sprd']
cntx = how_rpt['cntx']
extU_lns= how_rpt['cntb'] if cntx else 0
extD_lns= how_rpt['cnta'] if cntx else 0
# CONTEXT_WIDTH_U = get_opt('fif_context_width_before' , CONTEXT_WIDTH)
# CONTEXT_WIDTH_D = get_opt('fif_context_width_after' , CONTEXT_WIDTH)
# extU_lns= CONTEXT_WIDTH_U if cntx else 0
# extD_lns= CONTEXT_WIDTH_D if cntx else 0
pass; #LOG and log('repl_s,extU_lns,extD_lns={}',(repl_s,extU_lns,extD_lns))
# ext_lns = CONTEXT_WIDTH if cntx else 0
# pass; #LOG and log('repl_s,ext_lns={}',(repl_s,ext_lns))