emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: "Martin Yrjölä" <martin.yrjola@gmail.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-capture: fix capture breaking next headline
Date: Wed, 24 Oct 2018 09:35:18 +0200	[thread overview]
Message-ID: <87in1ryeyx.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <CAA5g2yaZqRa5RYM+O00rAPmqX3fodHNxKCPo+gP6wXhWoYgtcg@mail.gmail.com> ("Martin Yrjölä"'s message of "Sun, 21 Oct 2018 16:14:19 +0300")

Hello,

Martin Yrjölä <martin.yrjola@gmail.com> 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-capture.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)))))
>  
> +(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,

-- 
Nicolas Goaziou

      reply	other threads:[~2018-10-24  7:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-21 13:14 [PATCH] org-capture: fix capture breaking next headline Martin Yrjölä
2018-10-24  7:35 ` Nicolas Goaziou [this message]

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=87in1ryeyx.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=martin.yrjola@gmail.com \
    /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).