Browse Source

Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode

Carsten Dominik 15 years ago
parent
commit
d61e92fff3
3 changed files with 54 additions and 35 deletions
  1. 38 5
      contrib/babel/lisp/org-babel-exp.el
  2. 3 0
      contrib/lisp/org-babel-init.el
  3. 13 30
      lisp/org-exp-blocks.el

+ 38 - 5
contrib/babel/lisp/org-babel-exp.el

@@ -33,6 +33,7 @@
 (require 'org-exp-blocks)
 (org-export-blocks-add-block '(src org-babel-exp-src-blocks nil))
 (add-to-list 'org-export-interblocks '(src org-babel-exp-inline-src-blocks))
+(add-to-list 'org-export-interblocks '(lob org-babel-exp-lob-one-liners))
 
 (defun org-babel-exp-src-blocks (body &rest headers)
   "Process src block for export.  Depending on the 'export'
@@ -78,6 +79,30 @@ options and are taken from `org-babel-defualt-inline-header-args'."
                             (+ 6 (length (first info)) (length (second info))))))
         (replace-match replacement t t)))))
 
+(defun org-babel-exp-lob-one-liners (start end)
+  "Process #+lob (Library of Babel) calls between START and END for export.
+See `org-babel-exp-src-blocks' for export options. Currently the
+options are taken from `org-babel-default-header-args'."
+  (interactive)
+  (let (replacement)
+    (save-excursion
+      (goto-char start)
+      (while (and (< (point) end)
+		  (re-search-forward org-babel-lob-one-liner-regexp nil t))
+	(setq replacement
+	      (save-match-data
+		(org-babel-exp-do-export
+		 "emacs-lisp" "results"
+		 (org-babel-merge-params
+		  org-babel-default-header-args
+		  (org-babel-parse-header-arguments
+		   (org-babel-clean-text-properties
+		    (concat ":var results="
+			    (mapconcat #'identity (org-babel-lob-get-info) " ")))))
+		 'lob)))
+	(setq end (+ end (- (length replacement) (length (match-string 0)))))
+	(replace-match replacement t t)))))
+
 (defun org-babel-exp-do-export (lang body params type)
   (case (intern (or (cdr (assoc :exports params)) "code"))
     ('none "")
@@ -88,10 +113,13 @@ options and are taken from `org-babel-defualt-inline-header-args'."
                    (org-babel-exp-results body lang params type)))))
 
 (defun org-babel-exp-code (body lang params type)
-  (case type
-    ('inline (format "=%s=" body))
-    ('block (format "#+BEGIN_SRC %s\n%s%s\n#+END_SRC" lang body
-                    (if (string-match "\n$" body) "" "\n")))))
+    (case type
+      ('inline (format "=%s=" body))
+      ('block (format "#+BEGIN_SRC %s\n%s%s\n#+END_SRC" lang body
+		      (if (string-match "\n$" body) "" "\n")))
+      ('lob (save-excursion
+	      (re-search-backward org-babel-lob-one-liner-regexp)
+	      (format "#+BEGIN_SRC babel\n%s\n#+END_SRC" (first (org-babel-lob-get-info)))))))
 
 (defun org-babel-exp-results (body lang params type)
   (let ((params
@@ -122,7 +150,12 @@ options and are taken from `org-babel-defualt-inline-header-args'."
           (save-excursion ;; org-exp-blocks places us at the end of the block
             (re-search-backward org-babel-src-block-regexp nil t)
             (org-babel-execute-src-block
-             nil nil (org-babel-merge-params params '((:results . "replace")))) "")))))
+             nil nil (org-babel-merge-params params '((:results . "replace")))) ""))
+      ('lob
+          (save-excursion
+            (re-search-backward org-babel-lob-one-liner-regexp nil t)
+            (org-babel-execute-src-block
+             nil (list lang body (org-babel-merge-params params '((:results . "replace"))))) "")))))
 
 (provide 'org-babel-exp)
 ;;; org-babel-exp.el ends here

+ 3 - 0
contrib/lisp/org-babel-init.el

@@ -65,5 +65,8 @@
   (defun org-babel-load-library-of-babel ()
     (org-babel-lob-ingest (expand-file-name "library-of-babel.org" org-babel-lob-dir))))
 
+(unless (assoc "babel" org-src-lang-modes)
+  (add-to-list 'org-src-lang-modes (cons "babel" 'python)))
+
 (provide 'org-babel-init)
 ;;; org-babel-init.el ends here

+ 13 - 30
lisp/org-exp-blocks.el

@@ -60,11 +60,6 @@
 ;;            their own divs with author-specific ids allowing for css
 ;;            coloring of comments based on the author.
 ;;
-;; R :: Implements Sweave type exporting, evaluates blocks of R code,
-;;      and also replaces \R{} chunks in the file with their result
-;;      when passed to R.  This require the `R' command which is
-;;      provided by ESS (Emacs Speaks Statistics).
-;;
 ;;; Adding new blocks
 ;;
 ;; When adding a new block type first define a formatting function
@@ -76,17 +71,11 @@
   (require 'cl))
 (require 'org)
 
-(defvar comint-last-input-end)
-(defvar comint-prompt-regexp)
-(defvar comint-last-input-end)
 (defvar htmlp)
 (defvar latexp)
 (defvar docbookp)
 (defvar asciip)
 
-(declare-function comint-send-input "comint" (&optional no-newline artificial))
-(declare-function R "ext:ess" nil)
-
 (defun org-export-blocks-set (var value)
   "Set the value of `org-export-blocks' and install fontification."
   (set var value)
@@ -102,9 +91,7 @@
 (defcustom org-export-blocks
   '((comment org-export-blocks-format-comment t)
     (ditaa org-export-blocks-format-ditaa nil)
-    (dot org-export-blocks-format-dot nil)
-    (r org-export-blocks-format-R nil)
-    (R org-export-blocks-format-R nil))
+    (dot org-export-blocks-format-dot nil))
   "Use this a-list to associate block types with block exporting
 functions.  The type of a block is determined by the text
 immediately following the '#+BEGIN_' portion of the block header.
@@ -177,34 +164,30 @@ specified in BLOCKS which default to the value of
 `org-export-blocks-witheld'."
   (interactive)
   (save-window-excursion
-    (let ((count 0)
-	  (blocks org-export-blocks-witheld)
-	  (case-fold-search t)
+    (let ((case-fold-search t)
 	  (types '())
-	  indentation type func start end)
+	  indentation type func start)
       (flet ((interblock (start end)
-			 (save-match-data
-                           (mapcar (lambda (pair) (funcall (second pair) start end))
-                                   org-export-interblocks))))
+			 (mapcar (lambda (pair) (funcall (second pair) start end))
+				 org-export-interblocks)))
 	(goto-char (point-min))
-	(setf start (point))
+	(setq start (point))
 	(while (re-search-forward
 		"^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)[ \t]*\\(.*\\)?[\r\n]\\([^\000]*?\\)[\r\n][ \t]*#\\+end_\\S-+.*" nil t)
-          (save-match-data (setq indentation (length (match-string 1))))
-	  (save-match-data (setf type (intern (match-string 2))))
-	  (unless (memq type types) (setf types (cons type types)))
-	  (setf end (save-match-data (match-beginning 0)))
-	  (interblock start end)
-	  (if (setf func (cadr (assoc type org-export-blocks)))
+          (setq indentation (length (match-string 1)))
+	  (setq type (intern (match-string 2)))
+	  (unless (memq type types) (setq types (cons type types)))
+	  (save-match-data (interblock start (match-beginning 0)))
+	  (if (setq func (cadr (assoc type org-export-blocks)))
 	      (progn
                 (replace-match (save-match-data
-                                 (if (memq type blocks)
+                                 (if (memq type org-export-blocks-witheld)
                                      ""
                                    (apply func (save-match-data (org-remove-indentation (match-string 4)))
                                           (split-string (match-string 3) " ")))) t t)
                 ;; indent block
                 (indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))
-	  (setf start (save-match-data (match-end 0))))
+	  (setq start (match-end 0)))
 	(interblock start (point-max))))))
 
 (add-hook 'org-export-preprocess-hook 'org-export-blocks-preprocess)