diff --git a/doc/org-manual.org b/doc/org-manual.org index 4049a4e29..17b25fef4 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -5843,6 +5843,30 @@ either for all clocks or just for today. #+findex: org-columns-delete Delete the current column. +- {{{kbd(M-LEFT)}}} (~org-columns-move-left~) :: + + #+kindex: M-LEFT + #+findex: org-columns-move-left + Move the current column left. + +- {{{kbd(M-RIGHT)}}} (~org-columns-move-right~) :: + + #+kindex: M-RIGHT + #+findex: org-columns-move-right + Move the current column right. + +- {{{kbd(M-UP)}}} (~org-columns-move-row-up~) :: + + #+kindex: M-UP + #+findex: org-columns-move-row-up + Move the current row up. + +- {{{kbd(M-DOWN)}}} (~org-columns-move-row-down~) :: + + #+kindex: M-DOWN + #+findex: org-columns-move-row-down + Move the current row down. + *** Capturing column view :PROPERTIES: :DESCRIPTION: A dynamic block for column view. diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 11fdf2825..842d3fe4d 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -895,6 +895,11 @@ After: ** New features +*** Column view: new commands to move rows up & down +You can move rows up & down in column view with +~org-columns-move-row-up~ and ~org-columns-move-row-down~. +Keybindings are the same as ~org-move-subtree-up~ and ~org-move-subtree-down~ +=M-= and =M-=. *** Clock table can now produce quarterly reports =:step= clock table parameter can now be set to =quarter=. diff --git a/lisp/org-colview.el b/lisp/org-colview.el index 10eba15e6..6f0183ede 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -210,6 +210,8 @@ See `org-columns-summary-types' for details.") (org-defkey org-columns-map ">" #'org-columns-widen) (org-defkey org-columns-map [(meta right)] #'org-columns-move-right) (org-defkey org-columns-map [(meta left)] #'org-columns-move-left) +(org-defkey org-columns-map [(meta down)] #'org-columns-move-row-down) +(org-defkey org-columns-map [(meta up)] #'org-columns-move-row-up) (org-defkey org-columns-map [(shift meta right)] #'org-columns-new) (org-defkey org-columns-map [(shift meta left)] #'org-columns-delete) (dotimes (i 10) @@ -231,6 +233,8 @@ See `org-columns-summary-types' for details.") "--" ["Move column right" org-columns-move-right t] ["Move column left" org-columns-move-left t] + ["Move row up" org-columns-move-row-up t] + ["Move row down" org-columns-move-row-down t] ["Add column" org-columns-new t] ["Delete column" org-columns-delete t] "--" @@ -1021,6 +1025,27 @@ details." (org-columns-move-right) (backward-char 1))) +(defun org-columns--move-row (&optional up) + "Move the current table row down. +With non-nil optional argument UP, move it up." + (let ((inhibit-read-only t) + (col (current-column))) + (if up (org-move-subtree-up) + (org-move-subtree-down)) + (let ((org-columns-inhibit-recalculation t)) + (org-columns-redo) + (move-to-column col)))) + +(defun org-columns-move-row-down () + "Move the current table row down." + (interactive) + (org-columns--move-row)) + +(defun org-columns-move-row-up () + "Move the current table row up." + (interactive) + (org-columns--move-row 'up)) + (defun org-columns-store-format () "Store the text version of the current columns format. The format is stored either in the COLUMNS property of the node diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el index 8b537e5b5..37bc0a0b5 100644 --- a/testing/lisp/test-org-colview.el +++ b/testing/lisp/test-org-colview.el @@ -1093,6 +1093,71 @@ (list (get-char-property 1 'org-columns-value-modified) (get-char-property 2 'org-columns-value-modified)))))) +(ert-deftest test-org-colview/columns-move-row-down () + "Test `org-columns-move-row-down' specifications." + (should + (equal "* H +** B +** A +" + (org-test-with-temp-text "* H +** A +** B +" + (let ((org-columns-default-format "%ITEM")) (org-columns) + (next-line 1) + (org-columns-move-row-down) + (buffer-substring-no-properties (point-min) (point-max))))))) + +(ert-deftest test-org-colview/columns-move-row-up () + "Test `org-columns-move-row-up' specifications." + (should + (equal "* H +** B +** A +" + (org-test-with-temp-text "* H +** A +** B +" + (let ((org-columns-default-format "%ITEM")) (org-columns) + (next-line 2) + (org-columns-move-row-up) + (buffer-substring-no-properties (point-min) (point-max))))))) + +(ert-deftest test-org-colview/columns--move-row-stay-at-the-same-column () + "After function call 'org-columns--move-row' point should stay at the same column." + (should + (equal 35 + (org-test-with-temp-text "* H +** A +** B +" + (org-columns) + (next-line 1) + (forward-char 2) + (org-columns--move-row) + (current-column))))) + +(ert-deftest test-org-colview/columns-move-row-down-with-subheading () + "Test `org-columns-move-row-up' specifications with subheading." + (should + (equal "* H +** B +** A +*** A1 +" + + (org-test-with-temp-text "* H +** A +*** A1 +** B +" + (let ((org-columns-default-format "%ITEM")) (org-columns) + (next-line 1) + (org-columns-move-row-down) + (buffer-substring-no-properties (point-min) (point-max))))))) + (ert-deftest test-org-colview/columns-move-left () "Test `org-columns-move-left' specifications." ;; Error when trying to move the left-most column.