소스 검색

org.el (org-at-TBLFM-p): Add functon

* org.el (org-at-TBLFM-p): New defun.
(org-TBLFM-regexp): New defconst.

* testing/lisp/test-org-table.el: Add test.
Ippei FURUHASHI 12 년 전
부모
커밋
a268e33ef0
2개의 변경된 파일31개의 추가작업 그리고 0개의 파일을 삭제
  1. 12 0
      lisp/org.el
  2. 19 0
      testing/lisp/test-org-table.el

+ 12 - 0
lisp/org.el

@@ -4222,6 +4222,9 @@ This works for both table types.")
   (org-autoload "org-table"
 		'(org-table-begin org-table-blank-field org-table-end)))
 
+(defconst org-TBLFM-regexp "^[ \t]*#\\+TBLFM: "
+  "Detect a #+TBLFM line.")
+
 ;;;###autoload
 (defun turn-on-orgtbl ()
   "Unconditionally turn on `orgtbl-mode'."
@@ -4316,6 +4319,15 @@ If TABLE-TYPE is non-nil, also check for table.el-type tables."
 (declare-function org-clock-update-mode-line "org-clock" ())
 (declare-function org-resolve-clocks "org-clock"
 		  (&optional also-non-dangling-p prompt last-valid))
+
+(defun org-at-TBLFM-p (&optional pos)
+  "Return t when point (or POS) is in #+TBLFM line."
+  (save-excursion
+    (let ((pos pos)))
+    (goto-char (or pos (point)))
+    (beginning-of-line 1)
+    (looking-at org-TBLFM-regexp)))
+
 (defvar org-clock-start-time)
 (defvar org-clock-marker (make-marker)
   "Marker recording the last clock-in.")

+ 19 - 0
testing/lisp/test-org-table.el

@@ -749,6 +749,25 @@ reference (with row).  Format specifier N."
 ;;   "Remote reference."
 ;;   (should
 ;;    (string= "$3 = remote(FOO, @@#$2)" (org-table-convert-refs-to-rc "C& = remote(FOO, @@#B&)"))))
+(ert-deftest test-org-table/org-at-TBLFM-p ()
+  (org-test-with-temp-text-in-file
+      "
+| 1 |
+| 2 |
+#+TBLFM: $2=$1*2
+
+"
+    (goto-char (point-min))
+    (forward-line 2)
+    (should (equal (org-at-TBLFM-p) nil))
+
+    (goto-char (point-min))
+    (forward-line 3)
+    (should (equal (org-at-TBLFM-p) t))
+
+    (goto-char (point-min))
+    (forward-line 4)
+    (should (equal (org-at-TBLFM-p) nil))))
 
 (provide 'test-org-table)