emacs-devel
[Top][All Lists]
Advanced

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

Re: Why does dired go through extra efforts to avoid unibyte names


From: Eli Zaretskii
Subject: Re: Why does dired go through extra efforts to avoid unibyte names
Date: Wed, 03 Jan 2018 17:10:35 +0200

> From: Stefan Monnier <address@hidden>
> Date: Tue, 02 Jan 2018 23:14:20 -0500
> 
> >> I bumped into the following code in dired-get-filename:
> >> 
> >>      ;; The above `read' will return a unibyte string if FILE
> >>      ;; contains eight-bit-control/graphic characters.
> >>      (if (and enable-multibyte-characters
> >>               (not (multibyte-string-p file)))
> >>          (setq file (string-to-multibyte file)))
> >> 
> >> and I'm wondering why we don't want a unibyte string here.
> >> `vc-region-history` told me this comes from the commit appended below,
> >> which seems to indicate that we're worried about a subsequent encoding,
> >> but AFAIK unibyte file names are not (re)encoded, and passing them
> >> through string-to-multibyte would actually make things worse in this
> >> respect (since it might cause the kind of (re)encoding this is
> >> supposedly trying to avoid).
> >> 
> >> What am I missing?
> >
> > Why does it matter whether eight-bit-* characters are encoded one more
> > or one less time?
> 
> That's part of the question, indeed.

The question was meant to be rhetorical ;-)  Eight-bit-* characters
are not in general modified by encoding them, so you could encode them
any number of times and still get the same bytes as result.

> > As for the reason for using string-to-multibyte: maybe it's because we
> > use concat further down in the function, which will determine whether
> > the result will be unibyte or multibyte according to its own ideas of
> > what's TRT?
> 
> But `concat` will do a string-to-multibyte for us, if needed

Not if the other concatenated parts are ASCII (which tend to be
unibyte strings).

> This said, when that code was written, maybe `concat` used
> string-make-multibyte internally instead, so this call to
> string-to-multibyte might have been added to avoid using
> string-make-multibyte inside `concat`?

Could be.  I tried to look for relevant discussions around the time of
the commit, but couldn't find anything that would explain the reason.

> It would be good to have a concrete case that needed the above code, to
> see if the problem still exists.

Yep.



reply via email to

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