title: Batch file nested setlocal - setting optional arguments only once
body: <p>I have a batch file with some functions. Each function uses <code>setlocal</code> so that its variables do not contaminate the main batch script. I've noticed that I only need the argument <code>ENABLEDELAYEDEXPANSION</code> the first time in the main batch script rather than in each nested setlocal. For example:</p>
  
  <pre><code>@echo off
  setlocal ENABLEDELAYEDEXPANSION
  
  set VAR=hi
  CALL :function
  
  echo bye
  exit /b 0
  
  :function
  setlocal
  echo !VAR!
  exit /b 0
  </code></pre>
  
  <p>Is this allowed in batch file because I can't find it documented except as noted below. It's certainly a lot easier than to write just <code>setlocal</code> for each function rather than specify the additional arguments.</p>
  
  <p><code>setlocal /?</code> says this regarding ENABLEDELAYEDEXPANSION:</p>
  
  <blockquote>
    <p>These modifications last until the matching ENDLOCAL command,
    regardless of their setting prior to the SETLOCAL command.</p>
  </blockquote>
  
  <p>So maybe that would mean even with another setlocal the settings stay the same?</p>