Function: projectile--run-project-cmd

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

Signature

(projectile--run-project-cmd COMMAND COMMAND-MAP &key COMMAND-TYPE DIRECTORY SHOW-PROMPT PROMPT-PREFIX SAVE-BUFFERS USE-COMINT-MODE BUFFER-NAME-FUNCTION NO-CACHE)

Documentation

Run a project COMMAND, typically a test- or compile command.

Cache the COMMAND for later use inside the hash-table COMMAND-MAP. With NO-CACHE non-nil the command is not stored in COMMAND-MAP (though its result still enters the command history) unless the user edited it at the prompt. This is for function-derived commands, which must be re-resolved on every run so they can prompt again - but an edit is the user overriding that function, and overriding it once shouldn't have to be repeated on every run (issue #2097).

COMMAND-TYPE, when non-nil, is the lifecycle command type symbol
(e.g. compile or test) and is used to keep a per-type command
history for the prompt, in addition to the combined per-project one.

DIRECTORY, when non-nil, is where the command runs; it defaults to projectile-compilation-dir. The caller passes it when it has already resolved the directory, so the command it looked up and the directory it runs in can't diverge.

Normally you'll be prompted for a compilation command, unless variable compilation-read-command(var)/compilation-read-command(fun). You can force the prompt by setting SHOW-PROMPT. The prompt will be prefixed with PROMPT-PREFIX.

If SAVE-BUFFERS is non-nil save all projectile buffers before running the command.

BUFFER-NAME-FUNCTION, when non-nil, is used as the compilation-buffer-name-function for the compilation, taking precedence over the projectile-compilation-buffer-scope(var)/projectile-compilation-buffer-scope(fun) naming.

The placeholder %p in COMMAND is replaced with the project name.

The command actually run is returned.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(cl-defun projectile--run-project-cmd
    (command command-map &key command-type directory show-prompt prompt-prefix save-buffers use-comint-mode buffer-name-function no-cache)
  "Run a project COMMAND, typically a test- or compile command.

Cache the COMMAND for later use inside the hash-table COMMAND-MAP.
With NO-CACHE non-nil the command is not stored in COMMAND-MAP (though
its result still enters the command history) unless the user edited it
at the prompt.  This is for function-derived commands, which must be
re-resolved on every run so they can prompt again - but an edit is the
user overriding that function, and overriding it once shouldn't have to
be repeated on every run (issue #2097).

COMMAND-TYPE, when non-nil, is the lifecycle command type symbol
\(e.g. `compile' or `test') and is used to keep a per-type command
history for the prompt, in addition to the combined per-project one.

DIRECTORY, when non-nil, is where the command runs; it defaults to
`projectile-compilation-dir'.  The caller passes it when it has already
resolved the directory, so the command it looked up and the directory it
runs in can't diverge.

Normally you'll be prompted for a compilation command, unless
variable `compilation-read-command'.  You can force the prompt
by setting SHOW-PROMPT.  The prompt will be prefixed with PROMPT-PREFIX.

If SAVE-BUFFERS is non-nil save all projectile buffers before
running the command.

BUFFER-NAME-FUNCTION, when non-nil, is used as the
`compilation-buffer-name-function' for the compilation, taking
precedence over the `projectile-compilation-buffer-scope' naming.

The placeholder `%p' in COMMAND is replaced with the project name.

The command actually run is returned."
  (let* ((project-root (projectile-acquire-root))
         (default-directory (or directory (projectile-compilation-dir)))
         ;; What the caller resolved, before the user got a say - the two
         ;; differing is how we know the command was edited at the prompt.
         (derived-command command)
         (command (projectile-maybe-read-command show-prompt
                                                 command
                                                 prompt-prefix
                                                 command-type))
         (compilation-buffer-name-function compilation-buffer-name-function)
         (compilation-save-buffers-predicate compilation-save-buffers-predicate)
         ;; `compile' calls the buffer-name function with just the mode
         ;; name, so the command type has to reach it this way.
         (projectile--compilation-command-type command-type))
    (when command-map
      ;; A function-derived command (NO-CACHE) is re-resolved on every run so
      ;; it can prompt again (e.g. a CMake preset picker); don't freeze its
      ;; result in the cache, only feed it to the history below.  An edit at
      ;; the prompt is a different matter: the user has overridden the
      ;; function, so remember that instead of offering the function's
      ;; answer again next time (issue #2097).  `projectile-discard-command-cache'
      ;; hands the project back to the function.
      (unless (and no-cache (equal command derived-command))
        (puthash default-directory command command-map))
      ;; Record into the combined per-project history (read by
      ;; `projectile-repeat-last-command') and, when known, into the
      ;; per-type history used for this command's prompt.
      (projectile--command-history-insert
       (projectile--get-command-history project-root) command)
      (when command-type
        (projectile--command-history-insert
         (projectile--get-command-history project-root command-type) command)))
    (when save-buffers
      (save-some-buffers (not compilation-ask-about-save)
                         (lambda ()
                           (projectile-project-buffer-p (current-buffer)
                                                        project-root))))
    (let ((scope (projectile-compilation-buffer-scope)))
      (when (memq 'project scope)
        (setq compilation-save-buffers-predicate #'projectile-current-project-buffer-p))
      (cond (buffer-name-function
             (setq compilation-buffer-name-function buffer-name-function))
            (scope
             (setq compilation-buffer-name-function
                   #'projectile-compilation-buffer-name))))
    (unless command
      (user-error "No %scommand configured for project type `%s'"
                  (or prompt-prefix "") (projectile-project-type)))
    (unless (file-directory-p default-directory)
      (mkdir default-directory))
    ;; Substitute placeholders: %p -> project name
    (when (string-match-p "%p" command)
      (setq command (string-replace "%p" (projectile-project-name project-root) command)))
    (projectile-run-compilation command use-comint-mode)
    command))