diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 000a05804a8..bd1264b5525 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1387,15 +1387,33 @@ project-compilation-buffer-name-function project-prefixed-buffer-name) (function :tag "Custom function"))) +(defvar project-build-functions nil + "Special hook to find the project build configuration. +Each functions on this hook is called in turn with one +argument (project), and should return either nil to mean that it is not +applicable, or a plist with build configuration. + +The configuration can contain keys such as `:compile-dir', +`:compile-command', or others.") + ;;;###autoload (defun project-compile () - "Run `compile' in the project root." + "Run `compile' in the project build directory. +Uses the `project-build-functions' hook to determine the compile command +and the directory to run it in." (declare (interactive-only compile)) (interactive) - (let ((default-directory (project-root (project-current t))) - (compilation-buffer-name-function - (or project-compilation-buffer-name-function - compilation-buffer-name-function))) + (let* ((project (project-current t)) + (build-config (run-hook-with-args 'project-build-functions project)) + (default-directory (if (plist-get build-config :compile-dir) + (expand-file-name (plist-get build-config :compile-dir) + (project-root project)) + default-directory)) + (compile-command (or (plist-get build-config :compile-command) + compile-command)) + (compilation-buffer-name-function + (or project-compilation-buffer-name-function + compilation-buffer-name-function))) (call-interactively #'compile))) (defun project-recompile (&optional edit-command)