On 29/11/2022 12:17, João Távora wrote:
What do you mean, without breaking compatibility? Adding a new required argument means it will break any Lisp code that calls this function.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.
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.
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'.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.
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)))
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4