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

Hello,

Chris Kauffman <kauffman@cs.gmu.edu> 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 Goaziou                                                0x80A93738

  reply	other threads:[~2017-08-03 10:39 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
2017-08-03 10:37     ` Nicolas Goaziou [this message]
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=874ltplyxt.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=kauffman@cs.gmu.edu \
    --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).