emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: file-truename, convert-standard-filename


From: Drew Adams
Subject: RE: file-truename, convert-standard-filename
Date: Sat, 6 Feb 2010 12:46:02 -0800

> Let me try to step back a notch and try anew.

Thank you.

> There's a problem with file names, such as ".emacs", defined in Emacs
> Lisp code as literal strings: some filesystems don't allow such
> names.  `convert-standard-filename' was introduced to take a Posix
> file name and produce from it a file name that can be used instead on
> the particular filesystem.  So instead of
>   (defvar foo-file
>           (if (eq system-type 'foo)
>               "this"
>              (if (eq system-type 'bar)
>                  "that"
>                 ....
> we can now have just this:
>   (defvar foo-file (convert-standard-filename "this"))
> 
> So far so good?

Yes.

> Same considerations apply when a file name is constructed from
> fragments, like in (append ".emacs." (user-full-name) ".log")

OK. (But I think you meant `concat', not `append'.)

So it in fact has nothing specially to do with literal strings in source code.
That was apparently a red herring. (But you keep repeating it - e.g. see above;
so I wonder.)

This is the general rule, apparently:

> In order to get a file name that any supported platform could use, you
> need to run the result of this through `convert-standard-filename'.
> Okay?

I think so.

That means that in order to use ANY file name (any file-name string, no matter
where it was coded or how it is produced), you need to apply c-s-f to it, if you
don't know whether the name is supported by all platforms that might be used by
your code.

Am I wrong about that?

That would mean that the original code I showed would be necessary, and that
using f-t alone, without c-s-f, would not be sufficient. This is the original
code:

(string= (c-s-f (f-t FILE1)) (c-s-f (f-t FILE2)))

So am I misunderstanding now, or was your advice wrong that just f-t suffices
here? I'm not trying to point fingers - I appreciate your patient efforts to
explain; I'm just trying to understand.

> If this part is understood, then just use `convert-standard-filename'
> in any situation where a string to be used as a file name might not be
> valid on the underlying filesystem, 

Which for an unknown string (e.g. the string value of a variable) means ALL
situations, no? If I don't know which file system a user has, and I don't know
which file names are involved, then my code needs to call c-s-f for each file
name. No?

> like e.g. a literal `?' on a
> Windows disk.  An arbitrary string generally needs such a treatment,
> before it can safely be used as a file name.  That's why Emacs
> defcustoms use it.
> 
> Any questions so far?

I think I understand now - see above.
c-s-f is needed for an arbitrary string.

Confirmation or correction is welcome.

BTW, I notice that prior to Emacs 23 the Emacs source code did not use c-s-f
very much (e.g. defcustoms, such as in recentf.el); Emacs 23 uses it much more.
I suppose this means that we had more problems with this before Emacs 23.

But it does not seem like even the Emacs 23 source code calls c-s-f for all of
the situations that I think you're describing.

You seem to be saying that it's _nearly always needed_, unless (a) you know
which file system is being used, (b) you know the file name being used, and (c)
you know that that particular file name is a valid one for that particular file
system.

I haven't analyzed the Emacs code, but I don't get the impression that (a), (b),
and (c) are true for each file-name occurrence where it doesn't call c-s-f.
Maybe adding c-s-f everywhere is an ongoing thing, and the code just hasn't yet
caught up with the rule?

Thx - Drew





reply via email to

[Prev in Thread] Current Thread [Next in Thread]