Function: projectile--run-task

projectile--run-task is a byte-compiled function defined in projectile.el.

Signature

(projectile--run-task TASK-NAME COMMAND SHOW-PROMPT &optional CONFIRMED)

Documentation

Run TASK-NAME's COMMAND for the current project.

COMMAND is a shell command string, or a function returning one, called with default-directory set to the project root. With SHOW-PROMPT non-nil the command can always be edited before it's run; otherwise the command is offered for confirmation when compilation-read-command(var)/compilation-read-command(fun) is non-nil (the default), like the other lifecycle commands, unless CONFIRMED says the user already confirmed this exact command (the repeat case).

Task commands can come from a checked-out project's .dir-locals.el, whose projectile-tasks entries are accepted without the risky-local-variable prompt - that is only acceptable because this run-time confirmation is guaranteed, the same trade-off Emacs's compile-command makes.

The command is executed like the other lifecycle commands (see projectile--run-project-cmd), except that the output goes to a per-task compilation buffer. Return the command that was run, with the %p placeholder still intact.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defun projectile--run-task (task-name command show-prompt &optional confirmed)
  "Run TASK-NAME's COMMAND for the current project.

COMMAND is a shell command string, or a function returning one, called
with `default-directory' set to the project root.  With SHOW-PROMPT
non-nil the command can always be edited before it's run; otherwise
the command is offered for confirmation when `compilation-read-command'
is non-nil (the default), like the other lifecycle commands, unless
CONFIRMED says the user already confirmed this exact command (the
repeat case).

Task commands can come from a checked-out project's `.dir-locals.el',
whose `projectile-tasks' entries are accepted without the
risky-local-variable prompt - that is only acceptable because this
run-time confirmation is guaranteed, the same trade-off Emacs's
`compile-command' makes.

The command is executed like the other lifecycle commands (see
`projectile--run-project-cmd'), except that the output goes to a
per-task compilation buffer.  Return the command that was run, with
the `%p' placeholder still intact."
  (let* ((project-root (projectile-acquire-root))
         (command (if (functionp command)
                      (let ((default-directory project-root))
                        (funcall command))
                    command))
         ;; keyed like the per-type lifecycle histories, but per task
         (history-key (cons 'task task-name)))
    (unless (stringp command)
      (user-error "The command of task `%s' must be a string or a function returning one"
                  task-name))
    (when (or show-prompt
              (and compilation-read-command (not confirmed)))
      (setq command (projectile-read-command
                     (format "Task [%s] command: " task-name)
                     command
                     history-key)))
    ;; Any prompting already happened above, so bind
    ;; `compilation-read-command' to nil to stop
    ;; `projectile--run-project-cmd' from prompting a second time.
    (let ((compilation-read-command nil)
          (buffer-name (concat "*projectile-task: " task-name "*"
                               (when (memq 'project (projectile-compilation-buffer-scope))
                                 (concat "<" (projectile-project-name project-root) ">")))))
      (projectile--run-project-cmd command nil
                                   :save-buffers t
                                   :use-comint-mode (projectile-use-comint-mode-p 'task)
                                   :buffer-name-function (lambda (_mode) buffer-name)))
    ;; `command-map' is nil above, so `projectile--run-project-cmd' records
    ;; nothing; record the command - before `%p' expansion, like the other
    ;; lifecycle commands - into the combined per-project history (which
    ;; `projectile-repeat-last-command' reads) and the per-task one here.
    (projectile--command-history-insert
     (projectile--get-command-history project-root) command)
    (projectile--command-history-insert
     (projectile--get-command-history project-root history-key) command)
    (puthash project-root (cons task-name command) projectile-last-task-map)
    command))