From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Sorting buffer with string-collate-lessp Date: Tue, 26 May 2015 19:57:01 +0200 Message-ID: <87iobfql1u.fsf@gnu.org> References: <87egm34kt0.fsf@gmx.us> <87twuz1jig.fsf@gnu.org> <87mw0rfkzy.fsf@gmx.us> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1432663057 32224 80.91.229.3 (26 May 2015 17:57:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 May 2015 17:57:37 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Rasmus Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 26 19:57:27 2015 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 1YxJ6U-0007tX-V8 for geh-help-gnu-emacs@m.gmane.org; Tue, 26 May 2015 19:57:27 +0200 Original-Received: from localhost ([::1]:49640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxJ6U-0004D7-9M for geh-help-gnu-emacs@m.gmane.org; Tue, 26 May 2015 13:57:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxJ6K-0004D1-CU for help-gnu-emacs@gnu.org; Tue, 26 May 2015 13:57:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YxJ6A-0004Nq-2P for help-gnu-emacs@gnu.org; Tue, 26 May 2015 13:57:16 -0400 Original-Received: from out5-smtp.messagingengine.com ([66.111.4.29]:44721) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YxJ69-0004Nk-Vq for help-gnu-emacs@gnu.org; Tue, 26 May 2015 13:57:06 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 540EE20918 for ; Tue, 26 May 2015 13:57:05 -0400 (EDT) Original-Received: from frontend1 ([10.202.2.160]) by compute2.internal (MEProxy); Tue, 26 May 2015 13:57:05 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=smtpout; bh=B5mD1gNi4w7s3BHLZb3UtGmxd4k=; b=WuOMc MujdND8sN+Tnr/vo1E5x3W8pgtp5b1HhlU5kKmdEhncnGufla+2SVp3r6qx+LHDK Cmzz6kyHnefgjVfCS+0YH8TWbal8K2KmWHb9OdzMYPn/SGAVMlDfa2NkmWYm6Zz6 8q+9Q+hq+QEOZUUlLujQRVBN9b4Eu90XjDy9r8= X-Sasl-enc: XIAISQ3JDFR/Y+Lk4ujmV1Sby6Vb8Meq8RJnFXtz6A3q 1432663024 Original-Received: from thinkpad-t440p (unknown [2.160.192.232]) by mail.messagingengine.com (Postfix) with ESMTPA id 70586C00018; Tue, 26 May 2015 13:57:04 -0400 (EDT) Mail-Followup-To: Rasmus , help-gnu-emacs@gnu.org In-Reply-To: <87mw0rfkzy.fsf@gmx.us> (rasmus@gmx.us's message of "Tue, 26 May 2015 16:53:37 +0200") User-Agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 66.111.4.29 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:104588 Archived-At: Rasmus writes: >> So either my `cl-letf' usage is wrong or `sort-lines' doesn't really use >> `string<'. (Actually, `string<' is an alias to `string-lessp', so I >> also tried changing that accordingly, but still no effect...) > > I though sort-lines used compare-buffer-substrings, but this is just based > on the docstring. Ah, that's the reason it had no effect. :-) > It seems the nesting of parentheses is wrong in your example, but I > guess it just the example. I did not try to letf to temporarily > rename string<. No, indeed you have to replace `compare-buffer-substrings'. This seems to do the trick although my replacement lambda doesn't really satisfy the contract of the return value of `compare-buffer-substrings' but it seems to be good enough for usage in `sort-lines'. --8<---------------cut here---------------start------------->8--- (cl-letf (((symbol-function 'compare-buffer-substrings) (lambda (b1 s1 e1 b2 s2 e2) (if (string-collate-lessp (buffer-substring s1 e1) (buffer-substring s2 e2)) -1 1)))) (sort-lines nil (point-min) 191)) --8<---------------cut here---------------end--------------->8--- The (point-min) and 191 when performed in *scratch* sort the initial scratch message comment lines. Bye, Tassilo