title: Add a decorator function to org-capture-template
body: <p>I wrote a org-capture-templates which add entries to appropriate headings as:</p>
  <blockquote>
  <p>** Plan<br />
  ** Writing</p>
  </blockquote>
  <p>The org-capture-templates as:</p>
  <pre><code>(setq org-capture-templates
        '((&quot;p&quot; &quot;Plan&quot; entry
           (file+function &quot;~/Documents/OrgMode/ORG/Master/todo.today.org&quot;
                          (my-org-goto-last-headline &quot;\\*\\* Plan&quot;))
           &quot;* TODO %i%?&quot;)
          (&quot;w&quot; &quot;Writing&quot; entry
           (file+function &quot;~/Documents/OrgMode/ORG/Master/todo.today.org&quot;
                          (my-org-goto-last-headline &quot;\\*\\* Writing&quot;))
           &quot;* %i%? \n%T&quot;)))
  </code></pre>
  <p><code>my-org-goto-last-headline</code> was defined as a decorator:</p>
  <pre><code>(defun my-org-goto-last-headline (heading)
    (defun nested ()
      &quot;Move point to the last headline in file matching \&quot;** Headline\&quot;.&quot;
      (end-of-buffer)
      (re-search-backward heading))
    `nested)
  </code></pre>
  <p>Additionally, I set <code>lexical-binding: t</code></p>
  <p>Unfortunately, it report errors like:</p>
  <pre><code>org-capture-set-target-location: Invalid function: (my-org-goto-last-headline &quot;\\*\\* Plan&quot;)
  </code></pre>
  <p>How could I apply a decorator in such a org-capture-template?</p>