In Emacs 24.3.1 on Windows 7, how can I group directories first in dired?
Asked Answered
L

5

5

I have recently started to use dired in earnest, having belatedly checked out the advice to use C-x C-j given in one of the answers to this question. The 'jump' function is as useful as promised and has led me to investigate dired seriously. One snag is that I cannot group directories above files in dired buffers. I have tried putting the following in my .emacs.d file but it has no effect, presumably because I am running on Windows.

(setq dired-listing-switches "--group-directories-first -alh")

How can I achieve grouped directories above files in dired buffers in Windows 7?

[EDIT] as per the answer below, dired-sort-menu does seem to work - see following screenshot.

dired-sort-menu screenshot

Lover answered 16/9, 2013 at 8:41 Comment(0)
L
0

DiredSortMenu may help you with that. It has an option for sorting with directories first.

If you dont't use a package like that, you may find the "ls" options supported in Windows by doing C-h f RET insert-directory (as you guessed, "--group-directories-first" is not supported).

Lyricist answered 16/9, 2013 at 9:34 Comment(0)
I
6

There is actually an option for this if you're using the ls emulation, as on Windows:

(setq ls-lisp-dirs-first t)

See (customize-group 'ls-lisp) for all the options. There are some useful ones -

; hide the link count, user, and group columns - default is '(links uid gid)
(setq ls-lisp-verbosity nil)

; use ISO dates (the first is for recent dates, second for old dates)
(setq ls-lisp-format-time-list '("%Y-%m-%d %H:%M" "%Y-%m-%d %H:%M"))
(setq ls-lisp-use-localized-time-format t)

Giving you a listing like this -

total used in directory 27734 available 171804716
dr-xr-xr-x       40960 2015-02-12 00:47 .
drwxrwxrwx       16384 2015-02-11 17:37 ..
dr-xr-xr-x       32768 2015-02-07 09:41 bookshelf
drwxrwxrwx       12288 2014-12-03 00:06 library
drwxrwxrwx        8192 2014-08-17 08:21 office
dr-xr-xr-x       16384 2015-02-10 19:54 projects
-rw-rw-rw-       14073 2015-01-31 17:25 android.org
-rw-rw-rw-       65736 2015-02-05 17:09 archive.org
Inflatable answered 12/2, 2015 at 7:1 Comment(0)
N
1

In Emacs 25.3.1, directories get sorted by setting:

(setq dired-listing-switches "-al --group-directories-first")
Ngo answered 6/3, 2018 at 11:21 Comment(0)
L
0

DiredSortMenu may help you with that. It has an option for sorting with directories first.

If you dont't use a package like that, you may find the "ls" options supported in Windows by doing C-h f RET insert-directory (as you guessed, "--group-directories-first" is not supported).

Lyricist answered 16/9, 2013 at 9:34 Comment(0)
C
0

dired can either use ls to get the list of files, or use some internal Elisp code instead. By default under Windows it does not use ls (in other systems, by default it uses ls). The --group-directories-first option is not supported by the Elisp code, so if you want to use it, you need to set ls-lisp-use-insert-directory-program to nil so as to tell dired to use ls (and of course, that will only work if/when you have a proper ls.exe installed which does support --group-directories-first.

Clypeate answered 16/9, 2013 at 13:11 Comment(0)
G
0

Yes, DiredSortMenu is your friend. And dired-sort-menu+.el adds a few tweaks. Also, this EmacsWiki page has a bit more about sorting directories first, FWIW.

Gosplan answered 16/9, 2013 at 15:28 Comment(2)
Thanks. Is dired-sort-menu+.el a pure extension i.e. does it need dired-sort-menu or is it standalone?Lover
It requires dired-sort-menu.el (automatically) --- it just enhances it a bit. It binds 3 keys differently, to avoid conflicts; it avoids defining two options if you cannot use them (depending on your context); and it fixes a null buffer-file-name bug.Gosplan

© 2022 - 2024 — McMap. All rights reserved.