emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org f93cc661c6: org-element-set-contents: Do alter the


From: ELPA Syncer
Subject: [elpa] externals/org f93cc661c6: org-element-set-contents: Do alter the anonymous parents
Date: Fri, 3 Mar 2023 10:58:10 -0500 (EST)

branch: externals/org
commit f93cc661c656c7a74c67fd0299662d1604b2b243
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-element-set-contents: Do alter the anonymous parents
    
    * lisp/org-element.el (org-element-set-contents): Do alter anonymous
    elements (el1 el2 ...).  Such elements are used, for example, when
    parsing keyword values during export, like :title.
    * testing/lisp/test-org-element.el (test-org-element/set-contents):
    Add test.
    
    The patch fixed bug during export when exporting a subtree with
    option stat:nil.  The :title during subtree export is taken from the
    heading title and parsed.  However, the parsed value is stored outside
    the parse tree, in :title property of the INFO channel.  The parsed
    value does get filtered through `org-export--prune-tree', but before
    this commit, `org-element-set-contents' did not actually alter the
    out-of-AST-tree parent lists of elements.
    
    Reported-by: Leo Butler <Leo.Butler@umanitoba.ca>
    Link: https://orgmode.org/list/87mt4w8epo.fsf@t14.reltub.ca
---
 lisp/org-element.el              | 9 ++++++++-
 testing/lisp/test-org-element.el | 8 +++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index d7847a6780..f8442511cf 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -548,7 +548,14 @@ Return modified element."
   "Set ELEMENT's contents to CONTENTS.
 Return ELEMENT."
   (cond ((null element) contents)
-       ((not (symbolp (car element))) contents)
+       ((not (symbolp (car element)))
+         (if (not (listp element))
+             ;; Non-element.
+             contents
+           ;; Anonymous element (el1 el2 ...)
+           (setcar element (car contents))
+           (setcdr element (cdr contents))
+           element))
        ((cdr element) (setcdr (cdr element) contents) element)
        (t (nconc element contents))))
 
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 43f1d860f0..957e991944 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -125,7 +125,13 @@ Some other text
    (org-test-with-temp-text "* Headline\n *a*"
      (let ((tree (org-element-parse-buffer)))
        (org-element-set-contents (org-element-map tree 'bold 'identity nil t))
-       (org-element-contents (org-element-map tree 'bold 'identity nil t))))))
+       (org-element-contents (org-element-map tree 'bold 'identity nil t)))))
+  ;; Set contents of anonymous elements.
+  (should
+   (equal '#1=((b (:parent #1#)))
+          (let ((element '#1=((a (:parent #1#)) (b (:parent #1#)))))
+            (org-element-set-contents element `(b (:parent ,element)))
+            element))))
 
 (ert-deftest test-org-element/secondary-p ()
   "Test `org-element-secondary-p' specifications."



reply via email to

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