Function: projectile--dispatch-in-directory

projectile--dispatch-in-directory is a byte-compiled function defined in projectile.el.

Signature

(projectile--dispatch-in-directory DIRECTORY ACTION)

Documentation

Run transient ACTION with DIRECTORY as the project context.

ACTION (e.g. projectile-dispatch) is a transient prefix, so its suffix commands run after this function returns; a dynamic default-directory binding (or a temporary buffer) would be unwound by then. Instead set the current buffer's default-directory to DIRECTORY (the buffer that is current now is the one the suffix commands run in) for the lifetime of the transient, restoring it once the menu exits. This makes commands picked from the menu - like projectile-find-file - target the switched-to project.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defun projectile--dispatch-in-directory (directory action)
  "Run transient ACTION with DIRECTORY as the project context.
ACTION (e.g. `projectile-dispatch') is a transient prefix, so its suffix
commands run after this function returns; a dynamic `default-directory'
binding (or a temporary buffer) would be unwound by then.  Instead set
the current buffer's `default-directory' to DIRECTORY (the buffer that
is current now is the one the suffix commands run in) for the lifetime
of the transient, restoring it once the menu exits.  This makes commands
picked from the menu - like `projectile-find-file' - target the
switched-to project."
  (let ((buffer (current-buffer))
        (original-directory default-directory))
    (setq default-directory directory)
    (letrec ((restore
              (lambda ()
                (when (buffer-live-p buffer)
                  (with-current-buffer buffer
                    (setq default-directory original-directory)))
                (remove-hook 'transient-exit-hook restore))))
      (add-hook 'transient-exit-hook restore))
    ;; A transient prefix is an interactive-only command, so invoke it via
    ;; `call-interactively'.
    (call-interactively action)))