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

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

[elpa] externals/org 71a5f75bbb: Merge branch 'bugfix'


From: ELPA Syncer
Subject: [elpa] externals/org 71a5f75bbb: Merge branch 'bugfix'
Date: Tue, 13 Dec 2022 03:57:57 -0500 (EST)

branch: externals/org
commit 71a5f75bbbef5cc2dc9e6e4cc7d77560a39b1578
Merge: 45dc19516a 02909fe371
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    Merge branch 'bugfix'
---
 lisp/org-element.el     |  1 +
 lisp/ox.el              | 14 +++++++-----
 testing/lisp/test-ox.el | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 92780e0187..e3f0c82997 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -5295,6 +5295,7 @@ indentation removed from its contents."
 ;; `org-element--cache-diagnostics-ring-size', 
`org-element--cache-map-statistics',
 ;; `org-element--cache-map-statistics-threshold'.
 
+;;;###autoload
 (defvar org-element-use-cache t
   "Non-nil when Org parser should cache its results.")
 
diff --git a/lisp/ox.el b/lisp/ox.el
index 0a5ff67983..e9ec53747c 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -4758,23 +4758,27 @@ objects of the same type."
      (let ((counter 0))
        ;; Increment counter until ELEMENT is found again.
        (org-element-map (plist-get info :parse-tree)
-          (or types (org-element-type element))
+          (or (and types (cons (org-element-type element) types))
+               (org-element-type element))
         (lambda (el)
            (let ((cached (org-element-property :org-export--counter el)))
             (cond
              ((eq element el) (1+ counter))
               ;; Use cached result.
-              ((and cached (equal predicate (car cached)))
-               (cdr cached))
+              ((and cached
+                    (equal predicate (car cached))
+                    (equal types (cadr cached)))
+               (setq counter (nth 2 cached))
+               nil)
              ((not predicate)
                (cl-incf counter)
                (org-element-put-property
-                el :org-export--counter (cons predicate counter))
+                el :org-export--counter (list predicate types counter))
                nil)
              ((funcall predicate el info)
                (cl-incf counter)
                (org-element-put-property
-                el :org-export--counter (cons predicate counter))
+                el :org-export--counter (list predicate types counter))
                nil))))
         info 'first-match)))))
 
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 47f3f60750..cdb549df4b 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -405,6 +405,64 @@ Paragraph"
                   (options (org-export-get-environment backend t)))
              (list (plist-get options :k1) (plist-get options :k2)))))))
 
+(ert-deftest test-org-export/get-ordinal ()
+  "Test specifications for `org-export-get-ordinal'."
+  ;; Table numbering with, without predicates, and with other types.
+  (org-test-with-temp-text
+      "#+title: Table numbering test
+#+options: author:nil toc:nil
+
+#+caption: Should be Table 1
+| h1       | h2       | h3       |
+|----------+----------+----------|
+| abcdefgh | ijklmnop | qrstuvwx |
+
+#+caption: Should be Table 2
+| h1       | h2       | h3       |
+|----------+----------+----------|
+| abcdefgh | ijklmnop | qrstuvwx |
+
+#+caption: Should be Table 3
+| h1       | h2       | h3       |
+|----------+----------+----------|
+| abcdefgh | ijklmnop | qrstuvwx |
+
+#+caption: Should be Table 4
+| h1       | h2       | h3       |
+|----------+----------+----------|
+| abcdefgh | ijklmnop | qrstuvwx |"
+    (org-export-as
+     (org-export-create-backend
+      :parent 'org
+      :transcoders
+      '((table
+         .
+         (lambda (table contents info)
+           (let ((from-third (lambda (table info)
+                               (<= 3 (org-export-get-ordinal table info)))))
+             (pcase (org-element-interpret-data (org-export-get-caption table))
+               ("Should be Table 1"
+                (should (= 1 (org-export-get-ordinal table info)))
+                (should (= 2 (org-export-get-ordinal table info '(section))))
+                (should (= 1 (org-export-get-ordinal table info nil 
#'org-ascii--has-caption-p)))
+                (should (= 1 (org-export-get-ordinal table info nil 
from-third))))
+               ("Should be Table 2"
+                (should (= 2 (org-export-get-ordinal table info)))
+                (should (= 3 (org-export-get-ordinal table info '(section))))
+                (should (= 2 (org-export-get-ordinal table info nil 
#'org-ascii--has-caption-p)))
+                (should (= 1 (org-export-get-ordinal table info nil 
from-third))))
+               ("Should be Table 3"
+                (should (= 3 (org-export-get-ordinal table info)))
+                (should (= 4 (org-export-get-ordinal table info '(section))))
+                (should (= 3 (org-export-get-ordinal table info nil 
#'org-ascii--has-caption-p)))
+                (should (= 1 (org-export-get-ordinal table info nil 
from-third))))
+               ("Should be Table 4"
+                (should (= 4 (org-export-get-ordinal table info)))
+                (should (= 5 (org-export-get-ordinal table info '(section))))
+                (should (= 4 (org-export-get-ordinal table info nil 
#'org-ascii--has-caption-p)))
+                (should (= 2 (org-export-get-ordinal table info nil 
from-third))))))
+           "")))))))
+
 (ert-deftest test-org-export/set-title ()
   "Test title setting."
   ;; Without TITLE keyword.



reply via email to

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