From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gustavo Barros Subject: Bug: canceled capture operation results in demoted following heading when template ends with newline [9.2.4 (9.2.4-11-g1c3eae-elpaplus @ /home/gustavo/.emacs.d/elpa/org-plus-contrib-20190722/)] Date: Sun, 28 Jul 2019 16:34:07 -0300 Message-ID: <87sgqqq7gw.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:44678) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hrovu-00052m-75 for emacs-orgmode@gnu.org; Sun, 28 Jul 2019 15:34:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hrovs-00013Y-Rs for emacs-orgmode@gnu.org; Sun, 28 Jul 2019 15:34:14 -0400 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:44449) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hrovs-00013U-LJ for emacs-orgmode@gnu.org; Sun, 28 Jul 2019 15:34:12 -0400 Received: by mail-qt1-x82d.google.com with SMTP id 44so26584849qtg.11 for ; Sun, 28 Jul 2019 12:34:12 -0700 (PDT) Received: from gusbrs-laptop (ip-68-2-52-196.nyc.us.northamericancoax.com. [196.52.2.68]) by smtp.gmail.com with ESMTPSA id q2sm25072956qkc.118.2019.07.28.12.34.09 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 28 Jul 2019 12:34:10 -0700 (PDT) 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: emacs-orgmode@gnu.org Hi all, When the capture template ends with a newline character and the capture=20 process is canceled, the following heading gets demoted. And it=20 shouldn=E2=80=99t. Consider the following scenario. We have an agenda file with the=20 following content: #+name: ~/org/agenda.org #+begin_src org ,* Capture ,* Following heading #+end_src We start ~emacs -Q~, and do some basic setup: #+begin_src emacs-lisp (package-initialize) (global-set-key (kbd "C-c c") 'org-capture) (setq org-agenda-files '("~/org/agenda.org")) (setq org-refile-targets '((org-agenda-files :maxlevel . 2))) (setq org-capture-templates '(("t" "TODO entry" entry (file+headline "~/org/agenda.org" "Capture") "* TODO %?\n"))) #+end_src Now we start capture with "C-c c t" and cancel it with "C-c=20 k". Examination of "agenda.org" will show: #+name: ~/org/agenda.org #+begin_src org ,* Capture ,** Following heading #+end_src Both the line between them is gone, and "* Following heading" got=20 demoted, which is particularly unfortunate. I=E2=80=99m not sure that I found a general rule in this respect. I had me= t=20 this effect before in my workflow and vaguely associated it with a=20 trailing "\n". Investigating it further, I could find a recipe to=20 reproduce the effect, as shown, but I don=E2=80=99t really know how general= it=20 is. This effect does not occur if "\n" is removed from the template, and I=20 don=E2=80=99t know if its inclusion is to be considered bad practice,=20 particularly as the capture templates already have a structure to handle=20 empty lines. But, if my memory does not betray me in this respect, one=20 will find plenty of those laying around in folks configs. Best regards, Gustavo Barros. Emacs : GNU Emacs 26.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version=20 3.22.30) of 2019-04-19 Package: Org mode version 9.2.4 (9.2.4-11-g1c3eae-elpaplus @=20 /home/gustavo/.emacs.d/elpa/org-plus-contrib-20190722/) current state: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (setq org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode-configure-edit-buffer) org-metadown-hook '(org-babel-pop-to-session-maybe) org-clock-out-hook '(org-clock-remove-empty-clock-drawer) org-refile-targets '((org-agenda-files :maxlevel . 2)) org-agenda-files '("~/org/agenda.org") org-mode-hook '(#[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-show-all append=20 local] 5] #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook=20 org-babel-show-result-all append local] 5] org-babel-result-hide-spec org-babel-hide-all-hashes org-eldoc-load) org-archive-hook '(org-attach-archive-delete-maybe) org-confirm-elisp-link-function 'yes-or-no-p org-agenda-before-write-hook '(org-agenda-add-entry-text) org-metaup-hook '(org-babel-load-in-session-maybe) org-bibtex-headline-format-function #[257 "\300\236A\207" [:title] 3=20 "\n\n(fn ENTRY)"] org-babel-pre-tangle-hook '(save-buffer) org-tab-first-hook '(org-babel-hide-result-toggle-maybe org-babel-header-arg-expand) org-src-lang-modes '(("arduino" . arduino) ("redis" . redis) ("php"=20 . php) ("C" . c) ("C++" . c++) ("asymptote" . asy) ("bash" . sh) ("beamer" . latex) ("calc"=20 . fundamental) ("cpp" . c++) ("ditaa" . artist) ("dot"=20 . fundamental) ("elisp" . emacs-lisp) ("ocaml" . tuareg) ("screen" . shell-script) ("shell" . sh) ("sqlite" . sql)) org-occur-hook '(org-first-headline-recenter) org-cycle-hook '(org-cycle-hide-archived-subtrees=20 org-cycle-show-empty-lines org-optimize-window-after-visibility-change) org-speed-command-hook '(org-speed-command-activate org-babel-speed-command-activate) org-confirm-shell-link-function 'yes-or-no-p org-link-parameters '(("id" :follow org-id-open) ("eww" :follow eww :store org-eww-store-link) ("rmail" :follow org-rmail-open :store org-rmail-store-link) ("mhe" :follow org-mhe-open :store=20 org-mhe-store-link) ("irc" :follow org-irc-visit :store=20 org-irc-store-link :export org-irc-export) ("info" :follow org-info-open :export=20 org-info-export :store org-info-store-link) ("gnus" :follow org-gnus-open :store org-gnus-store-link) ("docview" :follow org-docview-open :export org-docview-export :store=20 org-docview-store-link) ("bibtex" :follow org-bibtex-open :store org-bibtex-store-link) ("bbdb" :follow org-bbdb-open :export=20 org-bbdb-export :complete org-bbdb-complete-link :store org-bbdb-store-link) ("w3m" :store org-w3m-store-link) ("file+sys") ("file+emacs") ("elfeed" :follow elfeed-link-open :store elfeed-link-store-link) ("doi" :follow org--open-doi-link) ("elisp" :follow org--open-elisp-link) ("file" :complete org-file-complete-link) ("ftp" :follow (lambda (path) (browse-url (concat "ftp:"=20 path)))) ("help" :follow org--open-help-link) ("http" :follow (lambda (path) (browse-url (concat "http:"=20 path)))) ("https" :follow (lambda (path) (browse-url (concat "https:"=20 path)))) ("mailto" :follow (lambda (path) (browse-url (concat "mailto:"=20 path)))) ("news" :follow (lambda (path) (browse-url (concat "news:"=20 path)))) ("shell" :follow org--open-shell-link)) org-capture-templates '(("t" "TODO entry" entry (file+headline "~/org/agenda.org" "Capture") "* TODO %?\n") ) )