all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil
@ 2025-02-03 18:10 Ship Mints
  2025-02-03 19:57 ` Eli Zaretskii
  2025-02-04  8:00 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 8+ messages in thread
From: Ship Mints @ 2025-02-03 18:10 UTC (permalink / raw)
  To: 76032

[-- Attachment #1: Type: text/plain, Size: 588 bytes --]

The following returns nil but I think this should return "~":

(file-name-directory "~") ; nil

If one considers "~" as the "user's root", it seems natural to respect "~"
as a directory equivalent and would be in harmony with:

(file-name-directory "/") which returns "/"

And also in harmony with:

(file-name-directory "~/") which returns "~/"

If one wants to guarantee a directory form, one does:

(file-name-as-directory "~") which does return "~/"

And this would allow this form to work:

(file-name-as-directory (file-name-directory "~")) rather than signal and
error.

-Stephane

[-- Attachment #2: Type: text/html, Size: 1613 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil
  2025-02-03 18:10 bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil Ship Mints
@ 2025-02-03 19:57 ` Eli Zaretskii
  2025-02-03 20:00   ` Ship Mints
  2025-02-04  8:00 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2025-02-03 19:57 UTC (permalink / raw)
  To: Ship Mints; +Cc: 76032

> From: Ship Mints <shipmints@gmail.com>
> Date: Mon, 3 Feb 2025 13:10:45 -0500
> 
> The following returns nil but I think this should return "~":
> 
> (file-name-directory "~") ; nil

file-name-directory is a purely syntactical function, it knows nothing
about the special meaning of "~".  It returns the "directory component
of a file name".  And "~" does not have such a component.

So I don't think it's a bug.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil
  2025-02-03 19:57 ` Eli Zaretskii
@ 2025-02-03 20:00   ` Ship Mints
  2025-02-03 22:25     ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: Ship Mints @ 2025-02-03 20:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 76032

[-- Attachment #1: Type: text/plain, Size: 757 bytes --]

Right. Let's consider this a feature request then. It's obvious that it's a
syntactical function but that doesn't prevent it from treating certain
strings specially. Or it has to be wrapped or guarded for the "user's root"
case.

On Mon, Feb 3, 2025 at 2:57 PM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Ship Mints <shipmints@gmail.com>
> > Date: Mon, 3 Feb 2025 13:10:45 -0500
> >
> > The following returns nil but I think this should return "~":
> >
> > (file-name-directory "~") ; nil
>
> file-name-directory is a purely syntactical function, it knows nothing
> about the special meaning of "~".  It returns the "directory component
> of a file name".  And "~" does not have such a component.
>
> So I don't think it's a bug.
>

[-- Attachment #2: Type: text/html, Size: 1303 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil
  2025-02-03 20:00   ` Ship Mints
@ 2025-02-03 22:25     ` Stefan Kangas
  2025-02-03 22:27       ` Ship Mints
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2025-02-03 22:25 UTC (permalink / raw)
  To: Ship Mints, Eli Zaretskii; +Cc: 76032

Ship Mints <shipmints@gmail.com> writes:

> Right. Let's consider this a feature request then. It's obvious that it's a
> syntactical function but that doesn't prevent it from treating certain
> strings specially. Or it has to be wrapped or guarded for the "user's root"
> case.

How about using this instead

    (expand-file-name "~")

?





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil
  2025-02-03 22:25     ` Stefan Kangas
@ 2025-02-03 22:27       ` Ship Mints
  0 siblings, 0 replies; 8+ messages in thread
From: Ship Mints @ 2025-02-03 22:27 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Zaretskii, 76032

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

The issue boils down to what other people have in their code that we can't
easily avoid. For example, code in project.el that needs help
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=75983


On Mon, Feb 3, 2025 at 5:25 PM Stefan Kangas <stefankangas@gmail.com> wrote:

> Ship Mints <shipmints@gmail.com> writes:
>
> > Right. Let's consider this a feature request then. It's obvious that
> it's a
> > syntactical function but that doesn't prevent it from treating certain
> > strings specially. Or it has to be wrapped or guarded for the "user's
> root"
> > case.
>
> How about using this instead
>
>     (expand-file-name "~")
>
> ?
>

[-- Attachment #2: Type: text/html, Size: 1292 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil
  2025-02-03 18:10 bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil Ship Mints
  2025-02-03 19:57 ` Eli Zaretskii
@ 2025-02-04  8:00 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2025-02-04 10:28   ` Ship Mints
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-02-04  8:00 UTC (permalink / raw)
  To: Ship Mints; +Cc: 76032

Ship Mints <shipmints@gmail.com> writes:

Hi,

> The following returns nil but I think this should return "~":
>
> (file-name-directory "~") ; nil
>
> If one considers "~" as the "user's root", it seems natural to respect
> "~" as a directory equivalent and would be in harmony with:

"~" is clearly a file name construct to be handled by
expand-file-name. We should not allow people to write too sloppy
code. There is a reason that Emacs has several operations for file
names, "since ever".

And remember, file-name-directoy has handlers, for example (but not
restricted to) Tramp. Not all of them in Emacs core. How do you want to
change them?

I'm against your proposal.

> -Stephane

Best regards, Michael.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil
  2025-02-04  8:00 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-02-04 10:28   ` Ship Mints
  2025-02-04 14:31     ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Ship Mints @ 2025-02-04 10:28 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 76032

[-- Attachment #1: Type: text/plain, Size: 1408 bytes --]

~ is the conventional equivalent of ~/, more precisely ~/. though the . is
elided nearly all the time, and hence not a file but a path to a directory.

In any case, if this will break things as a long-standing convention, let's
leave it alone. I definitely don't want to break Tramp or make maintenance
even more challenging than it already is.

I will guard my own code, add advice or replace erroneous code that I don't
control, and offer patches as I've been doing, like to project.el.

Please close this issue.

-Stephane

On Tue, Feb 4, 2025 at 3:00 AM Michael Albinus <michael.albinus@gmx.de>
wrote:

> Ship Mints <shipmints@gmail.com> writes:
>
> Hi,
>
> > The following returns nil but I think this should return "~":
> >
> > (file-name-directory "~") ; nil
> >
> > If one considers "~" as the "user's root", it seems natural to respect
> > "~" as a directory equivalent and would be in harmony with:
>
> "~" is clearly a file name construct to be handled by
> expand-file-name. We should not allow people to write too sloppy
> code. There is a reason that Emacs has several operations for file
> names, "since ever".
>
> And remember, file-name-directoy has handlers, for example (but not
> restricted to) Tramp. Not all of them in Emacs core. How do you want to
> change them?
>
> I'm against your proposal.
>
> > -Stephane
>
> Best regards, Michael.
>

[-- Attachment #2: Type: text/html, Size: 2503 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil
  2025-02-04 10:28   ` Ship Mints
@ 2025-02-04 14:31     ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2025-02-04 14:31 UTC (permalink / raw)
  To: Ship Mints; +Cc: michael.albinus, 76032-done

> Cc: 76032@debbugs.gnu.org
> From: Ship Mints <shipmints@gmail.com>
> Date: Tue, 4 Feb 2025 05:28:33 -0500
> 
> ~ is the conventional equivalent of ~/, more precisely ~/.

It is "equivalent" in some sense but not in others.  For the same
reason that "foo/" and "foo" are not necessarily equivalent in Emacs:
one has the form of a directory, the other has the form of a file
name.  We have functions like file-name-as-directory and
directory-file-name precisely because in some cases these are _not_
equivalent.

> I will guard my own code, add advice or replace erroneous code that I don't control, and offer patches as I've
> been doing, like to project.el.

That's the right thing to do, yes.

> Please close this issue.

Thanks, done.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-02-04 14:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-03 18:10 bug#76032: file-name-directory should treat "~" as the "user's root" and not return nil Ship Mints
2025-02-03 19:57 ` Eli Zaretskii
2025-02-03 20:00   ` Ship Mints
2025-02-03 22:25     ` Stefan Kangas
2025-02-03 22:27       ` Ship Mints
2025-02-04  8:00 ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-02-04 10:28   ` Ship Mints
2025-02-04 14:31     ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.