emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-metaup destructive when region active?
@ 2018-06-15  1:57 Adam Porter
  2018-06-15 16:59 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Adam Porter @ 2018-06-15  1:57 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I noticed that using org-metaup when a region is active seems to behave
in an unintuitive and potentially dangerous way.  I would expect that it
would behave similarly to org-refile when a region is active, but it
doesn't.

Looking at the code, I see that it does this:

┌────
│ (let* ((a (min (region-beginning) (region-end)))
│        (b (1- (max (region-beginning) (region-end))))
│        (c (save-excursion (goto-char a)
│                           (move-beginning-of-line 0)))
│        (d (save-excursion (goto-char a)
│                           (move-end-of-line 0) (point))))
│   (transpose-regions a b c d)
│   (goto-char c))
└────

It was difficult for me to understand what that would do, and the
docstring of transpose-regions didn't help.  So I did a small
experiment, defining that code as a command and calling it in this
buffer (where the region is marked with brackets):

┌────
│ abcd
│ [efgh
│ hijk]
│ lmno
└────

The result was this:

┌────
│ efgh
│ hij
│ abcdk
│ lmno
└────

Now for an example with Org headings, before:

┌────
│ * A
│ ** A1
│ ** A2
│ [* B
│ ** B1
│ ** B2]
│ * C
│ ** C1
│ ** C2
└────

After:

┌────
│ * A
│ ** A1
│ * B
│ ** B1
│ ** B
│ ** A22
│ * C
│ ** C1
│ ** C2
└────

As you can see, it's corrupted the outline: Heading B2 is now another B
but on the second level, and heading A2 is now a child of the
first-level B but named A22.  And these examples don't even have entry
text…

Ideally it would act on all headings in the region, but given the
complexity of doing that correctly, would it be a good first step to
simply do nothing when org-metaup is called and a region is active?  It
would at least avoid corrupting data.  I think that's a non-trivial
risk, because when I noticed this behavior, it was in a partially
collapsed outline, and some of the headings in the region (and their
entry content) seemed to vanish altogether; I only recovered them with
undo.

Thanks.

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

* Re: org-metaup destructive when region active?
  2018-06-15  1:57 org-metaup destructive when region active? Adam Porter
@ 2018-06-15 16:59 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2018-06-15 16:59 UTC (permalink / raw)
  To: Adam Porter; +Cc: Bastien Guerry, emacs-orgmode

Hello,

Adam Porter <adam@alphapapa.net> writes:

> I noticed that using org-metaup when a region is active seems to behave
> in an unintuitive and potentially dangerous way.  I would expect that it
> would behave similarly to org-refile when a region is active, but it
> doesn't.
>
> Looking at the code, I see that it does this:
>
> ┌────
> │ (let* ((a (min (region-beginning) (region-end)))
> │        (b (1- (max (region-beginning) (region-end))))
> │        (c (save-excursion (goto-char a)
> │                           (move-beginning-of-line 0)))
> │        (d (save-excursion (goto-char a)
> │                           (move-end-of-line 0) (point))))
> │   (transpose-regions a b c d)
> │   (goto-char c))
> └────
>
> It was difficult for me to understand what that would do, and the
> docstring of transpose-regions didn't help.  So I did a small
> experiment, defining that code as a command and calling it in this
> buffer (where the region is marked with brackets):
>
> ┌────
> │ abcd
> │ [efgh
> │ hijk]
> │ lmno
> └────
>
> The result was this:
>
> ┌────
> │ efgh
> │ hij
> │ abcdk
> │ lmno
> └────

This is now fixed. Thank you.

> Now for an example with Org headings, before:
>
> ┌────
> │ * A
> │ ** A1
> │ ** A2
> │ [* B
> │ ** B1
> │ ** B2]
> │ * C
> │ ** C1
> │ ** C2
> └────
>
> After:
>
> ┌────
> │ * A
> │ ** A1
> │ * B
> │ ** B1
> │ ** B
> │ ** A22
> │ * C
> │ ** C1
> │ ** C2

This is partly fixed, i.e., there is no more "2" left over.

> Ideally it would act on all headings in the region, but given the
> complexity of doing that correctly, would it be a good first step to
> simply do nothing when org-metaup is called and a region is active?  It
> would at least avoid corrupting data.  I think that's a non-trivial
> risk, because when I noticed this behavior, it was in a partially
> collapsed outline, and some of the headings in the region (and their
> entry content) seemed to vanish altogether; I only recovered them with
> undo.

I have no strong opinion on the subject. However, I agree this feature,
i.e., `org-metaup' (or `org-metadown') on a region can be removed
altogether, since this is but a glorified kill'n'yank process.

Nevertheless, I'm Cc'ing Bastien for his opinion, as he introduced the
feature in the first place.

I didn't write tests for the function because its specifications are not
completely defined yet.

Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2018-06-15 16:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-15  1:57 org-metaup destructive when region active? Adam Porter
2018-06-15 16:59 ` Nicolas Goaziou

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).