[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Patch] to correctly sort the items with emphasis marks in a list
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 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 |
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---
- Re: [Patch] to correctly sort the items with emphasis marks in a list, (continued)
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Maxim Nikulin, 2021/04/19
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Nicolas Goaziou, 2021/04/19
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Greg Minshall, 2021/04/19
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Tom Gillespie, 2021/04/19
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Greg Minshall, 2021/04/19
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Maxim Nikulin, 2021/04/19
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Nicolas Goaziou, 2021/04/19
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Maxim Nikulin, 2021/04/20
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Maxim Nikulin, 2021/04/20
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Nicolas Goaziou, 2021/04/20
- Re: [Patch] to correctly sort the items with emphasis marks in a list,
Maxim Nikulin <=
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Nicolas Goaziou, 2021/04/20
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Maxim Nikulin, 2021/04/21
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Juan Manuel Macías, 2021/04/21
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Maxim Nikulin, 2021/04/24
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Bastien, 2021/04/28
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Nicolas Goaziou, 2021/04/28
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Bastien, 2021/04/28
- Re: [Patch] to correctly sort the items with emphasis marks in a list, Bastien, 2021/04/28
Re: [Patch] to correctly sort the items with emphasis marks in a list, Juan Manuel Macías, 2021/04/12
Re: [Patch] to correctly sort the items with emphasis marks in a list, Ypo, 2021/04/12