[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 19:20:19 +0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 |
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?
- 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, Juan Manuel Macías, 2021/04/18
- 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/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 <=
- 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/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, 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