emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Maxim Nikulin <manikulin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [Patch] to correctly sort the items with emphasis marks in a list
Date: Mon, 19 Apr 2021 18:08:17 +0200	[thread overview]
Message-ID: <87r1j6b6ku.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <s5jtd3$qs6$1@ciao.gmane.io> (Maxim Nikulin's message of "Mon, 19 Apr 2021 19:34:42 +0700")

Hello,

Maxim Nikulin <manikulin@gmail.com> writes:

> Just a curiosity, what is style guide recommendation: let - lambda or
> cl-labels?

I stay away from CL as much as possible, otherwise newcomers will have
to learn two languages to start contributing, Elisp and CL (cl-loop,
ewww). CL is still necessary however, as we cannot use `seq' yet.

Also, there is `letrec' instead of `cl-labels'.

> 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.

--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 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?

> +      ;; Space role in sorting.
> +      ;; Test would fail for locales with ignored space, e.g. en_US, it works
> +      ;; in C and currently rare locales having significant space (es_ES, pl_PL)
> +      (should
> +       (equal "- Time stamp\n- Timer\n"
> +              (org-test-with-temp-text "- Timer\n- Time stamp\n"
> +                (org-sort-list t ?a)
> +                (buffer-string))))))

Since this test is bound to fail for some developers, I assume it
shouldn't be included.

> +  (dolist (case '(("Lost =in *verbatim* text= fragment" .
> +                   "Lost in *verbatim* text fragment")
> +                  ("Adjucent emphasis: *Overlapped* /regexps/" .
> +                   "Adjucent emphasis: Ovelapped regexps")))
                                          ^^^^
                                          typo

Regards,
-- 
Nicolas Goaziou


  reply	other threads:[~2021-04-19 16:12 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02 18:15 Juan Manuel Macías
2021-04-09 22:28 ` Nicolas Goaziou
2021-04-10  0:01   ` Juan Manuel Macías
2021-04-10 10:19     ` Nicolas Goaziou
2021-04-10 11:41       ` Juan Manuel Macías
2021-04-13 17:31         ` Maxim Nikulin
2021-04-13 19:08           ` Juan Manuel Macías
2021-04-14 15:42             ` Maxim Nikulin
2021-04-14 15:51               ` Maxim Nikulin
2021-04-14 17:07               ` Juan Manuel Macías
2021-04-14 21:36                 ` Juan Manuel Macías
2021-04-15 14:58                 ` Maxim Nikulin
2021-04-15 18:21                   ` Juan Manuel Macías
2021-04-16 14:59                     ` Maxim Nikulin
2021-04-16 15:30                       ` Maxim Nikulin
2021-04-17 13:27     ` Maxim Nikulin
2021-04-18 17:52       ` Juan Manuel Macías
2021-04-18 21:20         ` Juan Manuel Macías
2021-04-19  8:33           ` Nicolas Goaziou
2021-04-19 12:34             ` Maxim Nikulin
2021-04-19 16:08               ` Nicolas Goaziou [this message]
2021-04-19 17:00                 ` Greg Minshall
2021-04-19 17:17                   ` Tom Gillespie
2021-04-19 18:00                     ` Greg Minshall
2021-04-19 17:36                 ` Maxim Nikulin
2021-04-19 17:50                   ` Nicolas Goaziou
2021-04-20 12:37                     ` Maxim Nikulin
2021-04-20 12:20                 ` Maxim Nikulin
2021-04-20 13:57                   ` Nicolas Goaziou
2021-04-20 15:51                     ` Maxim Nikulin
2021-04-20 20:37                       ` Nicolas Goaziou
2021-04-21 13:10                         ` Maxim Nikulin
2021-04-21 15:45                           ` Juan Manuel Macías
2021-04-24 14:41                             ` Maxim Nikulin
2021-05-20 17:06                           ` [Patch] tests for org-remove-invisible Maxim Nikulin
2021-05-20 18:06                             ` Nicolas Goaziou
2021-09-27 16:53                               ` Max Nikulin
2021-05-15 20:43                     ` [Patch] to correctly sort the items with emphasis marks in a list Bastien
2021-05-15 22:09                       ` Nicolas Goaziou
2021-05-16  6:04                         ` Bastien
2021-04-28  5:46     ` Bastien
2021-04-28  6:37       ` Nicolas Goaziou
2021-04-28  6:49         ` Bastien
2021-04-28  8:04           ` Bastien
2021-05-15 13:32             ` Bastien
2021-05-15 15:10               ` Maxim Nikulin
2021-05-15 20:44                 ` Bastien
2021-04-12 13:50 Juan Manuel Macías
     [not found] <mailman.57.1618243212.17744.emacs-orgmode@gnu.org>
2021-04-12 18:51 ` Ypo
2021-04-12 23:18   ` Juan Manuel Macías
2021-04-12 23:52     ` Samuel Wales
2021-04-13 14:16       ` Juan Manuel Macías

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1j6b6ku.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@gmail.com \
    --subject='Re: [Patch] to correctly sort the items with emphasis marks in a list' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).