22from . import cs_common , cs_parser
33
44def format_string (view , text ):
5- with cs_common .Measure ("cljfmt fix {} chars" , len (text )):
6- try :
7- cmd = 'cljfmt.exe' if 'windows' == sublime .platform () else 'cljfmt'
8- cwd = None
9- if file := view .file_name ():
10- cwd = os .path .dirname (file )
11- elif folders := view .window ().folders ():
12- cwd = folders [0 ]
5+ try :
6+ cmd = 'cljfmt.exe' if 'windows' == sublime .platform () else 'cljfmt'
7+ cwd = None
8+ if file := view .file_name ():
9+ cwd = os .path .dirname (file )
10+ elif folders := view .window ().folders ():
11+ cwd = folders [0 ]
1312
14- proc = subprocess .run ([cmd , 'fix' , '-' ],
15- input = text ,
16- text = True ,
17- capture_output = True ,
18- check = True ,
19- cwd = cwd )
20- except FileNotFoundError :
21- sublime .error_message (f'`{ cmd } ` is not on $PATH' )
22- raise
23- if 'Failed' not in proc .stderr :
24- return proc .stdout
13+ proc = subprocess .run ([cmd , 'fix' , '-' ],
14+ input = text ,
15+ text = True ,
16+ capture_output = True ,
17+ check = True ,
18+ cwd = cwd )
19+ except FileNotFoundError :
20+ sublime .error_message (f'`{ cmd } ` is not on $PATH' )
21+ raise
22+ if 'Failed' not in proc .stderr :
23+ return proc .stdout
2524
2625def indent_lines (view , selections , edit ):
2726 regions = [region for region in selections if not region .empty ()]
@@ -48,9 +47,7 @@ def indent_lines(view, selections, edit):
4847
4948def newline_indent (view , point ):
5049 text = view .substr (sublime .Region (0 , point ))
51- parsed = None
52- with cs_common .Measure ("parse {} chars" , len (text )):
53- parsed = cs_parser .parse (text )
50+ parsed = cs_parser .parse (text )
5451 to_close = []
5552 node = parsed
5653 start = node .children [- 1 ].start if node .children else 0
0 commit comments