From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.bugs Subject: bug#41706: 26.1; sort-subr predicate cannot be set successfully Date: Thu, 11 Jun 2020 14:55:14 +0200 Message-ID: <87tuzhpxsd.fsf@web.de> References: <20200604110922.GA9116@atlantis> <87pnafxc7e.fsf@web.de> <20200604190526.GA14104@atlantis> <83d06dc3po.fsf@gnu.org> <87h7vpg85k.fsf@web.de> <83a71hbuvo.fsf@gnu.org> <874kriiw6l.fsf@web.de> <83k10e68nu.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="130629"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 41706@debbugs.gnu.org, post+ebugs@guelker.eu To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 11 15:06:00 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jjMu8-000Xsv-5g for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Jun 2020 15:06:00 +0200 Original-Received: from localhost ([::1]:45880 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jjMu6-0006UB-Nv for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Jun 2020 09:05:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jjMkU-00005u-45 for bug-gnu-emacs@gnu.org; Thu, 11 Jun 2020 08:56:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52960) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jjMkT-0001JW-QT for bug-gnu-emacs@gnu.org; Thu, 11 Jun 2020 08:56:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jjMkT-00013P-MV for bug-gnu-emacs@gnu.org; Thu, 11 Jun 2020 08:56:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Jun 2020 12:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41706 X-GNU-PR-Package: emacs Original-Received: via spool by 41706-submit@debbugs.gnu.org id=B41706.15918801264002 (code B ref 41706); Thu, 11 Jun 2020 12:56:01 +0000 Original-Received: (at 41706) by debbugs.gnu.org; 11 Jun 2020 12:55:26 +0000 Original-Received: from localhost ([127.0.0.1]:36273 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jjMjt-00012T-Il for submit@debbugs.gnu.org; Thu, 11 Jun 2020 08:55:26 -0400 Original-Received: from mout.web.de ([212.227.15.4]:54057) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jjMjr-00012B-81 for 41706@debbugs.gnu.org; Thu, 11 Jun 2020 08:55:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1591880115; bh=BXaTL/+kLpqCfyrSqAfLh87Bzuwh3biy0QRoRmKanDs=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=TksBQqd74zUZUYm++UrqrKRbloXc5Rz/JK3GNwSf6P9CCEysDRY9qaFAPXafFDuNT cQF+qYsN5viKvSiOLNoemNDY7GN6fCskPdsWF2Opdjfv6CWdRpztD4jAVCctKWSgSQ PGNxQNsZEeM6JWGu5V5pzY0zhpMJ6VtWW0D7s/QM= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from drachen.dragon ([94.217.119.187]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1Mv3US-1ism7H1fbk-00qwjs; Thu, 11 Jun 2020 14:55:15 +0200 In-Reply-To: <83k10e68nu.fsf@gnu.org> (Eli Zaretskii's message of "Wed, 10 Jun 2020 22:08:21 +0300") X-Provags-ID: V03:K1:nDV+qooVQcWwwiq4m3RlUABq4m0Kx9wvnJE21f27okg+lDt5oXV G677sJ69S+OoTIWX0FuxQLcyB/R+FWdGo/9fVEahB454vRbeC8XE95/kL6VtIiE/V1gUB/B R9SWYHyZ6ankqClQWbnw/Vypgr2pbwdEVVWwfBkk41kZz3RY+u2Q7r5oLO15+E+P7vO7D3T rNSLb1lm5vFv2I0I4I2zA== X-UI-Out-Filterresults: notjunk:1;V03:K0:Hgf+b1ho0GY=:si9hI995ueLIf+ujKijHgu JwSfDMQigU6ocHDKYL9mkRpJ7tWWEC6D07iRlsOoeWhaKPuRlkcBa4RClWlkbwRY7JdOihOYF ljJ7YhJnA7ejwi79wCgimlvJIFI/X/xG3bGZ9uY3OhRW5jVH4Wg/4Lu2Z3CGeDPVxzp9ggTw7 6hSfAiPhN6veuvRLciMiWUEdfPfH+M85DHSOIQQOxa9lp5hOFMCdEGmoR5MM0T42KkO6OtrAi f7XFPSB9sK2xPOnz6WYyT3yEV2m5bQvsVzqdz2kfekaEuc5Isv/iU3qh6JWJCrMgchU/TjipS Y7YEMWIRxUnmEszWRBNP1bjFjaqUWLoRbeDtWL8zOMpknzk6QRcC8mp/s7180nQOsjt3VgJX+ qfJu8RDIEEM1EAczDo1IugiLPuFsaBIdQ3oMzcnV7tJ6NWPh82X1wFOX2lnBkvzQThl7XG31E P8iDbBTx72b046IbF3S4of7msKwAuE1mkXWw45RNBjXNNz6FyiDP7/thR+DGYXHP2TI5kzmme 2aNTdvM5JuToXVw02Mwg5PPN8FARK/f4uJEHNnCtiWckjyGeIU1gFyRTk6J9neIN6PQh/8z0g P26iZXH9E2lEjmgfHPNvdATZtHdZwcFzJbqtbQxaDGCOaEsVAE9WxyR7l6wAMwKutP24cr0M7 Vcb2mGRZKdnnJy9T/9v+2sIbxBpbjBKBGf0N7q939gAt0L01/kUP8D/dDh67I3/ylDShHi/3W 8588q7jf7L/96X5B/TVsA89LNurOq11ViNRiWMSLFotUToEdBFMIqOpoHcAoXnVKBxMkz0r7 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181850 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: > That's a beginning, thanks. But it needs more work, IMO: > > . the cons cell case hints on a possible return value of STARTKEYFUN, > AFAIU, but the text doesn't say so > . the case of STARTKEYFUN being nil is another use case for what > PREDICATE must cope with, and the text should say so > . the text about ENDKEYFUN should also be augmented, IMO > . the description of PREDICATE should reference this text in some > useful way I must admit I found the doc sufficient for all of these. Actually, reading the implementation might be simpler than describing it: #+begin_src emacs-lisp (setq key (catch 'key (or (and startkeyfun (funcall startkeyfun)) ;; If key was not returned as value, ;; move to end of key and get key from the buffer. (let ((start (point))) (funcall (or endkeyfun (prog1 endrecfun (setq done t)))) (cons start (point)))))) #+end_src What the doc is missing to mention is the `catch' - `sort-regexp-fields' uses this feature for example. Here is an attempt (not including the `catch' feature), anyway: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=sort-subr.patch diff --git a/lisp/sort.el b/lisp/sort.el index de0e1b9519..e22f062dbd 100644 --- a/lisp/sort.el +++ b/lisp/sort.el @@ -80,7 +80,15 @@ sort-subr PREDICATE, if non-nil, is the predicate function for comparing keys; it is called with two arguments, the keys to compare, and should return non-nil if the first key should sort before the -second key. If PREDICATE is nil, comparison is done with `<' if +second key. The key values PREDICATE is called with are the +either the return values of STARTKEYFUN when that function is +specified and returns a non-nil value. In any other case the keys +are cons cells of the form (BEG . END), where BEG is the value of +point after calling STARTKEYFUN when given, else after calling +ENDRECFUN, and END is the value of point after calling ENDKEYFUN when +given, and after calling ENDRECFUN else. + +If PREDICATE is nil, comparison is done with `<' if the keys are numbers, with `compare-buffer-substrings' if the keys are cons cells (the car and cdr of each cons cell are taken as start and end positions), and with `string<' otherwise." --=-=-= Content-Type: text/plain What I also would like to add to the docstring of this function, and of that of `sort', is that the PREDICATE must be transitive and antisymmetric - mentioning only in the manual is not enough IMHO. > > BTW, what about the suggestion to support collation order out of the > > box? > > What collation would you like to support, and in what form? I don't know much about this stuff. The canonical way from my ignorant point of view would be that `compare-buffer-substrings' would not only respect `case-fold-search' but also some other variable which would tell how the behavior should be w.r.t. collation. Michael. --=-=-=--