From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id eQlfOSnHfmAi4QAAgWs5BA (envelope-from ) for ; Tue, 20 Apr 2021 14:20:57 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id WDb8MynHfmDZXQAAB5/wlQ (envelope-from ) for ; Tue, 20 Apr 2021 12:20:57 +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 5F71220979 for ; Tue, 20 Apr 2021 14:20:57 +0200 (CEST) Received: from localhost ([::1]:54744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYpNA-0003Zj-5N for larch@yhetil.org; Tue, 20 Apr 2021 08:20:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYpMk-0003ZJ-C9 for emacs-orgmode@gnu.org; Tue, 20 Apr 2021 08:20:31 -0400 Received: from ciao.gmane.io ([116.202.254.214]:59346) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYpMi-0005ui-Ou for emacs-orgmode@gnu.org; Tue, 20 Apr 2021 08:20:30 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lYpMf-0000GC-Ls for emacs-orgmode@gnu.org; Tue, 20 Apr 2021 14:20:25 +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 19:20:19 +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> 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: <87r1j6b6ku.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=1618921257; 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=s1WaHw71JDf/q5Q9jCy+yzQMKrbHJhLX1ir2ZNHfdp8=; b=PV1mIXNpwcGwHbafxBkWXSVx9LyPyRG/IdPieU7HTVGMIiwaghW9iY+AqSotfamyhmMAhE ilYgE/6d4aHW40MDplAn3QnsuO/LvPABPSKpY9N0WqCrSJ0fehjMwhDC0dakIVFaZUbiT/ rrOm2EiGaz91DKn6/qo3ZzDdsW2vC4LQOndGAWRcEkSmHc9ncthkxT1ACgPMsJbGwIBKtd MlaTTMlT/ko2U+SO8NZGO4bHD1P931jyxH4kt5coiJPi2jZYum9DnUyot1BpN77EavtSTQ zI9C9C7NL3XyABJ8wAtma9cHkC0ZH8rooXVINrVL2+laDRfLPtQY/HbOxrGixg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1618921257; a=rsa-sha256; cv=none; b=D5gMQ+6lH31ww7l45P1hAcMR1GlJJt9nK09Tcq3WRKcnJ6/AuOnr2078Xpt1JzwKDzfutE y8+M6d4uwdLV3lAbrSfNXBRD52/gaBQ/KX0DJmr5DGBsGS642YiUVQxPqirqSWcI07m/9o XR5LsHxbMc4s5o+ZR11LE46HCjZaPnP2CqzCGiFsQ4ZpYYfZealx/3rlplMvZ+vODZHr/T sBIJ4DN52ZDVZhB9wI7yPezM97VbuFdwNd+5pHpneFxRPkO+2lLMxtf+emZofJIl5x+TmY x+J9wmGIXRpJwZftgfgo5x2K+Iv24C1nPy0jQB4S13k0mw+ZOBaWDlpJwBR/jg== 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: 5F71220979 X-Spam-Score: -1.84 X-Migadu-Scanner: scn0.migadu.com X-TUID: XqkPx9Cjipau Hi, On 19/04/2021 23:08, Nicolas Goaziou wrote: > >> In my opinion, a more severe limitation comes from sequential >> regexp-based approach. Consider stripping markers from >> 1. "a =b *c* d= e" >> 2. "*b* /i/" > > Fair enough. Here comes another, more involved, attempt. Maybe first variant deserves to be committed while discussion of a better option is in progress. > --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 Sorry, I can not help you with polishing code of this function, I am not familiar with functions working on org element tree yet. I can not even determine what type of structure is returned when `org-sort-remove-invisible' is called from ert or from scratch buffer: (org-sort-remove-invisible "A") #("A" 0 1 (:parent (#("A" 0 1 ...)))) A couple of obvious problems: 1. Link handling #+begin_src elisp (org-sort-remove-invisible "- [[https://orgmode.org/submit?a=bc%20d&e=t+r#1234][a link]]") #+end_src #+RESULTS: : - [[https://orgmode.org/submit?a=bc%20d&e=t+r#1234][a link]] 2. Missed spaces #+begin_src elisp (org-sort-remove-invisible "A *b* /i/ t.") #+end_src #+RESULTS: : A bit. > (let ((tree (org-element-parse-secondary-string > s (org-element-restriction 'paragraph)))) > (org-element-map tree '(bold code italic 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. > (_ > (let ((contents (org-element-contents 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--- > > It is not perfect, but it does a better job. > > WDYT?