* 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
* Re: customized name sorting in dired
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-15 19:40 ` Drew Adams
1 sibling, 1 reply; 5+ messages in thread
From: Kevin Rodgers @ 2004-11-15 17:33 UTC (permalink / raw)
Florian von Savigny wrote:
> 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).
I'm not familiar with the ls -U option (a GNU extension?), but calling
dired like that works for me in Emacs 21.3 on Solaris. Perhaps you
could post your code and the resulting error message.
--
Kevin Rodgers
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: customized name sorting in dired
2004-11-15 11:06 customized name sorting in dired Florian von Savigny
2004-11-15 17:33 ` Kevin Rodgers
@ 2004-11-15 19:40 ` Drew Adams
1 sibling, 0 replies; 5+ messages in thread
From: Drew Adams @ 2004-11-15 19:40 UTC (permalink / raw)
Francis Wright (F.J.Wright@maths.qmw.ac.uk) has written library
dired-sort-menu.el, available on his Web site:
http://centaur.maths.qmw.ac.uk/Emacs/. This library lets you sort Dired
directories in many different ways, and provides both a menu-bar menu and a
popup menu to do it.
See `Dired Sort Menu' at http://www.emacswiki.org/cgi-bin/wiki/DiredMode for
more description and a screenshot.
- Drew
-----Original Message-----From: Florian von Savigny
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: customized name sorting in dired
2004-11-15 17:33 ` Kevin Rodgers
@ 2004-11-17 16:54 ` Florian von Savigny
2004-11-17 18:51 ` Kevin Rodgers
0 siblings, 1 reply; 5+ messages in thread
From: Florian von Savigny @ 2004-11-17 16:54 UTC (permalink / raw)
Kevin,
thanks very much. I ashamedly admit I have only now hit on the idea of
renaming the entries such that they should sort properly with standard
routines: beginning with YYMMDD, instead of ending with DDMMYY. Hence,
my current need for custom sorting is suddenly gone. However, I will
supply the answer in case anybody is interested in the problem (I am
of course interested, but the urge is gone).
So please, only bother with it if you find it plain interesting,
anybody. Thanks for having been helpful, Kevin.
Kevin Rodgers <ihs_4664@yahoo.com> writes:
> I'm not familiar with the ls -U option (a GNU extension?), but calling
> dired like that works for me in Emacs 21.3 on Solaris. Perhaps you
> could post your code and the resulting error message.
The manpage says "-U: do not sort; list entries in directory
order". The reason why I tried this was because I first tried a shell
version of what I was now trying to find for Emacs. I wrote a Perl
script that takes the directory entries and returns them in the sort
order I want, separated by spaces. Calling
ls -ld `sorting_script`
(-d because the entries are directories) would then display the usual
information but re-sort it - such as when you have three files a, b,
and c, and say "ls b a c": ls will resort them to "a b c". Adding the
-U switch has precluded this re-sorting on my system (maybe not the
task it was originally intended for). So much for that.
My idea how to implement this under Emacs was such: the documentation
for dired says:
(dired DIRNAME &optional SWITCHES)
...
If DIRNAME is a cons, its first element is taken as the directory name
and the rest as an explicit list of files to make directory entries
for.
I figured that to imitate the shell solution above, I had to supply
the directory name as the car, and the sorted list of entries as the
cons, which ls would dutyfully not re-sort if I supplied the -U
switch:
(defun dired-entries-in-my-order (dir)
"Run dired on DIR; display entries in proper order."
(interactive "DDirectory: ")
(dired (cons
dir
(sort (directory-files
dir
nil)
'by-date-in-name)) ;; see first posting
"lU"))
That seems to have been a misapprehension; the message is as
follows. Curiously, it is emitted no matter whether I do a (cd DIR)
first or not (if that made a difference, I would have an idea what the
problem is ...):
Reading directory /home/uebersetzer/auftraege/...
insert-directory: Reading directory: file or directory not found, hau45147ess030204
[hau45147ess030204 is the first entry of the sorted list]
Maybe this also helps (control characters replaced by Gnus):
Debugger entered--Lisp error: (file-error "Reading directory" "file or directory not found" "hau45147ess030204")
access-file("hau45147ess030204" "Reading directory")
insert-directory("hau45147ess030204" "lU" nil nil)
#[(x) "Ä\b \n\v$." [x switches wildcard full-p insert-directory] 5]("hau45147ess030204")
mapcar(#[(x) "Ä\b \n\v$." [x switches wildcard full-p insert-directory] 5] ("hau45147ess030204" "sta33609bie080304" "sta33609bie160304" "sel57439att300304" "med13008mar040604" "hau45147ess140404" "hau45147ess060504" "sel57439att270604" "sel57439att080704" "hau45147ess030804" "sel57439att100804" "sel57439att160904" "log41100mod180804" "5_5-35310cha230704" "sel57439att240904" "sel57439att081004" "med13008mar290604" "med13008mar160904" "log41100mod280904" "log41100mod191004" "hau45147ess200204" "log41100mod291004"))
dired-insert-directory(("/home/uebersetzer/auftraege/" "hau45147ess030204" "sta33609bie080304" "sta33609bie160304" "sel57439att300304" "med13008mar040604" "hau45147ess140404" "hau45147ess060504" "sel57439att270604" "sel57439att080704" "hau45147ess030804" "sel57439att100804" "sel57439att160904" "log41100mod180804" "5_5-35310cha230704" "sel57439att240904" "sel57439att081004" "med13008mar290604" "med13008mar160904" "log41100mod280904" "log41100mod191004" "hau45147ess200204" "log41100mod291004") "lU" nil)
dired-readin-insert(("/home/uebersetzer/auftraege/" "hau45147ess030204" "sta33609bie080304" "sta33609bie160304" "sel57439att300304" "med13008mar040604" "hau45147ess140404" "hau45147ess060504" "sel57439att270604" "sel57439att080704" "hau45147ess030804" "sel57439att100804" "sel57439att160904" "log41100mod180804" "5_5-35310cha230704" "sel57439att240904" "sel57439att081004" "med13008mar290604" "med13008mar160904" "log41100mod280904" "log41100mod191004" "hau45147ess200204" "log41100mod291004"))
dired-readin(("/home/uebersetzer/auftraege/" "hau45147ess030204" "sta33609bie080304" "sta33609bie160304" "sel57439att300304" "med13008mar040604" "hau45147ess140404" "hau45147ess060504" "sel57439att270604" "sel57439att080704" "hau45147ess030804" "sel57439att100804" "sel57439att160904" "log41100mod180804" "5_5-35310cha230704" "sel57439att240904" "sel57439att081004" "med13008mar290604" "med13008mar160904" "log41100mod280904" "log41100mod191004" "hau45147ess200204" "log41100mod291004") #<buffer auftraege>)
dired-internal-noselect(("/home/uebersetzer/auftraege/" "hau45147ess030204" "sta33609bie080304" "sta33609bie160304" "sel57439att300304" "med13008mar040604" "hau45147ess140404" "hau45147ess060504" "sel57439att270604" "sel57439att080704" "hau45147ess030804" "sel57439att100804" "sel57439att160904" "log41100mod180804" "5_5-35310cha230704" "sel57439att240904" "sel57439att081004" "med13008mar290604" "med13008mar160904" "log41100mod280904" "log41100mod191004" "hau45147ess200204" "log41100mod291004") "lU")
dired-noselect(("/home/uebersetzer/auftraege/" "hau45147ess030204" "sta33609bie080304" "sta33609bie160304" "sel57439att300304" "med13008mar040604" "hau45147ess140404" "hau45147ess060504" "sel57439att270604" "sel57439att080704" "hau45147ess030804" "sel57439att100804" "sel57439att160904" "log41100mod180804" "5_5-35310cha230704" "sel57439att240904" "sel57439att081004" "med13008mar290604" "med13008mar160904" "log41100mod280904" "log41100mod191004" "hau45147ess200204" "log41100mod291004") "lU")
dired(("/home/uebersetzer/auftraege/" "hau45147ess030204" "sta33609bie080304" "sta33609bie160304" "sel57439att300304" "med13008mar040604" "hau45147ess140404" "hau45147ess060504" "sel57439att270604" "sel57439att080704" "hau45147ess030804" "sel57439att100804" "sel57439att160904" "log41100mod180804" "5_5-35310cha230704" "sel57439att240904" "sel57439att081004" "med13008mar290604" "med13008mar160904" "log41100mod280904" "log41100mod191004" "hau45147ess200204" "log41100mod291004") "lU")
dired-entries-in-my-order("/home/uebersetzer/auftraege/")
eval((dired-entries-in-my-order "/home/uebersetzer/auftraege/"))
eval-last-sexp-1(t)
eval-last-sexp(t)
eval-print-last-sexp()
call-interactively(eval-print-last-sexp)
--
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
* Re: customized name sorting in dired
2004-11-17 16:54 ` Florian von Savigny
@ 2004-11-17 18:51 ` Kevin Rodgers
0 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2004-11-17 18:51 UTC (permalink / raw)
Florian von Savigny wrote:
> thanks very much. I ashamedly admit I have only now hit on the idea of
> renaming the entries such that they should sort properly with standard
> routines: beginning with YYMMDD, instead of ending with DDMMYY. Hence,
> my current need for custom sorting is suddenly gone. However, I will
> supply the answer in case anybody is interested in the problem (I am
> of course interested, but the urge is gone).
That's what I wanted to suggest, but I figured the files were named that
way for a reason. I prefer CCYY-MM-DD myself.
> So please, only bother with it if you find it plain interesting,
> anybody. Thanks for having been helpful, Kevin.
You're welcome!
> Kevin Rodgers <ihs_4664@yahoo.com> writes:
>
>>I'm not familiar with the ls -U option (a GNU extension?), but calling
>>dired like that works for me in Emacs 21.3 on Solaris. Perhaps you
>>could post your code and the resulting error message.
>
>
> The manpage says "-U: do not sort; list entries in directory
> order". The reason why I tried this was because I first tried a shell
> version of what I was now trying to find for Emacs. I wrote a Perl
> script that takes the directory entries and returns them in the sort
> order I want, separated by spaces. Calling
>
> ls -ld `sorting_script`
>
> (-d because the entries are directories) would then display the usual
> information but re-sort it - such as when you have three files a, b,
> and c, and say "ls b a c": ls will resort them to "a b c". Adding the
> -U switch has precluded this re-sorting on my system (maybe not the
> task it was originally intended for). So much for that.
Right.
> My idea how to implement this under Emacs was such: the documentation
> for dired says:
>
> (dired DIRNAME &optional SWITCHES)
> ...
> If DIRNAME is a cons, its first element is taken as the directory name
> and the rest as an explicit list of files to make directory entries
> for.
>
> I figured that to imitate the shell solution above, I had to supply
> the directory name as the car, and the sorted list of entries as the
> cons, which ls would dutyfully not re-sort if I supplied the -U
> switch:
>
>
> (defun dired-entries-in-my-order (dir)
> "Run dired on DIR; display entries in proper order."
> (interactive "DDirectory: ")
> (dired (cons
> dir
> (sort (directory-files
> dir
> nil)
> 'by-date-in-name)) ;; see first posting
> "lU"))
You need to pass SWITCHES as "-lU", because it is used as the value of
dired-listing-switches.
--
Kevin Rodgers
^ 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).