From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: sort-lines including non ASCII Date: Fri, 08 Jul 2016 13:01:56 +0300 Message-ID: <83twg0ih2j.fsf@gnu.org> References: <87bn2b6buh.fsf@mat.ucm.es> <83zipun8cf.fsf@gnu.org> <87inwiom3w.fsf@web.de> <877fcxyk9j.fsf@mat.ucm.es> <83eg75lbok.fsf@gnu.org> <8760shfm0u.fsf@web.de> <83twg1jsjf.fsf@gnu.org> <87wpkx73ry.fsf@web.de> <83furljkdb.fsf@gnu.org> <87mvltdpnl.fsf@web.de> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1467972328 24497 80.91.229.3 (8 Jul 2016 10:05:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 8 Jul 2016 10:05:28 +0000 (UTC) Cc: emacs-devel@gnu.org To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 08 12:05:24 2016 Return-path: Envelope-to: ged-emacs-devel@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 1bLSex-0002tZ-66 for ged-emacs-devel@m.gmane.org; Fri, 08 Jul 2016 12:05:23 +0200 Original-Received: from localhost ([::1]:44570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLSdl-0005gt-CD for ged-emacs-devel@m.gmane.org; Fri, 08 Jul 2016 06:04:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLSbr-0004GP-Nw for emacs-devel@gnu.org; Fri, 08 Jul 2016 06:02:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bLSbn-0007rZ-GH for emacs-devel@gnu.org; Fri, 08 Jul 2016 06:02:10 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:43332) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bLSbn-0007rV-Co; Fri, 08 Jul 2016 06:02:07 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3149 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1bLSbl-0003zj-KF; Fri, 08 Jul 2016 06:02:06 -0400 In-reply-to: <87mvltdpnl.fsf@web.de> (message from Michael Heerdegen on Fri, 08 Jul 2016 00:55:26 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:205417 Archived-At: > From: Michael Heerdegen > Date: Fri, 08 Jul 2016 00:55:26 +0200 > > > > BTW, a relevant question is: Is `compare-buffer-substring' faster than > > > `buffer-substring'+`string<'? > > > > Hard to say. Measuring is the easiest way to answer that. > > Here is a first try. The speed difference is negligible here. That's not unexpected, given that they do almost the same things. > -(defun sort-lines (reverse beg end) > +(defun sort-lines (reverse beg end &optional predicate) > "Sort lines in region alphabetically; argument means descending order. > Called from a program, there are three arguments: > REVERSE (non-nil means reverse order), BEG and END (region to sort). > @@ -210,7 +210,13 @@ sort-lines > (goto-char (point-min)) > (let ;; To make `end-of-line' and etc. to ignore fields. > ((inhibit-field-text-motion t)) > - (sort-subr reverse 'forward-line 'end-of-line))))) > + (sort-subr > + reverse #'forward-line #'end-of-line nil nil > + (and predicate > + (lambda (a b) > + (funcall predicate > + (buffer-substring (car a) (cdr a)) > + (buffer-substring (car b) (cdr b)))))))))) First, I suggest buffer-substring-no-properties, it should be faster (properties are not needed in the predicate, right?). More importantly, I might be missing something, but how does this support additional arguments to predicate, like those that string-collate-lessp accepts? Do you expect users to write their own predicate that hides those arguments? > > My opinion is the opposite: I think it's more important to have a > > command that could collate-order strings according to a user-specified > > locale, than make sort-lines more flexible on the Lisp level. > > What would you do? Just create an additional command? If that's the best idea, then yes. Thanks.