From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id oOsPKIJcnWXBgQEAkFu2QA (envelope-from ) for ; Tue, 09 Jan 2024 15:47:30 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id CDQ5IYJcnWU9XAEA62LTzQ (envelope-from ) for ; Tue, 09 Jan 2024 15:47:30 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=fmrrRs+Z; 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=1704811650; 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=v8e2ymSjFCVj05OgZIVc//t10XUyJihc26BE7WDU1ak=; b=BwpdkmavjZQ1KikzBpv5Tdhe0DgnDy2lxOyFT1wrSkUo06OA824+4b/Ftf0lshntpFVCkD dkBzsu0rP/8nIlxMTAeDy93vV79wmDH+dFYaDE4R7XvHr7htiiBQXP/c4ec0NQC9YLR1EI b6OlIg9JkrDGrBs0I13hjr+JGIW+PY2fV7ZSRv9k5XdfNObvdI+XR27UjOvWGDOrhpryvC qS+5u1CoExibxhFrTyQcAM7HXDIBCW8he37DiXAkqNDeKoHmN9TpVxB/a+C+K10tOn5zAd GwiEO5Q60ycfc3i0yKsWyZ2HzBK8UeMEjLr6tvpT94CQQrQz830QbMsU+T8tBw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1704811650; a=rsa-sha256; cv=none; b=rhy1a90DkX94k/WFoUObi5Z01IBg7bHW99fxSNpdTvC0UQ0tneKqWCodXfdUE46RbA06Rt AA8hTLCIvtUj1Y0iY4F0Rq53XDJDNVAp+uEZfFirVdpyzdKkkmLo0lgdoXKHjPHF5uH25f 46lGYCYfcls2fOYFUqN8JBS7Ax2SuybROIfWbd2KAV7DVuH3g+lo6Xsuf2SrSf+3wztv5H SQSMlZX9wzCc36IZ2NPxnZKMMucnSBBcAtG2DCeUgA62Fak/cEmx4+9ok2tGOqMV2tFeyu V7Bj7Ha2L9u93quOsYzDRVG8Orbrh2LIVJlVjbQY5LeyT/W66xNnFoCZThF7Dg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=fmrrRs+Z; 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 5F9D832DAC for ; Tue, 9 Jan 2024 15:47:30 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNDNM-00041D-50; Tue, 09 Jan 2024 09:46:45 -0500 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 1rNDNK-00040a-7W for emacs-orgmode@gnu.org; Tue, 09 Jan 2024 09:46:42 -0500 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rNDNH-0001VT-My for emacs-orgmode@gnu.org; Tue, 09 Jan 2024 09:46:41 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 4511A240028 for ; Tue, 9 Jan 2024 15:46:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1704811597; bh=QXUKhMgAvw6dLGO5u30HfhSLMYXdSS0Y0ESBe2kWcOw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=fmrrRs+ZfpnuGi9/6fJMmAtuctgobDW3grxBWSYOKXn33tiA1VAP0qivAidURTJpY Brx4U+LW6cjEE03j086d7q0SDP3+1BApweE/iTpWwzgwz1y+DjJVTFjQHGSCEd39ps fwYvlZ+tHeG7f/sHXtGE2o5SUgYzIx6IykwHugdIP5kMP8tDORCeO5f3J/wz+nFumq 7GWj99S+zxIwFMpmJ0z5W1g35ltG3EivWuzBJfrsJSSa3NWHI5RvawTUkPJaocIJnE kGkJWbPbgX9znEQGcLI6woG9/LA+FquHoTv7+UWAYIzrX3lLPxpdzFo7Hf28egBHD0 xsrrTix5Xx4hg== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4T8YfN1Pd2z9rxF; Tue, 9 Jan 2024 15:46:35 +0100 (CET) From: Ihor Radchenko To: gerard.vermeulen@posteo.net Cc: Emacs orgmode , emacs-orgmode-bounces+gerard.vermeulen=posteo.net@gnu.org Subject: Re: [PATCH] org-babel-demarcate-block: split using element API In-Reply-To: <261356c53e857e0bc4b04f884366edfa@posteo.net> References: <7e41f9b6e9026a404e256f33371e974c@posteo.net> <87zfxq78ff.fsf@localhost> <87zfxo3taa.fsf@localhost> <87v88a78qd.fsf@localhost> <7f23ea966f0f0aad3fad29b0b96864f3@posteo.net> <87y1d55fc6.fsf@localhost> <37fdcc4bfcf734c2e5ec439d40b4f7d8@posteo.net> <878r50yqmo.fsf@localhost> <442006329cfba666710c989aece5191a@posteo.net> <261356c53e857e0bc4b04f884366edfa@posteo.net> Date: Tue, 09 Jan 2024 14:49:47 +0000 Message-ID: <87bk9uy31w.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -8.01 X-Spam-Score: -8.01 X-Migadu-Queue-Id: 5F9D832DAC X-Migadu-Scanner: mx12.migadu.com X-TUID: 5QhQg/wALTFq gerard.vermeulen@posteo.net writes: > Attached you'll find a new patch fixing the three wrong lines in the > previous > and now the ERT test checks also for `user-error's. Thanks! >> 2. Your patch does not create space between the src blocks, unlike what >> we have on main. >> I think that you need to (1) create a single blank lines between >> blocks (set :post-blank property to 1); (2) keep the number blank >> lines after the last block the same as in the initial block (copy >> the >> :post-blank property and assign it to the last inserted src block). >> >> For C-u argument, do not do anything special - just keep the >> original >> :post-blank as is. It is the closest to what we have on main. >> > > The previous version of the patch had > + (insert (if arg (concat stars "\n") "")) > and now it has > + (insert (if arg (concat stars "\n") "\n")) > I prefer this over setting the :post-blank property because it is > simpler. Yet, it will lead to large spacing between src blocks in the following scenario: -------------------- #+begin_src emacs-lisp "This is test" "This is test2" "This is test3" #+end_src Paragraph. -------------------- Also, your new version of the patch will completely misbehave because of setting mark. Please, use `region-beginning' and `region-end' instead. Setting and checking mark is not to be done in Elisp - it only make sense when transient-mark-mode is enabled. > * Adding a user option for properties to set to nil in org-element-copy. > > This may be overkill, but something like: > > #+begin_src emacs-lisp :results nil :tangle no > (defcustom org-babel-demarcate-block-delete '(:caption :name) > "List of things to delete from blocks below the upper block when > splitting blocks by demarcation. Possible things are `:caption' to > delete \"#+CAPTION:\" keywords, `:header' to delete \"#+HEADER:\" > keywords, `:name' to delete \"#+NAME:\" keywords, and `switches' > to delete e.g. \"-i +n 10\" from the \"#+BEGIN_SRC\" line." > :group 'org-babel > :package-version '(Org . "9.7") > :type '(set :tag "Things to delete when splitting blocks by > demarcation" > (const :caption) > (const :header) > (const :name) > (const :switches)) > :initialize #'custom-initialize-default > :set (lambda (sym val) > (set-default sym val))) > #+end_src That would make sense. Although, we do not have to limit the possible options to just what you listed. Arbitrary affiliated keywords might also be excluded. For example, #+ATTR_HTML keyword is stored in src block object as :attr_html. > + ;; To simplify the (unless ... (user-error ...)). > + (unless (org-region-active-p) (set-mark (point))) Setting mark causes issue in my above example. > + ;; Test mark to be more specific than "Not at a block". > + (unless (and (>= (point) body-beg) (<= (mark) body-end)) > + (user-error "Select within the source block body to split it")) Here, it is better to use `region-beginning', `point', and `region-end'. `region-beginning', unlike mark and point, is guaranteed to be _before_ `region-end'. Mark may be before point, in contrast. You can write something like (unless (if (org-region-active-p) (<= body-beg (region-beginning) (region-end) body-end) (>= body-beg (point))) (user-error ...)) -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at