1
- import os
2
-
1
+ from __future__ import annotations
2
+ import stat
3
3
import sublime
4
4
5
+ from pathlib import Path
6
+
5
7
from ...latextools .utils .external_command import check_output
6
8
from ...latextools .utils .external_command import external_command
7
9
12
14
13
15
class SkimViewer (BaseViewer ):
14
16
15
- def forward_sync (self , pdf_file , tex_file , line , col , ** kwargs ):
16
- keep_focus = kwargs .pop ("keep_focus" , True )
17
- path_to_skim = "/Applications/Skim.app"
18
-
19
- if not os .path .exists (path_to_skim ):
20
- path_to_skim = check_output (
21
- [
22
- "osascript" ,
23
- "-e" ,
24
- 'POSIX path of (path to app id "net.sourceforge.skim-app.skim")' ,
25
- ],
26
- use_texpath = False ,
17
+ def forward_sync (self , pdf_file : str , tex_file : str , line : int , col : int , ** kwargs ) -> None :
18
+ keep_focus = kwargs .get ("keep_focus" , True )
19
+ skim_app = Path ("/Applications/Skim.app" )
20
+
21
+ if not skim_app .exists ():
22
+ skim_app = Path (
23
+ check_output (
24
+ [
25
+ "osascript" ,
26
+ "-e" ,
27
+ 'POSIX path of (path to app id "net.sourceforge.skim-app.skim")' ,
28
+ ],
29
+ use_texpath = False ,
30
+ )
27
31
)
28
32
29
- command = [
30
- os .path .join (path_to_skim , "Contents" , "SharedSupport" , "displayline" ),
31
- "-r" ,
32
- ]
33
+ command = [str (skim_app / "Contents" / "SharedSupport" / "displayline" ), "-r" ]
33
34
34
35
if keep_focus :
35
36
command .append ("-g" )
36
37
37
38
command += [str (line ), pdf_file , tex_file ]
38
39
39
40
external_command (command , use_texpath = False )
40
-
41
- def view_file (self , pdf_file , ** kwargs ):
42
- keep_focus = kwargs .pop ("keep_focus" , True )
43
- script_dir = os .path .join (sublime .cache_path (), "LaTeXTools" , "viewer" , "skim" )
44
- script_file = os .path .join (script_dir , "displayfile" )
45
- if not os .path .exists (script_file ):
41
+ if keep_focus :
42
+ self .focus_st ()
43
+
44
+ def view_file (self , pdf_file : str , ** kwargs ) -> None :
45
+ keep_focus = kwargs .get ("keep_focus" , True )
46
+ script_dir = Path (sublime .cache_path ()) / "LaTeXTools" / "viewer" / "skim"
47
+ script_dir .mkdir (parents = True , exist_ok = True )
48
+ script_file = script_dir / "displayfile"
49
+ if not script_file .exists ():
46
50
try :
47
- data = sublime .load_binary_resource (
48
- f"Packages/LaTeXTools/plugins/viewer/skim/displayfile"
51
+ data = (
52
+ sublime .load_binary_resource (
53
+ f"Packages/LaTeXTools/plugins/viewer/skim/displayfile"
54
+ )
55
+ .replace (b"\r \n " , b"\n " )
56
+ .replace (b"\r " , b"\n " )
49
57
)
50
58
except FileNotFoundError :
51
59
sublime .error_message (
52
- "Cannot find required scripts\n "
53
- "for 'skim' viewer in LaTeXTools package."
60
+ "Cannot find required scripts\n for 'skim' viewer in LaTeXTools package."
54
61
)
55
- else :
56
- with open (script_file , "wb" ) as fobj :
57
- fobj .write (data )
62
+ return
63
+
64
+ script_file .write_bytes (data )
65
+ script_file .chmod (script_file .stat ().st_mode | stat .S_IXUSR )
58
66
59
67
command = ["/bin/sh" , script_file , "-r" ]
60
68
@@ -64,9 +72,11 @@ def view_file(self, pdf_file, **kwargs):
64
72
command .append (pdf_file )
65
73
66
74
external_command (command , use_texpath = False )
75
+ if keep_focus :
76
+ self .focus_st ()
67
77
68
- def supports_keep_focus (self ):
78
+ def supports_keep_focus (self ) -> bool :
69
79
return True
70
80
71
- def supports_platform (self , platform ) :
81
+ def supports_platform (self , platform : str ) -> bool :
72
82
return platform == "osx"
0 commit comments