1

When I execute the function projectile-run-project I'm prompted to enter a run command. Fortunately the run command is already pre-set, because I added projectile-project-run-cmd to .dir-locals.el.

Ideally I would like projectile to immediately run the provided command without prompting me further. From reading the documentation I thought this is possible by providing an argument, so I tried this:

;; insdide use-package
:bind (([f5] .(lambda () (interactive) (projectile-run-project 'projectile-run-project-cmd))))

But when I press F5 now, I just get presented with the same pre-filled prompt again.

Is it possible to just immediately run the project executable?

Bonus question: Can you configure projectile-run-project-cmd inside the .projectile file or something, instead of using .dir-locals.el?

1

The documentation of projectile-run-project command describes this.

(projectile-run-project ARG)

Run project run command.

Normally you’ll be prompted for a compilation command, unless variable ‘compilation-read-command’. You can force the prompt with a prefix ARG.

So what you can do is:

(defun my-projectile-run-project (&optional prompt)
  (interactive "P")
  (let ((compilation-read-command
         (or (not (projectile-run-command (projectile-compilation-dir)))
             prompt)))
    (projectile-run-project prompt)))

This command will always run the previous shell command, unless it's used for the first time or it was called with a prefix argument.

  • I was not able to understand the documentation, but your function does what I want. Actually, I don't understand what the function does, either. For example I get the same result if I omit the (or (not)) part and simply (let (compilation-read-command prompt) ...). – B_old Mar 21 '18 at 14:10
  • The first argument to or is there to check if this command was run previously. – mkcms Mar 21 '18 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.