Browse Source

Allow Org-mode source code examples in LaTeX export

This did not work because the parser would still match headlines that
are really part of the examples.
Carsten Dominik 15 years ago
parent
commit
f759cc17a7
3 changed files with 22 additions and 5 deletions
  1. 9 0
      lisp/ChangeLog
  2. 5 5
      lisp/org-latex.el
  3. 8 0
      lisp/org-macs.el

+ 9 - 0
lisp/ChangeLog

@@ -1,3 +1,12 @@
+2009-11-25  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-latex.el (org-export-latex-parse-global)
+	(org-export-latex-parse-content)
+	(org-export-latex-parse-subcontent): Use
+	`org-re-search-forward-unprotected'.
+
+	* org-macs.el (org-re-search-forward-unprotected): New function.
+
 2009-11-24  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-mobile.el (org-mobile-agendas): New option.

+ 5 - 5
lisp/org-latex.el

@@ -744,7 +744,7 @@ Return a list reflecting the document structure."
     (goto-char (point-min))
     (let* ((cnt 0) output
 	   (depth org-export-latex-sectioning-depth))
-      (while (re-search-forward
+      (while (org-re-search-forward-unprotected
 	      (concat "^\\(\\(?:\\*\\)\\{"
 		      (number-to-string (+ (if odd 2 1) level))
 		      "\\}\\) \\(.*\\)$")
@@ -752,7 +752,7 @@ Return a list reflecting the document structure."
 	      (when (> level 0)
 		(save-excursion
 		  (save-match-data
-		    (re-search-forward
+		    (org-re-search-forward-unprotected
 		     (concat "^\\(\\(?:\\*\\)\\{"
 			     (number-to-string level)
 			     "\\}\\) \\(.*\\)$") nil t)))) t)
@@ -764,7 +764,7 @@ Return a list reflecting the document structure."
 	    (narrow-to-region
 	     (point)
 	     (save-match-data
-	       (if (re-search-forward
+	       (if (org-re-search-forward-unprotected
 		    (concat "^\\(\\(?:\\*\\)\\{"
 			    (number-to-string (+ (if odd 2 1) level))
 			    "\\}\\) \\(.*\\)$") nil t)
@@ -788,7 +788,7 @@ Return a list reflecting the document structure."
 (defun org-export-latex-parse-content ()
   "Extract the content of a section."
   (let ((beg (point))
-	(end (if (re-search-forward "^\\(\\*\\)+ .*$" nil t)
+	(end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
 		 (progn (beginning-of-line) (point))
 	       (point-max))))
     (buffer-substring beg end)))
@@ -796,7 +796,7 @@ Return a list reflecting the document structure."
 (defun org-export-latex-parse-subcontent (level odd)
   "Extract the subcontent of a section at LEVEL.
 If ODD Is non-nil, assume subcontent only contains odd sections."
-  (if (not (re-search-forward
+  (if (not (org-re-search-forward-unprotected
 	    (concat "^\\(\\(?:\\*\\)\\{"
 		    (number-to-string (+ (if odd 4 2) level))
 		    "\\}\\) \\(.*\\)$")

+ 8 - 0
lisp/org-macs.el

@@ -123,6 +123,14 @@ We use a macro so that the test can happen at compilation time."
      ,@body))
 (put 'org-if-unprotected-at 'lisp-indent-function 1)
 
+(defun org-re-search-forward-unprotected (&rest args)
+  "Like re-search-forward, but stop only in unprotected places."
+  (catch 'exit
+    (while t
+      (unless (apply 're-search-forward args)
+	(throw 'exit nil))
+      (unless (get-text-property (match-beginning 0) 'org-protected)
+	(throw 'exit (point))))))
 
 (defmacro org-with-remote-undo (_buffer &rest _body)
   "Execute BODY while recording undo information in two buffers."