org-table: Fix bug with "$>" reference

* lisp/org-table.el (org-table-analyze): Fix incorrect replacement for
  "$>" reference when the table ends on a hline.
* testing/lisp/test-org-table.el (test-org-table/end-on-hline): New
  test.
This commit is contained in:
Nicolas Goaziou 2015-11-11 00:37:57 +01:00
parent 73a5c27cc1
commit 57029084b5
2 changed files with 39 additions and 15 deletions

View File

@ -2534,24 +2534,27 @@ This function sets up the following dynamically scoped variables:
(push 'hline types) ; Add an imaginary extra hline to the end.
(setq org-table-current-line-types (apply #'vector (nreverse types)))
(setq org-table-dlines (apply #'vector (cons nil (nreverse dlines))))
(setq org-table-hlines (apply #'vector (cons nil (nreverse hlines))))
(forward-line -1)
(let* ((last-dline (car dlines))
(fields (org-split-string
(buffer-substring (line-beginning-position)
(line-end-position))
"[ \t]*|[ \t]*"))
(nfields (length fields))
al al2)
(setq org-table-current-ncol nfields)
(setq org-table-hlines (apply #'vector (cons nil (nreverse hlines)))))
;; Get the number of columns from the first data line in table.
(goto-char beg)
(forward-line (aref org-table-dlines 0))
(let* ((fields
(org-split-string
(buffer-substring (line-beginning-position) (line-end-position))
"[ \t]*|[ \t]*"))
(nfields (length fields))
al al2)
(setq org-table-current-ncol nfields)
(let ((last-dline
(aref org-table-dlines (1- (length org-table-dlines)))))
(dotimes (i nfields)
(let ((column (1+ i)))
(push (list (format "LR%d" column) last-dline column) al)
(push (cons (format "LR%d" column) (nth i fields)) al2)))
(setq org-table-named-field-locations
(append org-table-named-field-locations al))
(setq org-table-local-parameters
(append org-table-local-parameters al2)))))))
(push (cons (format "LR%d" column) (nth i fields)) al2))))
(setq org-table-named-field-locations
(append org-table-named-field-locations al))
(setq org-table-local-parameters
(append org-table-local-parameters al2))))))
(defun org-table-goto-field (ref &optional create-column-p)
"Move point to a specific field in the current table.

View File

@ -1767,6 +1767,27 @@ is t, then new columns should be added as needed"
(org-table-calc-current-TBLFM)
(buffer-string)))))
(ert-deftest test-org-table/end-on-hline ()
"Test with a table ending on a hline."
(should
(equal
(org-test-with-temp-text
"
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| | | |
|---+---+---|
<point>#+TBLFM: @3$2..@3$>=vsum(@1..@2)"
(org-table-calc-current-TBLFM)
(buffer-string))
"
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| | 7 | 9 |
|---+---+---|
#+TBLFM: @3$2..@3$>=vsum(@1..@2)")))
(provide 'test-org-table)
;;; test-org-table.el ends here