help-gnu-emacs
[Top][All Lists]
Advanced

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

customized name sorting in dired


From: Florian von Savigny
Subject: customized name sorting in dired
Date: Mon, 15 Nov 2004 12:06:53 +0100
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)


I have been searching the archive for this, but it looks as if this
particular idea has not yet been addressed:

I have a directory the entries of which contain a date in DDMMYY
format as the last part of their name. I would like to display these
entries sorted according to this date. I figure that it is possible to
sort a list of strings in that way roughly by providing the following
function as the predicate to sort:


(defun by-date-in-name (a b)
  "Returns t if the date in the first name is earlier 
  than the second, nil otherwise."
  (if (string< (substring a -2 nil) (substring b -2 nil))
      t
    (if (string< (substring a -4 -2) (substring b -4 -2))
       t
      (if (string< (substring a -6 -4) (substring b -6 -4))
          t
       nil))))


(Does not work perfectly yet, but I guess that simply requires some
tinkering.)

What puzzles me is how to get dired to sort the names by using this
sort routine. I have tried to pass dired its first argument as (cons
DIRNAME <sorted list>), and add the listing switches "lU" but that
seems to be a misapprehension of its usage (I get an error message
about dired trying to open the first entry of the list and saying it
has not found that directory).

[Under the shell, you can say "ls -lUd `sort_by_date_in_name`" if
sort_by_date_in_name is a script that returns the names in due order
and separated by a space]

Since actually it shouldn't be too complicated: is there any hook or
similar available to tell dired how to sort the names of the entries
of the directory it is operating upon?


-- 


Florian v. Savigny

If you are going to reply in private, please be patient, as I only
check for mail something like once a week. - Si vous allez répondre
personellement, patientez s.v.p., car je ne lis les courriels
qu'environ une fois par semaine.


reply via email to

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