emacs-orgmode
[Top][All Lists]
Advanced

[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: Nicolas Goaziou
Subject: Re: [Patch] to correctly sort the items with emphasis marks in a list
Date: Tue, 20 Apr 2021 15:57:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

Hello,

Maxim Nikulin <manikulin@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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]