From 951a6f250638a1dd60f6b3a941555586a0547580 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sat, 3 Mar 2012 07:35:12 -0700 Subject: [PATCH 1/5] fix code block replacement with results * lisp/ob.el (org-babel-find-named-result): Fix code block replacement with results. --- lisp/ob.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/ob.el b/lisp/ob.el index 701e923d4..39f53ef77 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -1497,7 +1497,8 @@ buffer or nil if no such result exists." (concat org-babel-result-regexp "[ \t]" (regexp-quote name) "[ \t\n\f\v\r]+") nil t) (when (and (string= "name" (downcase (match-string 1))) - (or (looking-at org-babel-src-block-regexp) + (or (beginning-of-line 1) + (looking-at org-babel-src-block-regexp) (looking-at org-babel-multi-line-header-regexp))) (throw 'is-a-code-block (org-babel-find-named-result name (point)))) (beginning-of-line 0) (point))))) From bf609d88443835c44870180c79ca9448da30f497 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 4 Mar 2012 11:57:16 +0100 Subject: [PATCH 2/5] org-export: Avoid duplicates in `org-export-collect-footnote-definitions' * contrib/lisp/org-element.el (org-element-map): New optional argument to avoid recursion into certain recursive types. * contrib/lisp/org-export.el (org-export-footnote-first-reference-p, org-export-get-footnote-number, org-export-collect-footnote-definitions): Use new argument from `org-element-map'. * testing/lisp/test-org-export.el: Add test. The new argument allows to force entering footnotes definitions at a certain time (when their first reference is found) but not a second time when they are encountered in the parse tree. Thanks to Jambunathan for reporting this. --- contrib/lisp/org-element.el | 25 ++++++++++++++++--------- contrib/lisp/org-export.el | 23 ++++++++++++++--------- testing/lisp/test-org-export.el | 15 ++++++++++++++- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/contrib/lisp/org-element.el b/contrib/lisp/org-element.el index 5dff9633f..e73c29b25 100644 --- a/contrib/lisp/org-element.el +++ b/contrib/lisp/org-element.el @@ -2935,7 +2935,7 @@ the current buffer." (insert string) (org-element-parse-objects (point-min) (point-max) nil restriction))) -(defun org-element-map (data types fun &optional info first-match) +(defun org-element-map (data types fun &optional info first-match no-recursion) "Map a function on selected elements or objects. DATA is the parsed tree, as returned by, i.e, @@ -2951,9 +2951,15 @@ not exportable according to that property list will be skipped. When optional argument FIRST-MATCH is non-nil, stop at the first match for which FUN doesn't return nil, and return that value. -Nil values returned from FUN are ignored in the result." - ;; Ensure TYPES is a list, even of one element. +Optional argument NO-RECURSION is a symbol or a list of symbols +representing elements or objects types. `org-element-map' won't +enter any recursive element or object whose type belongs to that +list. Though, FUN can still be applied on them. + +Nil values returned from FUN do not appear in the results." + ;; Ensure TYPES and NO-RECURSION are a list, even of one element. (unless (listp types) (setq types (list types))) + (unless (listp no-recursion) (setq no-recursion (list no-recursion))) ;; Recursion depth is determined by --CATEGORY. (let* ((--category (cond @@ -3008,12 +3014,13 @@ Nil values returned from FUN are ignored in the result." --blob)))) ;; Now determine if a recursion into --BLOB is ;; possible. If so, do it. - (when (or (memq --type org-element-recursive-objects) - (and (memq --type org-element-all-elements) - (not (eq --category 'elements))) - (and (memq --type org-element-greater-elements) - (not (eq --category 'greater-elements)))) - (funcall --walk-tree --blob))))) + (unless (memq --type no-recursion) + (when (or (and (memq --type org-element-greater-elements) + (not (eq --category 'greater-elements))) + (and (memq --type org-element-all-elements) + (not (eq --category 'elements))) + (memq --type org-element-recursive-objects)) + (funcall --walk-tree --blob)))))) (org-element-contents --data)))))) (catch 'first-match (funcall --walk-tree data) diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index 8174b8e9d..a946ebc87 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -2459,9 +2459,9 @@ DATA is the parse tree from which definitions are collected. INFO is the plist used as a communication channel. Definitions are sorted by order of references. They either -appear as Org data \(transcoded with `org-export-data'\) or as -a secondary string for inlined footnotes \(transcoded with -`org-export-secondary-string'\). Unreferenced definitions are +appear as Org data (transcoded with `org-export-data') or as +a secondary string for inlined footnotes (transcoded with +`org-export-secondary-string'). Unreferenced definitions are ignored." (let (num-alist (collect-fn @@ -2481,10 +2481,11 @@ ignored." ;; Also search in definition for nested footnotes. (when (eq (org-element-property :type fn) 'standard) (funcall collect-fn def))))) - info) - ;; Return final value. - (reverse num-alist))))) - (funcall collect-fn (plist-get info :parse-tree)))) + ;; Don't enter footnote definitions since it will happen + ;; when their first reference is found. + info nil 'footnote-definition))))) + (funcall collect-fn (plist-get info :parse-tree)) + (reverse num-alist))) (defun org-export-footnote-first-reference-p (footnote-reference info) "Non-nil when a footnote reference is the first one for its label. @@ -2512,7 +2513,9 @@ INFO is the plist used as a communication channel." ((eq (org-element-property :type fn) 'standard) (funcall search-refs (org-export-get-footnote-definition fn info))))) - info 'first-match))))) + ;; Don't enter footnote definitions since it will + ;; happen when their first reference is found. + info 'first-match 'footnote-definition))))) (equal (catch 'exit (funcall search-refs (plist-get info :parse-tree))) footnote-reference))))) @@ -2564,7 +2567,9 @@ INFO is the plist used as a communication channel." (funcall search-ref (org-export-get-footnote-definition fn info)) nil)))) - info 'first-match))))) + ;; Don't enter footnote definitions since it will happen + ;; when their first reference is found. + info 'first-match 'footnote-definition))))) (catch 'exit (funcall search-ref (plist-get info :parse-tree))))) diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el index ca1e441ac..034a9eab0 100644 --- a/testing/lisp/test-org-export.el +++ b/testing/lisp/test-org-export.el @@ -363,7 +363,20 @@ body\n"))) info (org-export-collect-tree-properties tree info 'test))) ;; Both footnotes should be seen. (should - (= (length (org-export-collect-footnote-definitions tree info)) 2)))))) + (= (length (org-export-collect-footnote-definitions tree info)) 2)))) + ;; 4. Test footnotes definitions collection. + (org-test-with-temp-text "Text[fn:1:A[fn:2]] [fn:3]. + +\[fn:2] B [fn:3] [fn::D]. + +\[fn:3] C." + (let ((tree (org-element-parse-buffer)) + (info (org-combine-plists + (org-export-initial-options) '(:with-footnotes t)))) + (setq info (org-combine-plists + info (org-export-collect-tree-properties tree info 'test))) + (should (= (length (org-export-collect-footnote-definitions tree info)) + 4)))))) (ert-deftest test-org-export/fuzzy-links () "Test fuzz link export specifications." From f18ea108aac35554a675bae46580daf2edd0ab09 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 4 Mar 2012 14:38:57 +0100 Subject: [PATCH 3/5] test-org-export: Fix broken test * testing/lisp/test-org-export.el (test-org-export/export-scope): In batch mode, `transient-mark-mode' must be turned on. --- testing/lisp/test-org-export.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el index 034a9eab0..3a86dcb6e 100644 --- a/testing/lisp/test-org-export.el +++ b/testing/lisp/test-org-export.el @@ -229,7 +229,9 @@ text ;; Region. (goto-char (point-min)) (forward-line 3) - (mark-paragraph) + (transient-mark-mode 1) + (push-mark (point) t t) + (goto-char (point-at-eol)) (should (equal (org-export-as 'test) "text\n"))))) (ert-deftest test-org-export/export-snippet () From f1a99ceddf37c2e30106dd35ff29e1ea4bce6f90 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 4 Mar 2012 15:53:55 +0100 Subject: [PATCH 4/5] test-org-footnote: Fix a broken test * testing/lisp/test-org-footnote.el: Fix failing `test-org-footnote/normalize-outside-org'. --- testing/lisp/test-org-footnote.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el index 52e553808..a768c70c9 100644 --- a/testing/lisp/test-org-footnote.el +++ b/testing/lisp/test-org-footnote.el @@ -212,7 +212,8 @@ Footnotes: ;; 3. As an exception, in `message-mode' buffer, if a signature is ;; present, insert footnotes before it. (let ((org-footnote-tag-for-non-org-mode-files nil) - (message-signature-separator "^-- $")) + (message-cite-prefix-regexp "\\([ ]*[_.[:word:]]+>+\\|[ ]*[]>|]\\)+") + (message-signature-separator "^-- $")) (with-temp-buffer (insert "Body[fn::def] -- From b549c6006511150a93bb97a539d400ab3ade4b75 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 4 Mar 2012 16:39:43 +0100 Subject: [PATCH 5/5] test-org-footnote: Fix a broken test (part 2) * testing/lisp/test-org-footnote.el: Fix `test-org-footnote/normalize-outside-org'. --- testing/lisp/test-org-footnote.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el index a768c70c9..91f2b97d6 100644 --- a/testing/lisp/test-org-footnote.el +++ b/testing/lisp/test-org-footnote.el @@ -210,17 +210,20 @@ Footnotes: \[1] Definition")))) ;; 3. As an exception, in `message-mode' buffer, if a signature is - ;; present, insert footnotes before it. - (let ((org-footnote-tag-for-non-org-mode-files nil) - (message-cite-prefix-regexp "\\([ ]*[_.[:word:]]+>+\\|[ ]*[]>|]\\)+") - (message-signature-separator "^-- $")) + ;; present, insert footnotes before it.n + (let ((org-footnote-tag-for-non-org-mode-files nil)) (with-temp-buffer (insert "Body[fn::def] -- Fake signature -- Signature") - (let ((major-mode 'message-mode)) (org-footnote-normalize)) + ;; Mimic `message-mode'. + (let ((major-mode 'message-mode) + (message-cite-prefix-regexp "\\([ ]*[_.[:word:]]+>+\\|[ ]*[]>|]\\)+") + (message-signature-separator "^-- $")) + (flet ((message-point-in-header-p nil nil)) + (org-footnote-normalize))) (should (equal (buffer-string) "Body[1]