From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id qAcsEB+9G2b0OwEAe85BDQ:P1 (envelope-from ) for ; Sun, 14 Apr 2024 13:25:19 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id qAcsEB+9G2b0OwEAe85BDQ (envelope-from ) for ; Sun, 14 Apr 2024 13:25:19 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rensoliemans.nl header.s=soverin header.b="f3wkaN/u"; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1713093919; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=0Ztiwra7a2O6wGZ21MgMBINQTYYNUC8Q+4XhHzl4xHs=; b=JecT2KsH1qzDKxsQ2/zO1epoNG1t+yE5HPIE25/g5C/uPcwAlVEkjO6Tq8WJwf6ZU9RTmi a1a2ZyrbelXb6il67680etchbYG8DsjRFZrWw909E/50R+1e5OUJ0iGlvYqgKD5MFY5cNu R+olxGm6AHs3PiT9WSLFpcgBQQucPFs0G5jqrZuZ72XmcJ0C2EgmzsH/7m3UOqZCbQQsWY K3gjNzOijjSgPTGSa/KTrojhu8kQX1TH5pWbmvWLq3lq1GTXl3GL4p13asYFWQi4TrWVPD ZTOEdncVlPq6FoZCwqwdBL0GkJWy8Lb2m0l/kUQzJmfEPTB5+JPvkL8auXNKvQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1713093919; a=rsa-sha256; cv=none; b=iYx2j5sqm2xWe90OTPnWbC8BouQyX2Zz8EfyT4yH4/SOI3PRSa8fYQowEBoLTKUM2hL8G9 9hQWaQKbiTT/o+wmxjoY33AZz2tjzpWaVNmy7xCriVaLCG04O8EFpLR0XW1FfgjFzoKCHS 1wEdJUbhUZeoUwFiwXY7r/7LX6Sg15w5tnTlNimHdKivq6j1pFDQMUi3DnO+dt+IkiQU8t UZ6PspHNBqe2B1Ac+zN1QENfsrc1SmikAsJxoAR94HeYWYtDJRT6BXV9tipfDHkFu4n/rW Yxgtm2s2jCGJlYKqXkjT9+mMND4YMoJKSWIEJn4XTY3QJ/4ejtjpcmlfRMMwDg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rensoliemans.nl header.s=soverin header.b="f3wkaN/u"; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=none Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1D2C352241 for ; Sun, 14 Apr 2024 13:25:19 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rvxyp-0006hQ-D9; Sun, 14 Apr 2024 07:25:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rvxym-0006gq-A6 for emacs-orgmode@gnu.org; Sun, 14 Apr 2024 07:25:00 -0400 Received: from outbound.soverin.net ([185.233.34.146]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rvxyi-0006r8-9J for emacs-orgmode@gnu.org; Sun, 14 Apr 2024 07:24:59 -0400 Received: from smtp.soverin.net (c04cst-smtp-sov02.int.sover.in [10.10.4.100]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by outbound.soverin.net (Postfix) with ESMTPS id 4VHSdF6x6hz5G; Sun, 14 Apr 2024 11:24:49 +0000 (UTC) Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4VHSdF41GPzBd; Sun, 14 Apr 2024 11:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=rensoliemans.nl; s=soverin; t=1713093889; bh=bgF6NZD7h9XdZBfmDUbRrLL19/dCJjsVO0sD/R72eAM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=f3wkaN/u/PmXKFC0SxqfXDT85Tv2fWv124x0aeLwAn1uo1nJpmxCTwS6sCZ64gIIp xm0kPNrk9uJBkgEaz1zgWYJNwMwxNxcoyu7oJi7mPbRzBIt8ibBgXZGxOf6OKj5aNr WcvIpMQnfSifW2ynrVYyyohd6bAQYKrH8YpI38ET7TCtBgdX5zx6Wsj/lGUZWERIYk pndrpc92y6l27Iz2sUDZOR6jHHzDjd04rLahntxFs4Dg8/QdJqaEG7Y3pDKmNCK+k4 sYP6Pg3aAydyxNdLTl35lXTZ8Xb9RsyIdgrYnXEx4IASiJzAY3ayCoyXl3s4x1hDvO K3xk/BLo4tLvQ== From: Rens Oliemans To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: [PATCH 1/2] org-capture: Allow entry template to start without heading In-Reply-To: <877chnc0lr.fsf@localhost> References: <87cyrg3qaa.fsf@rensoliemans.nl> <877chnc0lr.fsf@localhost> Date: Sun, 14 Apr 2024 13:24:49 +0200 Message-ID: <87jzl0rxtq.fsf@rensoliemans.nl> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.233.34.146; envelope-from=hallo@rensoliemans.nl; helo=outbound.soverin.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -3.98 X-Spam-Score: -3.98 X-Migadu-Queue-Id: 1D2C352241 X-Migadu-Scanner: mx13.migadu.com X-TUID: yhib1JARQgeR * lisp/org-capture.el (org-capture-place-entry): Prepend heading to template if the template does not yet start with a heading. * testing/lisp/test-org-capture.el (test-org-capture/entry): Add two tests: no error is raised when org-capture is called with a template that does not start with a heading; and org-capture should error with a template with a lower heading after a higher heading. Link: https://list.orgmode.org/877chnc0lr.fsf@localhost/ --- First iteration of these patches, please let me know if anything can be improved, either about the code or patches themselves (I am not used to sending patches via email). lisp/org-capture.el | 1 + testing/lisp/test-org-capture.el | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index da14f45c0..750778f8b 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1198,6 +1198,7 @@ may have been stored before." (exact-position (org-capture-get :exact-position)) (insert-here? (org-capture-get :insert-here)) (level 1)) + (unless (string-match "^*" template) (setq template (concat "* " template))) (org-capture-verify-tree template) (when exact-position (goto-char exact-position)) (cond diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el index 0ed44c6af..9ab078193 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -244,6 +244,23 @@ :immediate-finish t)))) (org-capture nil "t") (buffer-string)))) + ;; Do not raise an error on templates that do not start with a heading. + (should + (org-test-with-temp-text-in-file "" + (let* ((file (buffer-file-name)) + (org-capture-templates + `(("t" "Test" entry (file ,file) "Foo" + :immediate-finish t)))) + (org-capture nil "t")))) + ;; Raise an error on templates with a lower level heading after a + ;; higher level one. + (should-error + (org-test-with-temp-text-in-file "" + (let* ((file (buffer-file-name)) + (org-capture-templates + `(("t" "Test" entry (file ,file) "** X\n* Y" + :immediate-finish t)))) + (org-capture nil "t")))) ;; With a 0 prefix argument, ignore surrounding lists. (should (equal "Foo\n* X\nBar\n" -- 2.44.0