Skip to content

Conjure extension for evaluating effective root form in Rich comments

License

Notifications You must be signed in to change notification settings

walterl/conjure-efroot

Repository files navigation

Conjure Ef[fective]root

Conjure extension that allows evaluating top-level forms, ignoring comment forms. That is, evaluating the effective root form: the top-most form under the cursor that is not a comment-form.

During REPL driven development we often evaluate forms in so called Rich comment blocks: forms enclosed in a comment-form, which are ignored by the Clojure compiler, but very useful for development with a REPL.

Conjure supports evaluating the root form under the cursor, but when that root form is a comment-form, it dutifully does nothing. This is technically correct behavior, but it would be more convenient if we could easily evaluate the effective root form in Rich comments.

Efroot enables that behavior by adding the commands ConjureEvalEffectiveRootForm and ConjureEvalCommentEffectiveRootForm, which does the same as ConjureEvalRootForm and ConjureEvalCommentRootForm respectively, but ignores top-level comment-forms. These new commands reuse the original mappings.

Requires Conjure.

Installation

Using vim-plug:

Plug 'walterl/conjure-efroot'

Usage

Suppose you are testing generation of a configuration file in your REPL, in a Rich comment like in this example:

(comment
  (do
    (spit "config.edn" (pr-str (generate-config)))
    (let [config (edn/read-string (slurp "config.edn"))]
      (get-in config [:server :port])))
  )

When making changes inside the let-form's body, you want to re-evaluate the entire do-form, but moving the cursor back and forth between the editing position and the do-form (so you can call ConjureEvalCurrentForm) is cumbersome.

Calling :ConjureEvalEffectiveRootForm from the let-form's body will evaluate the do-form.

Mappings

  • <LocalLeader>er - Evaluates the effective root form under the cursor.
  • <LocalLeader>ecr - Evaluates the effective root form under the cursor and adds the result as a comment after the form.

The original ConjureEvalRootForm and ConjureEvalCommentRootForm commands are remapped to <LocalLeader>eR and <LocalLeader>ecR, respectively.

Caveats

Efroot does not use tree-sitter functionality. It also does more work than ConjureEvalRootForm, increasing with each form nesting level. Performance could therefore become an issue when evaluating deeply nested forms, but that has not been observed yet.

This is because Efroot first collects all forms along the form tree, "between" the current (inner-most) form and the root form, inclusive.

License

MIT

About

Conjure extension for evaluating effective root form in Rich comments

Topics

Resources

License

Stars

Watchers

Forks

Languages