all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* customized name sorting in dired
@ 2004-11-15 11:06 Florian von Savigny
  2004-11-15 17:33 ` Kevin Rodgers
  2004-11-15 19:40 ` Drew Adams
  0 siblings, 2 replies; 5+ messages in thread
From: Florian von Savigny @ 2004-11-15 11:06 UTC (permalink / raw)




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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-11-17 18:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-15 11:06 customized name sorting in dired Florian von Savigny
2004-11-15 17:33 ` Kevin Rodgers
2004-11-17 16:54   ` Florian von Savigny
2004-11-17 18:51     ` Kevin Rodgers
2004-11-15 19:40 ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.