2

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 Answer 1

3

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.

2
  • 1
    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) ...). Commented Mar 21, 2018 at 14:10
  • 1
    The first argument to or is there to check if this command was run previously. Commented Mar 21, 2018 at 14:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.