tonsky / Clojure-Sublimed

Clojure support for Sublime Text 4
MIT License
371 stars 22 forks source link

Add ClojureSublimedEval command wrap_fstr optional arg #102

Closed KGOH closed 7 months ago

KGOH commented 7 months ago

This satisfies the #101 requirements. The implementation adds optional argument wrap_fstr to the ClojureSublimedEval command. wrap_fstr should be a format string for the % operator

Example usage:

 {"keys": ["ctrl+shift+enter"],
  "command": "clojure_sublimed_eval",
  "args": {"wrap_fstr": "(doto %s clojure.pprint/pprint)"}
  "context": [{"key": "selector", "operator": "equal", "operand": "source.clojure"}]}

I have tested this update with the socket repl connection and the raw nREPL. All other ones should reuse the same logic as the raw nREPL. The original behavior of the ClojureSublimedEval is left as is by default, the update is backwards compatible

KGOH commented 7 months ago

Here are my neovintageous bindings, I use

"noremap FileType clj,cljs,cljc,bb,edn ,ep :ClojureSublimedEvalWithWrap wrap_fstr='(as-> %s $ (do (require [(symbol "clojure.pprint")]) (require [(symbol "clojure.java.io")]) (clojure.pprint/pprint $ (clojure.java.io/writer "/tmp/sublimed_output.edn")) $))'\|:OpenFile file='/tmp/sublimed_output.edn'<CR>
noremap FileType clj,cljs,cljc,bb,edn ,ep :ClojureSublimedEvalWithWrap wrap_fstr='(as-> %s $ (do (require [(symbol "fipp.edn")]) (require [(symbol "clojure.java.io")]) (fipp.edn/pprint $ {:writer (clojure.java.io/writer "/tmp/sublimed_output.edn")}) $))'\|:OpenFile file='/tmp/sublimed_output.edn'<CR>
noremap FileType clj,cljs,cljc,bb,edn ,ef :ClojureSublimedEvalWithWrap wrap_fstr='(as-> %s $ (do (require [(symbol "clojure.java.io")]) (with-open [w (clojure.java.io/writer "/tmp/sublimed_output.edn")] (binding [*print-length* nil *out* w] (pr $))) $))'\|:OpenFile file='/tmp/sublimed_output.edn'<CR>