emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subprojects in project.el


From: Dmitry Gutov
Subject: Re: Subprojects in project.el
Date: Tue, 29 Nov 2022 21:07:34 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

On 29/11/2022 12:17, João Távora wrote:
Sorry I hit "send" before I wanted to.  This line of course be

   (interactive (list (project-current t)))

And the docstring should be

   "Run `compile' in PROJECT's root."

'project-current', when called with MAYBE-PROMPT, is running in an
interactive setting.  It could then consult the value of the prefix
argument and decide to prompt the user about which project to use
(including super-projects).

You can use this technique to a add PROJECT argument to all the other
relevant project-* operations without breaking backward compatibility,
even for non-interactive Lisp uses.

What do you mean, without breaking compatibility? Adding a new required argument means it will break any Lisp code that calls this function.

At least that's how I understand our standard criteria for this thing.

And it's probably not that big a deal if we had no other choice, but we do. Update the commands to call a different new function. That will actually require *fewer* changes, as you might have noticed now.

In cases where a "P" prefix argument is already in use, like C-x p f,
we'd have to repurpose the "negative prefix" part to_not_  mean
INCLUDE-ALL.  You'd affect only the people who are currently using M--
C-x p f instead of C-u C-x p f.

This hints that the choice of whether to use the parent or not should be made inside the command implementation. Perhaps inside the 'interactive' form, but not inside 'project-current'.

The principle of separation of concerns suggests the same.

Something like:

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index c1245704bcc..9e5fcfe0b06 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1139,6 +1139,19 @@ project-prefixed-buffer-name
           (downcase mode)
           "*"))

+(defun project-parent (project)
+  (project-current nil (file-name-as-directory
+                        (file-name-directory
+                         (directory-file-name (project-root project))))))
+
+(defun project-current-or-parent (lookup-parent)
+  (let ((project (project-current t)))
+    (when lookup-parent
+      (setq project (project-parent project)))
+    (unless project
+      (user-error "No parent project"))
+    project))
+
 (defcustom project-compilation-buffer-name-function nil
   "Function to compute the name of a project compilation buffer.
 If non-nil, it overrides `compilation-buffer-name-function' for
@@ -1155,7 +1168,8 @@ project-compile
   "Run `compile' in the project root."
   (declare (interactive-only compile))
   (interactive)
-  (let ((default-directory (project-root (project-current t)))
+  (let ((default-directory (project-root (project-current-or-parent
+                                          (eq current-prefix-arg '-))))
         (compilation-buffer-name-function
          (or project-compilation-buffer-name-function
              compilation-buffer-name-function)))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]