Re: [O] Adding single cell movement to org-table
Hello, Chris Kauffman writes: > Attached are the updated patches for single cell movement in org > tables. Thank you! I squashed the various patches, fixed the docstrings and refactored a bit some functions. I also renamed `org-table-move-single-cell-*' into `org-table-move-cell-*', which is shorter and, IMO, not ambiguous. I pushed it in "next" branch, which will be merged with master once Org 9.2 is out. BTW, what is current status wrt FSF papers now? Regards, -- Nicolas Goaziou0x80A93738
Re: [O] Adding single cell movement to org-table
All- Attached are the updated patches for single cell movement in org tables. Notes: - Implemented all of Nicolas Goaziou's suggestions on this with some caveats described below - Part of the logic of the code requires boundary checking. I used the (org-table-analyze) to set variables org-table-current-ncol and org-table-dlines which are the limits of the table. This eliminated an internal helper function in the original version. - I made several of the functions internal with the naming convention `org-table--name' as per Nicolas' suggestion - Checks for in-table and table alignment are in the top-level functions `org-table-move-single-cell-up' etc.; I kept alignment in as otherwise the table looks awful as cells move around - Modified org.el to bind these to Shift-up and the like as per Carsten's suggestion - Tests defined in testing/lisp/org-test-table.el and I've done a fair amount of interactive testing to ensure the behavior looks correct. - Not sure if the patches will work exactly correctly due to the large gap in time between my initial work and completion; let me know if things don't look correct. - Attempted to get close to a correctly formatted commit messages but do make any necessary formatting changes for compliance. Cheers, Chris Kauffman On Fri, May 4, 2018 at 7:18 PM, stardiviner wrote: > That's really great. Thanks. > > -- > [ stardiviner ] don't need to convince with trends. >Blog: https://secure-web.cisco.com/1hJRqsuxlpwmP971H8dAeGulRNSKNY > 87qhElIE0kGFNVU8wi5u2jTzEhayLSBa8GhYPZPyxSM3aWcEqi0yTtMPyedB > ey2od2ROikNbAYTnTptEFLNGp6HovNx1ukbSykVmN4jthKPhqhL- > zPqBtiblX6c8EibrNqBfI2YR_DfuTSNew8YeBmyRu0Mr_ > et5PfrTaMoyrIurSC1ogXRXRMh8ds6CXnNjU7bhWZeOcjRQfyLbssZQ- > zuRp5pSm2JMyC0h7QmqikJC6pNGBrSYPaxd37aLkMNyqhF6LyEpq2LrpWkms4s56sq9R4_ > MUrvT16dpqMPPcp1pfA1DAaPt0DBOlZIDWuieyVZSmscuGyWN6hhiYyTc0EY-_ > iwmxe0UCfRK4t0adbHcAj0cYCdGjgliGOk9jHInQTGngBOSNT_htY/https% > 3A%2F%2Fstardiviner.github.io%2F >IRC(freenode): stardiviner >GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 > > > From 6f50526fa642ea74716dd4668e2b36b0ff9c6134 Mon Sep 17 00:00:00 2001 From: Chris Kauffman Date: Sun, 23 Jul 2017 00:13:11 -0400 Subject: [PATCH 1/8] 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 @@ -1436,6 +1436,77 @@ non-nil, the one above is used." (t (setq min mean) (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
Re: [O] Adding single cell movement to org-table
That's really great. Thanks. -- [ stardiviner ] don't need to convince with trends. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
Re: [O] Adding single cell movement to org-table
>>> "Chris" == Chris Kauffman writes: > I was the original person who was working on code for single cell movement > but got distracted by a move to the midwest, job change, and marriage. I > will attempt to complete the code in the next month to submit a patch. All very good reasons, especially the last one! All the best to both of you. smime.p7s Description: S/MIME cryptographic signature
Re: [O] Adding single cell movement to org-table
I was the original person who was working on code for single cell movement but got distracted by a move to the midwest, job change, and marriage. I will attempt to complete the code in the next month to submit a patch. Chris Kauffman On Fri, May 4, 2018 at 7:29 AM, stardiviner wrote: > Hi, dear Nicolas. Is this patch merged or not? > I "git log --grep 'cell'", have not found this commit. > Does this patch move single cell or move single row/column? > Currently, Org-mode built-in movement support for row and column only. > > -- > [ stardiviner ] don't need to convince with trends. >Blog: https://secure-web.cisco.com/1sdj- > xZLR6NqcfmWcqPL8xws9NwGLGIqxtf3bLvpn-RTcdJC0NapZkgAE_S_L7_ > 7FQ8W1k3rTbTZzLaYAAiRF8n8fIQJT5s0Sr-4G3n3a-hyOiksPjPSA_1BnaCm- > Fg7Amnwx2bB5F9wCuHrxtDhxEHh6RXVg03NeXnLzw_YjFaS8w5gvnhWqSIy9hZvn6aOWvlkP > Dy1hes_WNng6C3Qxy6ihxmpaPnSxvogd_rE1Ze31NZLD9Sv78ivAZwFmVIo7XHM > oqs7veAKqUQC34vVSTuuFOHTYwq6owLfaqIjwmM0PfF0pwhisMsEg9TUH_q11NPRKZmq_ > QDFgqNXgPAjptiFrPBU1l9t4IUw_Bv9YCoAoqT7ZLERUfLPj_ > 9osdz3g18A6DgpJuCUNJBlInzsqGSP5zv6-v7yXKRFHr61Q24_z0nNUeUzMneqeCHpRL13- > i7admqXNqD-HAlBD1WxP1g/https%3A%2F%2Fstardiviner.github.io%2F >IRC(freenode): stardiviner >GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 > > >
Re: [O] Adding single cell movement to org-table
Hi, dear Nicolas. Is this patch merged or not? I "git log --grep 'cell'", have not found this commit. Does this patch move single cell or move single row/column? Currently, Org-mode built-in movement support for row and column only. -- [ stardiviner ] don't need to convince with trends. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
Re: [O] Adding single cell movement to org-table
Hello, Chris Kauffman writes: > 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.). Thank you! Some comments follow. > ;;;###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) I don't think this function is necessary. There is already a similar mechanism with `org-table-current-ncol' and `org-table-current-dlines'. Besides, you only need to check if point is within the table, which is trivial: (skip-chars-backward " \t") (or (bolp) (looking-at-p "[ \t]*$")) for the row, `org-table-goto-line' returns nil if there is no such line. > +;;;###autoload > +(defun org-table-swap-cells (row1 col1 row2 col2) > + "Swap two cells indicated by the coordinates provided" Final dot missing. ROW1 COL1 ROW2 COL2 should be explained. > + (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))) This function can be made internal: no need to autoload it, and rename it as `org-table--swap-cells'. Besides, it shouldn't call `org-table-align', which is out of its scope. > +;;;###autoload > +(defun org-table-move-single-cell (direction) > + "Move the current cell in a cardinal direction according to the First line should be a sentence on its own. DIRECTION should be more explicit in the docstring. > +parameter symbol: 'up 'down 'left 'right. Swaps contents of `up', `down', `left' or `right'. Also, mind the two spaces after a full stop. > +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 This should be an internal function: `org-table--move-single-cell', and not autoloaded. As an internal function, there is no need to check for `org-at-table-p'. It's the responsibility of the callers to do so. Also, `org-table-check-inside-data-field' is more appropriate here. > +;;;###autoload > +(defun org-table-move-single-cell-up () > + "Move a single cell up in a table; swap with anything in target cell" Missing final full stop. > + (interactive) > + (org-table-move-single-cell 'up)) Per above, I suggest adding (org-table-check-inside-data-field) after the (interactive). The same goes for the other functions. Could you send an updated patch? Regards, -- Nicolas Goaziou0x80A93738
Re: [O] Adding single cell movement to org-table
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 wrote: > Hello, > > Chris Kauffman 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 ass...@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 > From b43054c9892f7e08fa958bcb5d8df978e6392d57 Mon Sep 17 00:00:00 2001 From: Chris Kauffman 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 From 6682b22642c34f61feee27cd44a503dd4c21e9cb Mon Sep 17 00:00:00 2001 From: Chris Kauffman 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 From 6be32b39c590d003be75a33033bb3301a11db483 Mon Sep 17 00:00:00 2001 From: Chris Kauffman 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-t
Re: [O] Adding single cell movement to org-table
Hi Chris, I really like this functionality, thank you! Has there been a discussion about a possible key binding for this feature? Carsten On Thu, Jul 27, 2017 at 10:20 PM, Chris Kauffman wrote: > 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. > > I just mailed ass...@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. > > Cheers, > Chris >
Re: [O] Adding single cell movement to org-table
Hello, Chris Kauffman 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 ass...@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
[O] Adding single cell movement to org-table
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. I just mailed ass...@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. Cheers, Chris