From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "spamfilteraccount@gmail.com" Newsgroups: gmane.emacs.help Subject: Re: Comparing non-English strings for sorting Date: Tue, 10 Feb 2009 02:47:41 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <290dbf13-a9d6-4c3a-a895-6bd895ab6c52@p37g2000yqd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1234281251 30077 80.91.229.12 (10 Feb 2009 15:54:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 10 Feb 2009 15:54:11 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 10 16:55:26 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LWuxI-000349-3h for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Feb 2009 16:55:24 +0100 Original-Received: from localhost ([127.0.0.1]:34411 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LWuvy-0004YJ-LA for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Feb 2009 10:54:02 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!a12g2000yqm.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 35 Original-NNTP-Posting-Host: 81.183.147.79 Original-X-Trace: posting.google.com 1234262861 16280 127.0.0.1 (10 Feb 2009 10:47:41 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 10 Feb 2009 10:47:41 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: a12g2000yqm.googlegroups.com; posting-host=81.183.147.79; posting-account=ksnUxwoAAAC32CfuC8oi8NKZxrTcNtdm User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.63 (Windows NT 5.1; U; en) Presto/2.1.1,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:166720 X-Mailman-Approved-At: Tue, 10 Feb 2009 10:47:54 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62033 Archived-At: On Feb 10, 7:31=A0am, "spamfilteracco...@gmail.com" wrote: > Hi, > > I see Emacs doesn't have builtin support for sorting non-Engish (UTF, > Unicode) strings in proper order. > > Has anyone written a comparison function which can handle sorting such > strings if the character order is provided? I wrote my own func. Wasn't that hard. Let me know if you spot some error in it or know a better way: (require 'cl) (let ((l '("str1" "str2" ...)) (order "a=E1bcde=E9fghijklmno=F3=F6=F5pqrstu=FA=FC=FBxyvz")) (sort l 'my-case-insensitive-nonenglish-string-comparator)) (defun my-case-insensitive-nonenglish-string-comparator (str1 str2) (let ((diff (some (lambda (char1 char2) (and (not (equal char1 char2)) (cons char1 char2))) (vconcat (downcase str1)) (vconcat (downcase str2))))) (if diff (let* ((char1 (car diff)) (char2 (cdr diff)) (pos1 (position char1 order)) (pos2 (position char2 order))) (if (and pos1 pos2) (< pos1 pos2) (< char1 char2))))))