From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sean McAfee Newsgroups: gmane.emacs.help Subject: Re: Is there a function to sort file names by file version number, like "ls -v"? Date: Thu, 23 May 2013 11:33:01 -0700 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1369334501 7134 80.91.229.3 (23 May 2013 18:41:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 23 May 2013 18:41:41 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 23 20:41:40 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UfaSJ-0001Ud-Kl for geh-help-gnu-emacs@m.gmane.org; Thu, 23 May 2013 20:41:39 +0200 Original-Received: from localhost ([::1]:57130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfaSJ-0000wq-5j for geh-help-gnu-emacs@m.gmane.org; Thu, 23 May 2013 14:41:39 -0400 Original-Path: usenet.stanford.edu!news.glorb.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 22 Injection-Info: mx05.eternal-september.org; posting-host="9602142ff40e0c8bd8027a6f5e009406"; logging-data="2593"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4Wpic0jin0F51Jkjam447VX5MRvC+jVQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) Cancel-Lock: sha1:F+j7LsNeGetC5wXEyWto2HBrq8w= sha1:U1xe0WQ6xmkMSGgThO6P0zyMkWE= Original-Xref: usenet.stanford.edu gnu.emacs.help:198741 X-Mailman-Approved-At: Thu, 23 May 2013 14:41:27 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:91007 Archived-At: florian@fsavigny.de (Florian v. Savigny) writes: > I am wondering if there is somehow a comparison function (of the same > category as string-lessp) in Elisp which compares file name strings by > these version numbers, so I could sort the result of > directory-file-names in the same way as "ls -v". I don't think so, but it's easy to write one: (defun versioned-filename-lessp (a b) (labels ((parse (str) (string-match "\\(?:~\\([0-9]+\\)~\\)?\\'" str) (cons (substring str 0 (match-beginning 0)) (and (match-beginning 1) (string-to-number (match-string 1 str)))))) (save-match-data (let ((ap (parse a)) (bp (parse b))) (or (string-lessp (car ap) (car bp)) (and (not (string-lessp (car bp) (car ap))) (cdr ap) (cdr bp) (< (cdr ap) (cdr bp))))))))