branch: externals/org
commit 22b9b48d239e4ce17b41977458f64e91d7e530d6
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    fixup: ox: Fix handling export option set by overriding keyword in derived 
backends
    
    * lisp/ox.el (org-export--parse-option-keyword):
    (org-export--get-subtree-options): Handle inheritance correctly for
    subtree keywords and #+options value as well.
    * testing/lisp/test-ox.el (test-org-export/get-subtree-options):
    (test-org-export/parse-option-keyword): Add more tests.
---
 lisp/ox.el              | 17 ++++++++++----
 testing/lisp/test-ox.el | 59 +++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index a16b64830d..8ec1b608f8 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1444,11 +1444,15 @@ specific items to read, if any."
        ;; Priority is given to backend specific options.
        (all (append (org-export-get-all-options backend)
                     org-export-options-alist))
-       (plist))
+       (plist)
+        seen-options)
     (when line
       (dolist (entry all plist)
        (let ((item (nth 2 entry)))
-         (when item
+         (when (and item
+                     ;; Only use the first option set by derived backend.
+                     (not (memq (car entry) seen-options)))
+            (push (car entry) seen-options)
            (let ((v (assoc-string item line t)))
              (when v (setq plist (plist-put plist (car entry) (cdr v)))))))))))
 
@@ -1480,12 +1484,17 @@ for export.  Return options as a plist."
         ;; Look for both general keywords and backend specific
         ;; options, with priority given to the latter.
         (options (append (org-export-get-all-options backend)
-                         org-export-options-alist)))
+                         org-export-options-alist))
+         seen-properties)
      ;; Handle other keywords.  Then return PLIST.
      (dolist (option options plist)
        (let ((property (car option))
             (keyword (nth 1 option)))
-        (when keyword
+        (when (and keyword
+                    ;; Only consider the first instance of property
+                    ;; In other words, derived backend settings take 
precendence.
+                    (not (memq property seen-properties)))
+           (push property seen-properties)
           (let ((value
                  (or (cdr (assoc keyword cache))
                      (let ((v (org-entry-get (point)
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index fb55b187d5..0cc46f84ed 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -212,7 +212,21 @@ num:2 <:active")))
           (plist-get options :section-numbers))))
   ;; Parse spaces inside brackets.
   (let ((options (org-export--parse-option-keyword "html-postamble:\"test 
space\"" 'html)))
-    (should (equal "test space" (plist-get options :html-postamble)))))
+    (should (equal "test space" (plist-get options :html-postamble))))
+  ;; Honor backend inheritance
+  (let* ((parent-backend (org-export-create-backend
+                         :options '((:k1 nil "parent-opt"))))
+         (child-backend (org-export-create-backend
+                         :parent parent-backend
+                         :options '((:k1 nil "child-opt")))))
+    (let ((options (org-export--parse-option-keyword "parent-opt:parent" 
parent-backend)))
+      (should (equal 'parent (plist-get options :k1))))
+    (let ((options (org-export--parse-option-keyword "child-opt:child 
parent-opt:parent" parent-backend)))
+      (should (equal 'parent (plist-get options :k1))))
+    (let ((options (org-export--parse-option-keyword "parent-opt:parent" 
child-backend)))
+      (should-not (plist-get options :k1)))
+    (let ((options (org-export--parse-option-keyword "child-opt:child 
parent-opt:parent" child-backend)))
+      (should (equal 'child (plist-get options :k1))))))
 
 (ert-deftest test-org-export/get-inbuffer-options ()
   "Test reading all standard export keywords."
@@ -440,7 +454,48 @@ Paragraph"
                             :options '((:k1 "A")
                                        (:k2 "A"))))
                   (options (org-export-get-environment backend t)))
-             (list (plist-get options :k1) (plist-get options :k2)))))))
+             (list (plist-get options :k1) (plist-get options :k2))))))
+  ;; Derived backend property takes precedence
+  (let* ((parent-backend (org-export-create-backend
+                         :options '(( :k1 "KEYWORD_PARENT"
+                                       nil "parent-default"))))
+         (child-backend (org-export-create-backend
+                         :parent parent-backend
+                         :options '(( :k1 "KEYWORD_CHILD"
+                                      nil "child-default")))))
+    (should
+     (equal "value"
+            (org-test-with-temp-text "* H
+:PROPERTIES:
+:EXPORT_KEYWORD_CHILD: value
+:END:
+<point>"
+              (plist-get (org-export-get-environment child-backend t) :k1))))
+    (should
+     (equal "value"
+            (org-test-with-temp-text "* H
+:PROPERTIES:
+:EXPORT_KEYWORD_CHILD: value
+:EXPORT_KEYWORD_PARENT: parent
+:END:
+<point>"
+              (plist-get (org-export-get-environment child-backend t) :k1))))
+    (should
+     (equal "child-default"
+            (org-test-with-temp-text "* H
+:PROPERTIES:
+:EXPORT_KEYWORD_PARENT: parent
+:END:
+<point>"
+              (plist-get (org-export-get-environment child-backend t) :k1))))
+    (should
+     (equal "parent-default"
+            (org-test-with-temp-text "* H
+:PROPERTIES:
+:EXPORT_KEYWORD_CHILD: parent
+:END:
+<point>"
+              (plist-get (org-export-get-environment parent-backend t) 
:k1))))))
 
 (ert-deftest test-org-export/get-ordinal ()
   "Test specifications for `org-export-get-ordinal'."

Reply via email to