Reference
Contents
Index
MinimalWorkingExamples.MWEResultMinimalWorkingExamples.mweMinimalWorkingExamples.set_defaults!MinimalWorkingExamples.@mwe
MinimalWorkingExamples.@mwe — Macro
@mwe begin
code
end [venue=:gh] [temp=true] [newprocess=true] [manifest=false] [advertise=nothing]
[packagespecs=PackageSpec[]] [manifest_path=nothing] [verbose=false] [stacktrace=false]Generate a Minimal Working Example (MWE) formatted as Markdown, then copy it to the clipboard.
The code is rendered as a copy-pasteable Julia script with the output of the final expression (and any print/logging calls) shown as #> comments.
Keyword arguments
venue=:gh: output format —:ghfor GitHub-Flavored Markdown (default),:slackfor Slack (strips the language identifier from the code fence).temp=true: create a temporary isolated environment and auto-add packages fromusing/import. Whenfalse, code runs in the current environment without auto-adding packages (to avoid polluting the user's project).newprocess=true: run the MWE in a fresh Julia process; startup files are disabled to ensure reproducibility. Ifnewprocess=false, the MWE runs in the current session. If alsotemp=true, a temporary project is activated for the execution and then restored.manifest=false: append theManifest.tomlin a collapsible<details>block.advertise: append a footer noting the date, this package, and Julia version used. Defaults totruefor:ghandfalsefor:slack; can be set explicitly to override.packagespecs=PackageSpec[]: vector ofPkg.PackageSpecs for packages that need a specific version, git revision, URL, or local path.manifest_path=nothing: path to an existingManifest.tomlto use as-is. Mutually exclusive withpackagespecs.verbose=false: iftrue, show Pkg output (downloads, resolver messages) during environment setup.stacktrace=false: iftrue, append the full stacktrace after the error message.
Comments in the code block are not preserved in the output. Use mwe if you need to preserve comments.
The defaults above (except packagespecs and manifest_path) can be changed persistently with set_defaults!.
Examples
@mwe begin
using Statistics
x = [1, 2, 3, 4, 5]
mean(x)
endProduces (copied to clipboard):
```julia
using Statistics
x = [1, 2, 3, 4, 5]
mean(x)
#> 3.0
```
<sup>Created on <date> with [MinimalWorkingExamples v<pkg-version>](https://github.com/BjarkeHautop/MinimalWorkingExamples.jl) using Julia <version></sup>Pin a package to a specific version:
using Pkg
@mwe begin
using Example
Example.hello("World")
end packagespecs=[PackageSpec(name="Example", version="0.5.3")]Include the stacktrace when an error is thrown:
@mwe begin
x = [1, 2, 3]
x[10]
end stacktrace=trueMinimalWorkingExamples.mwe — Function
mwe([code]; venue=:gh, temp=true, newprocess=true, manifest=false, advertise=nothing,
packagespecs=PackageSpec[], manifest_path=nothing, verbose=false, stacktrace=false)Function form of @mwe. Accepts code as a plain string. If code is omitted, reads Julia source from the clipboard.
Examples
# Run code already copied to the clipboard:
mwe()
# Format for Slack:
mwe(; venue=:slack)
# Run an explicit string:
mwe("""
using Statistics
mean([1, 2, 3])
""")
# Comments are preserved:
mwe("""
1+1 # This comment is preserved
""")MinimalWorkingExamples.MWEResult — Type
MWEResultWraps the Markdown string produced by @mwe. Displays silently in the REPL (the output is already printed on creation); access the Markdown string via .md.
MinimalWorkingExamples.set_defaults! — Function
set_defaults!(; kwargs...)Persistently override the default keyword arguments of @mwe and mwe using Preferences.jl.
Any of venue, temp, newprocess, manifest, advertise, verbose, and stacktrace may be set. Passing nothing for a key clears it, reverting to the built-in default.
Examples
# Always format for Slack and skip the isolated environment:
set_defaults!(venue=:slack, temp=false)
# Go back to the built-in venue default:
set_defaults!(venue=nothing)