emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Chris Kauffman <kauffman@cs.gmu.edu>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: Uwe Brauer <oub@mat.ucm.es>, emacs-orgmode@gnu.org
Subject: Re: Adding single cell movement to org-table
Date: Fri, 28 Jul 2017 23:00:20 -0400	[thread overview]
Message-ID: <CAKj7sHEAK5oMtKA0VrrbhVxgeuV-5WKcsDiGPV6Z3LBYDkQ6Wg@mail.gmail.com> (raw)
In-Reply-To: <877eytug62.fsf@nicolasgoaziou.fr>


[-- Attachment #1.1: Type: text/plain, Size: 1766 bytes --]

Apologies for the earlier diff-blast: I did not see the advice on the
org-mode contributions page that patches generated via
  git format-patch master
are preferred.  Please find four patches attached which now include
modifications to ORG-NEWS, org.texi, orgguid.texi, and keybindings
suggested by Carsten: S-up, S-down, S-left, S-right in org.el (via
org-shiftup etc.).

Cheers,
Chris


On Fri, Jul 28, 2017 at 4:19 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Chris Kauffman <kauffman@cs.gmu.edu> writes:
>
> > Greetings from a first-time contributor. Another patch contributor, Uwe
> > Brauer, recruited me after finding some code I had written to move single
> > org-table cells up/down/left/right.  I found this feature to be useful in
> > certain kinds of tables so wrote the functions for myself but am told
> that
> > others might benefit from it.
> >
> > I have formalized that code into a git repo with a feature branch on it
> > which may be found here:
> >   https://github.com/kauffman77/org-mode/tree/single-cell-table-move
> >
> > I have included documentation in org-table.el for the new functions and
> > tests for them.  If further work or documentation needs to be done,
> please
> > let me know. I am also not sure if I got the commit messages formatted to
> > the specification mentioned on the contributing page.  I am happy to
> > explain more if needed.
>
> Thank you.
>
> Could you send the patch here? It will ease reviewing it.
>
> It will also require an entry in ORG-NEWS and some documentation in
> org.texi.
>
> > I just mailed assign@gnu.org to get the copyright for the code resolved
> but
> > thought I would put up this branch now so others can have a look.
>
> Great!
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #1.2: Type: text/html, Size: 2606 bytes --]

[-- Attachment #2: 0005-Modified-orgguide.texi-to-include-documentation-of-s.patch --]
[-- Type: text/x-patch, Size: 849 bytes --]

From b43054c9892f7e08fa958bcb5d8df978e6392d57 Mon Sep 17 00:00:00 2001
From: Chris Kauffman <kauffman@ecs.gmu.edu>
Date: Fri, 28 Jul 2017 22:46:12 -0400
Subject: [PATCH 5/5] Modified orgguide.texi to include documentation of single
 cell movement functions.

---
 doc/orgguide.texi | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/doc/orgguide.texi b/doc/orgguide.texi
index 8c91aae3a..fc5c0c22c 100644
--- a/doc/orgguide.texi
+++ b/doc/orgguide.texi
@@ -647,6 +647,12 @@ Re-align, move to previous field.
 @item @key{RET}
 Re-align the table and move down to next row.  Creates a new row if
 necessary.
+@c
+@item S-@key{up}
+@itemx S-@key{down}
+@itemx S-@key{left}
+@itemx S-@key{right}
+Move single cells up, down, left, and right by swapping with adjacent cells.
 
 @tsubheading{Column and row editing}
 @item M-@key{left}
-- 
2.12.2


[-- Attachment #3: 0004-Modified-org.texi-to-include-documentation-of-single.patch --]
[-- Type: text/x-patch, Size: 1125 bytes --]

From 6682b22642c34f61feee27cd44a503dd4c21e9cb Mon Sep 17 00:00:00 2001
From: Chris Kauffman <kauffman@ecs.gmu.edu>
Date: Fri, 28 Jul 2017 22:37:31 -0400
Subject: [PATCH 4/5] Modified org.texi to include documentation of single cell
 movement functions.

---
 doc/org.texi | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/doc/org.texi b/doc/org.texi
index 101d532e3..55c8ebd27 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -2156,6 +2156,12 @@ NEWLINE, so it can be used to split a table.
 Move to beginning of the current table field, or on to the previous field.
 @orgcmd{M-e,org-table-end-of-field}
 Move to end of the current table field, or on to the next field.
+@c
+@orgcmd{S-@key{up},org-table-move-single-cell-up}
+@orgcmd{S-@key{down},org-table-move-single-cell-down}
+@orgcmd{S-@key{left},org-table-move-single-cell-left}
+@orgcmd{S-@key{right},org-table-move-single-cell-right}
+Move single cells up, down, left, and right by swapping with adjacent cells.
 
 @tsubheading{Column and row editing}
 @orgcmdkkcc{M-@key{left},M-@key{right},org-table-move-column-left,org-table-move-column-right}
-- 
2.12.2


[-- Attachment #4: 0003-Updates-to-ORG-NEWS-describing-single-cell-movement-.patch --]
[-- Type: text/x-patch, Size: 1516 bytes --]

From 6be32b39c590d003be75a33033bb3301a11db483 Mon Sep 17 00:00:00 2001
From: Chris Kauffman <kauffman@ecs.gmu.edu>
Date: Fri, 28 Jul 2017 22:18:28 -0400
Subject: [PATCH 3/5] Updates to ORG-NEWS describing single-cell movement
 functions.

---
 etc/ORG-NEWS | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index d7bd3e2ce..05efce4f4 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -291,6 +291,11 @@ This variable allow computed durations in tables to be zero-padded.
 *** New mode switch for table formulas : =U=
 This mode omits seconds in durations.
 
+*** New single table cell movement options : ~org-table-move-single-cell-up~
+Shift-Up, Shift-Down, Shift-Right, and Shift-Left now move single
+table cells in the corresponding directions by swapping with the
+adjacent cell.
+
 ** Removed functions
 
 *** Org Timeline
@@ -368,6 +373,21 @@ It is the reciprocal of ~org-list-to-lisp~, which see.
 
 Call ~org-agenda-set-restriction-lock~ from the agenda.
 
+*** ~org-table-move-single-cell~ and related
+
+Four new user functions to move single table cells in cardinal
+directions.
+
+- ~org-table-move-single-cell-up~
+- ~org-table-move-single-cell-down~
+- ~org-table-move-single-cell-left~
+- ~org-table-move-single-cell-right~
+
+Support functions which are used to facilitate single cell movement.
+- ~org-table-move-single-cell~ 
+- ~org-table-swap-cells~ 
+- ~org-table-max-line-col~
+
 ** Miscellaneous
 
 *** Allow multiple columns view
-- 
2.12.2


[-- Attachment #5: 0002-Added-keybindings-for-org-table-move-single-cell-fun.patch --]
[-- Type: text/x-patch, Size: 4606 bytes --]

From 9c900805937ebc21d468612d1c594381cca53cd2 Mon Sep 17 00:00:00 2001
From: Chris Kauffman <kauffman@ecs.gmu.edu>
Date: Fri, 28 Jul 2017 22:06:05 -0400
Subject: [PATCH 2/5] Added keybindings for org-table-move-single-cell-*
 functions: S-up, S-down, etc. Done via modifications to org-shiftup,
 org-shiftdown, etc.  Dispatching at the end of available contexts between
 behavior for clock table and function hooks.

---
 lisp/org.el | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 44abc0dbe..fc740bdca 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20477,8 +20477,10 @@ commands for more information."
 
 (defun org-shiftup (&optional arg)
   "Increase item in timestamp or increase priority of current headline.
-Calls `org-timestamp-up' or `org-priority-up', or `org-previous-item',
-depending on context.  See the individual commands for more information."
+Calls `org-timestamp-up' or `org-priority-up', or
+`org-previous-item', or `org-table-move-single-cell-up',
+depending on context.  See the individual commands for more
+information."
   (interactive "P")
   (cond
    ((run-hook-with-args-until-success 'org-shiftup-hook))
@@ -20494,6 +20496,7 @@ depending on context.  See the individual commands for more information."
    ((and (not org-support-shift-select) (org-at-item-p))
     (call-interactively 'org-previous-item))
    ((org-clocktable-try-shift 'up arg))
+   ((org-at-table-p) (org-table-move-single-cell-up))
    ((run-hook-with-args-until-success 'org-shiftup-final-hook))
    (org-support-shift-select
     (org-call-for-shift-select 'previous-line))
@@ -20501,8 +20504,9 @@ depending on context.  See the individual commands for more information."
 
 (defun org-shiftdown (&optional arg)
   "Decrease item in timestamp or decrease priority of current headline.
-Calls `org-timestamp-down' or `org-priority-down', or `org-next-item'
-depending on context.  See the individual commands for more information."
+Calls `org-timestamp-down' or `org-priority-down', or
+`org-next-item', or `org-table-move-single-cell-down', depending
+on context.  See the individual commands for more information."
   (interactive "P")
   (cond
    ((run-hook-with-args-until-success 'org-shiftdown-hook))
@@ -20518,6 +20522,7 @@ depending on context.  See the individual commands for more information."
    ((and (not org-support-shift-select) (org-at-item-p))
     (call-interactively 'org-next-item))
    ((org-clocktable-try-shift 'down arg))
+   ((org-at-table-p) (org-table-move-single-cell-down))
    ((run-hook-with-args-until-success 'org-shiftdown-final-hook))
    (org-support-shift-select
     (org-call-for-shift-select 'next-line))
@@ -20531,7 +20536,8 @@ Depending on context, this does one of the following:
 - on a headline, switch to the next TODO keyword.
 - on an item, switch entire list to the next bullet type
 - on a property line, switch to the next allowed value
-- on a clocktable definition line, move time block into the future"
+- on a clocktable definition line, move time block into the future
+- on a normal table, move a single cell right"
   (interactive "P")
   (cond
    ((run-hook-with-args-until-success 'org-shiftright-hook))
@@ -20554,6 +20560,7 @@ Depending on context, this does one of the following:
 	 (org-at-property-p))
     (call-interactively 'org-property-next-allowed-value))
    ((org-clocktable-try-shift 'right arg))
+   ((org-at-table-p) (org-table-move-single-cell-right))
    ((run-hook-with-args-until-success 'org-shiftright-final-hook))
    (org-support-shift-select
     (org-call-for-shift-select 'forward-char))
@@ -20567,7 +20574,8 @@ Depending on context, this does one of the following:
 - on a headline, switch to the previous TODO keyword.
 - on an item, switch entire list to the previous bullet type
 - on a property line, switch to the previous allowed value
-- on a clocktable definition line, move time block into the past"
+- on a clocktable definition line, move time block into the past
+- on a normal table, move a single cell left"
   (interactive "P")
   (cond
    ((run-hook-with-args-until-success 'org-shiftleft-hook))
@@ -20590,6 +20598,7 @@ Depending on context, this does one of the following:
 	 (org-at-property-p))
     (call-interactively 'org-property-previous-allowed-value))
    ((org-clocktable-try-shift 'left arg))
+   ((org-at-table-p) (org-table-move-single-cell-left))
    ((run-hook-with-args-until-success 'org-shiftleft-final-hook))
    (org-support-shift-select
     (org-call-for-shift-select 'backward-char))
-- 
2.12.2


[-- Attachment #6: 0001-org-table-Adding-single-cell-movement-functions-and-.patch --]
[-- Type: text/x-patch, Size: 16529 bytes --]

From 6f50526fa642ea74716dd4668e2b36b0ff9c6134 Mon Sep 17 00:00:00 2001
From: Chris Kauffman <kauffman@ecs.gmu.edu>
Date: Sun, 23 Jul 2017 00:13:11 -0400
Subject: [PATCH 1/5] org-table: Adding single cell movement functions and
 tests.

* org-mode/lisp/org-table.el: New functions for single table cell
  movement such as (org-table-move-single-cell-down)
* testing/lisp/test-org-table.el: Added tests for single table cell
  movement such as (test-org-table/move-single-cell-down)
---
 lisp/org-table.el              |  71 ++++++++
 testing/lisp/test-org-table.el | 385 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 456 insertions(+)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 37e40de1e..2b80bfc3a 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -1437,6 +1437,77 @@ non-nil, the one above is used."
 	       (if above min max))))))
 
 ;;;###autoload
+(defun org-table-max-line-col ()
+  "Return the maximum line and column of the current table as a
+list of two numbers"
+  (when (not (org-at-table-p))
+    (user-error "Not in an org-table"))
+  (let ((table-end (org-table-end)))
+    (save-mark-and-excursion
+     (goto-char table-end)
+     (org-table-previous-field)
+     (list (org-table-current-line) (org-table-current-column)))))
+
+;;;###autoload
+(defun org-table-swap-cells (row1 col1 row2 col2)
+  "Swap two cells indicated by the coordinates provided"
+  (let ((content1 (org-table-get row1 col1))
+	(content2 (org-table-get row2 col2)))
+    (org-table-put row1 col1 content2)
+    (org-table-put row2 col2 content1)
+    (org-table-align)))
+
+;;;###autoload
+(defun org-table-move-single-cell (direction)
+  "Move the current cell in a cardinal direction according to the
+parameter symbol: 'up 'down 'left 'right. Swaps contents of
+adjacent cell with current one."
+  (unless (org-at-table-p)
+    (error "No table at point"))
+  (let ((drow 0) (dcol 0))
+    (cond ((equal direction 'up)    (setq drow -1))
+	  ((equal direction 'down)  (setq drow +1))
+	  ((equal direction 'left)  (setq dcol -1))
+	  ((equal direction 'right) (setq dcol +1))
+	  (t (error "Not a valid direction, must be one of 'up 'down 'left 'right")))
+    (let* ((row1 (org-table-current-line))
+	   (col1 (org-table-current-column))
+	   (row2 (+ row1 drow))
+	   (col2 (+ col1 dcol))
+	   (max-row-col (org-table-max-line-col))
+	   (max-row (car max-row-col))
+	   (max-col (cadr max-row-col)))
+      (when (or (< col1 1) (< col2 1) (> col2 max-col) (< row2 1) (> row2 max-row))
+	(user-error "Cannot move cell further"))
+      (org-table-swap-cells row1 col1 row2 col2)
+      (org-table-goto-line row2)
+      (org-table-goto-column col2))))
+
+;;;###autoload
+(defun org-table-move-single-cell-up ()
+  "Move a single cell up in a table; swap with anything in target cell"
+  (interactive)
+  (org-table-move-single-cell 'up))
+
+;;;###autoload
+(defun org-table-move-single-cell-down ()
+  "Move a single cell down in a table; swap with anything in target cell"
+  (interactive)
+  (org-table-move-single-cell 'down))
+
+;;;###autoload
+(defun org-table-move-single-cell-left ()
+  "Move a single cell left in a table; swap with anything in target cell"
+  (interactive)
+  (org-table-move-single-cell 'left))
+
+;;;###autoload
+(defun org-table-move-single-cell-right ()
+  "Move a single cell right in a table; swap with anything in target cell"
+  (interactive)
+  (org-table-move-single-cell 'right))
+	
+;;;###autoload
 (defun org-table-delete-column ()
   "Delete a column from the table."
   (interactive)
diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el
index 99f593c25..de9a1ad4b 100644
--- a/testing/lisp/test-org-table.el
+++ b/testing/lisp/test-org-table.el
@@ -2102,6 +2102,391 @@ is t, then new columns should be added as needed"
 
 
 \f
+;;; Moving single cells
+(ert-deftest test-org-table/move-single-cell-down ()
+  "Test `org-table-move-single-cell-down' specifications."
+  ;; Error out when cell cannot be moved due to not in table,
+  ;; in the last row of the table, or is on a hline
+  (should-error
+   (org-test-with-temp-text "not in\na table\n"
+     (org-table-move-single-cell-down)))
+  (should-error
+   (org-test-with-temp-text "| a |"
+     (org-table-move-single-cell-down)))
+  (should-error
+   (org-test-with-temp-text "| a |\n"
+     (org-table-move-single-cell-down)))
+  (should-error
+   (org-test-with-temp-text "| a | <point>b |\n"
+     (org-table-move-single-cell-down)))
+  (should-error
+   (org-test-with-temp-text "| a | b |\n| <point>c | d |\n"
+     (org-table-move-single-cell-down)))
+  (should-error
+   (org-test-with-temp-text "| a | b |\n| c | <point>d |\n"
+     (org-table-move-single-cell-down)))
+  (should-error
+   (org-test-with-temp-text "| <point>a |\n|---|\n"
+     (org-table-move-single-cell-down)))
+  (should-error
+   (org-test-with-temp-text "|<point>---|\n| a |\n"
+     (org-table-move-single-cell-down)))
+  ;; Check for correct cell movement
+  (should (equal (concat "| c | b |\n"
+			 "| a | d |\n"
+			 "| e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| <point>a | b |\n"
+			     "| c | d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-down)
+		   (buffer-string))))
+  (should (equal (concat "| a | d |\n"
+			 "| c | b |\n"
+			 "| e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | <point>b |\n"
+			     "| c | d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-down)
+		   (buffer-string))))
+  (should (equal (concat "| a | b |\n"
+			 "| e | d |\n"
+			 "| c | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "| <point>c | d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-down)
+		   (buffer-string))))
+  (should (equal (concat "| a | d |\n"
+			 "| c | f |\n"
+			 "| e | b |\n")
+		 (org-test-with-temp-text
+		     (concat "| a |<point> b |\n"
+			     "| c | d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-down)
+		   (org-table-move-single-cell-down)
+		   (buffer-string))))
+  ;; Check for correct handling of hlines which should not change
+  ;; position on single cell moves
+  (should (equal (concat "| c | b |\n"
+			 "|---+---|\n"
+			 "| a | d |\n"
+			 "| e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| <point>a | b |\n"
+			     "|---+---|\n"
+			     "| c | d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-down)
+		   (buffer-string))))
+  (should (equal (concat "| a | d |\n"
+			 "|---+---|\n"
+			 "| c | f |\n"
+			 "| e | b |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | <point>b |\n"
+			     "|---+---|\n"
+			     "| c | d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-down)
+		   (org-table-move-single-cell-down)
+		   (buffer-string))))
+  (should (equal (concat "| a | b |\n"
+			 "|---+---|\n"
+			 "| c | f |\n"
+			 "| e | d |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "|---+---|\n"
+			     "| c | <point>d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-down)
+		   (buffer-string))))
+
+  ;; Move single cell even without a final newline. Seems that some
+  (should (equal (concat "| a | d |\n"
+			 "|---+---|\n"
+			 "| c | f |\n"
+			 "| e | b |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | <point>b |\n"
+			     "|---+---|\n"
+			     "| c | d |\n"
+			     "| e | f |")
+		   (org-table-move-single-cell-down)
+		   (org-table-move-single-cell-down)
+		   (buffer-string)))))
+(ert-deftest test-org-table/move-single-cell-up ()
+  "Test `org-table-move-single-cell-up' specifications."
+  ;; Error out when cell cannot be moved due to not in table,
+  ;; in the last row of the table, or is on a hline
+  (should-error
+   (org-test-with-temp-text "not in\na table\n"
+     (org-table-move-single-cell-up)))
+  (should-error
+   (org-test-with-temp-text "| a |"
+     (org-table-move-single-cell-up)))
+  (should-error
+   (org-test-with-temp-text "| a |\n"
+     (org-table-move-single-cell-up)))
+  (should-error
+   (org-test-with-temp-text "| <point>a | b |\n"
+     (org-table-move-single-cell-up)))
+  (should-error
+   (org-test-with-temp-text "| a | <point>b |\n| c | d |\n"
+     (org-table-move-single-cell-up)))
+  (should-error
+   (org-test-with-temp-text "| <point>a |\n|---|\n"
+     (org-table-move-single-cell-up)))
+  (should-error
+   (org-test-with-temp-text "|<point>---|\n| a |\n"
+     (org-table-move-single-cell-up)))
+  ;; Check for correct cell movement
+  (should (equal (concat "| c | b |\n"
+			 "| a | d |\n"
+			 "| e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "| <point>c | d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-up)
+		   (buffer-string))))
+  (should (equal (concat "| a | d |\n"
+			 "| c | b |\n"
+			 "| e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "| c | <point>d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-up)
+		   (buffer-string))))
+  (should (equal (concat "| a | b |\n"
+			 "| e | d |\n"
+			 "| c | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "| c | d |\n"
+			     "| <point>e | f |\n")
+		   (org-table-move-single-cell-up)
+		   (buffer-string))))
+  (should (equal (concat "| a | f |\n"
+			 "| c | b |\n"
+			 "| e | d |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "| c | d |\n"
+			     "| e |<point> f |\n")
+		   (org-table-move-single-cell-up)
+		   (org-table-move-single-cell-up)
+		   (buffer-string))))
+  ;; Check for correct handling of hlines which should not change
+  ;; position on single cell moves
+  (should (equal (concat "| c | b |\n"
+			 "|---+---|\n"
+			 "| a | d |\n"
+			 "| e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "|---+---|\n"
+			     "| <point>c | d |\n"
+			     "| e | f |\n")
+		   (org-table-move-single-cell-up)
+		   (buffer-string))))
+  (should (equal (concat "| a | f |\n"
+			 "|---+---|\n"
+			 "| c | b |\n"
+			 "| e | d |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "|---+---|\n"
+			     "| c | d |\n"
+			     "| e | <point>f |\n")
+		   (org-table-move-single-cell-up)
+		   (org-table-move-single-cell-up)
+		   (buffer-string))))
+  (should (equal (concat "| a | b |\n"
+			 "|---+---|\n"
+			 "| c | f |\n"
+			 "| e | d |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "|---+---|\n"
+			     "| c | d |\n"
+			     "| e | <point>f |\n")
+		   (org-table-move-single-cell-up)
+		   (buffer-string))))
+
+  ;; Move single cell even without a final newline. Seems that some
+  (should (equal (concat "| a | f |\n"
+			 "|---+---|\n"
+			 "| c | b |\n"
+			 "| e | d |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b |\n"
+			     "|---+---|\n"
+			     "| c | d |\n"
+			     "| e | <point>f |")
+		   (org-table-move-single-cell-up)
+		   (org-table-move-single-cell-up)
+		   (buffer-string)))))
+(ert-deftest test-org-table/move-single-cell-right ()
+  "Test `org-table-move-single-cell-right' specifications."
+  ;; Error out when cell cannot be moved due to not in table,
+  ;; in the last col of the table, or is on a hline
+  (should-error
+   (org-test-with-temp-text "not in\na table\n"
+     (org-table-move-single-cell-right)))
+  (should-error
+   (org-test-with-temp-text "| a |"
+     (org-table-move-single-cell-right)))
+  (should-error
+   (org-test-with-temp-text "| a |\n"
+     (org-table-move-single-cell-right)))
+  (should-error
+   (org-test-with-temp-text "| <point>a |\n| b |\n"
+     (org-table-move-single-cell-right)))
+  (should-error
+   (org-test-with-temp-text "| a | <point>b |\n| c | d |\n"
+     (org-table-move-single-cell-right)))
+  (should-error
+   (org-test-with-temp-text "| <point>a |\n|---|\n"
+     (org-table-move-single-cell-right)))
+  (should-error
+   (org-test-with-temp-text "|<point>---|\n| a |\n"
+     (org-table-move-single-cell-right)))
+  ;; Check for correct cell movement
+  (should (equal (concat "| b | a | c |\n"
+			 "| d | e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| <point>a | b | c |\n"
+			     "| d | e | f |\n")
+		   (org-table-move-single-cell-right)
+		   (buffer-string))))
+  (should (equal (concat "| b | c | a |\n"
+			 "| d | e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| <point>a | b | c |\n"
+			     "| d | e | f |\n")
+		   (org-table-move-single-cell-right)
+		   (org-table-move-single-cell-right)
+		   (buffer-string))))
+  (should (equal (concat "| a | b | c |\n"
+			 "| e | f | d |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | c |\n"
+			     "| <point> d | e | f |\n")
+		   (org-table-move-single-cell-right)
+		   (org-table-move-single-cell-right)
+		   (buffer-string))))
+  (should (equal (concat "| a | b | c |\n"
+			 "| d | f | e |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | c |\n"
+			     "| d | <point>e | f |\n")
+		   (org-table-move-single-cell-right)
+		   (buffer-string))))
+  (should (equal (concat "| a | b | c |\n"
+			 "|---+---+---|\n"
+			 "| e | f | d |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | c |\n"
+			     "|---+---+---|\n"
+			     "| <point>d | e | f |\n")
+		   (org-table-move-single-cell-right)
+		   (org-table-move-single-cell-right)
+		   (buffer-string))))
+  ;; Move single cell even without a final newline. Seems that some
+  (should (equal (concat "| a | b | c |\n"
+			 "|---+---+---|\n"
+			 "| e | d | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | c |\n"
+			     "|---+---+---|\n"
+			     "| <point>d | e | f |")
+		   (org-table-move-single-cell-right)
+		   (buffer-string)))))
+(ert-deftest test-org-table/move-single-cell-left ()
+  "Test `org-table-move-single-cell-left' specifications."
+  ;; Error out when cell cannot be moved due to not in table,
+  ;; in the last col of the table, or is on a hline
+  (should-error
+   (org-test-with-temp-text "not in\na table\n"
+     (org-table-move-single-cell-left)))
+  (should-error
+   (org-test-with-temp-text "| a |"
+     (org-table-move-single-cell-left)))
+  (should-error
+   (org-test-with-temp-text "| a |\n"
+     (org-table-move-single-cell-left)))
+  (should-error
+   (org-test-with-temp-text "| <point>a |\n| b |\n"
+     (org-table-move-single-cell-left)))
+  (should-error
+   (org-test-with-temp-text "| <point>a | b |\n| c | d |\n"
+     (org-table-move-single-cell-left)))
+  (should-error
+   (org-test-with-temp-text "| <point>a |\n|---|\n"
+     (org-table-move-single-cell-left)))
+  (should-error
+   (org-test-with-temp-text "|<point>---|\n| a |\n"
+     (org-table-move-single-cell-left)))
+  ;; Check for correct cell movement
+  (should (equal (concat "| b | a | c |\n"
+			 "| d | e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | <point>b | c |\n"
+			     "| d | e | f |\n")
+		   (org-table-move-single-cell-left)
+		   (buffer-string))))
+  (should (equal (concat "| c | a | b |\n"
+			 "| d | e | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | <point>c |\n"
+			     "| d | e | f |\n")
+		   (org-table-move-single-cell-left)
+		   (org-table-move-single-cell-left)
+		   (buffer-string))))
+  (should (equal (concat "| a | b | c |\n"
+			 "| f | d | e |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | c |\n"
+			     "| d | e | <point>f |\n")
+		   (org-table-move-single-cell-left)
+		   (org-table-move-single-cell-left)
+		   (buffer-string))))
+  (should (equal (concat "| a | b | c |\n"
+			 "| d | f | e |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | c |\n"
+			     "| d | e | <point>f |\n")
+		   (org-table-move-single-cell-left)
+		   (buffer-string))))
+  (should (equal (concat "| a | b | c |\n"
+			 "|---+---+---|\n"
+			 "| f | d | e |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | c |\n"
+			     "|---+---+---|\n"
+			     "| d | e | <point>f |\n")
+		   (org-table-move-single-cell-left)
+		   (org-table-move-single-cell-left)
+		   (buffer-string))))
+  ;; Move single cell even without a final newline. Seems that some
+  (should (equal (concat "| a | b | c |\n"
+			 "|---+---+---|\n"
+			 "| e | d | f |\n")
+		 (org-test-with-temp-text
+		     (concat "| a | b | c |\n"
+			     "|---+---+---|\n"
+			     "| d | <point>e | f |")
+		   (org-table-move-single-cell-left)
+		   (buffer-string))))
+  )
+
+\f
 ;;; Moving rows, moving columns
 
 (ert-deftest test-org-table/move-row-down ()
-- 
2.12.2


  reply	other threads:[~2017-07-29  3:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27 20:20 Adding single cell movement to org-table Chris Kauffman
2017-07-28  8:19 ` Nicolas Goaziou
2017-07-29  3:00   ` Chris Kauffman [this message]
2017-08-03 10:37     ` Nicolas Goaziou
2018-05-04 12:29       ` stardiviner
2018-05-04 14:04         ` Chris Kauffman
2018-05-04 14:31           ` Uwe Brauer
2018-05-05  0:18           ` stardiviner
2018-05-29 20:29             ` Chris Kauffman
2018-06-13 13:35               ` Nicolas Goaziou
2017-07-28  8:53 ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKj7sHEAK5oMtKA0VrrbhVxgeuV-5WKcsDiGPV6Z3LBYDkQ6Wg@mail.gmail.com \
    --to=kauffman@cs.gmu.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    --cc=oub@mat.ucm.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).