diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-01-25 22:47:24 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-01-25 22:55:53 +0100 |
commit | 9cf9f56ff624c7e3e9e5545b5d8ef15fd981d3fe (patch) | |
tree | 5eddfb0bf6f075b83f1e3f14b5f1fd8778ad067d | |
parent | 13424336a6f30c50952d291e7a82906c1210daf0 (diff) | |
download | org-mode-9cf9f56ff624c7e3e9e5545b5d8ef15fd981d3fe.tar.gz |
org-table: Fix `org-table-current-column' on hlines
* lisp/org-table.el (org-table-current-column): Return a meaningful
value also on hlines.
(org-table-toggle-column-width): Use `org-table-current-column'
instead of re-inventing wheel.
* testing/lisp/test-org-table.el (test-org-table/current-column): New
test.
-rw-r--r-- | lisp/org-table.el | 23 | ||||
-rw-r--r-- | testing/lisp/test-org-table.el | 15 |
2 files changed, 24 insertions, 14 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el index 0e035cb..a0a3295 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -1327,13 +1327,16 @@ value." ""))))) (defun org-table-current-column () - "Find out which column we are in." + "Return current column number." (interactive) (save-excursion - (let ((column 0) (pos (point))) + (let ((pos (point))) (beginning-of-line) - (while (search-forward "|" pos t) (cl-incf column)) - column))) + (if (not (search-forward "|" pos t)) 0 + (let ((column 1) + (separator (if (org-at-table-hline-p) "[+|]" "|"))) + (while (re-search-forward separator pos t) (cl-incf column)) + column))))) (defun org-table-current-dline () "Find out what table data line we are in. @@ -4040,8 +4043,7 @@ When called with `\\[universal-argument] \\[universal-argument]' \ prefix, expand all columns." (interactive "P") (unless (org-at-table-p) (user-error "Not in a table")) - (let* ((pos (point)) - (begin (org-table-begin)) + (let* ((begin (org-table-begin)) (end (org-table-end)) ;; Compute an upper bound for the number of columns. ;; Nonexistent columns are ignored anyway. @@ -4058,14 +4060,7 @@ prefix, expand all columns." (org-table--read-column-selection (read-string "Column ranges (e.g. 2-4 6-): ") max-columns) - ;; Find current column, even when on a hline. - (let ((separator (if (org-at-table-hline-p) "+" "|")) - (c 1)) - (save-excursion - (beginning-of-line) - (search-forward "|" pos t) - (while (search-forward separator pos t) (cl-incf c))) - (list c)))) + (list (org-table-current-column)))) ((pred stringp) (org-table--read-column-selection arg max-columns)) ((or `(4) `(16)) nil) (_ (user-error "Invalid argument: %S" arg))))) diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index 750290d..7c078d9 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -2588,6 +2588,21 @@ See also `test-org-table/copy-field'." ;;; Miscellaneous +(ert-deftest test-org-table/current-column () + "Test `org-table-current-column' specifications." + (should + (= 1 (org-test-with-temp-text "| <point>a |" + (org-table-current-column)))) + (should + (= 1 (org-test-with-temp-text "|-<point>--|" + (org-table-current-column)))) + (should + (= 2 (org-test-with-temp-text "| 1 | <point>2 |" + (org-table-current-column)))) + (should + (= 2 (org-test-with-temp-text "|---+-<point>--|" + (org-table-current-column))))) + (ert-deftest test-org-table/get-field () "Test `org-table-get-field' specifications." ;; Regular test. |