From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Marvin =?UTF-8?Q?G=C3=BClker?= Newsgroups: gmane.emacs.bugs Subject: bug#41706: 26.1; sort-subr predicate cannot be set successfully Date: Thu, 4 Jun 2020 21:05:26 +0200 Message-ID: <20200604190526.GA14104@atlantis> References: <20200604110922.GA9116@atlantis> <87pnafxc7e.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="1866"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 41706@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 04 21:06:14 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 1jgvBt-0000LT-TQ for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Jun 2020 21:06:14 +0200 Original-Received: from localhost ([::1]:41900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgvBs-0004Ww-Vf for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Jun 2020 15:06:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgvBi-0004U4-5e for bug-gnu-emacs@gnu.org; Thu, 04 Jun 2020 15:06:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jgvBh-00061Y-TJ for bug-gnu-emacs@gnu.org; Thu, 04 Jun 2020 15:06:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jgvBh-00086U-P3 for bug-gnu-emacs@gnu.org; Thu, 04 Jun 2020 15:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Marvin =?UTF-8?Q?G=C3=BClker?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 04 Jun 2020 19:06: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.159129750731063 (code B ref 41706); Thu, 04 Jun 2020 19:06:01 +0000 Original-Received: (at 41706) by debbugs.gnu.org; 4 Jun 2020 19:05:07 +0000 Original-Received: from localhost ([127.0.0.1]:47472 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jgvAp-00084x-CD for submit@debbugs.gnu.org; Thu, 04 Jun 2020 15:05:07 -0400 Original-Received: from mout-p-202.mailbox.org ([80.241.56.172]:29750) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jgvAn-00084I-Ka for 41706@debbugs.gnu.org; Thu, 04 Jun 2020 15:05:06 -0400 Original-Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 49dFZz32zFzQlJR; Thu, 4 Jun 2020 21:04:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=guelker.eu; s=MBO0001; t=1591297497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jFSEx/uvn1P5l/BpJODP2JAUMhEyOzuLzRAyEKV3uGc=; b=c2UPxdnRdG64sCXa0nFaAbn/MpGQ2HIK29SJcqcXpS4RnTbjS04DD8UqMF1uPEtkAjXYuZ 6ZV5QLDM3GDWBbjjSpws7xs9Zfl7cK4hI5JqDr3vwmnyUL2c5zJa0q8dxxl6qFURaJQXG2 M0D7ef7EEhduQCr6t3dQ2gL4yzCUsqh/tnFQWEfkn/mobANz3ot4U0mztysCSmytioFfsr wQzp+pnVkb3NWmyK/16ui5ZB3PQaxBTrZ9NRGmSWtrOkTPzl8rbrkkj+OMvIK98Yyy40le 0RZBl8Uu41ilkLgSi/UIrBwdrCKW9RtD13hgPsl56XvAIFaigCg0I5bDlnkvvw== Original-Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id nHllZbPc8vwS; Thu, 4 Jun 2020 21:04:55 +0200 (CEST) Content-Disposition: inline In-Reply-To: <87pnafxc7e.fsf@web.de> X-Rspamd-Queue-Id: F3D4217FA X-Rspamd-Score: -2.63 / 15.00 / 15.00 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:181523 Archived-At: Am 04. Juni 2020 um 14:11 Uhr +0200 schrieb Michael Heerdegen: >I think you use it wrong: the keys are not strings but cons cells. So >the predicate function should be something like >`compare-buffer-substrings'. You are correct. Your comment put me on the right track (but see below). This version works and sorts the lines according to the locale's rules: (defun my-sort-lines-collate (reverse beg end) (interactive "P\nr") (save-excursion (save-restriction (narrow-to-region beg end) (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 nil nil (lambda (a b) (string-collate-lessp (buffer-substring (car a) (cdr a)) (buffer-substring (car b) (cdr b))))))))) I have broken it slightly different for readability. The change I did was to use `buffer-substring' in the predicate lambda. It was not clear to me that the arguments given to the predicate function are actually buffer positions and not the buffer substrings themselves as I expected. This is not explained in the manual (section § 32.15) on `sort-subr'). >To understand how ‘sort-subr’ works, consider the whole accessible >portion of the buffer as being divided into disjoint pieces called >“sort records”. The records may or may not be contiguous, but they >must not overlap. A portion of each sort record (perhaps all of >it) is designated as the sort key. [...] >The argument PREDICATE is the function to use to compare keys. If >keys are numbers, it defaults to ‘<’; otherwise it defaults to >string<’. No further mention of how to use PREDICATE is made, and the manual continues with reproducing the source code of `sort-lines'. I took that section to mean that the PREDICATE is in the default case `<' and with strings `string<'. From the manual's text it became not clear to me under which condition the keys are not strings, and I assumed they will normally always be strings as buffer substrings are always strings. Now I see that the documentation for the `sort-subr' function is a little more specific, but still it doesn't really make clear which kind of "key" is received as arguments in the PREDICATE under which conditions. The call above appearently yields cons cell keys whose CAR and CDR correspond to buffer positions, but the documentation makes me suspect that calling `sort-subr' differently will yield other kinds of keys. I would suggest to amend the manual to be more precise about the arguments that PREDICATE receives, and perhaps add an example. Thank you for your explanation. -- Blog: https://mg.guelker.eu