emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [RFC] [feat] org-colview/org-columns: 'column view' moving rows up/down
@ 2023-04-06 10:11 Sławomir Grochowski
  2023-04-07 11:04 ` Ihor Radchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Sławomir Grochowski @ 2023-04-06 10:11 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2765 bytes --]

Dear All,

This is my first proposal & code submit. 
I will be very gratefull for you comments & feedback what can be done better.  

Recently I often use 'column view' feature. 
To my suprise in 'column view' user can't move rows up & down.
So I wrote a little code snippet to be able to do it, and I'm sharing it with you.

Questions:
1. Why user can't move rows up & down in 'column view'?
2. Is this was intentional design decision?

I think 'column view' is missing one the core feel & functionality of org-mode - moving rows (headings) up & down.
In my experiance with 'column view' & tables I shuffle a lot of columns & rows order.

In my point of view 'core fuctionalities of org-mode' are: 
1. moving 'things' headings, rows, columns
   1. horizontally (left-right)
   2. vertically (up-down)
2. cyclic visibility

Let's compare this functionality in 3 areas:  

|                   | heading | table | column view |
|-------------------+---------+-------+-------------|
| moving left-right | [X]     | [X]   | [X]         |
| moving up-down    | [X]     | [X]   | [ ]         |
| cyclic visibility | [X]     | NA    | [X]         |

Cyclic visibility does not apply to 'table' because it operate on simple data, which is not structured, nested.

'Column view' transform 'headings' into rows, and their properties into columns, creating a table.

'Column view' is a combination of 'table' & 'heading':
'Heading' gives a 'table' properties for columns and cyclic visibilty feature, because it provide nested structure.
'Table' gives a 'heading' a 'column view' on heading properties.

'Column view' is similar to 'table'. They operate on same actions & keybindings.

|                             | column view      | table            |
|-----------------------------+------------------+------------------|
| move column left-right      | [X]              | [X]              |
| move column left-right keys | meta left-right  | meta left-right  |
| move row up-down            | [ ]              | [X]              |
| move row up-down keys       |                  | meta up-down     |
| add column                  | [X]              | [X]              |
| add column keys             | shift-meta right | shift-meta right |
| remove column               | [X]              | [X]              |
| remove column keys          | shift-meta left  | shift-meta left  |

I thnik it would be beneficial to have consistance interface in 'column view' and 'table'.

Based on that, I propose to add functionality to 'move row up/down' in 'column view' and set keybinding the same as in table above -> meta up/down.
Patch is in the attachment.

What others think about it? 

Regards,
Sławomir Grochowski

[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 4416 bytes --]

From 1f0f2052b8dddf4982ab35267ed1564f2250784b Mon Sep 17 00:00:00 2001
From: Sławomir Grochowski <slawomir.grochowski@gmail.com>
Date: Mon, 3 Apr 2023 19:23:09 +0200
Subject: [PATCH] org-columns: add feat to move row up/down

---
 lisp/org-colview.el              | 22 +++++++++++
 testing/lisp/test-org-colview.el | 66 ++++++++++++++++++++++++++++++++
 2 files changed, 88 insertions(+)

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 92a3b473d..0971d5eef 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -209,6 +209,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)
@@ -1003,6 +1005,26 @@ details."
     (org-columns-move-right)
     (backward-char 1)))
 
+(defun org-columns--move-row (&optional up)
+    "Move table row. Calls `org-move-subtree-down' or `org-move-subtree-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 table row (subtree) down."
+  (interactive)
+  (org-columns--move-row))
+
+(defun org-columns-move-row-up ()
+  "Move table row (subtree) 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 9daec18e2..fd02f054c 100644
--- a/testing/lisp/test-org-colview.el
+++ b/testing/lisp/test-org-colview.el
@@ -1010,6 +1010,72 @@
 	    (list (get-char-property 1 'org-columns-value-modified)
 		  (get-char-property 2 'org-columns-value-modified))))))
 
+;; Each column is an overlay on top of a character.  So there has
+;; to be at least as many characters available on the line as
+;; columns to display.
+;; 'org-columns--display-here'
+(ert-deftest test-org-colview/bug-add-whitespace ()
+  "Insert space characters if number of characters on the line
+  is lower then number of columns."
+  :expected-result :failed
+  (should
+   (equal "* H
+** A
+** B
+"
+          (org-test-with-temp-text "* H
+** A
+** B
+"
+            (org-columns)
+            (buffer-substring-no-properties (point-min) (point-max))))))
+
+(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 ()
+  "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-down)
+          (current-column)))))
+
 (ert-deftest test-org-colview/columns-move-left ()
   "Test `org-columns-move-left' specifications."
   ;; Error when trying to move the left-most column.
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-08-20 19:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06 10:11 [RFC] [feat] org-colview/org-columns: 'column view' moving rows up/down Sławomir Grochowski
2023-04-07 11:04 ` Ihor Radchenko
2023-04-08 21:48   ` Sławomir Grochowski
2023-04-09  9:16     ` Ihor Radchenko
2023-04-11  8:49       ` Sławomir Grochowski
2023-04-12  9:09         ` Ihor Radchenko
2023-08-20 10:43           ` Ihor Radchenko
2023-08-20 17:44             ` Sławomir Grochowski
2023-08-20 19:39               ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).