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

    ox: Fix handling export option set by overriding keyword in derived backends
    
    * lisp/ox.el (org-export--get-inbuffer-options): When a derived
    backend override in-buffer keyword used to set export option, ignore
    the keyword from parent backend.
    * testing/lisp/test-ox.el (test-org-export/get-inbuffer-options): Add
    new tests.
    
    Reported-by: Pedro Andres Aranda Gutierrez <paag...@gmail.com>
    Link: 
https://orgmode.org/list/cao48bk9x-futfhnba2h5cs9huj8hoapm7r07rw3kxgj9qzr...@mail.gmail.com
---
 lisp/ox.el              | 14 +++++++++++---
 testing/lisp/test-ox.el | 26 ++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 274ca21c36..a16b64830d 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1521,10 +1521,18 @@ Assume buffer is in Org mode.  Narrowing, if any, is 
ignored."
     (let ((find-properties
           (lambda (keyword)
             ;; Return all properties associated to KEYWORD.
-            (let (properties)
+            (let (properties seen-properties)
               (dolist (option options properties)
-                (when (equal (nth 1 option) keyword)
-                  (cl-pushnew (car option) properties)))))))
+                 ;; Ignore all but first :export-property
+                 ;; This is to avoid situations like
+                 ;; (:parent-backend-property "PARENT_KEYWORD" ...)
+                 ;; (:child-backend-property "CHILD_KEYWORD" ...)
+                 ;; where we should ignore #+PARENT_KEYWORD when child
+                 ;; backend is used.
+                 (unless (memq (car option) seen-properties)
+                   (push (car option) seen-properties)
+                  (when (equal (nth 1 option) keyword)
+                    (cl-pushnew (car option) properties))))))))
       ;; Read options in the current buffer and return value.
       (dolist (entry (org-collect-keywords
                      (nconc (delq nil (mapcar #'cadr options))
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index ec16a75fc3..fb55b187d5 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -322,6 +322,32 @@ num:2 <:active")))
                                     (:k2 "KEYWORD")))))
            (org-test-with-temp-text "#+KEYWORD: value"
              (org-export--get-inbuffer-options backend)))))
+  ;; Derived backend keyword takes precendence
+  (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 '(:k1 "value")
+            (org-test-with-temp-text "#+KEYWORD_CHILD: value"
+              (org-export--get-inbuffer-options child-backend))))
+    (should
+     (equal '(:k1 "value")
+            (org-test-with-temp-text "#+KEYWORD_CHILD: value
+#+KEYWORD_PARENT: value2"
+              (org-export--get-inbuffer-options child-backend))))
+    (should
+     (equal '(:k1 "value")
+            (org-test-with-temp-text "#+KEYWORD_PARENT: value2
+#+KEYWORD_CHILD: value"
+              (org-export--get-inbuffer-options child-backend))))
+    (should
+     (equal nil ; Ignore KEYWORD_PARENT
+            (org-test-with-temp-text "#+KEYWORD_PARENT: value"
+              (org-export--get-inbuffer-options child-backend)))))
   ;; Keywords in commented subtrees are ignored.
   (should-not
    (equal "Me"

Reply via email to