From a525a7f2afd75b20861ed378149c3e878b471452 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sun, 19 Oct 2025 13:21:10 +0200 Subject: [PATCH] Fix project-recompile directory * lisp/progmodes/project.el: Remove stale compilation-read-command declarations. Autoload recompile for Emacs versions prior to 31, to allow calling project-recompile before project-compile (bug#74631). (project-recompile): Set compilation-directory to avoid recompile using a value unrelated to the current project (bug#68570). --- lisp/progmodes/project.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 3cd2b85e71d..516a53b61bf 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1720,10 +1720,6 @@ If you exit the `query-replace', you can later continue the 'default) (fileloop-continue)) -(defvar compilation-read-command) -(declare-function compilation-read-command "compile") -(declare-function recompile "compile") - (defun project-prefixed-buffer-name (mode) (concat "*" (if-let* ((proj (project-current nil))) @@ -1772,15 +1768,21 @@ If non-nil, it overrides `compilation-buffer-name-function' for (with-current-buffer orig-current-buffer (setq-local compile-command orig-compile-command)))))) +;; Autoloaded since Emacs 31. +(autoload 'recompile "compile" nil t) + ;;;###autoload (defun project-recompile (&optional edit-command) "Run `recompile' in the project root with an appropriate buffer." (declare (interactive-only recompile)) (interactive "P") - (let ((default-directory (project-root (project-current t))) - (compilation-buffer-name-function - (or project-compilation-buffer-name-function - compilation-buffer-name-function))) + (defvar compilation-directory) + (let* ((default-directory (project-root (project-current t))) + ;; The former overrides the latter in `recompile'. + (compilation-directory default-directory) + (compilation-buffer-name-function + (or project-compilation-buffer-name-function + compilation-buffer-name-function))) (recompile edit-command))) (defcustom project-ignore-buffer-conditions nil