From e860fbf22a22dcbde83c6d131c17ff0b71be6991 Mon Sep 17 00:00:00 2001 From: Bastien Date: Sat, 15 May 2021 22:03:47 +0200 Subject: [PATCH 1/2] lisp/org-list.el: Fix bug wrt updating statistics * lisp/org-list.el (org-update-checkbox-count): Don't update statistics when toggling a checkbox witin a heading that has COOKIE_DATA set to "todo". Reported-by: Michael Brand Link: https://orgmode.org/list/CALn3zohYfoyDm6w-AYWsVRSbOCndBPZQyb+YvHcaEby3JEhWMw@mail.gmail.com --- lisp/org-list.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lisp/org-list.el b/lisp/org-list.el index 39122e7ce..3a31ae30b 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -2484,10 +2484,10 @@ With optional prefix argument ALL, do this for the whole buffer." (let* ((cookie-re "\\(\\(\\[[0-9]*%\\]\\)\\|\\(\\[[0-9]*/[0-9]*\\]\\)\\)") (box-re "^[ \t]*\\([-+*]\\|\\([0-9]+\\|[A-Za-z]\\)[.)]\\)[ \t]+\ \\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?\\(\\[[- X]\\]\\)") + (cookie-data (or (org-entry-get nil "COOKIE_DATA") "")) (recursivep (or (not org-checkbox-hierarchical-statistics) - (string-match "\\" - (or (org-entry-get nil "COOKIE_DATA") "")))) + (string-match-p "\\" cookie-data))) (within-inlinetask (and (not all) (featurep 'org-inlinetask) (org-inlinetask-in-task-p))) @@ -2533,7 +2533,8 @@ With optional prefix argument ALL, do this for the whole buffer." (while (re-search-forward cookie-re end t) (let ((context (save-excursion (backward-char) (save-match-data (org-element-context))))) - (when (eq (org-element-type context) 'statistics-cookie) + (when (and (eq (org-element-type context) 'statistics-cookie) + (not (string-match-p "\\" cookie-data))) (push (append (list (match-beginning 1) (match-end 1) (match-end 2)) From 589962b7308daf1367453101042f2991afc1645e Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 16 May 2021 07:48:01 +0200 Subject: [PATCH 2/2] lisp/org.el: Fix bug in `org-sort-remove-invisible' * lisp/org.el (org-sort-remove-invisible): Rewrite using `org-element-interpret-data' to clean invisible parts more rigorously. Link: https://orgmode.org/list/87a6qg1rjx.fsf@posteo.net/ --- lisp/org.el | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index ccdd8e84f..d732b48fa 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8096,14 +8096,37 @@ Optional argument WITH-CASE means sort case-sensitively." with-case)) (defun org-sort-remove-invisible (s) - "Remove invisible part of links and emphasis markers from string S." - (remove-text-properties 0 (length s) org-rm-props s) - (replace-regexp-in-string - org-verbatim-re (lambda (m) (format "%s " (match-string 4 m))) - (replace-regexp-in-string - org-emph-re (lambda (m) (format " %s " (match-string 4 m))) - (org-link-display-format s) - t t) t t)) + "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))) (defvar org-after-sorting-entries-or-items-hook nil "Hook that is run after a bunch of entries or items have been sorted.