Function: project-compile

project-compile is an autoloaded, interactive and byte-compiled function defined in project.el.gz.

Signature

(project-compile)

Documentation

Run compile in the project root.

View in manual

Probably introduced at or before Emacs version 28.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/project.el.gz
;;;###autoload
(defun project-compile ()
  "Run `compile' in the project root."
  (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))
         (orig-current-buffer (and (derived-mode-p 'vc-compilation-mode)
                                   (local-variable-p 'compile-command)
                                   (current-buffer)))
         (orig-compile-command (and orig-current-buffer compile-command)))
    ;; If invoked from a `vc-compilation-mode' buffer, we want to ignore
    ;; `compile-command' because for this command we know the user wants
    ;; to build the project, not re-run a VC pull or push (bug#79658).
    ;; Do this without let-binding `compile-command', however, in order
    ;; that the user's command to build the project is not immediately
    ;; thrown away.  Essentially we want to turn the `setq' of
    ;; `compile-command' done by `compile' into a `setq-default'.
    (when orig-current-buffer
      (kill-local-variable 'compile-command))
    (unwind-protect (call-interactively #'compile)
      (when orig-current-buffer
        (with-current-buffer orig-current-buffer
          (setq-local compile-command orig-compile-command))))))