From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.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 CJB9IRLdG2Y0NwAAqHPOHw:P1 (envelope-from ) for ; Sun, 14 Apr 2024 15:41:38 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id CJB9IRLdG2Y0NwAAqHPOHw (envelope-from ) for ; Sun, 14 Apr 2024 15:41:38 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=KXONLNMj; 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=pass (policy=none) header.from=posteo.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1713102098; 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=e96TeI/6IZwj/K/BfrRpWJXHM/HsQB1RNksRnSIjPvk=; b=pa+lV9YRCvEoxJ3slqe4nlrYhJ3myXjRI3fooaRsazqZlYfLdtl5E0X6LJuQEBFIpJZFbK Y86YHfuoeJwHIX9cX2ji+ZWzdI5nVG0tHgyIGZ2Y970nNxpDz/oUDMuR2p2PsJWvnLEppC KRR0irQl5bGincEuklPVwCvg5QWwlD+7uctGcNkApN5MbMYKDsXUNyljPPmpRrXVm3aymd ZtdRqOJx/KRP/lVTtm682lqAlH4C1SMbEr66kjIf8RjJcOHE8lH0bjRKZYc5a0/UDk2Yul M/sUXTecubvl9f9+HM/0WX5MSHalSdPP21EVh8iDHxUo+wvV8P+EpJlA0VeYhg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1713102098; a=rsa-sha256; cv=none; b=mrNhGKJfRPWPnwt1kNpncw/Ta/AiFUyUUjeN8BDdK09jjr1ahpJ6MvvHPVOGwfe2+1OmBK QL1wL9mKztqflG5ApDLcGK4bsvtGI1LO12F7rBCCeECCGjASvZN1Rab9n5CeYFNZv7+5YT 0rB3hWJ25IdsPgW0vMmL65EY+es+lDsfQtk5r4RxpSAG6R4kBBtfHckkCig9XAx8cSOp/4 dV/gKYg5aj924AjYLo7TBwv2Qo8RT1mLMj0rLPTmmMvCO14mJExsjRSaZl95lLZ9ciociF z8AJMt1zfRQekDbAP+g0hcO9MZezrC0Encoqh3QhnlHnjDNKfxwcYZmcIn9YUQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=KXONLNMj; 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=pass (policy=none) header.from=posteo.net 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 30BFB607A3 for ; Sun, 14 Apr 2024 15:41:38 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rw06D-0002A9-0h; Sun, 14 Apr 2024 09:40:49 -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 1rw06A-00029j-JT for emacs-orgmode@gnu.org; Sun, 14 Apr 2024 09:40:46 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rw067-0004H5-Li for emacs-orgmode@gnu.org; Sun, 14 Apr 2024 09:40:46 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 1A36E240103 for ; Sun, 14 Apr 2024 15:40:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1713102041; bh=YYzMxsYc8kkfwsgFyemol1fQz/Al/O9lnR2Qnj9k15w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type: From; b=KXONLNMjzCy7rP5qHDMdWg1yfSl2Aw3rtccMLZ1DlENh5dLCEo6NGw8Vfd05oMkZS FkX9KAnNdRzZ+PmmsVdUCYrlrC+Xnh2un21zLPUqMD6N2p6xb0dyXuGxv8UiVOkenj wapn7zW8xmMKbHuWsC2Pt45Ov2AoKgRGLM2udoab3/m50X1H74xKl0PZiISoNkCR3+ pAO2X33rykyx5GIUcExCE6MtWuM9sGhFcOOBSn+C2YRVd7c3GCKSZDloKp+WKHyMSr Ke+5Tc34s8TXxiyV3y7+32RMT/rYKwRN/eoh+eb204tlVl5ZSoUqCdJykNnVzJu4yC sQGMhbBow5Gbw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4VHWdz5hYqz6tm4; Sun, 14 Apr 2024 15:40:39 +0200 (CEST) From: Ihor Radchenko To: Rens Oliemans Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH 1/2] org-capture: Allow entry template to start without heading In-Reply-To: <87jzl0rxtq.fsf@rensoliemans.nl> References: <87cyrg3qaa.fsf@rensoliemans.nl> <877chnc0lr.fsf@localhost> <87jzl0rxtq.fsf@rensoliemans.nl> Date: Sun, 14 Apr 2024 13:41:12 +0000 Message-ID: <87y19gqcxz.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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_MED=-2.3, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=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: -9.58 X-Spam-Score: -9.58 X-Migadu-Queue-Id: 30BFB607A3 X-Migadu-Scanner: mx13.migadu.com X-TUID: LFIyTVu+vKvn --=-=-= Content-Type: text/plain Rens Oliemans writes: > * 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). Thanks! I have improved your patches a little, fixing the regular expression used to match headings ("^*" is not accurate, you need org-outline-regexp-bol), and adding another test case. See the attached. Before I install the patches, may I know if you have FSF copyright assignment? See https://orgmode.org/worg/org-contribute.html#copyright --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v2-0001-org-capture-Allow-entry-template-to-start-without.patch >From 36639ac711f099b49900d886ad28d29abc1b29ed Mon Sep 17 00:00:00 2001 Message-ID: <36639ac711f099b49900d886ad28d29abc1b29ed.1713102029.git.yantar92@posteo.net> From: Rens Oliemans Date: Sun, 14 Apr 2024 13:24:49 +0200 Subject: [PATCH v2 1/2] org-capture: Allow entry template to start without heading * 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/ --- lisp/org-capture.el | 2 ++ testing/lisp/test-org-capture.el | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index da14f45c0..a95a38162 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1198,6 +1198,8 @@ (defun org-capture-place-entry () (exact-position (org-capture-get :exact-position)) (insert-here? (org-capture-get :insert-here)) (level 1)) + (unless (string-match org-outline-regexp-bol 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..4e9139c40 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -244,6 +244,30 @@ (ert-deftest test-org-capture/entry () :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")))) + (should + (org-test-with-temp-text-in-file "" + (let* ((file (buffer-file-name)) + (org-capture-templates + `(("t" "Test" entry (file ,file) "*bold*" + :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 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v2-0002-org-capture-Allow-table-line-entry-to-start-witho.patch >From af0b56f3338b8700bd6096e4963c95436b1a14b0 Mon Sep 17 00:00:00 2001 Message-ID: In-Reply-To: <36639ac711f099b49900d886ad28d29abc1b29ed.1713102029.git.yantar92@posteo.net> References: <36639ac711f099b49900d886ad28d29abc1b29ed.1713102029.git.yantar92@posteo.net> From: Rens Oliemans Date: Sun, 14 Apr 2024 13:24:51 +0200 Subject: [PATCH v2 2/2] org-capture: Allow table-line entry to start without | * lisp/org-capture.el (org-capture-place-table-line): Prepend table-line begin ('|') if the template does not start with it. * testing/lisp/test-org-capture.el (test-org-capture/table-line): Verify that a template gets prepended with a '|' if it does not start with it. --- lisp/org-capture.el | 15 ++++++++------- testing/lisp/test-org-capture.el | 10 ++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index a95a38162..205d09da8 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1356,13 +1356,14 @@ (defun org-capture-place-item () (defun org-capture-place-table-line () "Place the template as a table line." (require 'org-table) - (let ((text - (pcase (org-trim (org-capture-get :template)) - ((pred (string-match-p org-table-border-regexp)) - "| %?Bad template |") - (text (concat text "\n")))) - (table-line-pos (org-capture-get :table-line-pos)) - beg end) + (let* ((template (org-trim (org-capture-get :template))) + (text + (pcase template + ((pred (string-match-p org-table-border-regexp)) + (concat "| " template)) + (text (concat text "\n")))) + (table-line-pos (org-capture-get :table-line-pos)) + beg end) (cond ((org-capture-get :exact-position) (org-with-point-at (org-capture-get :exact-position) diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el index 4e9139c40..f97d08bce 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -613,6 +613,16 @@ (ert-deftest test-org-capture/table-line () "| 2 |" :immediate-finish t)))) (org-capture nil "t")) (buffer-string)))) + ;; Prepend | when the template does not start with it + (should + (equal "| 1 |\n| 2 |\n" + (org-test-with-temp-text-in-file "| 1 |\n" + (let* ((file (buffer-file-name)) + (org-capture-templates + `(("t" "Table" table-line (file ,file) + "2 |" :immediate-finish t)))) + (org-capture nil "t") + (buffer-string))))) ;; When `:prepend' is nil, add the row at the end of the table. (should (equal "| a |\n| x |\n" -- 2.44.0 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--