UndefVarError when including a snippet of code

Define this macro somewhere in your code:

macro def(name, definition)
    return quote
        macro $(esc(name))()
            esc($(Expr(:quote, definition)))
        end
    end
end

Then you can easily make macros to copy/paste

@def MyPlot begin
  plot(fancyobj)
  xlabel(); ylabel()...
  title(...)...
end

Then to paste it around

# some code 
@MyPlot  # paste here
# some code

Defining a macro for each snippet can’t be worse than making a new file for each one.

2 Likes