From: Caleb Chase <caleb@chasecaleb.com>
To: emacs-orgmode@gnu.org
Subject: [BUG] org-capture-kill: doesn't remove the right text region
Date: Thu, 14 Jul 2022 16:24:07 -0500 [thread overview]
Message-ID: <CAGyCDkPos+W_MEJffSZga83NsOLZx2XGTYEmSGQuHQvS-sNa8A@mail.gmail.com> (raw)
I discovered a bug with org-capture and org-capture kill when
canceling an item or plain type template on a heading that has only an
empty line for content. Minimal reproduction is as follows:
1. Add the following to =/tmp/capture-bug-init.el=:
#+begin_src emacs-lisp :noeval t
(require 'org)
(setq org-capture-templates
'(("i" "Repro: item type" item (file+headline
"/tmp/test-capture.org" "Foo") nil :unnarrowed t)
("p" "Repro: plain type" plain (file+headline
"/tmp/test-capture.org" "Foo") "Plain capture: %?" :unnarrowed t)))
(with-temp-buffer
;; FIXME BUG: occurs with empty line between headings.
(insert "* Foo\n\n* Bar\n")
;; FIXME WORKING: no empty line between headings.
;; (insert "* Foo\n* Bar\n")
;; FIXME WORKING: existing item between headings.
;; (insert "* Foo\n- Some note\n* Bar\n")
(write-file "/tmp/test-capture.org"))
(find-file "/tmp/test-capture.org")
(org-capture nil "i")
#+end_src
2. Run Emacs: =emacs -Q --load /tmp/capture-bug-init.el=
3. Cancel the capture with =C-c C-k=
4. Bug occurs: the dash is left behind, so the last line is now =-*
Bar= instead of =* Bar=.
You can also reproduce this bug with the plain type template I have
above. Notice the different commented-out variants illustrating when
it behaves properly. This bug occurs when there is a single blank
empty line between the two headings, but does not occur if there is
not empty line or if there is an existing item.
---
*POSSIBLE ROOT CAUSE*
I suspect the =:begin-marker= capture marker is determined incorrectly
for plain and item capture types. I haven't dug into the relevant
functions, =org-capture-place-item= and =org-capture-place-plain-text=
closely enough to know exactly what is going on, but here's a
workaround I came up with. It's obviously not the Right Solution (TM),
but at least it illustrates the problem:
#+begin_src emacs-lisp :noeval t
(defun capture-cancel-bug-fix ()
(let ((begin (org-capture-get :begin-marker 'local)))
(unless (equal (char-before begin) (string-to-char "\n"))
(setq org-capture-current-plist
(plist-put org-capture-current-plist
:begin-marker (1- begin))))))
(add-hook 'org-capture-mode-hook #'capture-cancel-bug-fix)
#+end_src
---
*CONTEXT*
- Emacs version: 28.1
- Org version: 9.5.4. More specifically, tested on current bugfix
branch revision 6dc785288d3514af4071f210dac0a18c14a6c45b and current
main branch revision d9479887226ad79a1a8de739e7be0fc1fffec536.
next reply other threads:[~2022-07-15 3:05 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-14 21:24 Caleb Chase [this message]
2022-07-17 10:00 ` [BUG] org-capture-kill: doesn't remove the right text region Ihor Radchenko
2022-07-24 6:21 ` Ihor Radchenko
2022-07-31 5:06 ` Ihor Radchenko
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=CAGyCDkPos+W_MEJffSZga83NsOLZx2XGTYEmSGQuHQvS-sNa8A@mail.gmail.com \
--to=caleb@chasecaleb.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).