GNU bug report logs - #79292
[PATCH] Improve project-compile command prompt

Previous Next

Package: emacs;

Reported by: Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com>

Date: Fri, 22 Aug 2025 16:48:01 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 79292 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#79292; Package emacs. (Fri, 22 Aug 2025 16:48:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 22 Aug 2025 16:48:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: [PATCH] Improve project-compile command prompt
Date: Fri, 22 Aug 2025 16:46:58 +0000
Improve 'project-compile' command prompt, which makes it more consistent with
the new project switch prompt introduced by commit 86e17fbcbddb, and makes it
clear to users which compilation command is being executed (default 'compile' or
'project-compile').


From 05fd5ea90e3fad1d20fe30f7597aae897cda438a Mon Sep 17 00:00:00 2001
From: Gabriel Ribeiro <gabriel376 <at> hotmail.com>
Date: Fri, 22 Aug 2025 13:40:53 -0300
Subject: [PATCH] Include project root in project-compile prompt

* lisp/progmodes/compile.el:
  (compilation-command-prompt): New user option.
  (compilation-read-command): Use it.
* lisp/progmodes/project.el:
  (project-compilation-command-prompt): New user option.
  (project--compilation-command-prompt): New function to generate the
  default project-compile prompt.
  (project-compile): Use it.
---
 etc/NEWS                  |  8 ++++++++
 lisp/progmodes/compile.el | 18 ++++++++++++++----
 lisp/progmodes/project.el | 18 +++++++++++++++++-
 3 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ebf03b53e12..4df47922bf7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -515,6 +515,10 @@ which removes all non-remote projects.
 *** New command 'project-save-some-buffers' bound to 'C-x p C-x s'.
 This is like 'C-x s', but only for this project's buffers.
 
+*** New user option 'project-compilation-command-prompt'
+This user option controls the computation of the minibuffer prompt for
+the 'projet-compile' command.  See also 'compilation-command-prompt'.
+
 *** 'project-remember-project' can now be called interactively.
 
 ---
@@ -595,6 +599,10 @@ To use the ':foreground' or current text color ensure the 'fill' attribute
 in the SVG is set to 'currentcolor', or set the image spec's ':css'
 value to 'svg {fill: currentcolor;}'.
 
+*** New user option 'compilation-command-prompt'
+This user option controls the computation of the minibuffer prompt for
+the `compile' command.  See also 'project-compilation-command-prompt'.
+
 
 * Editing Changes in Emacs 31.1
 
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 8cfa793cfc6..f192ab11406 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -121,6 +121,13 @@ compilation-hidden-output
                  (repeat regexp))
   :version "29.1")
 
+(defcustom compilation-command-prompt "Compile command: "
+  "String or function to call to compute the `compile' command
+minibuffer prompt."
+  :type '(choice string
+                 function)
+  :version "31.1")
+
 (defvar compilation-first-column 1
   "This is how compilers number the first column, usually 1 or 0.
 If this is buffer-local in the destination buffer, Emacs obeys
@@ -1815,10 +1822,13 @@ compilation-mode-font-lock-keywords
    compilation-mode-font-lock-keywords))
 
 (defun compilation-read-command (command)
-  (read-shell-command "Compile command: " command
-                      (if (equal (car compile-history) command)
-                          '(compile-history . 1)
-                        'compile-history)))
+  (let ((prompt (if (functionp compilation-command-prompt)
+                    (funcall compilation-command-prompt)
+                  compilation-command-prompt))
+        (initial (if (equal (car compile-history) command)
+                     '(compile-history . 1)
+                   'compile-history)))
+  (read-shell-command prompt command initial)))
 
 
 ;;;###autoload
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index efc00ac8733..f2294422b7a 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1605,6 +1605,21 @@ project-compilation-buffer-name-function
                         project-prefixed-buffer-name)
                  (function :tag "Custom function")))
 
+(defcustom project-compilation-command-prompt #'project--compilation-command-prompt
+  "String or function to call to compute the `project-compile' command
+minibuffer prompt."
+  :type '(choice string
+                 function)
+  :version "31.1")
+
+(defun project--compilation-command-prompt ()
+  (let ((project (project-current)))
+    (if project
+        (format-message "Compile command in `%s': "
+                        (propertize (project-root project)
+                                    'face 'font-lock-string-face))
+      "Compile command: ")))
+
 ;;;###autoload
 (defun project-compile ()
   "Run `compile' in the project root."
@@ -1613,7 +1628,8 @@ project-compile
   (let ((default-directory (project-root (project-current t)))
         (compilation-buffer-name-function
          (or project-compilation-buffer-name-function
-             compilation-buffer-name-function)))
+             compilation-buffer-name-function))
+        (compilation-command-prompt project-compilation-command-prompt))
     (call-interactively #'compile)))
 
 ;;;###autoload
-- 
2.34.1


---
Gabriel



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79292; Package emacs. (Fri, 22 Aug 2025 17:16:01 GMT) Full text and rfc822 format available.

Message #8 received at 79292 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com>
Cc: 79292 <at> debbugs.gnu.org
Subject: Re: bug#79292: [PATCH] Improve project-compile command prompt
Date: Fri, 22 Aug 2025 20:15:25 +0300
> From: Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com>
> Date: Fri, 22 Aug 2025 16:46:58 +0000
> msip_labels: 
> 
> Improve 'project-compile' command prompt, which makes it more consistent with
> the new project switch prompt introduced by commit 86e17fbcbddb, and makes it
> clear to users which compilation command is being executed (default 'compile' or
> 'project-compile').

Thanks, but IMO making compilation-command-prompt a defcustom is the
wrong way to implement this.  A defcustom is a user option, and thus
should not be overridden by Lisp programs, ever.  Instead, make it a
defvar, then Lisp programs could bind it to whatever values they want.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79292; Package emacs. (Wed, 27 Aug 2025 20:25:01 GMT) Full text and rfc822 format available.

Message #11 received at 79292 <at> debbugs.gnu.org (full text, mbox):

From: Rudolf Adamkovič <rudolf <at> adamkovic.org>
To: Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com>,
 79292 <at> debbugs.gnu.org
Subject: Re: bug#79292: [PATCH] Improve project-compile command prompt
Date: Wed, 27 Aug 2025 22:23:46 +0200
Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com> writes:

> +*** New user option 'project-compilation-command-prompt'
> +This user option controls the computation of the minibuffer prompt for
> +the 'projet-compile' command.  See also 'compilation-command-prompt'.
        ^^^^^^
         typo

Rudy
-- 
"We shall not cease from exploration
 And the end of all our exploring
 Will be to arrive where we started
 And know the place for the first time"
--- T. S. Eliot, Little Gidding, Four Quarters, 1943

Rudolf Adamkovič <rudolf <at> adamkovic.org> [he/him]
http://adamkovic.org




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79292; Package emacs. (Wed, 27 Aug 2025 20:45:01 GMT) Full text and rfc822 format available.

Message #14 received at 79292 <at> debbugs.gnu.org (full text, mbox):

From: Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: "79292 <at> debbugs.gnu.org" <79292 <at> debbugs.gnu.org>
Subject: Re: bug#79292: [PATCH] Improve project-compile command prompt
Date: Wed, 27 Aug 2025 20:43:51 +0000
I thought that temporarily binding an user-option was fine.  Anyway, here is
an updated version of the patch that uses a defvar.  Thanks!

From 4cabf62e8e6a6b7c8f3a0c4afa177a04b7594d88 Mon Sep 17 00:00:00 2001
From: Gabriel Ribeiro <gabriel376 <at> hotmail.com>
Date: Wed, 27 Aug 2025 17:38:23 -0300
Subject: [PATCH] Include project root in project-compile prompt

* lisp/progmodes/compile.el:
  (compilation-command-prompt): New variable.
  (compilation-read-command): Use it.
* lisp/progmodes/project.el:
  (project-compilation-command-prompt): New user option.
  (project--compilation-command-prompt): New function to generate the
  default project-compile prompt.
  (project-compile): Use it.
---
 etc/NEWS                  |  4 ++++
 lisp/progmodes/compile.el | 15 +++++++++++----
 lisp/progmodes/project.el | 18 +++++++++++++++++-
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index bd2ce33b851..0b183df629a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -516,6 +516,10 @@ project should be removed.
 *** New command 'project-save-some-buffers' bound to 'C-x p C-x s'.
 This is like 'C-x s', but only for this project's buffers.

+*** New user option 'project-compilation-command-prompt'
+This user option controls the computation of the minibuffer prompt for
+the 'project-compile' command.
+
 *** 'project-remember-project' can now be called interactively.

 ---
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el
index 8cfa793cfc6..5f75fc3abca 100644
--- a/lisp/progmodes/compile.el
+++ b/lisp/progmodes/compile.el
@@ -121,6 +121,10 @@ compilation-hidden-output
                  (repeat regexp))
   :version "29.1")

+(defvar compilation-command-prompt "Compile command: "
+  "String or function to call to compute the `compile' command
+minibuffer prompt.")
+
 (defvar compilation-first-column 1
   "This is how compilers number the first column, usually 1 or 0.
 If this is buffer-local in the destination buffer, Emacs obeys
@@ -1815,10 +1819,13 @@ compilation-mode-font-lock-keywords
    compilation-mode-font-lock-keywords))

 (defun compilation-read-command (command)
-  (read-shell-command "Compile command: " command
-                      (if (equal (car compile-history) command)
-                          '(compile-history . 1)
-                        'compile-history)))
+  (let ((prompt (if (functionp compilation-command-prompt)
+                    (funcall compilation-command-prompt)
+                  compilation-command-prompt))
+        (initial (if (equal (car compile-history) command)
+                     '(compile-history . 1)
+                   'compile-history)))
+  (read-shell-command prompt command initial)))



 ;;;###autoload
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 05f3a9991be..02382fd5c95 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1605,6 +1605,21 @@ project-compilation-buffer-name-function
                         project-prefixed-buffer-name)
                  (function :tag "Custom function")))

+(defcustom project-compilation-command-prompt #'project--compilation-command-prompt
+  "String or function to call to compute the `project-compile' command
+minibuffer prompt."
+  :type '(choice string
+                 function)
+  :version "31.1")
+
+(defun project--compilation-command-prompt ()
+  (let ((project (project-current)))
+    (if project
+        (format-message "Compile command in `%s': "
+                        (propertize (project-root project)
+                                    'face 'font-lock-string-face))
+      "Compile command: ")))
+
 ;;;###autoload
 (defun project-compile ()
   "Run `compile' in the project root."
@@ -1613,7 +1628,8 @@ project-compile
   (let ((default-directory (project-root (project-current t)))
         (compilation-buffer-name-function
          (or project-compilation-buffer-name-function
-             compilation-buffer-name-function)))
+             compilation-buffer-name-function))
+        (compilation-command-prompt project-compilation-command-prompt))
     (call-interactively #'compile)))

 ;;;###autoload
--
2.34.1


---
Gabriel

________________________________________
From: Eli Zaretskii <eliz <at> gnu.org>
Sent: Friday, August 22, 2025 2:15 PM
To: Gabriel do Nascimento Ribeiro
Cc: 79292 <at> debbugs.gnu.org
Subject: Re: bug#79292: [PATCH] Improve project-compile command prompt

> From: Gabriel do Nascimento Ribeiro <gabriel376 <at> hotmail.com>
> Date: Fri, 22 Aug 2025 16:46:58 +0000
> msip_labels:
>
> Improve 'project-compile' command prompt, which makes it more consistent with
> the new project switch prompt introduced by commit 86e17fbcbddb, and makes it
> clear to users which compilation command is being executed (default 'compile' or
> 'project-compile').

Thanks, but IMO making compilation-command-prompt a defcustom is the
wrong way to implement this.  A defcustom is a user option, and thus
should not be overridden by Lisp programs, ever.  Instead, make it a
defvar, then Lisp programs could bind it to whatever values they want.




This bug report was last modified 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.