Browse Source

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

Carsten Dominik 14 years ago
parent
commit
2ec171cc77
3 changed files with 34 additions and 10 deletions
  1. 18 3
      lisp/ob-dot.el
  2. 4 6
      lisp/ob-ref.el
  3. 12 1
      lisp/org.el

+ 18 - 3
lisp/ob-dot.el

@@ -47,17 +47,32 @@
   "Default arguments to use when evaluating a dot source block.")
 
 (defun org-babel-expand-body:dot (body params &optional processed-params)
-  "Expand BODY according to PARAMS, return the expanded body." body)
+  "Expand BODY according to PARAMS, return the expanded body."
+  (let ((vars (nth 1 (or processed-params
+			 (org-babel-process-params params)))))
+    (mapc
+     (lambda (pair)
+       (let ((name (symbol-name (car pair)))
+	     (value (cdr pair)))
+	 (setq body
+	       (replace-regexp-in-string
+		(concat "\$" (regexp-quote name))
+		(if (stringp value) value (format "%S" value))
+		body))))
+     vars)
+    body))
 
 (defun org-babel-execute:dot (body params)
   "Execute a block of Dot code with org-babel.
 This function is called by `org-babel-execute-src-block'."
-  (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
+  (let ((processed-params (org-babel-process-params params))
+	(result-params (split-string (or (cdr (assoc :results params)) "")))
         (out-file (cdr (assoc :file params)))
         (cmdline (cdr (assoc :cmdline params)))
         (cmd (or (cdr (assoc :cmd params)) "dot"))
         (in-file (make-temp-file "org-babel-dot")))
-    (with-temp-file in-file (insert body))
+    (with-temp-file in-file
+      (insert (org-babel-expand-body:dot body params processed-params)))
     (org-babel-eval (concat cmd " " in-file " " cmdline " -o " out-file) "")
     out-file))
 

+ 4 - 6
lisp/ob-ref.el

@@ -41,7 +41,7 @@
 ;; same file would be
 
 ;;  #+TBLNAME: sandbox
-;;  | 1 |       2 | 3 |
+;;  | 1 |         2 | 3 |
 ;;  | 4 | org-babel | 6 |
 ;;
 ;;  #+begin_src emacs-lisp :var table=sandbox
@@ -55,6 +55,7 @@
 
 (declare-function org-remove-if-not "org" (predicate seq))
 (declare-function org-at-table-p "org" (&optional table-type))
+(declare-function org-count "org" (CL-ITEM CL-SEQ))
 
 (defun org-babel-ref-variables (params)
   "Convert PARAMS to variable names and values.
@@ -108,13 +109,10 @@ return nil."
     (let ((case-fold-search t)
           type args new-refere new-referent result lob-info split-file split-ref
           index index-row index-col)
-      ;; if ref is indexed grab the indices -- beware nested indicies
+      ;; if ref is indexed grab the indices -- beware nested indices
       (when (and (string-match "\\[\\(.+\\)\\]" ref)
 		 (let ((str (substring ref 0 (match-beginning 0))))
-		   (= (length (org-remove-if-not
-			       (lambda (el) (equal ?( el)) (string-to-list "((eric))")))
-		      (length (org-remove-if-not
-			       (lambda (el) (equal ?) el)) (string-to-list "((eric))"))))))
+		   (= (org-count ?( str) (org-count ?) str))))
         (setq index (match-string 1 ref))
         (setq ref (substring ref 0 (match-beginning 0))))
       ;; assign any arguments to pass to source block

+ 12 - 1
lisp/org.el

@@ -17704,7 +17704,7 @@ Your bug report will be posted to the Org-mode mailing list.
 With prefix arg UNCOMPILED, load the uncompiled versions."
   (interactive "P")
   (require 'find-func)
-  (let* ((file-re "^\\(org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
+  (let* ((file-re "^\\(ob\\|org\\|orgtbl\\)\\(\\.el\\|-.*\\.el\\)")
 	 (dir-org (file-name-directory (org-find-library-name "org")))
 	 (dir-org-contrib (ignore-errors
 			   (file-name-directory
@@ -18225,6 +18225,17 @@ for the search purpose."
     (setq list (delete (pop elts) list)))
   list)
 
+(defun org-count (cl-item cl-seq)
+  "Count the number of occurrences of ITEM in SEQ.
+Taken from `count' in cl-seq.el with all keyword arguments removed."
+  (let ((cl-end (length cl-seq)) (cl-start 0) (cl-count 0)  cl-x)
+    (when (consp cl-seq) (setq cl-seq (nthcdr cl-start cl-seq)))
+    (while (< cl-start cl-end)
+      (setq cl-x (if (consp cl-seq) (pop cl-seq) (aref cl-seq cl-start)))
+      (if (equal cl-item cl-x) (setq cl-count (1+ cl-count)))
+      (setq cl-start (1+ cl-start)))
+    cl-count))
+
 (defun org-remove-if (predicate seq)
   "Remove everything from SEQ that fulfills PREDICATE."
   (let (res e)