|
5 | 5 |
|
6 | 6 | ns = 'sublime-clojure' |
7 | 7 |
|
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 | | - |
16 | 8 | def settings(): |
17 | 9 | return sublime.load_settings("Sublime Clojure.sublime-settings") |
18 | 10 |
|
@@ -119,7 +111,7 @@ def regions_touch(r1, r2): |
119 | 111 | class Connection: |
120 | 112 | def __init__(self): |
121 | 113 | self.host = 'localhost' |
122 | | - self.port = 5555 |
| 114 | + self.port = None |
123 | 115 | self.evals: dict[int, Eval] = {} |
124 | 116 | self.reset() |
125 | 117 |
|
@@ -175,8 +167,6 @@ def disconnect(self): |
175 | 167 | def ready(self): |
176 | 168 | return bool(self.socket and self.session) |
177 | 169 |
|
178 | | -conn = Connection() |
179 | | - |
180 | 170 | def handle_new_session(msg): |
181 | 171 | if "new-session" in msg and "id" in msg and msg["id"] in conn.evals: |
182 | 172 | eval = conn.evals[msg["id"]] |
@@ -285,8 +275,6 @@ def stop(self): |
285 | 275 | with self.condition: |
286 | 276 | self.condition.notify_all() |
287 | 277 |
|
288 | | -progress_thread = ProgressThread() |
289 | | - |
290 | 278 | def eval_msg(view, region, msg): |
291 | 279 | extended_region = view.line(region) |
292 | 280 | conn.erase_evals(lambda eval: eval.region() and eval.region().intersects(extended_region), view) |
@@ -593,12 +581,14 @@ def placeholder(self): |
593 | 581 | return "host:port" |
594 | 582 |
|
595 | 583 | 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()))] |
598 | 588 |
|
599 | 589 | def preview(self, text): |
600 | 590 | if not self.validate(text): |
601 | | - return "Invalid, expected <host>:<port>" |
| 591 | + return "Expected <host>:<port>" |
602 | 592 |
|
603 | 593 | def validate(self, text): |
604 | 594 | text = text.strip() |
@@ -651,7 +641,20 @@ def on_settings_change(): |
651 | 641 | progress_thread.update_phases(settings().get("progress_phases"), settings().get("progress_interval_ms")) |
652 | 642 |
|
653 | 643 | 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 |
655 | 658 | sublime.load_settings("Preferences.sublime-settings").add_on_change(ns, on_settings_change) |
656 | 659 | settings().add_on_change(ns, on_settings_change) |
657 | 660 | on_settings_change() |
|
0 commit comments