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

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

[elpa] externals/org f4aa3747e1 014/101: org-element: Preserve order of


From: ELPA Syncer
Subject: [elpa] externals/org f4aa3747e1 014/101: org-element: Preserve order of multiple affiliated keywords
Date: Sat, 1 Jul 2023 09:58:57 -0400 (EDT)

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

    org-element: Preserve order of multiple affiliated keywords
    
    * lisp/org-element.el: Do not reverse affiliated keyword order.
    (org-element-map): Remove special arrangement to restore keyword
    ordering.
    (org-element--interpret-affiliated-keywords): Obey the new keyword order.
    * lisp/ox.el (org-export-get-caption):
    * testing/lisp/test-org-element.el 
(test-org-element/affiliated-keywords-parser):
    * testing/lisp/test-org-element.el (test-org-element/interpret-data):
    Do not assume reverse order.
    
    This is one of the undocumented conventions that is inconsistent with
    other aspects of the parser.
---
 lisp/org-element.el              | 29 ++++++++++++++++-------------
 lisp/ox.el                       |  7 ++++---
 testing/lisp/test-org-element.el | 10 +++++-----
 3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 381509b52d..c23bc1b941 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4283,7 +4283,7 @@ When PARSE is non-nil, values from keywords belonging to
          (when (or (member kwd org-element-multiple-keywords)
                    ;; Attributes can always appear on multiple lines.
                    (string-match "^ATTR_" kwd))
-           (setq value (cons value (plist-get output kwd-sym))))
+           (setq value (nconc (plist-get output kwd-sym) (list value))))
          ;; Eventually store the new value in OUTPUT.
          (setq output (plist-put output kwd-sym value))
          ;; Move to next keyword.
@@ -4538,13 +4538,13 @@ looking into captions:
                           ((not value))
                           ((member kwd org-element-dual-keywords)
                            (if (member kwd org-element-multiple-keywords)
-                               (dolist (line (reverse value))
+                               (dolist (line value)
                                  (funcall --walk-tree (cdr line))
                                  (funcall --walk-tree (car line)))
                              (funcall --walk-tree (cdr value))
                              (funcall --walk-tree (car value))))
                           ((member kwd org-element-multiple-keywords)
-                           (mapc --walk-tree (reverse value)))
+                           (mapc --walk-tree value))
                           (t (funcall --walk-tree value))))))
                    ;; Determine if a recursion into --DATA is possible.
                    (cond
@@ -4950,20 +4950,23 @@ If there is no affiliated keyword, return the empty 
string."
                   ;; All attribute keywords can have multiple lines.
                   (string-match "^ATTR_" keyword))
               (mapconcat (lambda (line) (funcall keyword-to-org keyword line))
-                         (reverse value)
-                         "")
+                         value "")
             (funcall keyword-to-org keyword value)))))
      ;; List all ELEMENT's properties matching an attribute line or an
      ;; affiliated keyword, but ignore translated keywords since they
      ;; cannot belong to the property list.
-     (cl-loop for prop in (nth 1 element) by 'cddr
-             when (let ((keyword (upcase (substring (symbol-name prop) 1))))
-                    (or (string-match "^ATTR_" keyword)
-                        (and
-                         (member keyword org-element-affiliated-keywords)
-                         (not (assoc keyword
-                                     org-element-keyword-translation-alist)))))
-             collect prop)
+     (let (acc)
+       (org-element-properties-mapc
+        (lambda (prop _ _)
+          (let  ((keyword (upcase (substring (symbol-name prop) 1))))
+            (when (or (string-match "^ATTR_" keyword)
+                     (and
+                      (member keyword org-element-affiliated-keywords)
+                      (not (assoc keyword
+                                org-element-keyword-translation-alist))))
+              (push prop acc))))
+        element t)
+       (nreverse acc))
      "")))
 
 ;; Because interpretation of the parse tree must return the same
diff --git a/lisp/ox.el b/lisp/ox.el
index 70bba0cf5d..9cdb146971 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -3910,9 +3910,10 @@ Caption lines are separated by a white space."
        (`nil nil)
        (c
         (setq caption
-              (nconc (list " ")
-                     (copy-sequence c) caption)))))
-    (cdr caption)))
+               (if caption
+                  (nconc caption (list " ") (copy-sequence c))
+                 (copy-sequence c))))))
+    caption))
 
 
 ;;;; For Derived Backends
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index e4053f26be..9c44bd340f 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -374,7 +374,7 @@ Some other text
   ;; Parse multiple keywords.
   (should
    (equal
-    '("line2" "line1")
+    '("line1" "line2")
     (org-element-property
      :attr_ascii
      (org-test-with-temp-text
@@ -409,12 +409,12 @@ Some other text
   ;; Allow multiple caption keywords.
   (should
    (equal
-    '((("l2") "s2") (("l1") "s1"))
+    '((("l1") "s1") (("l2") "s2"))
     (org-test-with-temp-text "#+CAPTION[s1]: l1\n#+CAPTION[s2]: l2\nParagraph"
       (org-element-property :caption (org-element-at-point)))))
   (should
    (equal
-    '((("l1")) (nil "s1"))
+    '((nil "s1") (("l1")))
     (org-test-with-temp-text "#+CAPTION[s1]:\n#+CAPTION: l1\nParagraph"
       (org-element-property :caption (org-element-at-point)))))
   ;; Corner case: orphaned keyword at the end of an element.
@@ -2772,7 +2772,7 @@ Outside list"
   (should
    (equal
     (org-element-interpret-data
-     '(org-data nil (paragraph (:attr_ascii ("line2" "line1")) "Paragraph")))
+     '(org-data nil (paragraph (:attr_ascii ("line1" "line2")) "Paragraph")))
     "#+attr_ascii: line1\n#+attr_ascii: line2\nParagraph\n"))
   ;; Interpret parsed affiliated keywords.
   (should
@@ -2791,7 +2791,7 @@ Outside list"
    (equal
     (org-element-interpret-data
      '(org-data nil (paragraph
-                    (:caption ((("l2") "s2") (("l1") "s1"))) "Paragraph")))
+                    (:caption ((("l1") "s1") (("l2") "s2"))) "Paragraph")))
     "#+caption[s1]: l1\n#+caption[s2]: l2\nParagraph\n"))
   ;; Pseudo objects and elements are transparent.
   (should



reply via email to

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