diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2016-02-21 14:59:52 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2016-02-21 14:59:52 +0100 |
commit | b386089ee6c7e43e63786632a398e7b7ab4079de (patch) | |
tree | f7ab07d9c0b20ccd7cf6d80c60983f3d4528b9e3 | |
parent | cd5eb50fd1c2a68734da173ae65ffc85b26cd9b0 (diff) | |
download | org-mode-b386089ee6c7e43e63786632a398e7b7ab4079de.tar.gz |
org-colview: Fix `org-columns-new'
* lisp/org-colview.el (org-columns-new): Fix location of inserted
column. Properly handle non-interactive cases.
* testing/lisp/test-org-colview.el (test-org-colview/columns-new): New
test.
-rw-r--r-- | lisp/org-colview.el | 44 | ||||
-rw-r--r-- | testing/lisp/test-org-colview.el | 36 |
2 files changed, 58 insertions, 22 deletions
diff --git a/lisp/org-colview.el b/lisp/org-colview.el index 6618ab9..17e5e0b 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -807,42 +807,42 @@ When COLUMNS-FMT-STRING is non-nil, use it as the column format." (goto-char (car entry)) (org-columns--display-here (cdr entry))))))))) -(defun org-columns-new (&optional prop title width operator _f _p summarize) +(defun org-columns-new (&optional prop title width operator &rest _) "Insert a new column, to the left of the current column." (interactive) - (let* ((prop (or prop (completing-read + (let* ((automatic (org-string-nw-p prop)) + (prop (or prop (completing-read "Property: " (mapcar #'list (org-buffer-property-keys t nil t))))) - (title (or title - (read-string (format "Column title [%s]: " prop) prop))) + (title (if automatic title + (read-string (format "Column title [%s]: " prop) prop))) (width ;; WIDTH may be nil, but if PROP is provided, assume this is ;; the expected width. - (if prop width + (if automatic width ;; Use `read-string' instead of `read-number' to allow ;; empty width. (let ((w (read-string "Column width: "))) (and (org-string-nw-p w) (string-to-number w))))) (operator - (or operator - (org-string-nw-p - (completing-read - "Summary: " - (delete-dups - (mapcar (lambda (x) (list (car x))) - (append org-columns-summary-types - org-columns-summary-types-default))) - nil t)))) - (summarize (or summarize (org-columns--summarize operator))) + (if automatic operator + (org-string-nw-p + (completing-read + "Summary: " + (delete-dups + (mapcar (lambda (x) (list (car x))) + (append org-columns-summary-types + org-columns-summary-types-default))) + nil t)))) + (summarize (and prop operator (org-columns--summarize operator))) (edit (and prop (assoc-string prop org-columns-current-fmt-compiled t)))) - (if edit - (progn - (setcar edit prop) - (setcdr edit (list title width nil operator nil summarize))) - (let ((cell (nthcdr (1- (current-column)) - org-columns-current-fmt-compiled))) - (push (list prop title width nil operator nil summarize) (cdr cell)))) + (cond (edit (setcdr edit (list title width operator nil summarize))) + ((= (current-column) 0) + (push (list prop title width operator nil summarize) + org-columns-current-fmt-compiled)) + (t (push (list prop title width operator nil summarize) + (nthcdr (current-column) org-columns-current-fmt-compiled)))) (org-columns-store-format) (org-columns-redo))) diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el index e00d6b9..034fa49 100644 --- a/testing/lisp/test-org-colview.el +++ b/testing/lisp/test-org-colview.el @@ -523,6 +523,42 @@ (org-columns-default-format "%A{custom}")) (org-columns)) (get-char-property (point) 'org-columns-value-modified))))) +(ert-deftest test-org-colview/columns-new () + "Test `org-columns-new' specifications." + ;; Insert new column at the left of the current one. + (should + (equal '("FOO" "ITEM") + (org-test-with-temp-text "* H" + (let ((org-columns-default-format "%ITEM")) (org-columns)) + (org-columns-new "FOO") + (list (get-char-property (point) 'org-columns-key) + (get-char-property (1+ (point)) 'org-columns-key))))) + (should + (equal '("ITEM" "FOO" "ITEM") + (org-test-with-temp-text "* H" + (let ((org-columns-default-format "%ITEM %BAR")) (org-columns)) + (forward-char) + (org-columns-new "FOO") + (list (get-char-property (1- (point)) 'org-columns-key) + (get-char-property (point) 'org-columns-key) + (get-char-property (1+ (point)) 'org-columns-key))))) + ;; Update #+COLUMNS: keyword if needed. + (should + (equal "#+COLUMNS: %FOO %ITEM" + (org-test-with-temp-text "#+COLUMNS: %ITEM\n<point>* H" + (let ((org-columns-default-format "%ITEM")) (org-columns)) + (org-columns-new "FOO") + (goto-char (point-min)) + (buffer-substring-no-properties (point) (line-end-position))))) + (should + (equal "#+COLUMNS: %ITEM %FOO %BAR" + (org-test-with-temp-text "#+COLUMNS: %ITEM %BAR\n<point>* H" + (let ((org-columns-default-format "%ITEM %BAR")) (org-columns)) + (forward-char) + (org-columns-new "FOO") + (goto-char (point-min)) + (buffer-substring-no-properties (point) (line-end-position)))))) + (ert-deftest test-org-colview/columns-update () "Test `org-columns-update' specifications." ;; Update display. |