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: Wed, 30 Nov 2022 03:10:44 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

On 30/11/2022 00:52, João Távora wrote:
Dmitry Gutov <dgutov@yandex.ru> writes:

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

The example I gave you was for a function explicitly marked "interactive
only", so it's not a problem.  In fact all these functions should be
"interactive only".  But in other cases, make that argument optional.

The commands that are marked 'interactive-only' are those that we have decided are useless in Lisp programs. Others aren't marked such.

+(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)))

Sounds more complicated that it needs to be, and no reason why
project-current-or-parent shouldn't be just project-current, with
another optional argument at most.

If it's a new optional argument vs new function, I can see the benefits of either. OT1H, project-current is shorter.

OT2H, some code (or even a person) might like to check (fboundp 'project-current-or-parent).

Anyway, I'm not crazy about the name of the argument (lookup-parent), so suggestions are welcome on that.



reply via email to

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