1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-02 08:22:16 +00:00

org-capture: Fix row insertion in a table with a formula

* lisp/org-capture.el (org-capture-place-table-line): Insert new row
  above the formula, not below.
* testing/lisp/test-org-capture.el (test-org-capture/table-line): Add
  test.
This commit is contained in:
Nicolas Goaziou 2018-06-21 12:17:07 +02:00
parent c891b840d2
commit 547b431e70
2 changed files with 14 additions and 3 deletions

View File

@ -1220,10 +1220,11 @@ may have been stored before."
(while (re-search-forward org-table-dataline-regexp end t)
(pcase (org-element-lineage (org-element-at-point) '(table) t)
(`nil nil)
((and table
(guard (eq 'table.el (org-element-property :type table))))
nil)
(table
(goto-char (org-element-property :end table))
(skip-chars-backward " \r\t\n")
(forward-line)
(goto-char (org-element-property :contents-end table))
(narrow-to-region (org-element-property :post-affiliated table)
(point))
(throw :found t))))

View File

@ -233,6 +233,16 @@
:immediate-finish t))))
(org-capture nil "t"))
(buffer-string))))
;; Properly insert row with formulas.
(should
(equal "| 1 |\n| 2 |\n#+TBLFM: "
(org-test-with-temp-text-in-file "| 1 |\n#+TBLFM: "
(let* ((file (buffer-file-name))
(org-capture-templates
`(("t" "Table" table-line (file ,file)
"| 2 |" :immediate-finish t))))
(org-capture nil "t"))
(buffer-string))))
;; When `:prepend' is nil, add the row at the end of the table.
(should
(equal "| a |\n| x |\n"