projectile icon indicating copy to clipboard operation
projectile copied to clipboard

Unable to completing-read CMake preset the second time

Open laurynas-biveinis opened this issue 3 years ago • 5 comments

Expected behavior

projectile-configure-project, when run second time in a project, has some way (a prefix arg?) to select a (different) CMake preset again.

Actual behavior

Configure command: cmake . --preset <previously-selected-preset> prompt in minibuffer without completion for presets.

Steps to reproduce the problem

  • Have a CMake project with at least two configure presets
  • s-p C, select one of the presets
  • s-p C again, wishing to select the other preset

Environment & Version information

CMake 3.20.4

Projectile version information

Projectile 2.4.0

With a workaround for https://github.com/bbatsov/projectile/issues/1673 applied:

(defun dotfiles--projectile--cmake-all-command-presets (command-type)
  "Get CMake user and system COMMAND-TYPE presets."
  (projectile-flatten
   (mapcar (lambda (filename)
             (projectile--cmake-command-presets filename command-type))
           '("CMakeUserPresets.json" "CMakePresets.json"))))
(advice-add #'projectile--cmake-all-command-presets :override
            #'dotfiles--projectile--cmake-all-command-presets)

Emacs version

27.2

Operating system

macOS 11.4

laurynas-biveinis avatar Jun 17 '21 03:06 laurynas-biveinis

i think this is simply how the project-type-agnosticprojectile-configure-command works (https://github.com/bbatsov/projectile/blob/master/projectile.el#L4337). it will prefer to use the cached command. to get the behaviour you want, one would have to be able to disable caching of configuration commands. not sure if this is possible currently. it would be useful.

jehelset avatar Jun 17 '21 20:06 jehelset

as a quickfix you could use something like this:


(defun projectile-reconfigure-command (compile-dir)
  "Retrieve the configure command for COMPILE-DIR without considering history.

The command is determined like this:

- first we check for `projectile-project-configure-cmd' supplied
via .dir-locals.el

- finally we check for the default configure command for a
project of that type"
  (or projectile-project-configure-cmd
      (let ((cmd-format-string (projectile-default-configure-command (projectile-project-type))))
        (when cmd-format-string
          (format cmd-format-string (projectile-project-root) compile-dir)))))

(defun projectile-reconfigure-project (arg)
  "Run project configure command without considering command history.

Normally you'll be prompted for a compilation command, unless
variable `compilation-read-command'.  You can force the prompt
with a prefix ARG."
  (interactive "P")
  (let ((command (projectile-reconfigure-command (projectile-compilation-dir))))
    (projectile--run-project-cmd command projectile-configure-cmd-map
                                 :show-prompt arg
                                 :prompt-prefix "Configure command: "
                                 :save-buffers t)))

and bind projectile-reconfigure-command to a suitable key.

jehelset avatar Jun 17 '21 20:06 jehelset

Thanks @jehelset , I will try your code. I really like the concept of separate "reconfigure" command.

laurynas-biveinis avatar Jun 18 '21 11:06 laurynas-biveinis

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

stale[bot] avatar Apr 16 '22 10:04 stale[bot]

The issue still exists

laurynas-biveinis avatar Apr 17 '22 05:04 laurynas-biveinis