Browse Source

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

Carsten Dominik 14 years ago
parent
commit
6c2584c968

+ 46 - 2
contrib/babel/library-of-babel.org

@@ -96,9 +96,53 @@ plot(data)
 
 ** Gnuplot
 
-* Table/Matrix manipulation
+* Tables
+** LaTeX Table export
+This block can be used to wrap a table in the latex =longtable=
+environment, it takes the following arguments -- all but the first two
+are optional.
+| arg       | description                                                 |
+|-----------+-------------------------------------------------------------|
+| table     | a reference to the table                                    |
+| align     | optional alignment string                                   |
+| width     | optional width specification string                         |
+| hline     | the string to use as hline separator, defaults to "\\hline" |
+| head      | optional "head" string                                      |
+| firsthead | optional "firsthead" string                                 |
+| foot      | optional "foot" string                                      |
+| lastfoot  | optional "lastfoot" string                                  |
+
+#+srcname: longtable
+#+begin_src emacs-lisp :var table='((:table)) :var env="table" :var align='() :var width='() :var hline="\\hline" :var firsthead='() :var head='() :var foot='() :var lastfoot='() :noweb yes :results latex
+  (org-fill-template
+   "
+  \\begin{longtable}%width%align
+  %firsthead
+  %head
+  %foot
+  %lastfoot
+  
+  %table
+  \\end{longtable}\n"
+   (list
+    (cons "width"     (if width (format "{%s}" width) ""))
+    (cons "align"     (if align (format "{%s}" align) ""))
+    (cons "firsthead" (if firsthead (concat firsthead "\n\\endfirsthead\n") ""))
+    (cons "head"      (if head (concat head "\n\\endhead\n") ""))
+    (cons "foot"      (if foot (concat foot "\n\\endfoot\n") ""))
+    (cons "lastfoot"  (if lastfoot (concat lastfoot "\n\\endlastfoot\n") ""))
+    (cons "table" (orgtbl-to-generic
+                   (mapcar (lambda (lis)
+                             (if (listp lis)
+                                 (mapcar (lambda (el)
+                                           (if (stringp el)
+                                               el
+                                             (format "%S" el))) lis)
+                               lis)) table)
+                   (list :lend " \\\\" :sep " & " :hline hline)))))
+#+end_src
 
-Elegant lisp code for transposing a matrix.
+** Elegant lisp for transposing a matrix.
 
 #+tblname: transpose-example
 | 1 | 2 | 3 |

+ 30 - 20
lisp/babel/langs/ob-haskell.el

@@ -54,10 +54,12 @@
 
 (defun org-babel-expand-body:haskell (body params &optional processed-params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let (vars (nth 1 (or processed-params (org-babel-process-params params))))
+  (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
     (concat
      (mapconcat
-      (lambda (pair) (format "let %s = %s;" (car pair) (cdr pair)))
+      (lambda (pair) (format "let %s = %s"
+			(car pair)
+			(org-babel-haskell-var-to-haskell (cdr pair))))
       vars "\n") "\n" body "\n")))
 
 (defun org-babel-execute:haskell (body params)
@@ -68,7 +70,7 @@
          (vars (nth 1 processed-params))
          (result-type (nth 3 processed-params))
          (full-body (org-babel-expand-body:haskell body params processed-params))
-         (session (org-babel-prep-session:haskell session params))
+         (session (org-babel-haskell-initiate-session session params))
          (raw (org-babel-comint-with-output
 		  (session org-babel-haskell-eoe t full-body)
                 (insert (org-babel-trim full-body))
@@ -96,34 +98,35 @@
   "If there is not a current inferior-process-buffer in SESSION
 then create one.  Return the initialized session."
   ;; TODO: make it possible to have multiple sessions
-  (run-haskell) (current-buffer))
+  (or (get-buffer "*haskell*")
+      (save-window-excursion (run-haskell) (sleep-for 0.25) (current-buffer))))
 
-(defun org-babel-load-session:haskell (session body params)
+(defun org-babel-load-session:haskell
+  (session body params &optional processed-params)
   "Load BODY into SESSION."
   (save-window-excursion
-    (let* ((buffer (org-babel-prep-session:haskell session params))
+    (let* ((buffer (org-babel-prep-session:haskell
+		    session params processed-params))
            (load-file (concat (make-temp-file "org-babel-haskell-load") ".hs")))
       (with-temp-buffer
         (insert body) (write-file load-file)
         (haskell-mode) (inferior-haskell-load-file))
       buffer)))
 
-(defun org-babel-prep-session:haskell (session params)
+(defun org-babel-prep-session:haskell
+  (session params &optional processesed-params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
   (save-window-excursion
-    (org-babel-haskell-initiate-session session)
-    (let* ((vars (org-babel-ref-variables params))
-           (var-lines (mapconcat ;; define any variables
-                       (lambda (pair)
-                         (format "%s=%s"
-                                 (car pair)
-                                 (org-babel-ruby-var-to-ruby (cdr pair))))
-                       vars "\n"))
-           (vars-file (concat (make-temp-file "org-babel-haskell-vars") ".hs")))
-      (when vars
-        (with-temp-buffer
-          (insert var-lines) (write-file vars-file)
-          (haskell-mode) (inferior-haskell-load-file)))
+    (let ((pp (or processed-params (org-babel-process-params params)))
+	  (buffer (org-babel-haskell-initiate-session session)))
+      (org-babel-comint-in-buffer buffer
+      	(mapcar
+      	 (lambda (pair)
+      	   (insert (format "let %s = %s"
+      			   (car pair)
+      			   (org-babel-haskell-var-to-haskell (cdr pair))))
+      	   (comint-send-input nil t))
+      	 (nth 1 pp)))
       (current-buffer))))
 
 (defun org-babel-haskell-table-or-string (results)
@@ -140,6 +143,13 @@ Emacs-lisp table, otherwise return the results as a string."
                                                 "'" "\"" results))))))
      results)))
 
+(defun org-babel-haskell-var-to-haskell (var)
+  "Convert an elisp var into a string of haskell source code
+specifying a var of the same value."
+  (if (listp var)
+      (concat "[" (mapconcat #'org-babel-haskell-var-to-haskell var ", ") "]")
+    (format "%S" var)))
+
 (defun org-babel-haskell-export-to-lhs (&optional arg)
   "Export to a .lhs file with all haskell code blocks escaped
 appropriately.  When called with a prefix argument the resulting

+ 7 - 5
lisp/babel/langs/ob-python.el

@@ -101,7 +101,11 @@ specifying a var of the same value."
 (defun org-babel-python-table-or-string (results)
   "If the results look like a list or tuple, then convert them into an
 Emacs-lisp table, otherwise return the results as a string."
-  (org-babel-read
+  ((lambda (res)
+     (if (listp res)
+	 (mapcar (lambda (el) (if (equal el 'None) 'hline el)) res)
+       res))
+   (org-babel-read
    (if (or (string-match "^\\[.+\\]$" results)
 	   (string-match "^(.+)$" results))
        (org-babel-read
@@ -110,10 +114,8 @@ Emacs-lisp table, otherwise return the results as a string."
                  "\\[" "(" (replace-regexp-in-string
                             "\\]" ")" (replace-regexp-in-string
                                        ", " " " (replace-regexp-in-string
-                                                 "'" "\""
-						 (replace-regexp-in-string
-						  "None" "hline" results t)))))))
-     results)))
+                                                 "'" "\"" results t))))))
+     results))))
 
 (defvar org-babel-python-buffers '(:default . nil))
 

+ 1 - 3
lisp/babel/ob.el

@@ -30,9 +30,7 @@
 
 ;;; Code:
 (eval-when-compile (require 'cl))
-(eval-and-compile
-  (unless (fboundp 'declare-function)
-    (defmacro declare-function (fn file &optional arglist fileonly))))
+(require 'org-macs)
 
 (defvar org-babel-call-process-region-original)
 (declare-function show-all "outline" ())

+ 11 - 8
lisp/org-exp.el

@@ -1644,14 +1644,17 @@ When it is nil, all comments will be removed."
     (while (or (looking-at re)
 	       (re-search-forward re nil t))
       (setq pos (match-beginning 0))
-      (if (and commentsp
-	       (not (equal (char-before (match-end 1)) ?+)))
-	  (progn (add-text-properties
-		  (match-beginning 0) (match-end 0) '(org-protected t))
-		 (replace-match (format commentsp (match-string 2)) t t))
-	(goto-char (1+ pos))
-	(replace-match "")
-	(goto-char (max (point-min) (1- pos)))))))
+      (if (get-text-property (point) 'org-protected)
+	  (goto-char (1+ pos))
+	(if (and commentsp
+		 (not (equal (char-before (match-end 1)) ?+)))
+	    (progn (add-text-properties
+		    (match-beginning 0) (match-end 0) '(org-protected t))
+		   (replace-match (format commentsp (match-string 2)) t t))
+	  (goto-char (1+ pos))
+	  (replace-match "")
+	  (goto-char (max (point-min) (1- pos))))))))
+
 
 (defun org-export-mark-radio-links ()
   "Find all matches for radio targets and turn them into internal links."

+ 14 - 14
lisp/org-latex.el

@@ -1537,20 +1537,20 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
   "When OPT is non-nil convert fixed-width sections to LaTeX."
   (goto-char (point-min))
   (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
-    (if opt
-	(progn (goto-char (match-beginning 0))
-	       (insert "\\begin{verbatim}\n")
-	       (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
-		 (replace-match (concat (match-string 1)
-					(match-string 2)) t t)
-		 (forward-line))
-	       (insert "\\end{verbatim}\n\n"))
-      (progn (goto-char (match-beginning 0))
-	     (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
-	       (replace-match (concat "%" (match-string 1)
-				      (match-string 2)) t t)
-	       (forward-line))))))
-
+    (unless (get-text-property (point) 'org-example)
+     (if opt
+	 (progn (goto-char (match-beginning 0))
+		(insert "\\begin{verbatim}\n")
+		(while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
+		  (replace-match (concat (match-string 1)
+					 (match-string 2)) t t)
+		  (forward-line))
+		(insert "\\end{verbatim}\n\n"))
+       (progn (goto-char (match-beginning 0))
+	      (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
+		(replace-match (concat "%" (match-string 1)
+				       (match-string 2)) t t)
+		(forward-line)))))))
 
 (defvar org-table-last-alignment) ; defined in org-table.el
 (defvar org-table-last-column-widths) ; defined in org-table.el