GNU bug report logs - #62974
29.0.60; New buffers created with project-switch-to-buffer aren't in the project

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Thu, 20 Apr 2023 18:38:01 UTC

Severity: normal

Found in version 29.0.60

Fixed in version 30.1

Done: Dmitry Gutov <dmitry <at> gutov.dev>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: sbaugh <at> catern.com, Eli Zaretskii <eliz <at> gnu.org>, 62974 <at> debbugs.gnu.org
Subject: bug#62974: 29.0.60; New buffers created with project-switch-to-buffer aren't in the project
Date: Fri, 21 Apr 2023 12:25:49 -0400
Dmitry Gutov <dmitry <at> gutov.dev> writes:
> On 21/04/2023 16:17, sbaugh <at> catern.com wrote:
>> Eli Zaretskii<eliz <at> gnu.org>  writes:
>>>> From: Spencer Baugh<sbaugh <at> janestreet.com>
>>>> Date: Fri, 21 Apr 2023 07:46:14 -0400
>>>> Cc: Dmitry Gutov<dmitry <at> gutov.dev>,62974 <at> debbugs.gnu.org
>>>>
>>>>   But if it is in a subdirectory of the root, it also belongs to the
>>>>   project, doesn't it?  Exactly like the buffer from which this command
>>>>   is invoked, whose default-directory was a subdirectory of the root.
>>>>   No?
>>>>
>>>> That's fine, I wouldn't want to change that behavior, the behavior I'd want to change is when invoking
>>>> the command from a buffer which is not in a project, or by invoking it after C-x p p to switch projects.
>>> The recipe you posted didn't include "C-x p p", though.
>> My recipe was an example of "command from a buffer which is not in a
>> project".  Here's a recipe for the issue using C-x p p:
>> 1. (setq project-switch-use-entire-map t)
>> 2. Be in a buffer in project A
>> 3. C-x p p b to switch to project B and select a buffer in project B
>> 4. Type a buffer name which doesn't exist
>> 5. The resulting buffer is in project A, not B
>
> Thanks.
>
> How does this look?
>
> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
> index a18b918db62..94c7f8f547a 100644
> --- a/lisp/progmodes/project.el
> +++ b/lisp/progmodes/project.el
> @@ -1314,13 +1314,17 @@ project--read-project-buffer
>              (and (memq (cdr buffer) buffers)
>                   (not
>                    (project--buffer-check
> -                   (cdr buffer) project-ignore-buffer-conditions))))))
> -    (read-buffer
> -     "Switch to buffer: "
> -     (when (funcall predicate (cons other-name other-buffer))
> -       other-name)
> -     nil
> -     predicate)))
> +                   (cdr buffer) project-ignore-buffer-conditions)))))
> +         (buffer (read-buffer
> +                  "Switch to buffer: "
> +                  (when (funcall predicate (cons other-name other-buffer))
> +                    other-name)
> +                  nil
> +                  predicate)))
> +    (if (get-buffer buffer)
> +        buffer
> +      (let ((default-directory (project-root pr)))
> +        (get-buffer-create buffer)))))
>
>  ;;;###autoload
>  (defun project-switch-to-buffer (buffer-or-name)

That looks good and it fixes all the bug cases I mentioned.

But what about the case where the old buffer was already in the project?

1. In a buffer visiting project-a/some/dir/file.el
2. C-x p b nonexisting-buffer RET

Existing behavior, and possibly desirable behavior:
3. default-directory in new buffer: project-a/some/dir/

With your change:
3. default-directory in new buffer: project-a/





This bug report was last modified 2 years and 26 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.