GNU bug report logs - #60188
30.0.50; zerop cpd-length are not all handled in project--read-file-cpd-relative

Previous Next

Package: emacs;

Reported by: Shuguang Sun <shuguang79 <at> qq.com>

Date: Mon, 19 Dec 2022 05:14:01 UTC

Severity: normal

Found in version 30.0.50

To reply to this bug, email your comments to 60188 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#60188; Package emacs. (Mon, 19 Dec 2022 05:14:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Shuguang Sun <shuguang79 <at> qq.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 19 Dec 2022 05:14:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Shuguang Sun <shuguang79 <at> qq.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; zerop cpd-length are not all handled in
 project--read-file-cpd-relative
Date: Mon, 19 Dec 2022 13:12:09 +0800
Dear all,

When I call C-x p d (project-find-dir), it reports the error message:
`project--read-file-cpd-relative: Wrong type argument: stringp, nil`

Finaly I found it is due the the zero length of
`common-parent-directory` in `project--read-file-cpd-relative` as I
using `fd` to provide the list of dirs which does not include the common
project root in the returnd dirs.

In `project--read-file-cpd-relative`, the zero length of
`common-parent-directory` is handled for `prompt` but not for `abbr-cpd`
which will be used as parameter of `string-prefix-p`.

Below is the diff and a working patch. But no sure for the impact of HIST.

```
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 559da6dd649..8c4ea8eeca0 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1039,7 +1039,9 @@ project--read-file-cpd-relative
          (_ (when included-cpd
               (setq substrings (cons "./" substrings))))
          (new-collection (project--file-completion-table substrings))
-         (abbr-cpd (abbreviate-file-name common-parent-directory))
+         (abbr-cpd (if (zerop cpd-length)
+                       ""
+                     (abbreviate-file-name common-parent-directory)))
          (relname (cl-letf ((history-add-new-input nil)
                             ((symbol-value hist)
                              (mapcan
```

Best Regards,
Shuguang Sun

In GNU Emacs 30.0.50 (build 1, x86_64-w64-mingw32) of 2022-12-18 built
 on YJ190169
Repository revision: 2c2ecb46b0ad3e841ac9551e3a80d02893cdf6ec
Repository branch: master
Windowing system distributor 'Microsoft Corp.', version 10.0.22621
System Description: Microsoft Windows 10 Home China (v10.0.2009.22621.963)

Configured using:
 'configure --without-pop --with-native-image-api
 --with-native-compilation --with-tree-sitter --without-compress-install
 '--program-transform-name=s/^ctags$/ctags.emacs/''

Configured features:
ACL DBUS GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES
NATIVE_COMP NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XPM ZLIB




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60188; Package emacs. (Mon, 19 Dec 2022 19:51:01 GMT) Full text and rfc822 format available.

Message #8 received at 60188 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Shuguang Sun <shuguang79 <at> qq.com>
Cc: 60188 <at> debbugs.gnu.org
Subject: Re: bug#60188: 30.0.50; zerop cpd-length are not all handled in
 project--read-file-cpd-relative
Date: Mon, 19 Dec 2022 21:50:02 +0200
> When I call C-x p d (project-find-dir), it reports the error message:
> `project--read-file-cpd-relative: Wrong type argument: stringp, nil`
>
> Finaly I found it is due the the zero length of
> `common-parent-directory` in `project--read-file-cpd-relative` as I
> using `fd` to provide the list of dirs which does not include the common
> project root in the returnd dirs.
>
> In `project--read-file-cpd-relative`, the zero length of
> `common-parent-directory` is handled for `prompt` but not for `abbr-cpd`
> which will be used as parameter of `string-prefix-p`.
>
> Below is the diff and a working patch. But no sure for the impact of HIST.
>
> ```
> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
> index 559da6dd649..8c4ea8eeca0 100644
> --- a/lisp/progmodes/project.el
> +++ b/lisp/progmodes/project.el
> @@ -1039,7 +1039,9 @@ project--read-file-cpd-relative
>           (_ (when included-cpd
>                (setq substrings (cons "./" substrings))))
>           (new-collection (project--file-completion-table substrings))
> -         (abbr-cpd (abbreviate-file-name common-parent-directory))
> +         (abbr-cpd (if (zerop cpd-length)
> +                       ""
> +                     (abbreviate-file-name common-parent-directory)))

Strange, I can't reproduce the problem.  When cpd-length is 0,
then for the empty string (abbreviate-file-name "") returns "".




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60188; Package emacs. (Mon, 19 Dec 2022 21:56:02 GMT) Full text and rfc822 format available.

Message #11 received at 60188 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Shuguang Sun <shuguang79 <at> qq.com>, 60188 <at> debbugs.gnu.org
Subject: Re: bug#60188: 30.0.50; zerop cpd-length are not all handled in
 project--read-file-cpd-relative
Date: Mon, 19 Dec 2022 23:55:35 +0200
On 19/12/2022 07:12, Shuguang Sun via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
> Finaly I found it is due the the zero length of
> `common-parent-directory` in `project--read-file-cpd-relative` as I
> using `fd` to provide the list of dirs which does not include the common
> project root in the returnd dirs.

Does that mean that it returns relative file names?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60188; Package emacs. (Mon, 19 Dec 2022 23:47:02 GMT) Full text and rfc822 format available.

Message #14 received at 60188 <at> debbugs.gnu.org (full text, mbox):

From: "Shuguang Sun" <shuguang79 <at> qq.com>
To: "Juri Linkov" <juri <at> linkov.net>
Cc: 60188 <60188 <at> debbugs.gnu.org>
Subject: Re: bug#60188: 30.0.50; zerop cpd-length are not all handled
 inproject--read-file-cpd-relative
Date: Tue, 20 Dec 2022 07:45:50 +0800
[Message part 1 (text/plain, inline)]
In my case,&nbsp;common-parent-directory is nil.






------------------ Original ------------------

&gt; When I call C-x p d (project-find-dir), it reports the error message:
&gt; `project--read-file-cpd-relative: Wrong type argument: stringp, nil`
&gt;
&gt; Finaly I found it is due the the zero length of
&gt; `common-parent-directory` in `project--read-file-cpd-relative` as I
&gt; using `fd` to provide the list of dirs which does not include the common
&gt; project root in the returnd dirs.
&gt;
&gt; In `project--read-file-cpd-relative`, the zero length of
&gt; `common-parent-directory` is handled for `prompt` but not for `abbr-cpd`
&gt; which will be used as parameter of `string-prefix-p`.
&gt;
&gt; Below is the diff and a working patch. But no sure for the impact of HIST.
&gt;
&gt; ```
&gt; diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
&gt; index 559da6dd649..8c4ea8eeca0 100644
&gt; --- a/lisp/progmodes/project.el
&gt; +++ b/lisp/progmodes/project.el
&gt; @@ -1039,7 +1039,9 @@ project--read-file-cpd-relative
&gt;           (_ (when included-cpd
&gt;                (setq substrings (cons "./" substrings))))
&gt;           (new-collection (project--file-completion-table substrings))
&gt; -         (abbr-cpd (abbreviate-file-name common-parent-directory))
&gt; +         (abbr-cpd (if (zerop cpd-length)
&gt; +                       ""
&gt; +                     (abbreviate-file-name common-parent-directory)))

Strange, I can't reproduce the problem.  When cpd-length is 0,
then for the empty string (abbreviate-file-name "") returns "".
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60188; Package emacs. (Mon, 19 Dec 2022 23:50:02 GMT) Full text and rfc822 format available.

Message #17 received at 60188 <at> debbugs.gnu.org (full text, mbox):

From: "Shuguang Sun" <shuguang79 <at> qq.com>
To: "Dmitry Gutov" <dgutov <at> yandex.ru>,
 "60188" <60188 <at> debbugs.gnu.org>
Subject: Re: bug#60188: 30.0.50; zerop cpd-length are not all handled
 inproject--read-file-cpd-relative
Date: Tue, 20 Dec 2022 07:48:55 +0800
[Message part 1 (text/plain, inline)]
Yes. It is relative file names and&nbsp;common-parent-directory is nil.


------------------ Original ------------------


On 19/12/2022 07:12, Shuguang Sun via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
&gt; Finaly I found it is due the the zero length of
&gt; `common-parent-directory` in `project--read-file-cpd-relative` as I
&gt; using `fd` to provide the list of dirs which does not include the common
&gt; project root in the returnd dirs.

Does that mean that it returns relative file names?
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60188; Package emacs. (Tue, 20 Dec 2022 00:56:02 GMT) Full text and rfc822 format available.

Message #20 received at 60188 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Shuguang Sun <shuguang79 <at> qq.com>, 60188 <60188 <at> debbugs.gnu.org>
Subject: Re: bug#60188: 30.0.50; zerop cpd-length are not all handled
 inproject--read-file-cpd-relative
Date: Tue, 20 Dec 2022 02:55:04 +0200
On 20/12/2022 01:48, Shuguang Sun wrote:
> Yes. It is relative file names and common-parent-directory is nil.
> 
> 
> ------------------ Original ------------------
> 
> On 19/12/2022 07:12, Shuguang Sun via Bug reports for GNU Emacs, the
> Swiss army knife of text editors wrote:
>  > Finaly I found it is due the the zero length of
>  > `common-parent-directory` in `project--read-file-cpd-relative` as I
>  > using `fd` to provide the list of dirs which does not include the common
>  > project root in the returnd dirs.
> 
> Does that mean that it returns relative file names?

I think the easiest solution is to make sure the returned file names are 
absolute ones (you'll need to do a bunch of 'concat' calls, but that has 
limited overhead). I want to work on that inefficency in project-files a 
little later, but now it's how it is.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60188; Package emacs. (Tue, 20 Dec 2022 08:43:02 GMT) Full text and rfc822 format available.

Message #23 received at 60188 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: "Shuguang Sun" <shuguang79 <at> qq.com>
Cc: 60188 <60188 <at> debbugs.gnu.org>
Subject: Re: bug#60188: 30.0.50; zerop cpd-length are not all handled
 inproject--read-file-cpd-relative
Date: Tue, 20 Dec 2022 10:41:27 +0200
>> Strange, I can't reproduce the problem. When cpd-length is 0,
>> then for the empty string (abbreviate-file-name "") returns "".

> In my case, common-parent-directory is nil.

I see.  This is because common-parent-directory is defined as:

  (if (> (length common-prefix) 0)
      (file-name-directory common-prefix))

But maybe it should also have the 'else' branch like:

  (if (> (length common-prefix) 0)
      (file-name-directory common-prefix)
    "")




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60188; Package emacs. (Wed, 21 Dec 2022 08:49:02 GMT) Full text and rfc822 format available.

Message #26 received at 60188 <at> debbugs.gnu.org (full text, mbox):

From: Shuguang Sun <shuguang79 <at> qq.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 60188 <at> debbugs.gnu.org
Subject: Re: bug#60188: 30.0.50; zerop cpd-length are not all handled in
 project--read-file-cpd-relative
Date: Wed, 21 Dec 2022 16:48:37 +0800
Juri Linkov <juri <at> linkov.net> writes:

>> When I call C-x p d (project-find-dir), it reports the error message:
>> `project--read-file-cpd-relative: Wrong type argument: stringp, nil`
>>
>> Finaly I found it is due the the zero length of
>> `common-parent-directory` in `project--read-file-cpd-relative` as I
>> using `fd` to provide the list of dirs which does not include the common
>> project root in the returnd dirs.
>>
>> In `project--read-file-cpd-relative`, the zero length of
>> `common-parent-directory` is handled for `prompt` but not for `abbr-cpd`
>> which will be used as parameter of `string-prefix-p`.
>>
>> Below is the diff and a working patch. But no sure for the impact of HIST.
>>
>> ```
>> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
>> index 559da6dd649..8c4ea8eeca0 100644
>> --- a/lisp/progmodes/project.el
>> +++ b/lisp/progmodes/project.el
>> @@ -1039,7 +1039,9 @@ project--read-file-cpd-relative
>>           (_ (when included-cpd
>>                (setq substrings (cons "./" substrings))))
>>           (new-collection (project--file-completion-table substrings))
>> -         (abbr-cpd (abbreviate-file-name common-parent-directory))
>> +         (abbr-cpd (if (zerop cpd-length)
>> +                       ""
>> +                     (abbreviate-file-name common-parent-directory)))
>
> Strange, I can't reproduce the problem.  When cpd-length is 0,
> then for the empty string (abbreviate-file-name "") returns "".
>
>
>
>

Actually in my case, it is `(abbreviate-file-name nil)`. As `fd` returns
relative path, common-parent-directory is nil.

-- 
Best Regards
Shuguang Sun




This bug report was last modified 1 year and 125 days ago.

Previous Next


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