all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#67438: 29.1; WDired uses `substitute-in-file-name', so `$$' is changed to `$' - undocumented?
@ 2023-11-24 23:35 Drew Adams
  2023-11-25  8:11 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2023-11-24 23:35 UTC (permalink / raw)
  To: 67438

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






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

* bug#67438: 29.1; WDired uses `substitute-in-file-name', so `$$' is changed to `$' - undocumented?
  2023-11-24 23:35 bug#67438: 29.1; WDired uses `substitute-in-file-name', so `$$' is changed to `$' - undocumented? Drew Adams
@ 2023-11-25  8:11 ` Eli Zaretskii
  2023-11-25  8:44   ` Andreas Schwab
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2023-11-25  8:11 UTC (permalink / raw)
  To: Drew Adams; +Cc: 67438

> From: Drew Adams <drew.adams@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.





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

* bug#67438: 29.1; WDired uses `substitute-in-file-name', so `$$' is changed to `$' - undocumented?
  2023-11-25  8:11 ` Eli Zaretskii
@ 2023-11-25  8:44   ` Andreas Schwab
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2023-11-25  8:44 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 67438, Drew Adams

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@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."





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

end of thread, other threads:[~2023-11-25  8:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-24 23:35 bug#67438: 29.1; WDired uses `substitute-in-file-name', so `$$' is changed to `$' - undocumented? Drew Adams
2023-11-25  8:11 ` Eli Zaretskii
2023-11-25  8:44   ` Andreas Schwab

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.