From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6FvTC0v6fmARngAAgWs5BA (envelope-from ) for ; Tue, 20 Apr 2021 17:59:07 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id MB+LB0v6fmDraQAA1q6Kng (envelope-from ) for ; Tue, 20 Apr 2021 15:59:07 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A813220A5D for ; Tue, 20 Apr 2021 17:59:06 +0200 (CEST) Received: from localhost ([::1]:53176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYsmG-0001lp-HN for larch@yhetil.org; Tue, 20 Apr 2021 11:59:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYsfT-0005TA-QZ for emacs-orgmode@gnu.org; Tue, 20 Apr 2021 11:52:03 -0400 Received: from ciao.gmane.io ([116.202.254.214]:42604) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYsfR-0005b5-PK for emacs-orgmode@gnu.org; Tue, 20 Apr 2021 11:52:03 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lYsfM-0008Fm-Hb for emacs-orgmode@gnu.org; Tue, 20 Apr 2021 17:51:56 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Maxim Nikulin Subject: Re: [Patch] to correctly sort the items with emphasis marks in a list Date: Tue, 20 Apr 2021 22:51:47 +0700 Message-ID: References: <87a6qg1rjx.fsf@posteo.net> <874kgft7n1.fsf@nicolasgoaziou.fr> <87blanxb1z.fsf@posteo.net> <87lf9fa3ak.fsf@posteo.net> <87sg3n8f33.fsf@posteo.net> <87tuo2d670.fsf@nicolasgoaziou.fr> <87r1j6b6ku.fsf@nicolasgoaziou.fr> <87a6pt9hyd.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 In-Reply-To: <87a6pt9hyd.fsf@nicolasgoaziou.fr> Content-Language: en-US Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1618934346; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Psbn4mr9q5utBllxXqynilZ2pd3n3y8oe9TTcaqWabU=; b=EoTibRvyXc9Ie68iGCOfNzuvBs0nS1iEC1VkARxJ5TbkjLZBFQ33v0EzDnoPF4Ax91CRhr XsGqcTd9tz7x3FfWylN959i41JTzZrRi7uai4cs1og9r+/9f9Yn4a8mxTB/qhRf08qivE5 Oii/trrKlNdKN8mCLpjpvLcnjdMeBeoBuT3cEdsQCZxMN4xeU9WZIXb5hY28dE04Yt/d+6 WZynbZU4Bc6u7kkPPr5sonBWowB55j3vWqdhrc7B/vZg9NwQMvhTH4hVrKMenf+/8s0LS9 9GhgTU/GwETz/EU1oug39N3k8tXP3ZPmaXjOpHOzcfj8+zq4jwRPr1ZuuewR8Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1618934346; a=rsa-sha256; cv=none; b=ueVWl3ohafuyA4Mu0kevOsydJ/ky7NtF2KdwdWtRUjDx+OUnIgoOz8a6vEsZkjexji7xAN 2w2757IlPU0MrIqwzDxo+i3q4HCQkkgrbB88lhJz/DOFhEhTv241o30NJ+HDCQU++FFTWy SdiheSLcxmedN/pCyg+Y3hr3iWL+5+YrZztxVIkl6pMqcW/KVQx8Extwp12UulIbwO55aR np41KSOHldY2mPyjW/v7eaY9V3isl1mD1Jfl8uNDo8CZWnlnH6L9PHJe4001ohWeNwBqNf 40uqmtBysDsihjQQUQHMoazQEouVRzekfGgZi0EmlZJTtNVpeFnosi8htkSIEg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.84 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: A813220A5D X-Spam-Score: -1.84 X-Migadu-Scanner: scn0.migadu.com X-TUID: rNj6qIt/f1O5 On 20/04/2021 20:57, Nicolas Goaziou wrote: > Maxim Nikulin writes: >> (org-sort-remove-invisible "A") >> #("A" 0 1 (:parent (#("A" 0 1 ...)))) > > This is a string. Thank you, from second attempt I have managed to strip text properties. Since the intended usage of return value is sorting key, would not it benefit from passing result through the following expression? (set-text-properties 0 (length s) nil s) An alternative is to clean up keys in `org-sort-list' function. > Ah! I forgot the link part! Hopefully done here. Surprisingly there are still cases when the old approach works better: (let ((s (org-sort-remove-invisible "A /wrapping [[https://orgmode.org/?a=b&c=d#e][link]] emphasis/"))) (set-text-properties 0 (length s) nil s) s) "A wrapping [[https://orgmode.org?a=b&c=d#e][link]] emphasis/" I expect "A wrapping link emphasis". In the meanwhile I have tried (benchmark-run 1 (org-sort-list t ?a)) in a file (1100 lines) obtained using grep '^- ' doc/org-manual.org >/tmp/list.org It seems, performance is still acceptable (single run hardly could be considered as an accurate test): (1.115571472 18 0.5986466069999999) ; new variant (0.260384514 1 0.09805475199999947) ; original code > --8<---------------cut here---------------start------------->8--- > (defun org-sort-remove-invisible (s) > "Remove emphasis markers and any invisible property from string S. > Assume S may contain only objects." > ;; org-element-interpret-data clears any text property, including > ;; invisible part. > (org-element-interpret-data > (let ((tree (org-element-parse-secondary-string > s (org-element-restriction 'paragraph)))) > (org-element-map tree '(bold code italic link strike-through underline verbatim) > (lambda (o) > (pcase (org-element-type o) > ;; Terminal object. Replace it with its value. > ((or `code `verbatim) > (let ((new (org-element-property :value o))) > (org-element-insert-before new o) > (org-element-put-property > new :post-blank (org-element-property :post-blank o)))) > ;; Non-terminal objects. Splice contents. > (type > (let ((contents > (or (org-element-contents o) > (and (eq type 'link) > (list (org-element-property :raw-link o))))) > (c nil)) > (while contents > (setq c (pop contents)) > (org-element-insert-before c o)) > (org-element-put-property > c :post-blank (org-element-property :post-blank o))))) > (org-element-extract-element o))) > ;; Return modified tree. > tree))) > --8<---------------cut here---------------end--------------->8---