obsidian-wielder icon indicating copy to clipboard operation
obsidian-wielder copied to clipboard

Evaluate on command?

Open EricR opened this issue 3 years ago • 2 comments
trafficstars

Is it possible to evaluate code blocks on command rather than instantaneously as code gets typed? I could see this potentially being problematic if I’m typing code that does something state changing like, say, modifies my vault (e.g., I’m deleting a file by path name and I’m typing out the path name in quotes).

EricR avatar Jun 13 '22 02:06 EricR

Yeah, could provide this as an setting for the plugin, something like Evaluate automatically which when toggled off, would require the user to run a command to evaluate the document.

Although, I'd advise against the approach of doing potentially destructive things without wrapping them in something that requires user action.

So instead of just doing something like this, which would delete a file when evaluated (so when the document is loaded, by default):

(delete-file filename)

You'd do something like this:

(defn $button [filename]
  [:button
    {:onClick #(delete-file filename)}
    "Delete " filename])

(*renderReagent [$button "file-to-be-deleted"])

Which would render a button to be clicked to have the file to be deleted.

With that said, having the option of choosing when evaluation happens is not a bad idea :)

victorb avatar Jun 13 '22 08:06 victorb

Just chiming in to say that I'd be in favor of a mode that requires explicit action on behalf of the user to execute code

matthewdowney avatar Nov 22 '22 23:11 matthewdowney