unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: Strange `file-name-sans-extension' behavior
       [not found] <uptxa211i.fsf@oracle.com>
@ 2002-07-27 18:53 ` Richard Stallman
  2002-08-09  7:38   ` Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2002-07-27 18:53 UTC (permalink / raw)
  Cc: emacs-devel

Does this fix it?

*** files.el.~1.598.~	Fri Jul 26 11:47:31 2002
--- files.el	Sat Jul 27 14:16:42 2002
***************
*** 2468,2475 ****
        (if (and (string-match "\\.[^.]*\\'" file)
  	       (not (eq 0 (match-beginning 0))))
  	  (if (setq directory (file-name-directory filename))
! 	      (expand-file-name (substring file 0 (match-beginning 0))
! 				directory)
  	    (substring file 0 (match-beginning 0)))
  	filename))))
  
--- 2468,2476 ----
        (if (and (string-match "\\.[^.]*\\'" file)
  	       (not (eq 0 (match-beginning 0))))
  	  (if (setq directory (file-name-directory filename))
! 	      ;; Don't use expand-file-name here; if DIRECTORY is relative,
! 	      ;; we don't want to expand it.
! 	      (concat directory (substring file 0 (match-beginning 0)))
  	    (substring file 0 (match-beginning 0)))
  	filename))))

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

* Re: Strange `file-name-sans-extension' behavior
  2002-07-27 18:53 ` Strange `file-name-sans-extension' behavior Richard Stallman
@ 2002-08-09  7:38   ` Stefan Monnier
  2002-08-10 17:16     ` Richard Stallman
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2002-08-09  7:38 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

> Does this fix it?
> 
> *** files.el.~1.598.~	Fri Jul 26 11:47:31 2002
> --- files.el	Sat Jul 27 14:16:42 2002
> ***************
> *** 2468,2475 ****
>         (if (and (string-match "\\.[^.]*\\'" file)
>   	       (not (eq 0 (match-beginning 0))))
>   	  (if (setq directory (file-name-directory filename))
> ! 	      (expand-file-name (substring file 0 (match-beginning 0))
> ! 				directory)
>   	    (substring file 0 (match-beginning 0)))
>   	filename))))
>   
> --- 2468,2476 ----
>         (if (and (string-match "\\.[^.]*\\'" file)
>   	       (not (eq 0 (match-beginning 0))))
>   	  (if (setq directory (file-name-directory filename))
> ! 	      ;; Don't use expand-file-name here; if DIRECTORY is relative,
> ! 	      ;; we don't want to expand it.
> ! 	      (concat directory (substring file 0 (match-beginning 0)))
>   	    (substring file 0 (match-beginning 0)))
>   	filename))))

Could we introduce a new function for that or some way to tell
`expand-file-name' not to do the expansion if the dir is relative ?
The current elisp primitives make it very difficult to reconstruct
a file name that was just taken apart.  The missing piece is
indeed this "concat a (potentially relative) directory name
and a file name but without making it absolute and without
adding "./" in front".


	Stefan

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-09  7:38   ` Stefan Monnier
@ 2002-08-10 17:16     ` Richard Stallman
  2002-08-12 15:58       ` Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2002-08-10 17:16 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

    Could we introduce a new function for that or some way to tell
    `expand-file-name' not to do the expansion if the dir is relative ?

In principle this is ok, but why is concat not correct?
In this very limited situation, it ought to be correct as
far as I can tell.

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-10 17:16     ` Richard Stallman
@ 2002-08-12 15:58       ` Stefan Monnier
  2002-08-12 17:28         ` Eli Zaretskii
  2002-08-13  1:48         ` Strange `file-name-sans-extension' behavior Richard Stallman
  0 siblings, 2 replies; 18+ messages in thread
From: Stefan Monnier @ 2002-08-12 15:58 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, Jens.Schmidt27, emacs-devel

>     Could we introduce a new function for that or some way to tell
>     `expand-file-name' not to do the expansion if the dir is relative ?
> 
> In principle this is ok, but why is concat not correct?
> In this very limited situation, it ought to be correct as
> far as I can tell.

Is it correct for VMS ?
Maybe in practice it works for all systems we care about, but in theory
string concatenation has nothing to do intrinsically with generating
a filename by combining a relative directory name and a relative filename.


	Stefan

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-12 15:58       ` Stefan Monnier
@ 2002-08-12 17:28         ` Eli Zaretskii
  2002-08-12 18:21           ` Andreas Schwab
  2002-08-13 22:47           ` Richard Stallman
  2002-08-13  1:48         ` Strange `file-name-sans-extension' behavior Richard Stallman
  1 sibling, 2 replies; 18+ messages in thread
From: Eli Zaretskii @ 2002-08-12 17:28 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

> From: "Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu>
> 
> Is it correct for VMS ?
> Maybe in practice it works for all systems we care about, but in theory
> string concatenation has nothing to do intrinsically with generating
> a filename by combining a relative directory name and a relative filename.

Strictly speaking, it isn't correct even for Windows, as this
example shows:

	c: + bar -> c:./bar, not c:/bar

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-12 17:28         ` Eli Zaretskii
@ 2002-08-12 18:21           ` Andreas Schwab
  2002-08-13 22:47           ` Richard Stallman
  1 sibling, 0 replies; 18+ messages in thread
From: Andreas Schwab @ 2002-08-12 18:21 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, Jens.Schmidt27, emacs-devel

"Eli Zaretskii" <eliz@is.elta.co.il> writes:

|> > From: "Stefan Monnier" <monnier+gnu/emacs@rum.cs.yale.edu>
|> > 
|> > Is it correct for VMS ?
|> > Maybe in practice it works for all systems we care about, but in theory
|> > string concatenation has nothing to do intrinsically with generating
|> > a filename by combining a relative directory name and a relative filename.
|> 
|> Strictly speaking, it isn't correct even for Windows, as this
|> example shows:
|> 
|> 	c: + bar -> c:./bar, not c:/bar

But c:bar should be correct.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-12 15:58       ` Stefan Monnier
  2002-08-12 17:28         ` Eli Zaretskii
@ 2002-08-13  1:48         ` Richard Stallman
  1 sibling, 0 replies; 18+ messages in thread
From: Richard Stallman @ 2002-08-13  1:48 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, Jens.Schmidt27, emacs-devel

    > In principle this is ok, but why is concat not correct?
    > In this very limited situation, it ought to be correct as
    > far as I can tell.

    Is it correct for VMS ?

I think so.

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-12 17:28         ` Eli Zaretskii
  2002-08-12 18:21           ` Andreas Schwab
@ 2002-08-13 22:47           ` Richard Stallman
  2002-08-14 11:03             ` Eli Zaretskii
  1 sibling, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2002-08-13 22:47 UTC (permalink / raw)
  Cc: monnier+gnu/emacs, Jens.Schmidt27, emacs-devel

    Strictly speaking, it isn't correct even for Windows, as this
    example shows:

	    c: + bar -> c:./bar, not c:/bar

I don't understand this example, partly because the two parts
are not labeled as to what they mean.  "c: + bar -> c:./bar"
could be a statement of what something actually does (what something?),
or it could be a statement of what something ought to do.
I can't tell which.

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-13 22:47           ` Richard Stallman
@ 2002-08-14 11:03             ` Eli Zaretskii
  2002-08-14 23:14               ` Richard Stallman
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2002-08-14 11:03 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

> Date: Tue, 13 Aug 2002 16:47:00 -0600 (MDT)
> From: Richard Stallman <rms@gnu.org>
> 
> 	    c: + bar -> c:./bar, not c:/bar
> 
> I don't understand this example

It means that to produce a full file name from a relative directory
"c:" and a relative file name "bar", a function should yield
"c:./bar".

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-14 11:03             ` Eli Zaretskii
@ 2002-08-14 23:14               ` Richard Stallman
  2002-08-15 16:51                 ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2002-08-14 23:14 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

    It means that to produce a full file name from a relative directory
    "c:" and a relative file name "bar", a function should yield
    "c:./bar".

Is this really relevant to file-name-sans-extension?
The directory it uses is the one that was in the argument file name.
If it was valid there, it should be equally valid in the result.
If it is not valid in the result, I guess it was not valid in
the argument.

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-14 23:14               ` Richard Stallman
@ 2002-08-15 16:51                 ` Eli Zaretskii
  2002-08-16  2:31                   ` Richard Stallman
  0 siblings, 1 reply; 18+ messages in thread
From: Eli Zaretskii @ 2002-08-15 16:51 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

> Date: Wed, 14 Aug 2002 17:14:22 -0600 (MDT)
> From: Richard Stallman <rms@gnu.org>
> 
>     It means that to produce a full file name from a relative directory
>     "c:" and a relative file name "bar", a function should yield
>     "c:./bar".
> 
> Is this really relevant to file-name-sans-extension?

Perhaps not, I admit that I don't fully understand the precise
context of this discussion.

I was replying to the question whether `concat' is a universally
correct way of constructing file names from a directory name and a
file name.

> The directory it uses is the one that was in the argument file name.
> If it was valid there, it should be equally valid in the result.
> If it is not valid in the result, I guess it was not valid in
> the argument.

The problem is the slash you append to the directory if it doesn't
end in a slash.

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

* Re: Strange `file-name-sans-extension' behavior
  2002-08-15 16:51                 ` Eli Zaretskii
@ 2002-08-16  2:31                   ` Richard Stallman
  2002-08-16 17:17                     ` `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior ) Stefan Monnier
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2002-08-16  2:31 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

    > The directory it uses is the one that was in the argument file name.
    > If it was valid there, it should be equally valid in the result.
    > If it is not valid in the result, I guess it was not valid in
    > the argument.

    The problem is the slash you append to the directory if it doesn't
    end in a slash.

I don't see any code in file-name-sans-extension to append a slash to
the directory name.  It gets the directory name with
file-name-directory and uses it without further change.

Where is the slash appended?

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

* `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior )
  2002-08-16  2:31                   ` Richard Stallman
@ 2002-08-16 17:17                     ` Stefan Monnier
  2002-08-17  4:51                       ` Richard Stallman
  0 siblings, 1 reply; 18+ messages in thread
From: Stefan Monnier @ 2002-08-16 17:17 UTC (permalink / raw)
  Cc: eliz, Jens.Schmidt27, emacs-devel

>     > The directory it uses is the one that was in the argument file name.
>     > If it was valid there, it should be equally valid in the result.
>     > If it is not valid in the result, I guess it was not valid in
>     > the argument.
> 
>     The problem is the slash you append to the directory if it doesn't
>     end in a slash.
> 
> I don't see any code in file-name-sans-extension to append a slash to
> the directory name.  It gets the directory name with
> file-name-directory and uses it without further change.
> 
> Where is the slash appended?

The `Subject:' had not been updated, so it was misleading.
The discussion is about whether or not we need a new function
that is like expand-file-name but does not necessarily return
an absolute file name.   Currently when you need to combine a
relative dir with a file name, you need to use
(concat (file-name-as-directory foo) bar), but the fact that `concat'
works for this is purely accidental (and might not even be always true
for currently supported systems, according to Eli).

I've sometimes tried to use
  (let ((default-directory nil)) (expand-file-name bar foo))
or
  (let ((default-directory "")) (expand-file-name bar foo))

but it prepends "/" or "./" to the result.


	Stefan

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

* Re: `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior )
  2002-08-16 17:17                     ` `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior ) Stefan Monnier
@ 2002-08-17  4:51                       ` Richard Stallman
  2002-08-18 19:25                         ` Eli Zaretskii
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2002-08-17  4:51 UTC (permalink / raw)
  Cc: eliz, Jens.Schmidt27, emacs-devel

    The `Subject:' had not been updated, so it was misleading.
    The discussion is about whether or not we need a new function
    that is like expand-file-name but does not necessarily return
    an absolute file name.

I treated that as a subtopic of the issue of what to do with
file-name-sans-extension, and considered it only in reference to that
main topic.  Now I will address the new topic

As far as I can see, if you don't insist on an absolute file name,
it is correct to use concat.  As far as I can see, Eli's example
is only an issue if you want an absolute file name:

>     It means that to produce a full file name from a relative directory
>     "c:" and a relative file name "bar", a function should yield
>     "c:./bar".

Eli, is c:bar an invalid file name on MSDOS?

So it seems that in the case where you are happy to have
a non-absolute file name as the result, there is no problem.

    I've sometimes tried to use
      (let ((default-directory nil)) (expand-file-name bar foo))
    or
      (let ((default-directory "")) (expand-file-name bar foo))

    but it prepends "/" or "./" to the result.

Is that what you had in mind when you spoke of appending a slash?  It
would follow that these methods are not good ones.  However, that
doesn't say anything about whether concat is a good method.

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

* Re: `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior )
  2002-08-17  4:51                       ` Richard Stallman
@ 2002-08-18 19:25                         ` Eli Zaretskii
  2002-08-19 15:32                           ` Stefan Monnier
  2002-08-19 18:39                           ` Richard Stallman
  0 siblings, 2 replies; 18+ messages in thread
From: Eli Zaretskii @ 2002-08-18 19:25 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

> Date: Fri, 16 Aug 2002 22:51:10 -0600 (MDT)
> From: Richard Stallman <rms@gnu.org>
> 
> As far as I can see, if you don't insist on an absolute file name,
> it is correct to use concat.  As far as I can see, Eli's example
> is only an issue if you want an absolute file name:
> 
> >     It means that to produce a full file name from a relative directory
> >     "c:" and a relative file name "bar", a function should yield
> >     "c:./bar".
> 
> Eli, is c:bar an invalid file name on MSDOS?

"c:bar" is a valid file name on DOS and Windows file systems.  It
means `bar' in the default directory of the C: drive.  In other words,
it's the same as "c:./bar".

> So it seems that in the case where you are happy to have
> a non-absolute file name as the result, there is no problem.

There should be no problem if none of the functions involved convert
"c:" to "c:/".  I don't recall if that's so and don't have time to
check, but I wouldn't be surprised if Emacs primitives already take
care of this.

It's the case of application code doing (concat dir "/" file) is what
worries me.

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

* Re: `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior )
  2002-08-18 19:25                         ` Eli Zaretskii
@ 2002-08-19 15:32                           ` Stefan Monnier
  2002-08-19 18:39                           ` Richard Stallman
  1 sibling, 0 replies; 18+ messages in thread
From: Stefan Monnier @ 2002-08-19 15:32 UTC (permalink / raw)
  Cc: rms, Jens.Schmidt27, emacs-devel

> It's the case of application code doing (concat dir "/" file) is what
> worries me.

These are wrong anyway.  (concat (file-name-as-directory dir) file) is
what they should use instead (at least as long as there is no
expand-relative-file-name function).


	Stefan

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

* Re: `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior )
  2002-08-18 19:25                         ` Eli Zaretskii
  2002-08-19 15:32                           ` Stefan Monnier
@ 2002-08-19 18:39                           ` Richard Stallman
  2002-08-20 11:33                             ` Eli Zaretskii
  1 sibling, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2002-08-19 18:39 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

    It's the case of application code doing (concat dir "/" file) is what
    worries me.

That is a different case--if dir is really a directory name, it is
simply incorrect to add an explicit slash.  You must be thinking of a
case where DIR is a directory file name rather than a directory name.
The right way to handle that situation is

  (concat (file-name-as-directory dirfile) file)

Do you see any case where that would give incorrect result
on MS systems?

I will update the documentation in lispref/files.texi to discuss
this issue.

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

* Re: `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior )
  2002-08-19 18:39                           ` Richard Stallman
@ 2002-08-20 11:33                             ` Eli Zaretskii
  0 siblings, 0 replies; 18+ messages in thread
From: Eli Zaretskii @ 2002-08-20 11:33 UTC (permalink / raw)
  Cc: Jens.Schmidt27, emacs-devel

> Date: Mon, 19 Aug 2002 12:39:16 -0600 (MDT)
> From: Richard Stallman <rms@gnu.org>
> 
> The right way to handle that situation is
> 
>   (concat (file-name-as-directory dirfile) file)
> 
> Do you see any case where that would give incorrect result
> on MS systems?

Looks like file-name-as-directory needs some work on MS systems:

  M-: (file-name-as-directory "d:") RET => "d:/"

This is wrong (I verified that the cwd on drive D: is not the root
directory).

I'll try to see how to fix that.

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

end of thread, other threads:[~2002-08-20 11:33 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <uptxa211i.fsf@oracle.com>
2002-07-27 18:53 ` Strange `file-name-sans-extension' behavior Richard Stallman
2002-08-09  7:38   ` Stefan Monnier
2002-08-10 17:16     ` Richard Stallman
2002-08-12 15:58       ` Stefan Monnier
2002-08-12 17:28         ` Eli Zaretskii
2002-08-12 18:21           ` Andreas Schwab
2002-08-13 22:47           ` Richard Stallman
2002-08-14 11:03             ` Eli Zaretskii
2002-08-14 23:14               ` Richard Stallman
2002-08-15 16:51                 ` Eli Zaretskii
2002-08-16  2:31                   ` Richard Stallman
2002-08-16 17:17                     ` `concat' a dir and a file (was: Strange `file-name-sans-extension' behavior ) Stefan Monnier
2002-08-17  4:51                       ` Richard Stallman
2002-08-18 19:25                         ` Eli Zaretskii
2002-08-19 15:32                           ` Stefan Monnier
2002-08-19 18:39                           ` Richard Stallman
2002-08-20 11:33                             ` Eli Zaretskii
2002-08-13  1:48         ` Strange `file-name-sans-extension' behavior Richard Stallman

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).