<p dir="auto">From this <a href="https://discourse.julialang.org/t/escaping-in-nested-expr/6481/3" rel="nofollow">discourse thread</a>. Here is what I was trying:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="macro color_output(enabled, block)
    quote
        prev_color = Base.have_color
        eval(Base, :(have_color = $$enabled))
        $(esc(block))
        eval(Base, :(have_color = $prev_color))
    end
end"><pre class="notranslate"><code class="notranslate">macro color_output(enabled, block)
    quote
        prev_color = Base.have_color
        eval(Base, :(have_color = $$enabled))
        $(esc(block))
        eval(Base, :(have_color = $prev_color))
    end
end
</code></pre></div>
<p dir="auto">In a nested quotenode, you can use <code class="notranslate">$$var</code> to access <code class="notranslate">var</code> in the outer scope, and I'd expect to be able to use <code class="notranslate">$var</code> to access one level up, but it doesn't seem to work.</p>
<p dir="auto">As seen in:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="macro m()
  quote
    x = &quot;x&quot;
    quote
      $x
    end
  end
end"><pre class="notranslate"><span class="pl-k">macro</span> <span class="pl-en">m</span>()
  <span class="pl-k">quote</span>
    x <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">"</span>x<span class="pl-pds">"</span></span>
    <span class="pl-k">quote</span>
      <span class="pl-k">$</span>x
    <span class="pl-k">end</span>
  <span class="pl-k">end</span>
<span class="pl-k">end</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; @m()
ERROR: UndefVarError: x not defined
"><pre class="notranslate"><code class="notranslate">julia&gt; @m()
ERROR: UndefVarError: x not defined

</code></pre></div>
<p dir="auto">Tested on today's master and <code class="notranslate">0.4.6</code>.</p>
<p dir="auto">...</p>