From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] org-capture: fix capture breaking next headline Date: Wed, 24 Oct 2018 09:35:18 +0200 Message-ID: <87in1ryeyx.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFDhb-0006Ha-Tn for emacs-orgmode@gnu.org; Wed, 24 Oct 2018 03:35:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFDhW-0005L0-4w for emacs-orgmode@gnu.org; Wed, 24 Oct 2018 03:35:37 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:47653) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gFDhR-0005AS-2p for emacs-orgmode@gnu.org; Wed, 24 Oct 2018 03:35:30 -0400 In-Reply-To: ("Martin =?utf-8?B?WXJqw7Zsw6QiJ3M=?= message of "Sun, 21 Oct 2018 16:14:19 +0300") 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: Martin =?utf-8?B?WXJqw7Zsw6Q=?= Cc: Org Mode Hello, Martin Yrj=C3=B6l=C3=A4 writes: > I have noticed my capture workflow breaking org document hierarchies. > Here is an example: > > Start with the org document: > > * A > * B > > An org capture template inserts a headline under A. > > * A > ** [point here] > * B > > When I navigate to the end of the narrowed capture buffer (e.g. > `(end-of-buffer)') and insert text, it will break the B headline like > this: > > * A > ** > inserted text[point here]* B > > I expected the following behavior > > * A > ** inserted text[point here] > * B > [...] > --- > lisp/org-capture.el | 2 +- > testing/lisp/test-org-capture.el | 15 +++++++++++++++ > 2 files changed, 16 insertions(+), 1 deletion(-) > > diff --git a/lisp/org-capture.el b/lisp/org-capture.el > index cbc72d43b..fb445d22b 100644 > --- a/lisp/org-capture.el > +++ b/lisp/org-capture.el > @@ -1139,7 +1139,7 @@ may have been stored before." > (unless (org-at-heading-p) (outline-next-heading)) > (let ((end (point))) > (org-capture-mark-kill-region beg end) > - (org-capture-narrow beg end) > + (org-capture-narrow beg (1- end)) > (when (or (re-search-backward "%\\?" beg t) > (re-search-forward "%\\?" end t)) > (replace-match "")))))) > diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-cap= ture.el > index 31522c1f2..351fe5101 100644 > --- a/testing/lisp/test-org-capture.el > +++ b/testing/lisp/test-org-capture.el > @@ -160,6 +160,21 @@ > (org-capture-kill)) > (buffer-string))))) >=20=20 > +(ert-deftest test-org-capture/insert-at-end-safe () > + "Test that capture does not break next headline." > + (should > + (equal > + "* A\n** H1 Capture text\n* B\n" > + (org-test-with-temp-text-in-file "* A\n* B\n" > + (let* ((file (buffer-file-name)) > + (org-capture-templates > + `(("t" "Todo" entry (file+headline ,file "A") "** H1 %?")))) > + (org-capture nil "t") > + (goto-char (point-max)) > + (insert "Capture text") > + (org-capture-finalize)) > + (buffer-string))))) Fixed. I used a slightly different fix, but kept your test. Thank you. Regards, --=20 Nicolas Goaziou