Skip to content

Commit 7528876

Browse files
committed
Settings can now be specified in main Settings file
1 parent 7b22d23 commit 7528876

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
Syntax has been significantly reworked.
44

5-
- New syntax that can highlight reader comments `comment.reader` together with the following
6-
form
5+
- New syntax that can highlight reader comments `comment.reader` together with the following form
76
- Highlight `(comment ...)` blocks as `comment.form`
87
- Highlight namespaces in symbols as `meta.namespace.symbol`
98
- Highlight unused symbols as `source.symbol.unused`
@@ -15,6 +14,7 @@ Syntax has been significantly reworked.
1514
Other changes:
1615

1716
- Allow using `cljfmt` for formatting (requires `cljfmt` binary on `$PATH`)
17+
- Settings can now be specified in main `Preferences.sublime-settings` as well. Just prepend `clojure_sublimed_` to each setting’s name.
1818

1919
### 3.8.0 - Aug 8, 2024
2020

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,20 @@ Finally, to clear evaluation results run `Clojure Sublimed: Clear Evaluation Res
297297

298298
To edit settings, run `Preferences: Clojure Sublimed Settings` command.
299299

300+
If you prefer setting settings in main file, you can do so by prepending `"clojure_sublimed_"` to each setting name. E.g.
301+
302+
```
303+
"debug": True,
304+
```
305+
306+
in `Clojure Sublimed.sublime-settings` becomes
307+
308+
```
309+
"clojure_sublimed_debug": True,
310+
```
311+
312+
in `Preferences.sublime-settings`. Settings from `Preferences.sublime-settings` take priority.
313+
300314
## Session-wide settings
301315

302316
It is sometimes desirable to set dynamic Clojure vars for the whole session. To do that, edit `"eval_shared"` setting. For example:

cs_common.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,36 @@ def settings():
3838
"""
3939
return sublime.load_settings("Clojure Sublimed.sublime-settings")
4040

41+
def main_settings():
42+
return sublime.load_settings("Preferences.sublime-settings")
43+
4144
def setting(key, default = None):
4245
"""
4346
Shortcut to get value of a particular plugin setting
4447
"""
45-
return settings().get(key, default)
48+
s = main_settings()
49+
if s and (res := s.get("clojure_sublimed_" + key)) is not None:
50+
return res
51+
s = settings()
52+
if s and (res := s.get(key)) is not None:
53+
return res
54+
return default
4655

4756
def on_settings_change(tag, callback):
4857
"""
4958
Subscribe to settings change
5059
"""
51-
settings().add_on_change(tag, lambda: callback(settings()))
52-
callback(settings())
60+
main_settings().add_on_change(tag, callback)
61+
settings().add_on_change(tag, callback)
62+
callback()
5363

5464
def clear_settings_change(tag):
5565
"""
5666
Unsubscribe from settings change
5767
"""
68+
main_settings().clear_on_change(tag)
5869
settings().clear_on_change(tag)
59-
70+
6071
def wrap_width(view):
6172
if (w := setting('wrap_width')):
6273
return w
@@ -257,7 +268,7 @@ def plugin_loaded():
257268
elif os.path.isdir(package_path):
258269
# Package is a directory, so get its basename
259270
package = os.path.basename(package_path)
260-
on_settings_change(__name__, lambda _: colors.clear())
271+
on_settings_change(__name__, lambda: colors.clear())
261272

262273
def plugin_unloaded():
263274
for state in states.values():

cs_progress.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ def __init__(self):
1414
self.interval = 100
1515

1616
def update_phases(self, phases, interval):
17-
self.phases = phases
17+
if phases is not None:
18+
self.phases = phases
1819
self.phase_idx = 0
19-
self.interval = interval
20+
if interval is not None:
21+
self.interval = interval
2022
if len(phases) > 1:
2123
self.start()
2224
else:
@@ -26,9 +28,7 @@ def phase(self):
2628
return self.phases[self.phase_idx]
2729

2830
def run_loop(self):
29-
settings = cs_common.settings()
30-
if settings.to_dict():
31-
self.update_phases(settings.get("progress_phases"), settings.get("progress_interval_ms"))
31+
thread.update_phases(cs_common.setting("progress_phases"), cs_common.setting("progress_interval_ms"))
3232
while True:
3333
if not self.running:
3434
break
@@ -74,9 +74,8 @@ def on_activated_async(self, view):
7474
"""
7575
thread.wake()
7676

77-
def on_settings_change(settings):
78-
if settings.to_dict():
79-
thread.update_phases(settings.get("progress_phases"), settings.get("progress_interval_ms"))
77+
def on_settings_change():
78+
thread.update_phases(cs_common.setting("progress_phases"), cs_common.setting("progress_interval_ms"))
8079

8180
def plugin_loaded():
8281
cs_common.on_settings_change(__name__, on_settings_change)

0 commit comments

Comments
 (0)