title: trigger advice on a function only when called from a certain other function
body: <p>I am trying to work around the restriction that <code>dired-do-shell-command</code> (bound to <code>!</code>) cannot be called on current and parent directories <code>.</code> and <code>..</code>'. The stack-trace is pasted at the bottom.</p>
  
  <p>I can define an advice as below to bypass this error:</p>
  
  <pre><code>(defadvice dired-get-filename (before h-no-error-if-not-filep activate)
    (ad-set-arg 1 t))
  </code></pre>
  
  <p><strong>But this affects all calls to the <code>dired-get-filename</code>.</strong> I would like it to trigger only when the stack is <code>dired-do-shell-command -&gt; dired-get-marked-files -&gt; dired-get-filename</code>.</p>
  
  <p>The only approaches I can think of are as follows</p>
  
  <ul>
  <li>Search for matches in <code>(with-output-to-string (backtrace))</code> in the advise definition</li>
  <li>Add around advises to the other methods to set some variable which can be tested in the advise definition.</li>
  </ul>
  
  <p>Is there better way to do it? I guess I am looking for access to the current stack-trace as a data structure instead of the string from <code>(backtrace)</code></p>
  
  <pre><code>Debugger entered--Lisp error: (error "Cannot operate on `.' or `..'")
    signal(error ("Cannot operate on `.' or `..'"))
    error("Cannot operate on `.' or `..'")
    dired-get-filename(t)
    dired-get-marked-files(t nil)
    (let ((files (dired-get-marked-files t current-prefix-arg))) (list (dired-read-shell-command (concat "! on " "%s: ") current-prefix-arg files) current-prefix-arg files))
    call-interactively(dired-do-shell-command nil nil)
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/13055903/why-can-dired-do-shell-command-not-operate-on-or">Why can dired-do-shell-command not operate on &#39;.&#39; or &#39;..&#39;?</a></p>