Browse Source

Merge branch 'master' into max-sticky-agenda

Max Mikhanosha 13 years ago
parent
commit
cf55d4338a

+ 16 - 9
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)

+ 14 - 9
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)))))
 
 

+ 17 - 2
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 ()
@@ -363,7 +365,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."

+ 8 - 4
testing/lisp/test-org-footnote.el

@@ -210,16 +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-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]