Browse Source

Merge branch 'master' of orgmode.org:org-mode

Bastien Guerry 11 years ago
parent
commit
a30567a114
4 changed files with 54 additions and 27 deletions
  1. 20 13
      doc/org.texi
  2. 6 2
      lisp/ob-core.el
  3. 12 1
      lisp/ob-ref.el
  4. 16 11
      testing/lisp/test-org-table.el

+ 20 - 13
doc/org.texi

@@ -2547,21 +2547,28 @@ for Calc}.
 @cindex row, of field coordinates
 @cindex column, of field coordinates
 
-For Calc formulas and Lisp formulas @code{@@#} and @code{$#} can be used to
-get the row or column number of the field where the formula result goes.
-The traditional Lisp formula equivalents are @code{org-table-current-dline}
-and @code{org-table-current-column}.  Examples:
+One of the very first actions during evaluation of Calc formulas and Lisp
+formulas is to substitute @code{@@#} and @code{$#} in the formula with the
+row or column number of the field where the current result will go to.  The
+traditional Lisp formula equivalents are @code{org-table-current-dline} and
+@code{org-table-current-column}.  Examples:
 
-@example
-if(@@# % 2, $#, string(""))   @r{column number on odd lines only}
-$3 = remote(FOO, @@@@#$2)      @r{copy column 2 from table FOO into}
-                             @r{column 3 of the current table}
-@end example
+@table @code
+@item if(@@# % 2, $#, string(""))
+Insert column number on odd rows, set field to empty on even rows.
+@item $2 = '(identity remote(FOO, @@@@#$1))
+Copy text or values of each row of column 1 of the table named @code{FOO}
+into column 2 of the current table.
+@item @@3 = 2 * remote(FOO, @@1$$#)
+Insert the doubled value of each column of row 1 of the table named
+@code{FOO} into row 3 of the current table.
+@end table
 
-@noindent For the second example, table FOO must have at least as many rows
-as the current table.  Note that this is inefficient@footnote{The computation time scales as
-O(N^2) because table FOO is parsed for each field to be copied.} for large
-number of rows.
+@noindent For the second/third example, the table named @code{FOO} must have
+at least as many rows/columns as the current table.  Note that this is
+inefficient@footnote{The computation time scales as O(N^2) because the table
+named @code{FOO} is parsed for each field to be read.} for large number of
+rows/columns.
 
 @subsubheading Named references
 @cindex named references

+ 6 - 2
lisp/ob-core.el

@@ -530,7 +530,8 @@ For the format of SAFE-LIST, see `org-babel-safe-header-args'."
      (org-babel-header-args-safe-fn org-babel-safe-header-args))
 
 (defvar org-babel-default-inline-header-args
-  '((:session . "none") (:results . "replace") (:exports . "results"))
+  '((:session . "none") (:results . "replace")
+    (:exports . "results") (:hlines . "yes"))
   "Default arguments to use when evaluating an inline source block.")
 (put 'org-babel-default-inline-header-args 'safe-local-variable
      (org-babel-header-args-safe-fn org-babel-safe-header-args))
@@ -1928,7 +1929,10 @@ following the source block."
 			    (cond
 			     ((looking-at (concat org-babel-result-regexp "\n"))
 			      (throw 'non-comment t))
-			     ((looking-at "^[ \t]*#") (end-of-line 1))
+			     ((and (looking-at "^[ \t]*#")
+				   (not (looking-at
+					 org-babel-lob-one-liner-regexp)))
+			      (end-of-line 1))
 			     (t (throw 'non-comment nil))))))
 		      (let ((this-hash (match-string 5)))
 			(prog1 (point)

+ 12 - 1
lisp/ob-ref.el

@@ -85,7 +85,9 @@ the variable."
       (cons (intern var)
 	    (let ((out (save-excursion
 			 (when org-babel-current-src-block-location
-			   (goto-char org-babel-current-src-block-location))
+			   (goto-char (if (markerp org-babel-current-src-block-location)
+					  (marker-position org-babel-current-src-block-location)
+					org-babel-current-src-block-location)))
 			 (org-babel-read ref))))
 	      (if (equal out ref)
 		  (if (string-match "^\".*\"$" ref)
@@ -184,6 +186,11 @@ the variable."
 		   (or (looking-at org-babel-src-block-regexp)
 		       (looking-at org-babel-multi-line-header-regexp))))
 	    (setq type 'source-block))
+	   ((and (looking-at org-babel-src-name-regexp)
+		 (save-excursion
+		   (forward-line 1)
+		   (looking-at org-babel-lob-one-liner-regexp)))
+	    (setq type 'call-line))
 	   (t (while (not (setq type (org-babel-ref-at-ref-p)))
 		(forward-line 1)
 		(beginning-of-line)
@@ -199,6 +206,10 @@ the variable."
 		    (source-block (org-babel-execute-src-block
 				   nil nil (if org-babel-update-intermediate
 					       nil params)))
+		    (call-line (save-excursion
+				 (forward-line 1)
+				 (org-babel-lob-execute
+				  (org-babel-lob-get-info))))
 		    (lob          (org-babel-execute-src-block
 				   nil lob-info params))
 		    (id           (org-babel-ref-headline-body)))))

+ 16 - 11
testing/lisp/test-org-table.el

@@ -20,10 +20,9 @@
 
 ;;;; Comments:
 
-;; Template test file for Org-mode tests.  First the tests that are
-;; also a howto example collection as a user documentation, more or
-;; less all those using `org-test-table-target-expect'.  Then the
-;; internal and more abstract tests.  See also the doc string of
+;; Template test file for Org-mode tests.  Many tests are also a howto
+;; example collection as a user documentation, more or less all those
+;; using `org-test-table-target-expect'.  See also the doc string of
 ;; `org-test-table-target-expect'.
 
 ;;; Code:
@@ -553,7 +552,8 @@ reference (with row).  Mode string N."
 ))
 
 (ert-deftest test-org-table/copy-field ()
-  "Experiments on how to copy one field into another field."
+  "Experiments on how to copy one field into another field.
+See also `test-org-table/remote-reference-access'."
   (let ((target
 	 "
 | 0                | replace |
@@ -772,21 +772,26 @@ reference (with row).  Mode string N."
 ;;    (string= "$3 = remote(FOO, @@#$2)" (org-table-convert-refs-to-rc "C& = remote(FOO, @@#B&)"))))
 
 (ert-deftest test-org-table/remote-reference-access ()
-  "Access to remote reference."
+  "Access to remote reference.
+See also `test-org-table/copy-field'."
   (org-test-table-target-expect
    "
 #+NAME: table
-|   | 42 |
+|   | x   42 |   |
 
-| replace |   |
+| replace | replace |
 "
    "
 #+NAME: table
-|   | 42 |
+|   | x   42 |   |
 
-| 42 |   |
+| x   42 | 84 x |
 "
-   1 "#+TBLFM: $1 = remote(table, @1$2)"))
+   1 (concat "#+TBLFM: "
+	     ;; Copy text without calculation: Use Lisp formula
+	     "$1 = '(identity remote(table, @1$2)) :: "
+	     ;; Do a calculation: Use Calc (or Lisp ) formula
+	     "$2 = 2 * remote(table, @1$2)")))
 
 (ert-deftest test-org-table/org-at-TBLFM-p ()
   (org-test-with-temp-text-in-file