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

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

Re: Is there a function to sort file names by file version number, like


From: Sean McAfee
Subject: Re: Is there a function to sort file names by file version number, like "ls -v"?
Date: Thu, 23 May 2013 13:28:22 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

florian@fsavigny.de (Florian v. Savigny) writes:
> You call that easy ... I'm wondering how long it took you?

Oh, maybe 5-10 minutes, including testing.  I've written similar
routines in other languages before, which sped things up a bit.

>   > (defun versioned-filename-lessp (a b)
>   >   (labels ((parse (str)
>
> I was wondering about these two functions, "labels" and "parse", but
> emacs does not seem to know them either. Are you assuming that some
> library is loaded, maybe? (I am using Emacs 24.3.1.)

labels is a macro that defines local functions, in this case one called
"parse".  See:

http://www.gnu.org/software/emacs/manual/html_node/cl/Obsolete-Macros.html

(Apparently I ought to be using cl-labels instead of labels now.)

It lives in the "cl" (Common Lisp) package, and is loaded when first
used.  You can evaluate the expression (require 'cl) to pull in the
package explicitly.

If it's not clear, the parse routine I defined takes a filename as an
argument, and returns a cons cell that contains the decomposed contents
of the name.  A name with a tilde-delimited version suffix, like say
"foo~5~", is transformed into ("foo" . 5), and a name without such a
suffix, like say "bar", becomes just ("bar" . nil).  The main body of
versioned-filename-lessp just compares two such decompositions.


reply via email to

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