Hello, Maxim Nikulin <maniku...@gmail.com> writes:
> Maybe first variant deserves to be committed while discussion of a > better option is in progress. I'd rather not, since we're currently considering a somewhat different path. The problem has been there for ages anyway. > 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 ...)))) This is a string. > 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]] Ah! I forgot the link part! Hopefully done here. --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--- > 2. Missed spaces > > #+begin_src elisp > (org-sort-remove-invisible "A *b* /i/ t.") > #+end_src > > #+RESULTS: > : A bit. You need to update Org. I added a fix for that in "org-element" yesterday. Regards, -- Nicolas Goaziou