[Top][All Lists]

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

bug#25485: 25.1; Having trouble setting --time-style in dired-listing-sw

From: Chunyang Xu
Subject: bug#25485: 25.1; Having trouble setting --time-style in dired-listing-switches
Date: Sat, 28 Jan 2017 09:01:15 +0800
User-agent: mu4e 0.9.18; emacs 25.1.1

Eli Zaretskii writes:

>> From: Chunyang Xu <address@hidden>
>> Cc: address@hidden
>> Date: Fri, 20 Jan 2017 01:20:45 +0800
>> Eli Zaretskii writes:
>> >> From: Chunyang Xu <address@hidden>
>> >> Date: Thu, 19 Jan 2017 22:34:31 +0800
>> >>
>> >> I want to custom the file timestamps used in dired through the option:
>> >>
>> >>   --time-style='+%_m月 %d %H:%M'
>> >>
>> >> then I adjust `dired-listing-switches' accordingly:
>> >>
>> >>   (setq dired-listing-switches "-al --time-style='+%_m月 %d %H:%M'")
>> >>
>> >> However, it doesn't work, it signals an error, here is the Backtrace:
>> >
>> > Isn't --time-style a GNU ls extension?  You are on Darwin, so do you
>> > have GNU ls installed?  What happens if you use that option from the
>> > shell prompt?
>> Yes, and yes, and I have set shell and Emacs to use GNU ls, thus in
>> shell (via M-x shell) it works like expected:
> Your setting of dired-listing-switches assumes that the 'ls' command
> will be run by a shell: you use shell quoting.  But that's not what
> Dired does, it in most cases invokes 'ls' directly, and for that it
> needs to split the switches into individual options.  It does that by
> calling split-string on the value of dired-listing-switches, which of
> course knows nothing about the '..' quoting.  That's why 'ls' fails:
> it gets the --time-style option split between several separate
> command-line arguments.
> What this means is that currently Dired doesn't support switches that
> include embedded whitespace at all.  One way of lifting at least some
> of that limitation is the simple patch below; it will require you to
> format your switches like this:
>   (setq dired-listing-switches "-al \"--time-style=+%_m月 %d %H:%M\"")
> The function combine-and-quote-strings can help in producing the
> correct format.  Given that we document this, is this an acceptable
> solution?  (It won't work on MS-Windows, but the default there is not
> to call external programs at all, so I think it's not a terrible loss,
> for those Windows users who set up their systems to use 'ls'.)
> Here's the proposed patch; comments are welcome:
> diff --git a/lisp/files.el b/lisp/files.el
> index 25392fd..0a7b6a2 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -6572,7 +6572,7 @@ insert-directory
>                               (unless (equal switches "")
>                                 ;; Split the switches at any spaces so we can
>                                 ;; pass separate options as separate args.
> -                               (split-string switches)))
> +                               (split-string-and-unquote switches)))
>                             ;; Avoid lossage if FILE starts with `-'.
>                             '("--")
>                             (progn

I have tried the patch and changed dired-listing-switches accordingly,
it works now. Thus the solution is acceptable to me.

My first thought was, we can make dired-listing-switches also accepts a
list of arguments, then something like this

(setq dired-listing-switches
      (list "-al" "--time-style=+%_m月 %d %H:%M"))

should just work. But it will require much more work and I have no idea
how 'C-u M-x dired-sort-toggle-or-edit' can work as usual.

reply via email to

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