From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kyle Meyer Subject: Re: Cut and paste an entry programmatically Date: Fri, 28 Jun 2019 20:58:00 -0400 Message-ID: <87lfxlky1z.fsf@kyleam.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:38513) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hh1gx-0007kC-6C for emacs-orgmode@gnu.org; Fri, 28 Jun 2019 20:58:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hh1gw-00041E-3A for emacs-orgmode@gnu.org; Fri, 28 Jun 2019 20:58:10 -0400 Received: from pb-smtp20.pobox.com ([173.228.157.52]:62395) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hh1gv-0003yr-PE for emacs-orgmode@gnu.org; Fri, 28 Jun 2019 20:58:10 -0400 In-Reply-To: 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: Michael Brand , Samuel Wales Cc: Org Mode Michael Brand writes: [...] > With your idea I debug printed kill-ring and found that after the > second invocation of org-cut-subtree during ~M-: (temp) RET M-: (temp) > RET~ it consists of only one list element with a string containing > both 1 and 2 instead of one list element with only 1 and another with > only 2. So to me this looks like a bug in org-cut-subtree. Hmm I don't consider that a bug. It's documented behavior for kill commands to append to the last kill when called successively. ,----[ C-h f kill-region RET ] | [...] | Any command that calls this function is a "kill command". | If the previous command was also a kill command, | the text killed this time appends to the text killed last time | to make one entry in the kill ring. | [...] `---- To get a better feel for what's happening, I'd suggest evaluating kill-region with C-u C-M-x and stepping through its execution. In addition to what Samuel posted, another way for a lisp caller to avoid the append behavior if desired is to let-bind this-command so that kill-region's attempt to set it to kill-region doesn't work. Using your example, that'd be #+begin_src emacs-lisp (defun temp () (let (this-command) (org-cut-subtree)) (org-forward-heading-same-level 2) (org-paste-subtree)) #+end_src -- Kyle