unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Emacs and Squiggles as filenames
@ 2005-07-07 19:07 D Goel
  2005-07-09  4:21 ` Richard M. Stallman
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: D Goel @ 2005-07-07 19:07 UTC (permalink / raw)



(expand-file-name (file-name-nondirectory fname) dir)


should return fname back.  It is like an identity, right?  If not,
what is the way to *always* correctly do an expand-file-name ?

The exception I saw was here:

If there exists a file named "~" in my ~/tmp/, I see funny things:

(expand-file-name (file-name-nondirectory "~/tmp/~") "~/tmp"), returns

=>/home/deego instead of /home/deego/tmp/~ 
 

^^ I had a function doing recursive stuff using directory-files.. and
	ascending up 2 directories like this caused an infinite loop..



Other interesting things:

(file-truename "~/tmp/~")
=> "/home/deego/tmp/~"



Yet, "~/tmp/~" is apparently the correct representation, as returned by
 (directory-files "~/tmp" t)

Moreover, (directory-files "~/tmp" nil) simply returns "~".


Is an escape missing somewhere in emacs internals?  Or, is an elisp
user supposed to call some escaping functions before doing
expand-file-name ?

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

* Re: Emacs and Squiggles as filenames
  2005-07-07 19:07 Emacs and Squiggles as filenames D Goel
@ 2005-07-09  4:21 ` Richard M. Stallman
  2005-07-09  4:21 ` Richard M. Stallman
  2005-07-10  4:05 ` Paul Jarc
  2 siblings, 0 replies; 11+ messages in thread
From: Richard M. Stallman @ 2005-07-09  4:21 UTC (permalink / raw)
  Cc: emacs-devel

    (file-truename "~/tmp/~")
    => "/home/deego/tmp/~"

That is correct.

    Yet, "~/tmp/~" is apparently the correct representation, as returned by
     (directory-files "~/tmp" t)

They are both correct representations.  However, I am surprised
that directory-files returns names using ~/.  It does not do so
when I try it.

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

* Re: Emacs and Squiggles as filenames
  2005-07-07 19:07 Emacs and Squiggles as filenames D Goel
  2005-07-09  4:21 ` Richard M. Stallman
@ 2005-07-09  4:21 ` Richard M. Stallman
  2005-07-10  4:05 ` Paul Jarc
  2 siblings, 0 replies; 11+ messages in thread
From: Richard M. Stallman @ 2005-07-09  4:21 UTC (permalink / raw)
  Cc: emacs-devel

    If there exists a file named "~" in my ~/tmp/, I see funny things:

    (expand-file-name (file-name-nondirectory "~/tmp/~") "~/tmp"), returns

    =>/home/deego instead of /home/deego/tmp/~ 

That is a painful one.  I am not sure what we could do to fix it,
other than make expand-file-name not handle ~.  And I think that would
cause much worse problems, and fixing them would require a major
redesign that would break lots of Lisp code.

It is possible to refer to that file by writing `./~'.
So that expression would work right if we made file-name-nondirectory
return "./~".  But I think that would break other things too.

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

* Re: Emacs and Squiggles as filenames
  2005-07-07 19:07 Emacs and Squiggles as filenames D Goel
  2005-07-09  4:21 ` Richard M. Stallman
  2005-07-09  4:21 ` Richard M. Stallman
@ 2005-07-10  4:05 ` Paul Jarc
  2005-07-10  8:31   ` David Kastrup
  2005-07-11 12:37   ` D Goel
  2 siblings, 2 replies; 11+ messages in thread
From: Paul Jarc @ 2005-07-10  4:05 UTC (permalink / raw)
  Cc: emacs-devel

"D Goel" <deego@gnufans.org> wrote:
> (expand-file-name (file-name-nondirectory fname) dir)
>
>
> should return fname back.  It is like an identity, right?  If not,
> what is the way to *always* correctly do an expand-file-name ?

This works for me:
(concat (file-name-as-directory "~/tmp")
        (file-name-nondirectory "~/tmp/~"))


paul

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

* Re: Emacs and Squiggles as filenames
  2005-07-10  4:05 ` Paul Jarc
@ 2005-07-10  8:31   ` David Kastrup
  2005-07-11  5:34     ` Richard M. Stallman
  2005-07-11 12:37   ` D Goel
  1 sibling, 1 reply; 11+ messages in thread
From: David Kastrup @ 2005-07-10  8:31 UTC (permalink / raw)
  Cc: emacs-devel

prj@po.cwru.edu (Paul Jarc) writes:

> "D Goel" <deego@gnufans.org> wrote:
>> (expand-file-name (file-name-nondirectory fname) dir)
>>
>>
>> should return fname back.  It is like an identity, right?  If not,
>> what is the way to *always* correctly do an expand-file-name ?
>
> This works for me:
> (concat (file-name-as-directory "~/tmp")
>         (file-name-nondirectory "~/tmp/~"))

I am afraid that the former version is _so_ ingrained into Elisp code
that we should add advice into DOC strings and Elisp manual.

_If_ the latter is sure to work under all circumstances.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: Emacs and Squiggles as filenames
  2005-07-10  8:31   ` David Kastrup
@ 2005-07-11  5:34     ` Richard M. Stallman
  2005-07-11  7:53       ` David Kastrup
  0 siblings, 1 reply; 11+ messages in thread
From: Richard M. Stallman @ 2005-07-11  5:34 UTC (permalink / raw)
  Cc: deego, emacs-devel

    >> (expand-file-name (file-name-nondirectory fname) dir)
    >>
    >>
    >> should return fname back.  It is like an identity, right?  If not,
    >> what is the way to *always* correctly do an expand-file-name ?
    >
    > This works for me:
    > (concat (file-name-as-directory "~/tmp")
    >         (file-name-nondirectory "~/tmp/~"))

    I am afraid that the former version is _so_ ingrained into Elisp code
    that we should add advice into DOC strings and Elisp manual.

It is not just frequent, it is what we have always called "the right
way".  Using concat has been slightly deprecated, partly because it
won't work in the case where the directory name fails to end in a
slash.  Many places in the code were written to use expand-file-name
because it was the preferred method.

I think that using concat will always work right when the directory
name is properly formatted.  However, rather than recommend use of
concat, I would rather define a new function specifically for this
purpose.  It could be called `merge-file-name'.

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

* Re: Emacs and Squiggles as filenames
  2005-07-11  5:34     ` Richard M. Stallman
@ 2005-07-11  7:53       ` David Kastrup
  2005-07-11 21:14         ` Richard M. Stallman
  0 siblings, 1 reply; 11+ messages in thread
From: David Kastrup @ 2005-07-11  7:53 UTC (permalink / raw)
  Cc: deego, emacs-devel

"Richard M. Stallman" <rms@gnu.org> writes:

>     >> (expand-file-name (file-name-nondirectory fname) dir)
>     >>
>     >>
>     >> should return fname back.  It is like an identity, right?  If not,
>     >> what is the way to *always* correctly do an expand-file-name ?
>     >
>     > This works for me:
>     > (concat (file-name-as-directory "~/tmp")
>     >         (file-name-nondirectory "~/tmp/~"))
>
>     I am afraid that the former version is _so_ ingrained into Elisp code
>     that we should add advice into DOC strings and Elisp manual.
>
> It is not just frequent, it is what we have always called "the right
> way".  Using concat has been slightly deprecated, partly because it
> won't work in the case where the directory name fails to end in a
> slash.

Can't happen when file-name-as-directory is used, right?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: Emacs and Squiggles as filenames
  2005-07-10  4:05 ` Paul Jarc
  2005-07-10  8:31   ` David Kastrup
@ 2005-07-11 12:37   ` D Goel
  2005-07-11 13:41     ` David Kastrup
  1 sibling, 1 reply; 11+ messages in thread
From: D Goel @ 2005-07-11 12:37 UTC (permalink / raw)


prj@po.cwru.edu (Paul Jarc) writes:

> "D Goel" <deego@gnufans.org> wrote:
>> (expand-file-name (file-name-nondirectory fname) dir)
>>

> This works for me:
> (concat (file-name-as-directory "~/tmp")
>         (file-name-nondirectory "~/tmp/~"))
>


Thanks, I will use just that. 

(I do remember reading in the manual though that the former is
preferable, because it is portable across OSes, including VMS..)



DG                                 http://gnufans.net/
--

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

* Re: Emacs and Squiggles as filenames
  2005-07-11 12:37   ` D Goel
@ 2005-07-11 13:41     ` David Kastrup
  2005-07-11 15:32       ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: David Kastrup @ 2005-07-11 13:41 UTC (permalink / raw)
  Cc: emacs-devel

"D Goel" <deego@gnufans.org> writes:

> prj@po.cwru.edu (Paul Jarc) writes:
>
>> "D Goel" <deego@gnufans.org> wrote:
>>> (expand-file-name (file-name-nondirectory fname) dir)
>>>
>
>> This works for me:
>> (concat (file-name-as-directory "~/tmp")
>>         (file-name-nondirectory "~/tmp/~"))
>>
>
>
> Thanks, I will use just that. 
>
> (I do remember reading in the manual though that the former is
> preferable, because it is portable across OSes, including VMS..)

The latter, with file-name-as-directory, should also do the trick on
VMS unless I am mistaken.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

* Re: Emacs and Squiggles as filenames
  2005-07-11 13:41     ` David Kastrup
@ 2005-07-11 15:32       ` Stefan Monnier
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2005-07-11 15:32 UTC (permalink / raw)
  Cc: D Goel, emacs-devel

>>>> (expand-file-name (file-name-nondirectory fname) dir)
>> 
>>> This works for me:
>>> (concat (file-name-as-directory "~/tmp")
>>>         (file-name-nondirectory "~/tmp/~"))

Note that other than the issue of filenames like "~", `concat' is useful
also in the case where `dir' is not an absolute directory and you don't
want the output to be an absolute filename either.


        Stefan

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

* Re: Emacs and Squiggles as filenames
  2005-07-11  7:53       ` David Kastrup
@ 2005-07-11 21:14         ` Richard M. Stallman
  0 siblings, 0 replies; 11+ messages in thread
From: Richard M. Stallman @ 2005-07-11 21:14 UTC (permalink / raw)
  Cc: deego, emacs-devel

    > It is not just frequent, it is what we have always called "the right
    > way".  Using concat has been slightly deprecated, partly because it
    > won't work in the case where the directory name fails to end in a
    > slash.

    Can't happen when file-name-as-directory is used, right?

The method of using concat *and* file-name-as-directory is a reliable
method.  However, it is considerably more cumbersome than just using
concat--or just using expand-file-name.

So maybe it will work better to define a convenient function
as the new recommendation.

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

end of thread, other threads:[~2005-07-11 21:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-07 19:07 Emacs and Squiggles as filenames D Goel
2005-07-09  4:21 ` Richard M. Stallman
2005-07-09  4:21 ` Richard M. Stallman
2005-07-10  4:05 ` Paul Jarc
2005-07-10  8:31   ` David Kastrup
2005-07-11  5:34     ` Richard M. Stallman
2005-07-11  7:53       ` David Kastrup
2005-07-11 21:14         ` Richard M. Stallman
2005-07-11 12:37   ` D Goel
2005-07-11 13:41     ` David Kastrup
2005-07-11 15:32       ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).