This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathsublime.go
108 lines (94 loc) · 2.54 KB
/
sublime.go
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
package sublime
import (
"encoding/json"
"fmt"
"github.com/quarnster/completion/editor"
"os"
"os/user"
"path/filepath"
"runtime"
)
var verbose = true
func init() {
editor.Register(&Sublime{})
}
type Sublime struct{}
func (s *Sublime) writeDefaultConfig(user, p string) error {
rpc := filepath.Join(user, "completion.rpc")
f, err := os.Create(filepath.Join(p, "completion.sublime-settings"))
if err != nil {
return err
}
defer f.Close()
bin, err := filepath.Abs(os.Args[0])
if err != nil {
return err
}
bin_bytes, err := json.Marshal(bin)
if err != nil {
return err
}
bin_ := string(bin_bytes[:])
f.WriteString(fmt.Sprintf(`{
"daemon_command": [%s, "daemon", "-proto=unix", "-port=%s", "-remove=true"],
"launch_daemon": true,
"proto": "unix",
"port": "%s"
}
`, bin_, rpc, rpc))
return nil
}
func (s *Sublime) Install() error {
var (
st_paths []string
files = []string{
"3rdparty/jsonrpc.py",
"editor/sublime/plugin.py",
"editor/sublime/Default.sublime-keymap",
"editor/sublime/Main.sublime-menu",
}
)
u, err := user.Current()
if err != nil {
return err
}
switch runtime.GOOS {
case "darwin":
st_paths = append(st_paths, filepath.Join(u.HomeDir, "Library", "Application Support", "Sublime Text 2", "Packages"))
st_paths = append(st_paths, filepath.Join(u.HomeDir, "Library", "Application Support", "Sublime Text 3", "Packages"))
case "linux":
st_paths = append(st_paths, filepath.Join(u.HomeDir, ".config", "sublime-text-2", "Packages"))
st_paths = append(st_paths, filepath.Join(u.HomeDir, ".config", "sublime-text-3", "Packages"))
case "windows":
st_paths = append(st_paths, filepath.Join(os.Getenv("APPDATA"), "Sublime Text 2", "Packages"))
st_paths = append(st_paths, filepath.Join(os.Getenv("APPDATA"), "Sublime Text 3", "Packages"))
default:
return fmt.Errorf("Don't know where to install Sublime Text files on OS %s", runtime.GOOS)
}
for i := range st_paths {
if fi, err := os.Stat(st_paths[i]); err != nil || !fi.IsDir() {
continue
}
p := filepath.Join(st_paths[i], "completion")
u := filepath.Join(st_paths[i], "User")
os.Mkdir(p, 0755)
for _, f := range files {
if err := editor.Copy(f, filepath.Join(p, filepath.Base(f))); err != nil {
return err
}
}
if err := s.writeDefaultConfig(u, p); err != nil {
return err
}
}
return nil
}
func (s *Sublime) Name() string {
return "st"
}
func (s *Sublime) Description() string {
return "Sublime Text 2 and Sublime Text 3"
}
func (s *Sublime) Uninstall() error {
return fmt.Errorf("Sublime.Uninstall not implemented")
}