emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Michael Brand <michael.ch.brand@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: Fwd: Cut and paste an entry programmatically
Date: Thu, 27 Jun 2019 15:50:35 +0200	[thread overview]
Message-ID: <CALn3zogvOD76bWi+0hqDUJp+dtWXFX8qky0Sj-Lhw07AE41a7A@mail.gmail.com> (raw)
In-Reply-To: <CALn3zojt7gsD_GqUvDz09s136mWXERPEh99aFMBeRAbbqcN-xg@mail.gmail.com>

Hi all

I am still blocked with this issue. It looks like the content that is
pasted with the second invocation of org-paste-subtree is not just the
second org-cut-subtree but the accumulation of the first and the
second org-cut-subtree together. This MCE seems better to me than the
previous one as it does not use save-excursion:

#+begin_src emacs-lisp :results silent
  (defun temp ()
    (goto-char (point-min))
    (org-cut-subtree)
    (forward-line 2)
    (org-paste-subtree))
#+end_src

#+begin_src org
,* 1
,* 2
,* 3
,* 4
#+end_src

~M-: (temp) RET M-: (temp) RET~ results in

#+begin_src org
,* 3
,* 1
,* 1
,* 2
,* 4
#+end_src

with an unexpected reinsertion of "1" when inserting "2" resulting in
a duplicate "1".

Michael



---------- Forwarded message ---------
From: Michael Brand <michael.ch.brand@gmail.com>
Date: Thu, May 16, 2019 at 6:40 PM
Subject: Cut and paste an entry programmatically
To: Org Mode <emacs-orgmode@gnu.org>

Hi all

I would like to ask for some help to understand what am I doing wrong
with this minimal complete example:

#+begin_src org
,* 1
,* 2
,* 3
,* 4
#+end_src

#+begin_src emacs-lisp :results silent
  (defun temp ()
    (org-cut-subtree)
    (org-forward-heading-same-level 2)
    (org-paste-subtree))
#+end_src

When with point on 1 you do

    M-: (progn (save-excursion (temp)) (save-excursion (temp))) RET

the resulting buffer is the expected reordered 3, 1, 2, 4. When you do

    M-: (save-excursion (temp)) RET M-: (save-excursion (temp)) RET

the resulting buffer is 3, 1, 1, 2, 4 which is not what I want (Emacs
26.1 and today's Org mode master). Why is this and how to resolve?

Michael

  parent reply	other threads:[~2019-06-27 13:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16 16:40 Cut and paste an entry programmatically Michael Brand
2019-05-17 10:16 ` Michael Brand
2019-06-27 13:50 ` Michael Brand [this message]
2019-06-27 21:57 ` Samuel Wales
2019-06-28 11:07   ` Michael Brand
2019-06-29  0:58     ` Kyle Meyer
2019-06-29  7:27       ` Michael Brand

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=CALn3zogvOD76bWi+0hqDUJp+dtWXFX8qky0Sj-Lhw07AE41a7A@mail.gmail.com \
    --to=michael.ch.brand@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).