summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2010-07-12 10:42:59 -0700
committerEric Schulte <schulte.eric@gmail.com>2010-07-12 12:33:15 -0700
commite8033b7f04a09cdbb7b092be5a7ed1f62828694d (patch)
tree1910d391d7c741e890a37a005a0f0bdfc27345d7
parent1e502168543de178a1acd7caa541d5bffe8d6ae4 (diff)
downloadorg-mode-e8033b7f04a09cdbb7b092be5a7ed1f62828694d.tar.gz
org-exp: raise an error when trying to export code blocks w/o languages
* lisp/ob.el (org-babel-get-src-block-info): ensure that we don't match (and return info for) source blocks without a language * lisp/org-exp.el (org-export-replace-src-segments-and-examples): updated source code block regexp so that the presence of a language can be explicitly checked. Also now raising an error when a source block does not have a language.
-rw-r--r--lisp/ob.el3
-rw-r--r--lisp/org-exp.el30
2 files changed, 22 insertions, 11 deletions
diff --git a/lisp/ob.el b/lisp/ob.el
index ea85638..08b9fae 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -143,7 +143,8 @@ added to the header-arguments-alist."
(setq indent (car (last info)))
(setq info (butlast info))
(forward-line -1)
- (if (looking-at org-babel-src-name-w-name-regexp)
+ (if (and (looking-at org-babel-src-name-w-name-regexp)
+ (match-string 2))
(progn
(setq info (append info (list (org-babel-clean-text-properties
(match-string 2)))))
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index f1cea62..55b8812 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -2107,19 +2107,29 @@ in the list) and remove property and value from the list in LISTVAR."
lang code trans opts indent caption)
(goto-char (point-min))
(while (re-search-forward
- "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
+ "\\(^\\([ \t]*\\)#\\+BEGIN_SRC:?\\([ \t]+\\([^ \t\n]+\\)\\)?\\(.*\\)\n\\([^\000]+?\n\\)[ \t]*#\\+END_SRC.*\n?\\)\\|\\(^\\([ \t]*\\)#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)[ \t]*#\\+END_EXAMPLE.*\n?\\)"
nil t)
(if (match-end 1)
- ;; src segments
- (setq lang (match-string 3)
- opts (match-string 4)
- code (match-string 5)
- indent (length (match-string 2))
- caption (get-text-property 0 'org-caption (match-string 0)))
+ (if (not (match-string 4))
+ (error "source block missing language specification: %s"
+ (let* ((body (match-string 6))
+ (nothing (message "body:%s" body))
+ (preview (or (and (string-match
+ "^[ \t]*\\([^\n\r]*\\)" body)
+ (match-string 1 body)) body)))
+ (if (> (length preview) 35)
+ (concat (substring preview 0 32) "...")
+ preview)))
+ ;; src segments
+ (setq lang (match-string 4)
+ opts (match-string 5)
+ code (match-string 6)
+ indent (length (match-string 2))
+ caption (get-text-property 0 'org-caption (match-string 0))))
(setq lang nil
- opts (match-string 8)
- code (match-string 9)
- indent (length (match-string 7))
+ opts (match-string 9)
+ code (match-string 10)
+ indent (length (match-string 8))
caption (get-text-property 0 'org-caption (match-string 0))))
(setq trans (org-export-format-source-code-or-example