From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Porter Subject: org-metaup destructive when region active? Date: Thu, 14 Jun 2018 20:57:11 -0500 Message-ID: <87wov0hkw8.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTdzR-0007Eb-7k for emacs-orgmode@gnu.org; Thu, 14 Jun 2018 21:57:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTdzM-0005j4-AP for emacs-orgmode@gnu.org; Thu, 14 Jun 2018 21:57:25 -0400 Received: from [195.159.176.226] (port=56575 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fTdzM-0005i4-1z for emacs-orgmode@gnu.org; Thu, 14 Jun 2018 21:57:20 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fTdxC-0005qu-Lu for emacs-orgmode@gnu.org; Fri, 15 Jun 2018 03:55:06 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org 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.