Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sort directories then files in Dired.

272 views
Skip to first unread message

Oleksandr Gavenko

unread,
Sep 5, 2010, 2:47:25 PM9/5/10
to help-gn...@gnu.org
ls have option --group-directories-first. But then I set
'dired-listing-switches' to '-al --group-directories-first'
output seems damaged:

 e:/home/devel/autorpg:
total used in directory 1 available 13039040
281474976729852 0drwxrwxrwx 1 sasha Отсутствует 0 2007-09-05 ..
1407374883569819 0drwxrwxrwx 1 sasha Отсутствует 0 2009-08-24 .
1125899906859437 0drwxrwxrwx 1 sasha Отсутствует 0 2009-08-24 .hg
2533274790412740 1-rw-rw-rw- 1 sasha Отсутствует 209 2009-08-24
README
562949953438149 0drwxrwxrwx 1 sasha Отсутствует 0 2009-08-24
very-dumb-game

--
Best regards!


Thamer Mahmoud

unread,
Sep 5, 2010, 4:02:12 PM9/5/10
to help-gn...@gnu.org
Oleksandr Gavenko <gave...@gmail.com> writes:

I don't use --group-directories-first, sorry. Perhaps you should
consider reporting this as a bug.

As an alternative, I use the following code in ~/.emacs which
essentially does the same thing:

(defun mydired-sort ()
"Sort dired listings with directories first."
(save-excursion
(let (buffer-read-only)
(forward-line 2) ;; beyond dir. header
(sort-regexp-fields t "^.*$" "[ ]*." (point) (point-max)))
(set-buffer-modified-p nil)))

(defadvice dired-readin
(after dired-after-updating-hook first () activate)
"Sort dired listings with directories first before adding marks."
(mydired-sort))

For more sorting options, see:
http://www.emacswiki.org/emacs/DiredSortDirectoriesFirst
http://www.emacswiki.org/emacs/DiredSortMenu

--
Thamer


Drew Adams

unread,
Sep 5, 2010, 5:16:20 PM9/5/10
to Thamer Mahmoud, help-gn...@gnu.org
FYI - dired-sort-menu.el and dired-sort-menu+.el give you all kinds of useful
sort orders for Dired.

http://www.emacswiki.org/emacs/DiredSortMenu

Tim X

unread,
Sep 5, 2010, 6:10:00 PM9/5/10
to
Oleksandr Gavenko <gave...@gmail.com> writes:

You could use the ls-lisp package, which comes with emacs and set
ls-lisp-dirs-first to have the directories listed first in dired. You
may need to add (require 'ls-lisp) to your .emacs

,----[ C-h v ls-lisp-dirs-first RET ]
| ls-lisp-dirs-first is a variable defined in `ls-lisp.el'.
| Its value is t
|
| Documentation:
| Non-nil causes ls-lisp to sort directories first in any ordering.
| (Or last if it is reversed.) Follows Microsoft Windows Explorer.
|
| You can customize this variable.
|
| [back]
`----

Tim

--
tcross (at) rapttech dot com dot au

Oleksandr Gavenko

unread,
Sep 17, 2010, 9:25:09 AM9/17/10
to help-gn...@gnu.org
Thanks all for replay.

'dired-listing-switches' not work for me because I use
Emacs on Windows and so 'ls-lisp-use-insert-directory-program'
by default set to 'nil'.

I check 'ls-lisp.el' and found easy solution for my needs.
'ls-lisp-dirs-first' is essential part of them, but
you can find they all useful:

;; If non-nil - use 'insert-directory-program', which I dislike.
(setq ls-lisp-use-insert-directory-program nil)
(setq ls-lisp-ignore-case t)
(setq ls-lisp-dirs-first t)
(if (eq system-type 'windows-nt)
(setq ls-lisp-verbosity nil)
(setq ls-lisp-verbosity '(links uid gid)))
;; Force use 'ls-lisp-format-time-list'.
(setq ls-lisp-use-localized-time-format t)
(setq ls-lisp-format-time-list
'("%Y-%m-%d %H:%M"
"%Y-%m-%d "))

--
Best regards and happy hacking!


0 new messages