diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e200b6..c17f4ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 3.7.1 - Mar 15, 2024 + +- Added `expand` argument to `clojure_sublimed_eval` command + ### 3.7.0 - Mar 14, 2024 - New feature: Watches! Added `Add Watch` command diff --git a/README.md b/README.md index bfa3e53..0f613d4 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,15 @@ If you now press `ctrl+p` on a form like `(+ 1 2)`, the actual eval sent to REPL Which will pretty-print evaluation result to stdout. This pattern might be useful for large results that don’t fit inline. +We can implement macroexpand this way: + +``` +{"keys": ["ctrl+e"], + "command": "clojure_sublimed_eval", + "args": {"transform": "(macroexpand-1 '%code)", + "expand": true}} +``` + Another use-case might be “eval to buffer”: ``` diff --git a/cs_eval.py b/cs_eval.py index 6fac484..a4ed81c 100644 --- a/cs_eval.py +++ b/cs_eval.py @@ -283,12 +283,18 @@ class ClojureSublimedEvalCommand(sublime_plugin.TextCommand): """ Eval selected code or topmost form is selection is collapsed """ - def run(self, edit, print_quota = None, transform = None): + def run(self, edit, print_quota = None, transform = None, expand = False): state = cs_common.get_state(self.view.window()) + + transform_fn = None if transform: - state.conn.eval(self.view, self.view.sel(), format_code_fn(transform), print_quota = print_quota) - else: - state.conn.eval(self.view, self.view.sel(), print_quota = print_quota) + transform_fn = format_code_fn(transform) + + on_finish = None + if expand: + on_finish = lambda _: self.view.run_command("clojure_sublimed_toggle_info", {}) + + state.conn.eval(self.view, self.view.sel(), transform_fn = transform_fn, print_quota = print_quota, on_finish = on_finish) def is_enabled(self): return cs_conn.ready(self.view.window())