Skip to content

Commit 0412e11

Browse files
committed
Moved initialization to plugin_loaded, removed hardcoded 5555
1 parent 82e884b commit 0412e11

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

package.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@
55

66
ns = 'sublime-clojure'
77

8-
package_path = os.path.dirname(os.path.abspath(__file__))
9-
if os.path.isfile(package_path):
10-
# Package is a .sublime-package so get its filename
11-
package, _ = os.path.splitext(os.path.basename(package_path))
12-
elif os.path.isdir(package_path):
13-
# Package is a directory, so get its basename
14-
package = os.path.basename(package_path)
15-
168
def settings():
179
return sublime.load_settings("Sublime Clojure.sublime-settings")
1810

@@ -119,7 +111,7 @@ def regions_touch(r1, r2):
119111
class Connection:
120112
def __init__(self):
121113
self.host = 'localhost'
122-
self.port = 5555
114+
self.port = None
123115
self.evals: dict[int, Eval] = {}
124116
self.reset()
125117

@@ -175,8 +167,6 @@ def disconnect(self):
175167
def ready(self):
176168
return bool(self.socket and self.session)
177169

178-
conn = Connection()
179-
180170
def handle_new_session(msg):
181171
if "new-session" in msg and "id" in msg and msg["id"] in conn.evals:
182172
eval = conn.evals[msg["id"]]
@@ -285,8 +275,6 @@ def stop(self):
285275
with self.condition:
286276
self.condition.notify_all()
287277

288-
progress_thread = ProgressThread()
289-
290278
def eval_msg(view, region, msg):
291279
extended_region = view.line(region)
292280
conn.erase_evals(lambda eval: eval.region() and eval.region().intersects(extended_region), view)
@@ -593,12 +581,14 @@ def placeholder(self):
593581
return "host:port"
594582

595583
def initial_text(self):
596-
if conn.host and conn.port:
597-
return f'{conn.host}:{conn.port}'
584+
return conn.host + ":" + (str(conn.port) if conn.port else "")
585+
586+
def initial_selection(self):
587+
return [(len(conn.host + ":"), len(self.initial_text()))]
598588

599589
def preview(self, text):
600590
if not self.validate(text):
601-
return "Invalid, expected <host>:<port>"
591+
return "Expected <host>:<port>"
602592

603593
def validate(self, text):
604594
text = text.strip()
@@ -651,7 +641,20 @@ def on_settings_change():
651641
progress_thread.update_phases(settings().get("progress_phases"), settings().get("progress_interval_ms"))
652642

653643
def plugin_loaded():
654-
connect('localhost', 5555) # FIXME
644+
global package, conn, progress_thread
645+
646+
package_path = os.path.dirname(os.path.abspath(__file__))
647+
if os.path.isfile(package_path):
648+
# Package is a .sublime-package so get its filename
649+
package, _ = os.path.splitext(os.path.basename(package_path))
650+
elif os.path.isdir(package_path):
651+
# Package is a directory, so get its basename
652+
package = os.path.basename(package_path)
653+
654+
conn = Connection()
655+
progress_thread = ProgressThread()
656+
657+
# connect('localhost', 5555) # FIXME
655658
sublime.load_settings("Preferences.sublime-settings").add_on_change(ns, on_settings_change)
656659
settings().add_on_change(ns, on_settings_change)
657660
on_settings_change()

0 commit comments

Comments
 (0)