GNU bug report logs - #67438
29.1; WDired uses `substitute-in-file-name', so `$$' is changed to `$' - undocumented?

Previous Next

Package: emacs;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Fri, 24 Nov 2023 23:37:01 UTC

Severity: normal

Found in version 29.1

To reply to this bug, email your comments to 67438 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#67438; Package emacs. (Fri, 24 Nov 2023 23:37:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Drew Adams <drew.adams <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 24 Nov 2023 23:37:01 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: 29.1; WDired uses `substitute-in-file-name', so `$$' is changed to
 `$' - undocumented?
Date: Fri, 24 Nov 2023 23:35:54 +0000
emacs -Q

C-x d aaa   ; Go to a directory with a file named `aaa'

C-x C-q

Append $$$$ to the file name, to give `aaa$$$$'

C-x C-q

The resulting file was named `aaa$$', not `aaa$$$$'.

It seems that every occurrence of `$$' in a file name is treated as just
`$'.  (The position of the `$$' in the new file name seems to be
irrelevant.)

I see this in older Emacs releases as well.  I found nothing in the doc
that would indicate that this is supposed to happen (and preferably
why).  And the only occurrence of char `$' in wdired.el seems benign.

Ah, I found it - it comes from `substitute-in-file-name':

  (substitute-in-file-name "aa$$$$") ; -> "aa$$"

But is that appropriate behavior in this context?  If it is, then maybe
the doc should tell you what to do if you want literal `$' chars.  (I
tried escaping with `\$`, but that ended up being changed to `/' and
changing the file to an empty directory!)

OK, the doc of `substitute-in-file-name' says to use `$$' to get a
single `$'.  So that's clear enough.  But what's not clear from the
WDired doc is that that function is used (instead of `expand-file-name')
by WDired.

The WDired doc is pretty scant, overall.  This, at least, should be
mentioned I think.  And any other gotchas - special (non-literal)
treatment of the text used in file names.  That would include use of
`\' as a directory separator on MS Windows, I suppose.


In GNU Emacs 29.1 (build 2, x86_64-w64-mingw32) of 2023-08-02 built on
 AVALON
Windowing system distributor 'Microsoft Corp.', version 10.0.19045
System Description: Microsoft Windows 10 Pro (v10.0.2009.19045.3570)

Configured using:
 'configure --with-modules --without-dbus --with-native-compilation=aot
 --without-compress-install --with-tree-sitter CFLAGS=-O2'

Configured features:
ACL 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

(NATIVE_COMP present but libgccjit not available)

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1252





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67438; Package emacs. (Sat, 25 Nov 2023 08:12:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 67438 <at> debbugs.gnu.org
Subject: Re: bug#67438: 29.1;
 WDired uses `substitute-in-file-name', so `$$' is changed to `$' -
 undocumented?
Date: Sat, 25 Nov 2023 10:11:11 +0200
> From: Drew Adams <drew.adams <at> oracle.com>
> Date: Fri, 24 Nov 2023 23:35:54 +0000
> 
> emacs -Q
> 
> C-x d aaa   ; Go to a directory with a file named `aaa'
> 
> C-x C-q
> 
> Append $$$$ to the file name, to give `aaa$$$$'
> 
> C-x C-q
> 
> The resulting file was named `aaa$$', not `aaa$$$$'.
> 
> It seems that every occurrence of `$$' in a file name is treated as just
> `$'.  (The position of the `$$' in the new file name seems to be
> irrelevant.)
> 
> I see this in older Emacs releases as well.  I found nothing in the doc
> that would indicate that this is supposed to happen (and preferably
> why).  And the only occurrence of char `$' in wdired.el seems benign.
> 
> Ah, I found it - it comes from `substitute-in-file-name':
> 
>   (substitute-in-file-name "aa$$$$") ; -> "aa$$"
> 
> But is that appropriate behavior in this context?

The $ processing is an integral part of the Emacs interpretation of
file names.  The Emacs user manual says in "File Names":

     The character ‘$’ is used to substitute an environment variable into
  a file name.  The name of the environment variable consists of all the
  alphanumeric characters after the ‘$’; alternatively, it can be enclosed
  in braces after the ‘$’.  For example, if you have used the shell
  command ‘export FOO=rms/hacks’ to set up an environment variable named
  ‘FOO’, then both ‘/u/$FOO/test.c’ and ‘/u/${FOO}/test.c’ are
  abbreviations for ‘/u/rms/hacks/test.c’.  If the environment variable is
  not defined, no substitution occurs, so that the character ‘$’ stands
  for itself.  Note that environment variables set outside Emacs affect
  Emacs only if they are applied before Emacs is started.

     To access a file with ‘$’ in its name, if the ‘$’ causes expansion,
  type ‘$$’.  This pair is converted to a single ‘$’ at the same time that
  variable substitution is performed for a single ‘$’.  Alternatively,
  quote the whole file name with ‘/:’ (*note Quoted File Names::).  File
  names which begin with a literal ‘~’ should also be quoted with ‘/:’.

You will see this behavior _everywhere_ where Emacs accepts file names
from the user.  For example, try:

  M-x rename-file RET foo RET foo$$$$ RET

the resulting file name will be "foo$$", with 2 $ characters instead
of 4.

WDired interprets file names in the same way, and that is OK because
anything else would be inconsistent.

> If it is, then maybe the doc should tell you what to do if you want
> literal `$' chars.

It's hard to find where and how to document that in WDired's doc
string, without also describing the other special processing of file
names.

Again, this is part of the basic file-name semantics in Emacs, so
repeating it in every command that accepts file names would be
excessive and unjustified.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#67438; Package emacs. (Sat, 25 Nov 2023 08:45:02 GMT) Full text and rfc822 format available.

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

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 67438 <at> debbugs.gnu.org, Drew Adams <drew.adams <at> oracle.com>
Subject: Re: bug#67438: 29.1; WDired uses `substitute-in-file-name', so `$$'
 is changed to `$' - undocumented?
Date: Sat, 25 Nov 2023 09:44:45 +0100
On Nov 25 2023, Eli Zaretskii wrote:

> WDired interprets file names in the same way, and that is OK because
> anything else would be inconsistent.

If you edit a file name that contains a $ sequence that is altered by
substitute-in-file-name you must change each $ to $$ that you want to
keep.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."




This bug report was last modified 161 days ago.

Previous Next


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