From 37369815b555ba1f2df168ac45c83237c628d609 Mon Sep 17 00:00:00 2001 From: Ippei FURUHASHI Date: Tue, 2 Apr 2013 18:09:26 +0900 Subject: [PATCH 2/4] org-table.el (org-TBLFM-begin): Add function * org-table.el (org-TBLFM-begin): Add function. * testing/lisp/test-org-table.el: Add test. --- lisp/org-table.el | 14 +++++ testing/lisp/test-org-table.el | 123 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 0 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index f087cf7..78fbb2e 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -52,6 +52,8 @@ (defvar orgtbl-after-send-table-hook nil to the receiver position, otherwise, if table is not sent, the functions are not run.") +(defvar org-TBLFM-begin-regexp "|\n[ \t]*#\\+TBLFM: ") + (defcustom orgtbl-optimized (eq org-enable-table-editor 'optimized) "Non-nil means use the optimized table editor version for `orgtbl-mode'. In the optimized version, the table editor takes over all simple keys that @@ -3169,6 +3171,18 @@ (defun org-table-iterate-buffer-tables () (setq checksum c1))) (user-error "No convergence after %d iterations" imax)))))) +(defun org-TBLFM-begin () + "Find the beginning of the TBLFM lines and return its position. +Return nil when the beginning of TBLFM line was not found." + (save-excursion + (if (progn (forward-line 1) + (re-search-backward + org-TBLFM-begin-regexp + nil t)) + (progn (beginning-of-line 2) + (point)) + nil))) + (defun org-table-expand-lhs-ranges (equations) "Expand list of formulas. If some of the RHS in the formulas are ranges or a row reference, expand diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index ea8c4d8..805f57a 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -769,6 +769,129 @@ (defconst references/target-special " (forward-line 4) (should (equal (org-at-TBLFM-p) nil)))) +(ert-deftest test-org-table/org-TBLFM-begin () + (org-test-with-temp-text-in-file + " +| 1 | +| 2 | +#+TBLFM: $2=$1*2 + +" + (goto-char (point-min)) + (should (equal (org-TBLFM-begin) + nil)) + + (goto-char (point-min)) + (forward-line 1) + (should (equal (org-TBLFM-begin) + nil)) + + (goto-char (point-min)) + (forward-line 3) + (should (= (org-TBLFM-begin) + 14)) + + (goto-char (point-min)) + (forward-line 4) + (should (= (org-TBLFM-begin) + 14)) + + )) + +(ert-deftest test-org-table/org-TBLFM-begin-for-multiple-TBLFM-lines () + "For multiple #+TBLFM lines." + (org-test-with-temp-text-in-file + " +| 1 | +| 2 | +#+TBLFM: $2=$1*1 +#+TBLFM: $2=$1*2 + +" + (goto-char (point-min)) + (should (equal (org-TBLFM-begin) + nil)) + + (goto-char (point-min)) + (forward-line 1) + (should (equal (org-TBLFM-begin) + nil)) + + (goto-char (point-min)) + (forward-line 3) + (should (= (org-TBLFM-begin) + 14)) + + (goto-char (point-min)) + (forward-line 4) + (should (= (org-TBLFM-begin) + 14)) + + (goto-char (point-min)) + (forward-line 5) + (should (= (org-TBLFM-begin) + 14)) + + )) + +(ert-deftest test-org-table/org-TBLFM-begin-for-pultiple-TBLFM-lines-blocks () + (org-test-with-temp-text-in-file + " +| 1 | +| 2 | +#+TBLFM: $2=$1*1 +#+TBLFM: $2=$1*2 + +| 6 | +| 7 | +#+TBLFM: $2=$1*1 +#+TBLFM: $2=$1*2 + +" + (goto-char (point-min)) + (should (equal (org-TBLFM-begin) + nil)) + + (goto-char (point-min)) + (forward-line 1) + (should (equal (org-TBLFM-begin) + nil)) + + (goto-char (point-min)) + (forward-line 3) + (should (= (org-TBLFM-begin) + 14)) + + (goto-char (point-min)) + (forward-line 4) + (should (= (org-TBLFM-begin) + 14)) + + (goto-char (point-min)) + (forward-line 5) + (should (= (org-TBLFM-begin) + 14)) + + (goto-char (point-min)) + (forward-line 6) + (should (= (org-TBLFM-begin) + 14)) + + (goto-char (point-min)) + (forward-line 8) + (should (= (org-TBLFM-begin) + 61)) + + (goto-char (point-min)) + (forward-line 9) + (should (= (org-TBLFM-begin) + 61)) + + (goto-char (point-min)) + (forward-line 10) + (should (= (org-TBLFM-begin) + 61)))) + (provide 'test-org-table) ;;; test-org-table.el ends here -- 1.7.9.msysgit.0