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