unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#45765: [PATCH] 28.0.50; Change default-directory before prompting in project-compile
@ 2021-01-10 12:57 Kévin Le Gouguec
  2021-01-11  0:47 ` Dmitry Gutov
  2021-01-11 18:35 ` Juri Linkov
  0 siblings, 2 replies; 12+ messages in thread
From: Kévin Le Gouguec @ 2021-01-10 12:57 UTC (permalink / raw)
  To: 45765; +Cc: Juri Linkov

[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]

Hello,

Unlike project-shell-command, project-compile first prompts for a
command, then binds default-directory and calls compile.  Binding
default-directory first makes completion work from the project root,
which is useful for completing on filenames relative to the root, on
targets from the toplevel Makefile, etc.

I see three ways to achieve this:

(1) Rewrite project-compile with call-interactively, the way
project-shell-command is written (see patch #1).

(2) Set COMMAND to nil in the interactive spec, then prompt for it after
binding default-directory (see patch #2).

(3) Let-binding default-directory once in the interactive spec, and
again before calling compile.


I'm assuming (1) is out of the question, given 2020-06-02
"* lisp/progmodes/project.el (project-vc-dir, project-shell): New
commands." (2c1e5b9e77).  I'm CC'ing Juri to get his opinion though;
project-compile is new in Emacs 28.1, so its argument list is not yet
set in stone.

I've taken a stab at (2), but my patch changes the semantics of COMMAND
for an edge case: for now calling (project-compile nil) from Lisp causes
(compile nil) to be called (which errors out); with my patch,
(project-compile nil) yields a prompt.

This can be solved using called-interactively-p (or using an optional
INTERACTIVE argument); I just don't know if it's worth the hassle?

I haven't given much thought to (3), so I haven't yet figured out how to
avoid prompting twice for the project (on the rare occasions where
prompting is needed).


Thanks for your time.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Change-default-directory-before-prompting-in-project-1.patch --]
[-- Type: text/x-patch, Size: 1666 bytes --]

From 801311cef5a825af93a41cc044b4f753b648a866 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= <kevin.legouguec@gmail.com>
Date: Sun, 10 Jan 2021 10:43:41 +0100
Subject: [PATCH] Change default-directory before prompting in project-compile

This causes command completion to work from the project root, letting
users complete top-level folders, make targets, etc.

* lisp/progmodes/project.el (project-compile): Simplify using
call-interactively, as done with project(-aysnc)-shell-command.
---
 lisp/progmodes/project.el | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 62c3cf44cb..06966f33b7 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -970,20 +970,11 @@ compilation-read-command
 (declare-function compilation-read-command "compile")
 
 ;;;###autoload
-(defun project-compile (command &optional comint)
-  "Run `compile' in the project root.
-Arguments the same as in `compile'."
-  (interactive
-   (list
-    (let ((command (eval compile-command)))
-      (require 'compile)
-      (if (or compilation-read-command current-prefix-arg)
-	  (compilation-read-command command)
-	command))
-    (consp current-prefix-arg)))
-  (let* ((pr (project-current t))
-         (default-directory (project-root pr)))
-    (compile command comint)))
+(defun project-compile ()
+  "Run `compile' in the project root."
+  (interactive)
+  (let ((default-directory (project-root (project-current t))))
+    (call-interactively #'compile)))
 
 (defun project--read-project-buffer ()
   (let* ((pr (project-current t))
-- 
2.29.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-Change-default-directory-before-prompting-in-project-2.patch --]
[-- Type: text/x-patch, Size: 1842 bytes --]

From b1b10d01a83b2b07a27ce6bcf12cf000fabaf22a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= <kevin.legouguec@gmail.com>
Date: Sun, 10 Jan 2021 13:18:07 +0100
Subject: [PATCH] Change default-directory before prompting in project-compile

This causes command completion to work from the project root, letting
users complete top-level folders, make targets, etc.

* lisp/progmodes/project.el (project-compile): Read command after
binding default-directory to project root.
---
 lisp/progmodes/project.el | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 62c3cf44cb..1e7f6d7c06 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -974,15 +974,17 @@ project-compile
   "Run `compile' in the project root.
 Arguments the same as in `compile'."
   (interactive
-   (list
-    (let ((command (eval compile-command)))
-      (require 'compile)
-      (if (or compilation-read-command current-prefix-arg)
-	  (compilation-read-command command)
-	command))
-    (consp current-prefix-arg)))
-  (let* ((pr (project-current t))
-         (default-directory (project-root pr)))
+   (list nil
+         (consp current-prefix-arg)))
+  ;; Bind `default-directory' before prompting for COMMAND, so that
+  ;; command completion works from the project root.
+  (let ((default-directory (project-root (project-current t)))
+        (command (or command
+                     (let ((command (eval compile-command)))
+                       (require 'compile)
+                       (if (or compilation-read-command current-prefix-arg)
+	                   (compilation-read-command command)
+                         command)))))
     (compile command comint)))
 
 (defun project--read-project-buffer ()
-- 
2.29.2


[-- Attachment #4: Type: text/plain, Size: 845 bytes --]



In GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
 of 2021-01-04 built on my-little-tumbleweed
Repository revision: 2c847902522ae74c9b25b2a3fa60565e0187fd0a
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12010000
System Description: openSUSE Tumbleweed

Configured using:
 'configure --with-xwidgets --with-cairo'

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF
ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS XWIDGETS JSON
PDUMPER LCMS2

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_TIME: en_GB.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=local
  locale-coding-system: utf-8-unix

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-01-19 19:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-10 12:57 bug#45765: [PATCH] 28.0.50; Change default-directory before prompting in project-compile Kévin Le Gouguec
2021-01-11  0:47 ` Dmitry Gutov
2021-01-11 18:35 ` Juri Linkov
2021-01-11 19:13   ` Dmitry Gutov
2021-01-11 21:24     ` Kévin Le Gouguec
2021-01-12 18:46       ` Juri Linkov
2021-01-13  1:06         ` Dmitry Gutov
2021-01-13 18:05           ` Juri Linkov
2021-01-13 19:46           ` Kévin Le Gouguec
2021-01-16  3:51             ` Dmitry Gutov
2021-01-19 17:38               ` Juri Linkov
2021-01-19 19:50                 ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).